Skip to content

Commit 3575455

Browse files
dhkts1smfrench
authored andcommitted
ksmbd: lock the binding preauth session in smb3_preauth_hash_rsp
smb3_preauth_hash_rsp() computes the SMB3.1.1 preauth integrity hash on the response path. For a binding SESSION_SETUP it looks up the per-connection preauth_session and reads its Preauth_HashValue. smb2_sess_setup() frees that preauth_session under ksmbd_conn_lock(). Two SMB2 requests on one connection can run concurrently, so an unlocked lookup and hash can use a preauth_session after another worker frees it. Take ksmbd_conn_lock() before selecting conn->binding and hold it across the selected preauth hash lookup and update. This preserves the existing hash selection while preventing the lookup-to-use lifetime race. Fixes: 1c5daa2 ("ksmbd: handle channel binding with a different user") Signed-off-by: Gil Portnoy <dddhkts1@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent b106657 commit 3575455

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9808,22 +9808,21 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work)
98089808
}
98099809

98109810
if (le16_to_cpu(rsp->Command) == SMB2_SESSION_SETUP_HE && sess) {
9811-
__u8 *hash_value;
9811+
ksmbd_conn_lock(conn);
98129812

98139813
if (conn->binding) {
98149814
struct preauth_session *preauth_sess;
98159815

98169816
preauth_sess = ksmbd_preauth_session_lookup(conn, sess->id);
9817-
if (!preauth_sess)
9818-
return;
9819-
hash_value = preauth_sess->Preauth_HashValue;
9820-
} else {
9821-
hash_value = sess->Preauth_HashValue;
9822-
if (!hash_value)
9823-
return;
9817+
if (preauth_sess)
9818+
ksmbd_gen_preauth_integrity_hash(conn,
9819+
work->response_buf,
9820+
preauth_sess->Preauth_HashValue);
9821+
} else if (sess->Preauth_HashValue) {
9822+
ksmbd_gen_preauth_integrity_hash(conn, work->response_buf,
9823+
sess->Preauth_HashValue);
98249824
}
9825-
ksmbd_gen_preauth_integrity_hash(conn, work->response_buf,
9826-
hash_value);
9825+
ksmbd_conn_unlock(conn);
98279826
}
98289827
}
98299828

0 commit comments

Comments
 (0)