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=1796384806; b=31+QHWMavaKkn1qpSpZpaJHeige90OL51YGLwBXW73VMH0nzeDMUbcqAQEfRJcvpVg1p K4ds52cHtWQd4pzw8HOeLv6+2X/VwFMrJwlTo00pZQl0T3FpRdWo/sJ37PGLtuBRwcoWD QGirNVCXCFL2NPDTbOEISmi0P6OG9/DWCvjGmCkMSY9QY4Btt1cs5u9mpBH+Il4QYc1L5 QcQO9heZbDEedHz/eZ4tif5ielJfekzPlOqJbCeRkJPf3aQQMpxVMXw2KfMUnnZzn3eQr J4U+rgy7LYddddAPnw+bN06clhf0k3TFpMGiYQ4IdVrhYBI277r3VG4N9WtOJvIhIfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384806; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=oZ5MZVqP67hwzrt3x535G9Vo9CcuQgKv85Gg7TkmrSE=; b=fZmsgQgsBZ0WkzHSUEH34QrQ7gowNkfcWT5d/JDbgJSHuBmXkLji9asrzH15AN+FLsXm S6YiqRIycOojocxgF3IcG9VwpvC3n7VjJrZ7kNhoMQl3oSFaJu1KgQSBi8C+kru0WTQeL mAN7FXX5nis4m8tNyYdbEeNlNRUQH+es/IeJuxCECptLLD+ct3Vvi1PKMQrGTnx7BohkO L02u5MVer3sI85ohphIdYvLrFMY6M0FrDDjr8F3/638HNusv7mzac+o8HYFiJcIGEK4zP uYBLm2B/o32npHAwkjyAYvTr1ccqwiP3i01ByQ2SoCOjQ6JrvNYGOuU+jO597jzStlQ== 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=dlGwBcyk; 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 E6D8C606A33C for ; Fri, 4 Dec 2026 11:46:45 +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=dlGwBcyk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 078BE1F000CE; Fri, 4 Dec 2026 11:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796384805; bh=oZ5MZVqP67hwzrt3x535G9Vo9CcuQgKv85Gg7TkmrSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dlGwBcykxNJe2ElWMOeZma2emkBd7AUY4P0AScCGy/7x34GL1/SREw3kKQKduHLY2 AF2J8ELBqYpEXKB1G67jaTa6LcKmT9TlX2vlpAj1maL/vukRn6AGpPUHFfJ6MSWCYt oObujXm5OEv0nEAKMgfX9t2EPhjpSe8xVA9ROZBF155qtGiy0HH0+htYbN2MQP/v28 FEDqB5pm1qOL2N+Y9v5+kz1+zerYA2CVm0repIb2SWBAq8HUa2LTNhqdDreiu1MQ0o 5U51ykOHYTqFdghn1Zronk2CZXQl8dzmxypWDrfeBvntRzRaqEtWRVqQ2tS6IYceGT 4zCXKLK4R9s5w== From: Sasha Levin To: stable@vger.kernel.org Cc: Suyuan Wang , Daniel Birtwhistle , Kaixuan Li , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.12.y] smb: client: fail SMB2 responses with a bad signature Date: Fri, 4 Dec 2026 06:46:43 -0500 Message-ID: <20261204114601.2774959-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120232-parsley-drop-down-ba42@gregkh> References: <2026120232-parsley-drop-down-ba42@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 31d22af0c626c..f3c08cddb8184 100644 --- a/fs/smb/client/smb2transport.c +++ b/fs/smb/client/smb2transport.c @@ -887,9 +887,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 d67c1d200a6af..b49c4cfb49ceb 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -1280,6 +1280,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