All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Bundschuh <mkbund@amazon.com>
To: Paulo Alcantara <pc@manguebit.org>, Namjae Jeon <linkinjeon@kernel.org>
Cc: Steve French <smfrench@gmail.com>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	"Tom Talpey" <tom@talpey.com>,
	Bharath SM <bharathsm@microsoft.com>,
	David Howells <dhowells@redhat.com>, Diego Oliva <diego@bynar.io>,
	<linux-cifs@vger.kernel.org>, <samba-technical@lists.samba.org>,
	<linux-kernel@vger.kernel.org>,
	Mark Bundschuh <mkbund@amazon.com>, <stable@vger.kernel.org>
Subject: [PATCH] smb: client: handle zero DataOffset in CIFSSMBRead()
Date: Tue, 1 Dec 2026 20:06:39 +0000	[thread overview]
Message-ID: <20261201200639.339917-1-mkbund@amazon.com> (raw)

commit 5be5bdda5863 ("smb: client: reject out-of-bounds DataOffset in
CIFSSMBRead()") rejects any reply whose DataOffset points inside the
READ_ANDX header, including a DataOffset of 0. Windows sends a DataOffset
of 0 for a read at or beyond EOF, which cifs_readv_receive() and
SMB2_read() both accept by treating the data as starting right after the
header.

Handle it the same way in CIFSSMBRead() rather than rejecting it, and
keep the check that DataOffset + DataLength lies within the received
response.

Fixes: 5be5bdda5863 ("smb: client: reject out-of-bounds DataOffset in CIFSSMBRead()")
Cc: stable@vger.kernel.org # 6.19.x
Signed-off-by: Mark Bundschuh <mkbund@amazon.com>
---
Found while backporting 5be5bdda5863 to older kernels that still read
through CIFSSMBRead() in ->read_folio. Against a Windows Server 2025
SMB1 share, reading a file whose size is a multiple of the page size
then fails with EIO at the read past EOF.

On current kernels the SFU and mfsymlinks parsers are the remaining
callers of CIFSSMBRead(). A READ response with a DataOffset of 0, which
cifs_readv_receive() and SMB2_read() already accept, makes those lookups
fail with EIO instead of being parsed.

 fs/smb/client/cifssmb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c
index 68f05a52605f..5059967b274b 100644
--- a/fs/smb/client/cifssmb.c
+++ b/fs/smb/client/cifssmb.c
@@ -1728,6 +1728,9 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
 		data_length += le16_to_cpu(pSMBr->DataLength);
 		*nbytes = data_length;
 
+		if (data_offset < sizeof(*pSMBr))
+			data_offset = sizeof(*pSMBr);
+
 		/*check that DataLength would not go beyond end of SMB */
 		if ((data_length > CIFSMaxBufSize)
 				|| (data_length > count)) {
@@ -1736,8 +1739,7 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
 			rc = smb_EIO2(smb_eio_trace_read_overlarge,
 				      data_length, count);
 			*nbytes = 0;
-		} else if (data_offset < sizeof(*pSMBr) ||
-			   (size_t)data_offset + data_length > rsp_iov.iov_len) {
+		} else if ((size_t)data_offset + data_length > rsp_iov.iov_len) {
 			/* check that the data lies within the received response */
 			cifs_dbg(FYI, "%s: bad data offset %u length %u for response of %zu\n",
 				 __func__, data_offset, data_length, rsp_iov.iov_len);

base-commit: 7ccb044c27720d48175577080b851f047ddcfd1c
-- 
2.50.1


             reply	other threads:[~2026-12-01 20:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 20:06 Mark Bundschuh [this message]
2026-12-01 21:08 ` [PATCH] smb: client: handle zero DataOffset in CIFSSMBRead() Paulo Alcantara

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=20261201200639.339917-1-mkbund@amazon.com \
    --to=mkbund@amazon.com \
    --cc=bharathsm@microsoft.com \
    --cc=dhowells@redhat.com \
    --cc=diego@bynar.io \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.