[PATCH v2 2/2] smb: client: don't use read data that failed signature verification
From: Suyuan Wang via B4 Relay
Date: Sun Nov 15 2026 - 23:06:36 EST
From: Suyuan Wang <stevewong@xxxxxxxxxxx>
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@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
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