Skip to contentSkip to conversation

ocfs2: dlm: validate cancel join message length and fields

PATCH New Jenny Guanni Qu 1 participant 1 message Mar 13 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: dlm: validate cancel join message length and fields

dlm_cancel_join_handler() casts msg->buf to struct dlm_cancel_join and accesses its fields without verifying that the received message length is at least sizeof(struct dlm_cancel_join). A short message from a cluster peer can cause out-of-bounds reads.

Additionally, cancel->name_len is not validated before being passed to __dlm_lookup_domain_full() which uses it as a memcmp length, and cancel->domain is logged with %s which reads until a NUL terminator that may not exist within the received payload.

Add a message length check, validate name_len against O2NM_MAX_NAME_LEN, and use %.*s for bounded logging.

The OOB read pattern was confirmed with KASAN using a test module that accesses fields past a short kmalloc'd buffer matching the handler's cast pattern.

Fixes 6714d8e86bf4 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem")
---
 fs/ocfs2/dlm/dlmdomain.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/ocfs2/dlm/dlmdomain.c +8 -2
index 2018501b2249..43fead9c5e90 100644
@@ -1323,10 +1323,16 @@ static int dlm_cancel_join_handler(struct o2net_msg *msg, u32 len, void *data,
 	struct dlm_cancel_join *cancel;
 	struct dlm_ctxt *dlm = NULL;
 
+	if (len < sizeof(struct dlm_cancel_join))
+		return -EINVAL;
+
 	cancel = (struct dlm_cancel_join *) msg->buf;
 
-	mlog(0, "node %u cancels join on domain %s\n", cancel->node_idx,
-		  cancel->domain);
+	if (cancel->name_len >= O2NM_MAX_NAME_LEN)
+		return -EINVAL;
+
+	mlog(0, "node %u cancels join on domain %.*s\n", cancel->node_idx,
+		  cancel->name_len, cancel->domain);
 
 	spin_lock(&dlm_domain_lock);
 	dlm = __dlm_lookup_domain_full(cancel->domain, cancel->name_len);
Signature · 1 line
2.34.1