ksmbd: refuse reauthentication of an expired session as another user
Subsystems (3)
PATCH 1/1 ksmbd: refuse reauthentication of an expired session as another user
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.
--- fs/smb/server/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/server/smb2pdu.c +11 -0
@@ -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; }
Signature · 1 line
2.43.0
Quoted 18 lines · Michail Andreas Michalopoulos
When a Kerberos session expires, its owner can reauthenticate it. For an NTLM reauthentication,
ntlm_authenticate()only compares the new user withsess->userwhen the session is still valid. An expired session is inSMB2_SESSION_IN_PROGRESSduring the reauthentication, so it takes the other branch and simply setssess->userto 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 structksmbd_useris overwritten without being freed.
krb5_authenticate()already refuses a different user in this case, and the valid-session branch ofntlm_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.
Quoted 6 lines
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")Signed-off-by Michail Andreas Michalopoulos <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!