Skip to content

Commit 2d39d3c

Browse files
namjaejeonpopcornmix
authored andcommitted
ksmbd: fix null pointer dereference in destroy_previous_session
commit 7ac5b66 upstream. If client set ->PreviousSessionId on kerberos session setup stage, NULL pointer dereference error will happen. Since sess->user is not set yet, It can pass the user argument as NULL to destroy_previous_session. sess->user will be set in ksmbd_krb5_authenticate(). So this patch move calling destroy_previous_session() after ksmbd_krb5_authenticate(). Cc: stable@vger.kernel.org Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-27391 Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 22d9231 commit 2d39d3c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,17 +1605,18 @@ static int krb5_authenticate(struct ksmbd_work *work,
16051605
out_len = work->response_sz -
16061606
(le16_to_cpu(rsp->SecurityBufferOffset) + 4);
16071607

1608-
/* Check previous session */
1609-
prev_sess_id = le64_to_cpu(req->PreviousSessionId);
1610-
if (prev_sess_id && prev_sess_id != sess->id)
1611-
destroy_previous_session(conn, sess->user, prev_sess_id);
1612-
16131608
retval = ksmbd_krb5_authenticate(sess, in_blob, in_len,
16141609
out_blob, &out_len);
16151610
if (retval) {
16161611
ksmbd_debug(SMB, "krb5 authentication failed\n");
16171612
return -EINVAL;
16181613
}
1614+
1615+
/* Check previous session */
1616+
prev_sess_id = le64_to_cpu(req->PreviousSessionId);
1617+
if (prev_sess_id && prev_sess_id != sess->id)
1618+
destroy_previous_session(conn, sess->user, prev_sess_id);
1619+
16191620
rsp->SecurityBufferLength = cpu_to_le16(out_len);
16201621

16211622
if ((conn->sign || server_conf.enforced_signing) ||

0 commit comments

Comments
 (0)