From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385218; b=bXvVk3ooRUJSx3RPBJeO5lgXfzVikpbgypgpnBXoPQ9PNurXDr9B+yA9VwHGG7h2Ml3m 1qy5fyhoORP1owlhvpcO/tXlwgnwdWvze0rAk0gLVU5zEUQhAaX5mAHjIEP2hoQawzAC+ Xced5qvloQc1P1aOVzgn7CgcwgZ9ymVjcr/7F+Bafwf3tuiADE8EjmsSUJ21iD7liugqR CSvy80KtyR1q2yp3WlVOt+hbvLtVSCtr5qZ/0Plf2QXtw5lY6AQmhMgUiCeMPyx4RQalW oPfgA/ctffJSE4PPChJjzmW3zYlqFBTs1uOXWlhw20lnQx3BQDPU+jMgSSmPgtN3LRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385218; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=agB8SY6/kie/Hc2AhZyA53p8X3kerVi14lrkX/7JT7w=; b=wrIb1N9sm4mxiIjl1mnQAHgS9CpeOP06y0w2h1Poe6ULkwudse5s+tVx+tUYX1HSvXiQ gsfcpNfXYsuhwf5TpOVs4OEDwjiXHi+jXMvUephnJjXMHz+q5LEKJQnVTuBsYoSNI804V bP08HwbWp9Ct0/heb69Ky6fIj4mMc1g/Gx5+p23hhqt7LMsHZ172A9EtQxQZMg043QCi9 ojqf/awyyHJItFQWK+T+kSEsjri4DgI3bmTWaPvC+PmWoBA2tGqBXJqq5weDVLzI+3qnp 5HDVNZrdgrugJPHoXMt4rKw1BuKd+ecguF+SkHV2iKdBtwiOqVMJYtmJuxN5oj+LqSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="HYmIQ/t0"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB62606A322 for ; Fri, 4 Dec 2026 11:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HYmIQ/t0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CE4B1F00A08; Fri, 4 Dec 2026 11:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385218; bh=agB8SY6/kie/Hc2AhZyA53p8X3kerVi14lrkX/7JT7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HYmIQ/t0rDY/VipAEXTm+F9FF+Cd9LirXZ2LQfw0SsZ8TdZ3kPe0I5j6rZvf61JW+ 4k9UxCFwOR2GpDTEVz3ycRvs4gky3viL7+EtPnVPWKcy/1RU7N5ntzOfTN4Oh1iFd5 8Ms0J8RBit8uj2PcSrYxYBM96Y46qGTm/lye2qyPUD3jznIBr1/4R7yjyatOYvB/M5 gDO6g2mUkq2fuvO6nlrFLIQurNPySNVVTHr7U4WKDn7xiA8m72Q2cNWrkzHBvQa/vR ehG6JuxZh/EHj/yHzTQKPBDRcw8abr7VzL6WnIajP8Oo3MOQMHScPqfanBeHlzcI9S 4zo0yCWHZCP3A== From: Sasha Levin To: stable@vger.kernel.org Cc: Suyuan Wang , Daniel Birtwhistle , Kaixuan Li , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.1.y] smb: client: fail SMB2 responses with a bad signature Date: Fri, 4 Dec 2026 06:53:36 -0500 Message-ID: <20261204115308.2874918-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120234-smokeless-ninja-33d1@gregkh> References: <2026120234-smokeless-ninja-33d1@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Suyuan Wang [ 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 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 Signed-off-by: Kaixuan Li Signed-off-by: Suyuan Wang Signed-off-by: Paulo Alcantara Signed-off-by: Sasha Levin --- 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