[PATCH] ksmbd: refuse reauthentication of an expired session as another user
From: Michail Andreas Michalopoulos
Date: Mon Nov 09 2026 - 15:08:08 EST
When a Kerberos session expires, its owner can reauthenticate it. For an
NTLM reauthentication, ntlm_authenticate() only compares the new user with
sess->user when the session is still valid. An expired session is in
SMB2_SESSION_IN_PROGRESS during the reauthentication, so it takes the
other branch and simply sets sess->user to the new user:
- the session's open files, tree connects and other state, created under
the original user's identity, now belong to whichever user just
authenticated, and a later Kerberos reauthentication is compared
against that user rather than the original one;
- the original struct ksmbd_user is overwritten without being freed.
krb5_authenticate() already refuses a different user in this case, and
the valid-session branch of ntlm_authenticate() does too. Do the same for
an expired session: compare with the existing user and refuse a different
one with -EKEYREJECTED, freeing the newly looked-up user either way.
An AI assistant was used to find and fix this and as an independent
reviewer.
Fixes: a47634cd729b ("ksmbd: expire SMB sessions when Kerberos tickets expire")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Michail Andreas Michalopoulos <mike.michalo@xxxxxxxxx>
---
fs/smb/server/smb2pdu.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index b084cca8813cc..234439c1526f9 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2365,6 +2365,17 @@ static int ntlm_authenticate(struct ksmbd_work *work,
return -EKEYREJECTED;
}
ksmbd_free_user(user);
+ } else if (sess->user) {
+ /*
+ * Reauthentication of an expired session: as for a valid
+ * session, and as krb5_authenticate() does, it must be by the
+ * same user. Replacing sess->user would also leak the old one.
+ */
+ if (!ksmbd_compare_user(sess->user, user)) {
+ ksmbd_free_user(user);
+ return -EKEYREJECTED;
+ }
+ ksmbd_free_user(user);
} else {
sess->user = user;
}
--
2.43.0