* [PATCH v2 0/2] smb: client: don't use SMB2 responses that fail signature verification
@ 2026-11-16 4:06 Suyuan Wang via B4 Relay
2026-11-16 4:06 ` [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature Suyuan Wang via B4 Relay
2026-11-16 4:06 ` [PATCH v2 2/2] smb: client: don't use read data that failed signature verification Suyuan Wang via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-16 4:06 UTC (permalink / raw)
To: linkinjeon, pc
Cc: ematsumiya, sprasad, linux-cifs, bharathsm, ronniesahlberg,
samba-technical, daniel.birtwhistle, linux-kernel, smfrench,
dhowells, tom
v1 made smb2_check_receive() return the error when a response signature
doesn't verify. Sashiko pointed out that this isn't enough:
compound_send_recv() still passes the response buffer to the caller, and
smb2_compound_op() parses it anyway. It also found that
smb2_readv_callback() can drop the error when the read reaches EOF.
Patch 1 is v1 plus not passing the response on in compound_send_recv().
Patch 2 fixes the read path.
I tested this in QEMU (x86_64, next-20261109, PROVE_LOCKING on) against
Samba 4.15 with "server signing = mandatory", through a proxy that
changes responses without fixing the signature:
- EndOfFile in the QUERY_INFO response of the open/query/close compound
(stat): with v1 the forged size is copied into the open info, and stat
only shows the right size because the caller takes -EACCES for
STATUS_ACCESS_DENIED and opens the file again. With v2 stat fails with
EACCES.
- READ data, cache=none: without patch 2, cat prints the modified data.
With it, the read fails with EACCES.
- A file name in QUERY_DIRECTORY (the v1 test): still EACCES, and the
handle from the CREATE in that compound is closed ("Close unmatched
open").
- Without the proxy, stat, read, write, ls and rm work as before.
Enzo's point about SMB 3.1.1 tree connect responses is not covered here,
that can be a follow-up.
Changes in v2:
- Patch 1: also don't hand the response to the caller in
compound_send_recv() (Sashiko)
- Patch 2: new
- v1: https://lore.kernel.org/all/20261113-smb2-sign-v1-1-937ee7c20f08@gmail.com/
---
Suyuan Wang (2):
smb: client: fail SMB2 responses with a bad signature
smb: client: don't use read data that failed signature verification
fs/smb/client/smb2pdu.c | 2 ++
fs/smb/client/smb2transport.c | 6 +++++-
fs/smb/client/transport.c | 6 ++++++
3 files changed, 13 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature 2026-11-16 4:06 [PATCH v2 0/2] smb: client: don't use SMB2 responses that fail signature verification Suyuan Wang via B4 Relay @ 2026-11-16 4:06 ` Suyuan Wang via B4 Relay 2026-11-18 22:02 ` Paulo Alcantara 2026-11-16 4:06 ` [PATCH v2 2/2] smb: client: don't use read data that failed signature verification Suyuan Wang via B4 Relay 1 sibling, 1 reply; 5+ messages in thread From: Suyuan Wang via B4 Relay @ 2026-11-16 4:06 UTC (permalink / raw) To: linkinjeon, pc Cc: ematsumiya, sprasad, linux-cifs, bharathsm, ronniesahlberg, samba-technical, daniel.birtwhistle, linux-kernel, smfrench, dhowells, tom From: Suyuan Wang <stevewong@hust.edu.cn> smb2_check_receive() checks the response signature when signing is on, but a failed check is only logged: rc = smb2_verify_signature(&rqst, server); if (rc) cifs_server_dbg(VFS, "SMB signature verification returned ...", rc); ... return map_smb2_to_linux_error(mid->resp_buf, log_error); The status from the response is returned as usual, and the caller goes on to use a response whose signature is wrong. This is the path for synchronous and compound requests and for smb2_writev_callback(). On a signed but unencrypted connection, anyone who can modify the traffic can change e.g. a directory listing or file attributes, and the client accepts it. Return the verification error instead. That alone is not enough for compound_send_recv(), which still hands the response buffer to the caller after check_receive() fails. smb2_compound_op() then maps the status from that buffer again and copies the payload out, and other callers look at the buffer on error too, e.g. smb2_open_file() parses a symlink target out of a STATUS_STOPPED_ON_SYMLINK response. So also mark the mid MID_RESPONSE_MALFORMED, and have compound_send_recv() handle it like a mid in a bad state: mark the earlier mids cancelled, so that a CREATE which did succeed gets its handle closed, and don't pass any response on. Unlike the SMB1 fix in commit dc96f01d54cc ("smb: client: terminate session upon failed client required signing"), don't reconnect: this runs in the thread that sent the request, and only cifsd should call cifs_reconnect(). And fail the request whichever side required signing, since a response with a bad signature can't be trusted either way. Found with a static analysis tool and checked by hand. Reported-by: Daniel Birtwhistle <daniel.birtwhistle@gehealthcare.com> Closes: https://lore.kernel.org/linux-cifs/SN4PR22MB28883DAF57E0B4D4BFB1C22AEEC42@SN4PR22MB2888.namprd22.prod.outlook.com/ Fixes: 3c1bf7e48e9e ("CIFS: Enable signing in SMB2") Cc: stable@vger.kernel.org Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn> --- fs/smb/client/smb2transport.c | 6 +++++- fs/smb/client/transport.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c index 080864b24a0c..5d6871553ee9 100644 --- a/fs/smb/client/smb2transport.c +++ b/fs/smb/client/smb2transport.c @@ -711,9 +711,13 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, int rc; rc = smb2_verify_signature(&rqst, server); - if (rc) + if (rc) { cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n", rc); + /* compound_send_recv() must not pass this response on */ + mid->mid_state = MID_RESPONSE_MALFORMED; + return rc; + } } return map_smb2_to_linux_error(mid->resp_buf, log_error); diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c index d0d0159c1061..f1ba9701b545 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -1110,6 +1110,12 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, rc = server->ops->check_receive(mid[i], server, flags & CIFS_LOG_ERROR); + if (mid[i]->mid_state != MID_RESPONSE_READY) { + /* Bad signature, don't let the caller parse any response */ + cifs_mark_compound_mids_cancelled(mid, i); + num_processed = 0; + goto out; + } num_processed = i + 1; } -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature 2026-11-16 4:06 ` [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature Suyuan Wang via B4 Relay @ 2026-11-18 22:02 ` Paulo Alcantara 0 siblings, 0 replies; 5+ messages in thread From: Paulo Alcantara @ 2026-11-18 22:02 UTC (permalink / raw) To: shyckless, linkinjeon Cc: ematsumiya, sprasad, linux-cifs, bharathsm, ronniesahlberg, samba-technical, daniel.birtwhistle, linux-kernel, smfrench, dhowells, tom Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org> writes: > From: Suyuan Wang <stevewong@hust.edu.cn> > > smb2_check_receive() checks the response signature when signing is on, > but a failed check is only logged: > > rc = smb2_verify_signature(&rqst, server); > if (rc) > cifs_server_dbg(VFS, "SMB signature verification returned ...", > rc); > ... > return map_smb2_to_linux_error(mid->resp_buf, log_error); > > The status from the response is returned as usual, and the caller goes > on to use a response whose signature is wrong. This is the path for > synchronous and compound requests and for smb2_writev_callback(). On a > signed but unencrypted connection, anyone who can modify the traffic > can change e.g. a directory listing or file attributes, and the client > accepts it. > > Return the verification error instead. That alone is not enough for > compound_send_recv(), which still hands the response buffer to the > caller after check_receive() fails. smb2_compound_op() then maps the > status from that buffer again and copies the payload out, and other > callers look at the buffer on error too, e.g. smb2_open_file() parses > a symlink target out of a STATUS_STOPPED_ON_SYMLINK response. So also > mark the mid MID_RESPONSE_MALFORMED, and have compound_send_recv() handle > it like a mid in a bad state: mark the earlier mids cancelled, so that a > CREATE which did succeed gets its handle closed, and don't pass any > response on. > > Unlike the SMB1 fix in commit dc96f01d54cc ("smb: client: terminate > session upon failed client required signing"), don't reconnect: this > runs in the thread that sent the request, and only cifsd should call > cifs_reconnect(). And fail the request whichever side required signing, > since a response with a bad signature can't be trusted either way. > ... Applied. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] smb: client: don't use read data that failed signature verification 2026-11-16 4:06 [PATCH v2 0/2] smb: client: don't use SMB2 responses that fail signature verification Suyuan Wang via B4 Relay 2026-11-16 4:06 ` [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature Suyuan Wang via B4 Relay @ 2026-11-16 4:06 ` Suyuan Wang via B4 Relay 2026-11-18 22:02 ` Paulo Alcantara 1 sibling, 1 reply; 5+ messages in thread From: Suyuan Wang via B4 Relay @ 2026-11-16 4:06 UTC (permalink / raw) To: linkinjeon, pc Cc: ematsumiya, sprasad, linux-cifs, bharathsm, ronniesahlberg, samba-technical, daniel.birtwhistle, linux-kernel, smfrench, dhowells, tom From: Suyuan Wang <stevewong@hust.edu.cn> When smb2_readv_callback() finds a bad signature, it sets the error in rdata->result but leaves rdata->got_bytes alone. Further down, a short read that reaches the remote EOF clears the error again: size_t trans = rdata->subreq.transferred + rdata->got_bytes; if (trans < rdata->subreq.len && rdata->subreq.start + trans >= netfs_read_remote_i_size(inode)) { rdata->result = 0; and got_bytes is then added to subreq.transferred. So the last part of a file, or all of a small one, is returned even though its signature is wrong. Clear got_bytes when the signature check fails, as the retry path in the same function already does. Found with a static analysis tool and checked by hand. Fixes: 1da29f2c39b6 ("netfs, cifs: Fix handling of short DIO read") Cc: stable@vger.kernel.org Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn> --- fs/smb/client/smb2pdu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index f85595136ef8..1245572c022e 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4723,6 +4723,8 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) rc); rdata->subreq.error = rc; rdata->result = rc; + /* the data can't be trusted, don't count it */ + rdata->got_bytes = 0; if (is_replayable_error(rc)) { trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed); -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] smb: client: don't use read data that failed signature verification 2026-11-16 4:06 ` [PATCH v2 2/2] smb: client: don't use read data that failed signature verification Suyuan Wang via B4 Relay @ 2026-11-18 22:02 ` Paulo Alcantara 0 siblings, 0 replies; 5+ messages in thread From: Paulo Alcantara @ 2026-11-18 22:02 UTC (permalink / raw) To: shyckless, linkinjeon Cc: ematsumiya, sprasad, linux-cifs, bharathsm, ronniesahlberg, samba-technical, daniel.birtwhistle, linux-kernel, smfrench, dhowells, tom Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org> writes: > From: Suyuan Wang <stevewong@hust.edu.cn> > > When smb2_readv_callback() finds a bad signature, it sets the error in > rdata->result but leaves rdata->got_bytes alone. Further down, a short > read that reaches the remote EOF clears the error again: > > size_t trans = rdata->subreq.transferred + rdata->got_bytes; > if (trans < rdata->subreq.len && > rdata->subreq.start + trans >= netfs_read_remote_i_size(inode)) { > rdata->result = 0; > > and got_bytes is then added to subreq.transferred. So the last part of a > file, or all of a small one, is returned even though its signature is > wrong. > > Clear got_bytes when the signature check fails, as the retry path in the > same function already does. Please check sashiko's review. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 22:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-16 4:06 [PATCH v2 0/2] smb: client: don't use SMB2 responses that fail signature verification Suyuan Wang via B4 Relay 2026-11-16 4:06 ` [PATCH v2 1/2] smb: client: fail SMB2 responses with a bad signature Suyuan Wang via B4 Relay 2026-11-18 22:02 ` Paulo Alcantara 2026-11-16 4:06 ` [PATCH v2 2/2] smb: client: don't use read data that failed signature verification Suyuan Wang via B4 Relay 2026-11-18 22:02 ` Paulo Alcantara
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®