All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Suyuan Wang <stevewong@hust.edu.cn>,
	Daniel Birtwhistle <daniel.birtwhistle@gehealthcare.com>,
	Kaixuan Li <kaixuan.li@ntu.edu.sg>,
	Paulo Alcantara <pc@manguebit.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1.y] smb: client: fail SMB2 responses with a bad signature
Date: Fri,  4 Dec 2026 06:53:36 -0500	[thread overview]
Message-ID: <20261204115308.2874918-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120234-smokeless-ninja-33d1@gregkh>

From: Suyuan Wang <stevewong@hust.edu.cn>

[ Upstream commit 2a5bd7a2bbb787483cd69ecf099e2b591e3633b2 ]

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>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/smb/client/smb2transport.c | 7 +++++--
 fs/smb/client/transport.c     | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c
index b8441ffcff768..be1115c19eb3c 100644
--- a/fs/smb/client/smb2transport.c
+++ b/fs/smb/client/smb2transport.c
@@ -880,9 +880,12 @@ 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);
+					rc);
+			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 e41cd9581cd43..53fb914ff4ad1 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -1310,6 +1310,14 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
 
 		rc = server->ops->check_receive(midQ[i], server,
 						     flags & CIFS_LOG_ERROR);
+		if (midQ[i]->mid_state != MID_RESPONSE_READY) {
+			spin_lock(&server->mid_lock);
+			for (j = 0; j < i; j++)
+				midQ[j]->mid_flags |= MID_WAIT_CANCELLED;
+			spin_unlock(&server->mid_lock);
+			num_processed = 0;
+			goto out;
+		}
 		num_processed = i + 1;
 	}
 
-- 
2.53.0


      reply	other threads:[~2026-12-04 11:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:55 FAILED: patch "[PATCH] smb: client: fail SMB2 responses with a bad signature" failed to apply to 6.1-stable tree gregkh
2026-12-04 11:53 ` Sasha Levin [this message]

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=20261204115308.2874918-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=daniel.birtwhistle@gehealthcare.com \
    --cc=kaixuan.li@ntu.edu.sg \
    --cc=pc@manguebit.org \
    --cc=stable@vger.kernel.org \
    --cc=stevewong@hust.edu.cn \
    /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.