From: Dudu Lu <phx0fer@gmail.com>
To: linux-cifs@vger.kernel.org
Cc: sfrench@samba.org, Dudu Lu <phx0fer@gmail.com>
Subject: [PATCH] smb: client: Fix integer underflow in receive_encrypted_read()
Date: Mon, 13 Apr 2026 16:59:57 +0800 [thread overview]
Message-ID: <20260413085957.77355-1-phx0fer@gmail.com> (raw)
In receive_encrypted_read(), the length of data to read from the socket
is computed as:
len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
server->vals->read_rsp_size;
OriginalMessageSize comes from the server's transform header and is
untrusted. If a malicious server sends a value smaller than
read_rsp_size (sizeof(struct smb2_read_rsp), ~80 bytes), the unsigned
subtraction wraps to a very large value (~4GB). This value is then
passed to netfs_alloc_folioq_buffer() and cifs_read_iter_from_socket(),
causing either:
- A massive allocation attempt that fails with -ENOMEM (DoS)
- Under extreme memory pressure, potential heap corruption
The existing validation in smb3_receive_transform() only checks
that pdu_length >= orig_len + sizeof(transform_hdr), which does
not prevent orig_len from being smaller than read_rsp_size.
Fix this by adding a check that OriginalMessageSize is at least
read_rsp_size before the subtraction.
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
fs/smb/client/smb2ops.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 509fcea28a42..ca90f96052d4 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -4943,6 +4943,14 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
goto free_dw;
server->total_read += rc;
+ if (le32_to_cpu(tr_hdr->OriginalMessageSize) <
+ server->vals->read_rsp_size) {
+ cifs_server_dbg(VFS, "OriginalMessageSize %u too small for read response (%u)\n",
+ le32_to_cpu(tr_hdr->OriginalMessageSize),
+ server->vals->read_rsp_size);
+ rc = -EINVAL;
+ goto free_dw;
+ }
len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
server->vals->read_rsp_size;
dw->len = len;
--
2.39.3 (Apple Git-145)
reply other threads:[~2026-04-13 9:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260413085957.77355-1-phx0fer@gmail.com \
--to=phx0fer@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=sfrench@samba.org \
/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