mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ksmbd: validate DataOffset in smb2_write_pipe()
@ 2026-01-22  2:10 Kery Qi
  2026-01-22  4:39 ` Namjae Jeon
  0 siblings, 1 reply; 2+ messages in thread
From: Kery Qi @ 2026-01-22  2:10 UTC (permalink / raw)
  To: linkinjeon, smfrench
  Cc: senozhatsky, tom, mmakassikis, linux-cifs, linux-kernel, Kery Qi

The check of DataOffset in smb2_write_pipe() is insufficient. If
DataOffset is 0 or smaller than offsetof(struct smb2_write_req, Buffer),
data_buf will point to the SMB2 header instead of the actual data
buffer, leading to out-of-bounds read.

This is the same issue that was fixed in smb2_write() by commit
ac60778b87e4 ("ksmbd: prevent out of bound read for SMB2_WRITE"),
but the fix was not applied to smb2_write_pipe().

Add a check to ensure DataOffset is at least offsetof(struct
smb2_write_req, Buffer) to prevent this issue.

Fixes: 158a66b245739 ("ksmbd: validate length in smb2_write()")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
 fs/smb/server/smb2pdu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 2fcd0d4d1fb0..1f1086023e74 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -6932,6 +6932,12 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)
 		goto out;
 	}
 
+	if (le16_to_cpu(req->DataOffset) <
+	    offsetof(struct smb2_write_req, Buffer)) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	data_buf = (char *)(((char *)&req->hdr.ProtocolId) +
 			   le16_to_cpu(req->DataOffset));
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ksmbd: validate DataOffset in smb2_write_pipe()
  2026-01-22  2:10 [PATCH] ksmbd: validate DataOffset in smb2_write_pipe() Kery Qi
@ 2026-01-22  4:39 ` Namjae Jeon
  0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-01-22  4:39 UTC (permalink / raw)
  To: Kery Qi; +Cc: smfrench, senozhatsky, tom, mmakassikis, linux-cifs, linux-kernel

On Thu, Jan 22, 2026 at 11:10 AM Kery Qi <qikeyu2017@gmail.com> wrote:
>
> The check of DataOffset in smb2_write_pipe() is insufficient. If
> DataOffset is 0 or smaller than offsetof(struct smb2_write_req, Buffer),
> data_buf will point to the SMB2 header instead of the actual data
> buffer, leading to out-of-bounds read.
How can out-of-bounds occur when the previous checks ensure that the
length does not exceed the request buffer?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-22  4:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-22  2:10 [PATCH] ksmbd: validate DataOffset in smb2_write_pipe() Kery Qi
2026-01-22  4:39 ` Namjae Jeon

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®