Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] smb: client: handle zero DataOffset in CIFSSMBRead()
@ 2026-12-01 20:06 Mark Bundschuh
  2026-12-01 21:08 ` Paulo Alcantara
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Bundschuh @ 2026-12-01 20:06 UTC (permalink / raw)
  To: Paulo Alcantara, Namjae Jeon
  Cc: Steve French, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
	Bharath SM, David Howells, Diego Oliva, linux-cifs,
	samba-technical, linux-kernel, Mark Bundschuh, stable

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


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

end of thread, other threads:[~2026-12-01 21:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 20:06 [PATCH] smb: client: handle zero DataOffset in CIFSSMBRead() Mark Bundschuh
2026-12-01 21:08 ` Paulo Alcantara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox