From: Paulo Alcantara <pc@manguebit.org>
To: Diego Oliva <diego@bynar.io>, Namjae Jeon <linkinjeon@kernel.org>,
linux-cifs@vger.kernel.org
Cc: 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>,
Jeff Layton <jlayton@kernel.org>,
samba-technical@lists.samba.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] smb: client: reject short WRITE responses in the SMB1 write paths
Date: Sun, 13 Sep 2026 16:03:05 -0300 [thread overview]
Message-ID: <1cd47320f94f87c18b12e88256741eb2@manguebit.org> (raw)
In-Reply-To: <20260911145758.3833254-2-diego@bynar.io>
Diego Oliva <diego@bynar.io> writes:
> cifs_writev_callback(), CIFSSMBWrite() and CIFSSMBWrite2() all read
> Count and CountHigh out of the WRITE_RSP returned by the server
> without first checking that a whole WRITE_RSP was actually received.
> The length of the response is available to each of them, in
> mid->response_pdu_len, bytes_returned and rsp_iov.iov_len
> respectively, but none of them constrains it to be at least
> sizeof(WRITE_RSP) before those fields are dereferenced. In the
> asynchronous case cifs_check_receive() has run first, but it only
> verifies the signature and maps the SMB error; it performs no length
> validation.
>
> A malicious or compromised SMB1 server can therefore return a response
> shorter than the WRITE_RSP header and still have it parsed. In
> CIFSSMBWrite() the response buffer is the request buffer, since
> smb_init() hands out a single allocation for both, so the count is
> read back out of the request that was just sent; in the other two the
> reply lives in the demultiplex thread's buffer, so it comes from
> recycled slab memory. Either way the client reports a number of bytes
> written that the server never sent. SMB1 is not negotiated by default;
> reaching this code requires an explicit vers=1.0 mount.
>
> Reject the response unless it is at least sizeof(WRITE_RSP) bytes
> long. This cannot reject a conforming server: WRITE_RSP is documented
> as wct = 6, so the smallest valid reply is
> sizeof(struct smb_hdr) + 2 * 6 + 2, which is sizeof(WRITE_RSP).
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: c28c89fc43e3 ("cifs: add cifs_async_writev")
> Cc: <stable@vger.kernel.org> # 6.19.x
> Assisted-by: Bynario AI
> Signed-off-by: Diego Oliva <diego@bynar.io>
> ---
> fs/smb/client/cifssmb.c | 21 +++++++++++++++++++++
> fs/smb/client/trace.h | 1 +
> 2 files changed, 22 insertions(+)
>
> diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c
> index f9aff0712794..b1525d491ce5 100644
> --- a/fs/smb/client/cifssmb.c
> +++ b/fs/smb/client/cifssmb.c
> @@ -1880,6 +1880,12 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
> cifs_stats_inc(&tcon->stats.cifs_stats.num_writes);
> if (rc) {
> cifs_dbg(FYI, "Send error in write = %d\n", rc);
> + } else if (bytes_returned < (int)sizeof(WRITE_RSP)) {
> + /* check that the received response can hold a whole WRITE_RSP */
Please don't add these useless comments. The bound check, trace and
debug messages are already enough to understand it.
Ditto for the rest of the series.
Also, check sashiko comments [1] and see if any of those make sense to
address.
Thanks.
[1] https://sashiko.dev/#/patchset/20260911145758.3833254-1-diego%40bynar.io
next prev parent reply other threads:[~2026-09-13 19:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 14:57 [PATCH 0/3] smb: client: validate SMB1 write and query response lengths Diego Oliva
2026-09-11 14:57 ` [PATCH 1/3] smb: client: reject short WRITE responses in the SMB1 write paths Diego Oliva
2026-09-13 19:03 ` Paulo Alcantara [this message]
2026-09-11 14:57 ` [PATCH 2/3] smb: client: reject over-long write counts in cifs_writev_callback() Diego Oliva
2026-09-11 14:57 ` [PATCH 3/3] smb: client: reject short responses in SMBQueryInformation() Diego Oliva
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=1cd47320f94f87c18b12e88256741eb2@manguebit.org \
--to=pc@manguebit.org \
--cc=bharathsm@microsoft.com \
--cc=dhowells@redhat.com \
--cc=diego@bynar.io \
--cc=jlayton@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ronniesahlberg@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sprasad@microsoft.com \
--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 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®