[PATCH v5 1/8] ksmbd: verify the signature of session binding requests
From: Michail Andreas Michalopoulos
Date: Wed Nov 11 2026 - 23:49:44 EST
When multichannel is enabled, smb2_sess_setup() accepts a binding
request on a new connection once it finds the session and sees
SMB2_FLAGS_SIGNED, but never checks the signature: SESSION_SETUP is
exempt from the generic check in __process_request(), because
work->sess is not set for it. The request then goes through
authentication, and the response is signed with the session's signing
key, since the request claims to be signed.
So anyone who knows a SessionId and ClientGUID can open a connection
and have the server sign STATUS_MORE_PROCESSING_REQUIRED responses with
another client's session key, each with a fresh NTLM challenge and at a
MessageId of their choice: a signing oracle.
MS-SMB2 3.3.5.2.4 requires the server to verify a binding request with
Session.SigningKey and to fail it with STATUS_ACCESS_DENIED if that
fails. It does so while receiving the message, before the checks of
3.3.5.5, so do it right after the check that the request is signed. The
failure response is not signed, because work->sess is only set once the
request has been accepted.
smb2_check_sign_req() and smb3_check_sign_req() zero the Signature
field in place to compute the MAC. Restore it in both before they
return, as generate_preauth_hash() later hashes the request as received
into the channel's SMB 3.1.1 preauth integrity hash.
A session that is still being set up has no signing key yet: the key is
all zeroes until authentication completes. Refuse a binding request for
it before verifying, in both binding branches, with the
STATUS_REQUEST_NOT_ACCEPTED that 3.3.5.5 gives for such a session
(3.3.5.2.4 would answer STATUS_NOT_SUPPORTED, as the key is NULL), so
that a request is never verified against a missing key. Set
SMB2_SESSION_VALID with smp_store_release() and read the state with
smp_load_acquire(), so that a session seen as valid has its key.
The other binding branch, which rejects a binding request that is not a
valid multichannel bind, verifies the signature as well. A missing
negation on the multichannel flag made that branch unreachable for an
SMB 3.x request when multichannel is disabled: such a request fell
through to the reauthentication path instead and was answered with an
unsigned STATUS_USER_SESSION_DELETED. Correct the condition so the
request is verified and rejected there.
That branch signs its refusal of a verified request with the session's
key. An SMB 3.x connection binding to an SMB 2.x session now gets there
too, and the connection's own handler would sign with the SMB 3.x
signing key, which such a session does not have. Sign that response
with smb2_set_sign_rsp(), as is already done the other way round.
An AI assistant was used to draft the patch and as an independent
reviewer.
Reported-by: Ian Bridges <icb@xxxxxxxxxxxx>
Closes: https://lore.kernel.org/all/20261103171742.18816-1-icb@xxxxxxxxxxxx/
Fixes: f5a544e3bab7 ("ksmbd: add support for SMB3 multichannel")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Michail Andreas Michalopoulos <mike.michalo@xxxxxxxxx>
---
fs/smb/server/server.c | 9 ++++++
fs/smb/server/smb2pdu.c | 69 ++++++++++++++++++++++++++++++++---------
2 files changed, 63 insertions(+), 15 deletions(-)
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 064f99427ca6f..51aa981bcef4e 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -322,10 +322,19 @@ static void __handle_ksmbd_work(struct ksmbd_work *work,
if (work->sess &&
(work->sess->sign || smb3_11_final_sess_setup_resp(work) ||
conn->ops->is_sign_req(work, command))) {
+ /*
+ * A refused binding request is answered with the key
+ * of the session, which can be of another dialect
+ * family than this connection.
+ */
if (command == SMB2_SESSION_SETUP_HE &&
work->sess->dialect >= SMB30_PROT_ID &&
conn->dialect < SMB30_PROT_ID)
smb3_set_sign_rsp(work);
+ else if (command == SMB2_SESSION_SETUP_HE &&
+ work->sess->dialect < SMB30_PROT_ID &&
+ conn->dialect >= SMB30_PROT_ID)
+ smb2_set_sign_rsp(work);
else
conn->ops->set_sign_rsp(work);
}
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index b084cca8813cc..3d9b966235dbb 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2558,6 +2558,23 @@ static int krb5_authenticate(struct ksmbd_work *work,
}
#endif
+/*
+ * A binding request must be signed with the signing key of the session it
+ * binds to (MS-SMB2 3.3.5.2.4). Check it before the request is processed
+ * and before any response is signed with that key.
+ */
+static bool smb2_check_binding_sign_req(struct ksmbd_work *work,
+ struct ksmbd_session *sess)
+{
+ struct ksmbd_session *prev_sess = work->sess;
+ int ret;
+
+ work->sess = sess;
+ ret = smb3_check_sign_req(work);
+ work->sess = prev_sess;
+ return ret;
+}
+
int smb2_sess_setup(struct ksmbd_work *work)
{
struct ksmbd_conn *conn = work->conn;
@@ -2635,22 +2652,33 @@ int smb2_sess_setup(struct ksmbd_work *work)
goto out_err;
}
+ /*
+ * A session that is still being set up has no signing key
+ * yet, so there is nothing to verify a binding request with.
+ * Pairs with smp_store_release() in smb2_sess_setup().
+ */
+ if (smp_load_acquire(&sess->state) == SMB2_SESSION_IN_PROGRESS) {
+ rc = -EACCES;
+ goto out_err;
+ }
+
if (!(req->hdr.Flags & SMB2_FLAGS_SIGNED)) {
rc = -EINVAL;
goto out_err;
}
+ /* As part of receiving the request (MS-SMB2 3.3.5.2.4) */
+ if (!smb2_check_binding_sign_req(work, sess)) {
+ rc = -EKEYREJECTED;
+ goto out_err;
+ }
+
if (memcmp(conn->ClientGUID, sess->ClientGUID,
SMB2_CLIENT_GUID_SIZE)) {
rc = -ENOENT;
goto out_err;
}
- if (sess->state == SMB2_SESSION_IN_PROGRESS) {
- rc = -EACCES;
- goto out_err;
- }
-
if (sess->state == SMB2_SESSION_EXPIRED) {
rc = -EFAULT;
goto out_err;
@@ -2675,21 +2703,23 @@ int smb2_sess_setup(struct ksmbd_work *work)
conn->binding = true;
} else if ((conn->dialect < SMB30_PROT_ID ||
- server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL) &&
+ !(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)) &&
(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
sess = ksmbd_session_lookup_slowpath(le64_to_cpu(req->hdr.SessionId));
if (sess) {
- int sign_ret;
+ int sign_ret = 0;
work->sess = sess;
installed = true;
- if (sess->dialect >= SMB30_PROT_ID)
- sign_ret = smb3_check_sign_req(work);
- else
- sign_ret = smb2_check_sign_req(work);
- if (sess->state != SMB2_SESSION_VALID ||
- !(req->hdr.Flags & SMB2_FLAGS_SIGNED) ||
- !sign_ret) {
+ /* Only a valid session has a signing key to check with */
+ if (smp_load_acquire(&sess->state) == SMB2_SESSION_VALID &&
+ (req->hdr.Flags & SMB2_FLAGS_SIGNED)) {
+ if (sess->dialect >= SMB30_PROT_ID)
+ sign_ret = smb3_check_sign_req(work);
+ else
+ sign_ret = smb2_check_sign_req(work);
+ }
+ if (!sign_ret) {
ksmbd_user_session_put(sess);
work->sess = NULL;
sess = NULL;
@@ -2928,7 +2958,12 @@ int smb2_sess_setup(struct ksmbd_work *work)
destroy_previous_session(conn, sess->user, previous_session_id);
if (!ksmbd_conn_need_reconnect(conn)) {
ksmbd_conn_set_good(conn);
- sess->state = SMB2_SESSION_VALID;
+ /*
+ * The session's keys are generated by now. Pairs with
+ * smp_load_acquire() where a binding request is
+ * verified with them.
+ */
+ smp_store_release(&sess->state, SMB2_SESSION_VALID);
}
}
@@ -12853,6 +12888,8 @@ int smb2_check_sign_req(struct ksmbd_work *work)
ksmbd_sign_smb2_pdu(work->conn, work->sess->sess_key, iov, 1,
signature);
+ /* Restore the request as received, for the SMB 3.1.1 preauth hash */
+ memcpy(hdr->Signature, signature_req, SMB2_SIGNATURE_SIZE);
if (crypto_memneq(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
pr_err("bad smb2 signature\n");
@@ -12972,6 +13009,8 @@ int smb3_check_sign_req(struct ksmbd_work *work)
iov[0].iov_len = len;
ksmbd_sign_smb3_pdu(conn, signing_key, iov, 1, signature);
+ /* Restore the request as received, for the SMB 3.1.1 preauth hash */
+ memcpy(hdr->Signature, signature_req, SMB2_SIGNATURE_SIZE);
if (crypto_memneq(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
pr_err("bad smb2 signature\n");
--
2.43.0