Skip to content

Commit 9b493ab

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix null pointer dereference error in generate_encryptionkey
If client send two session setups with krb5 authenticate to ksmbd, null pointer dereference error in generate_encryptionkey could happen. sess->Preauth_HashValue is set to NULL if session is valid. So this patch skip generate encryption key if session is valid. Cc: [email protected] Reported-by: [email protected] # ZDI-CAN-27654 Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4e45cca commit 9b493ab

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,11 +1621,24 @@ static int krb5_authenticate(struct ksmbd_work *work,
16211621

16221622
rsp->SecurityBufferLength = cpu_to_le16(out_len);
16231623

1624-
if ((conn->sign || server_conf.enforced_signing) ||
1624+
/*
1625+
* If session state is SMB2_SESSION_VALID, We can assume
1626+
* that it is reauthentication. And the user/password
1627+
* has been verified, so return it here.
1628+
*/
1629+
if (sess->state == SMB2_SESSION_VALID) {
1630+
if (conn->binding)
1631+
goto binding_session;
1632+
return 0;
1633+
}
1634+
1635+
if ((rsp->SessionFlags != SMB2_SESSION_FLAG_IS_GUEST_LE &&
1636+
(conn->sign || server_conf.enforced_signing)) ||
16251637
(req->SecurityMode & SMB2_NEGOTIATE_SIGNING_REQUIRED))
16261638
sess->sign = true;
16271639

1628-
if (smb3_encryption_negotiated(conn)) {
1640+
if (smb3_encryption_negotiated(conn) &&
1641+
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
16291642
retval = conn->ops->generate_encryptionkey(conn, sess);
16301643
if (retval) {
16311644
ksmbd_debug(SMB,
@@ -1638,6 +1651,7 @@ static int krb5_authenticate(struct ksmbd_work *work,
16381651
sess->sign = false;
16391652
}
16401653

1654+
binding_session:
16411655
if (conn->dialect >= SMB30_PROT_ID) {
16421656
chann = lookup_chann_list(sess, conn);
16431657
if (!chann) {

0 commit comments

Comments
 (0)