From: xuehaolin@uniontech.com
To: aahringo@redhat.com, teigland@redhat.com
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
xuehaolin <xuehaolin@uniontech.com>
Subject: [PATCH v2] dlm: fix out-of-bounds read triggered by short rcom messages
Date: Fri, 4 Dec 2026 10:19:10 +0800 [thread overview]
Message-ID: <20261204021910.706512-1-xuehaolin@uniontech.com> (raw)
In-Reply-To: <20261203070904.510344-1-xuehaolin@uniontech.com>
From: xuehaolin <xuehaolin@uniontech.com>
The dlm_validate_incoming_buffer() in midcomms.c only checks that
received messages are at least sizeof(struct dlm_header) (16 bytes).
It does not verify that rcom messages meet the sizeof(struct dlm_rcom)
(48 bytes) minimum. A malicious cluster member can send a DLM_RCOM_LOOKUP
or DLM_RCOM_NAMES message with h_length set to 16, causing the payload
length calculation in receive_rcom_lookup() / receive_rcom_names():
len = le16_to_cpu(rc_in->rc_header.h_length) - sizeof(struct dlm_rcom);
to produce a negative value (16 - 48 = -32). In the LOOKUP path, the
negative len is passed to dlm_master_lookup() -> _dlm_master_lookup(),
where the signed comparison "len > DLM_RESNAME_MAXLEN" (-32 > 64)
evaluates to false, allowing the negative length to reach
jhash(name, len, 0); promoted to unsigned for jhash it becomes
approximately 4 GB, triggering an out-of-bounds read and kernel
oops/panic (CWE-125, remote DoS). In the NAMES path, the negative
inlen reaches dlm_copy_master_names(), where the signed "inlen > 1"
check misroutes it — a logic bug rather than an out-of-bounds access.
Fix this by restoring the sizeof(struct dlm_rcom) length check in
dlm_midcomms_receive_buffer_3_1() before the message is handed to the
recovery layer: the DLM_MSG case validates its message size, but the
DLM_RCOM case lost this check when the midcomms receive path was
restructured, leaving only a stale "length already checked" comment.
Additionally, guard the entry of dlm_receive_rcom() with the same
check as defense-in-depth covering all rcom entry paths, using a
rejection log that references only the validated header fields, and
harden _dlm_master_lookup() in lock.c by adding a "len < 0" guard to
the existing bounds check, in case other call paths bypass the rcom
dispatch validation.
Found by an internal automated security research pipeline (static
analysis scan with automated triage and audit). The fix was drafted
within the same pipeline and is submitted after review by the human
signer. Reproduction was confirmed on a test VM with a kernel module
demonstrating the out-of-bounds read.
Fixes: 63e711b08160 ("fs: dlm: create midcomms nodes when configure")
Signed-off-by: xuehaolin <xuehaolin@uniontech.com>
---
fs/dlm/lock.c | 2 +-
fs/dlm/midcomms.c | 7 ++++++-
fs/dlm/rcom.c | 6 ++++++
3 files changed, 13 insertions(+), 2 deletions(-)
Changes in v2:
- restore the sizeof(struct dlm_rcom) length check in
dlm_midcomms_receive_buffer_3_1(); the DLM_MSG case kept its check
when the midcomms receive path was restructured, the DLM_RCOM case
lost it, leaving a stale "length already checked" comment
- stop dereferencing rc->rc_type in the short-message rejection path
of dlm_receive_rcom(); the guard now logs the validated h_length
only, since rc_type sits beyond the 16 bytes that
dlm_validate_incoming_buffer() guarantees
- point Fixes at 63e711b08160, the commit that dropped the midcomms
length check, instead of the original DLM import
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index c715e171bab7..56ec68e28f93 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -1270,7 +1270,7 @@ static int _dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *na
int our_nodeid = dlm_our_nodeid();
int dir_nodeid, error;
- if (len > DLM_RESNAME_MAXLEN)
+ if (len < 0 || len > DLM_RESNAME_MAXLEN)
return -EINVAL;
if (from_nodeid == our_nodeid) {
diff --git a/fs/dlm/midcomms.c b/fs/dlm/midcomms.c
index 045431524494..495b2517ef7e 100644
--- a/fs/dlm/midcomms.c
+++ b/fs/dlm/midcomms.c
@@ -815,7 +815,12 @@ static void dlm_midcomms_receive_buffer_3_1(const union dlm_packet *p, int nodei
switch (p->header.h_cmd) {
case DLM_RCOM:
- /* length already checked */
+ if (msglen < sizeof(struct dlm_rcom)) {
+ log_print("rcom msg too small: %u, will skip this message from node %d",
+ msglen, nodeid);
+ return;
+ }
+
break;
case DLM_MSG:
if (msglen < sizeof(struct dlm_message)) {
diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c
index be1a71a6303a..fe23b92a3faf 100644
--- a/fs/dlm/rcom.c
+++ b/fs/dlm/rcom.c
@@ -586,6 +586,12 @@ void dlm_receive_rcom(struct dlm_ls *ls, const struct dlm_rcom *rc, int nodeid)
uint32_t status;
uint64_t seq;
+ if (le16_to_cpu(rc->rc_header.h_length) < sizeof(struct dlm_rcom)) {
+ log_error(ls, "rcom message from %d is too short (%u bytes)",
+ nodeid, le16_to_cpu(rc->rc_header.h_length));
+ return;
+ }
+
switch (rc->rc_type) {
case cpu_to_le32(DLM_RCOM_STATUS_REPLY):
reply = 1;
--
2.43.0
next prev parent reply other threads:[~2026-12-04 2:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 7:09 [PATCH] " xuehaolin
2026-12-04 2:19 ` xuehaolin [this message]
2026-12-04 3:16 ` [PATCH v3] " xuehaolin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204021910.706512-1-xuehaolin@uniontech.com \
--to=xuehaolin@uniontech.com \
--cc=aahringo@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=teigland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®