Skip to contentSkip to conversation

ksmbd: Fix dangling pointer in krb_authenticate

PATCH New Leon Chen 1 participant 1 message Mar 2 Stable branch

lore
Share & tools
lore

Leon Chen

author
#0 lore raw

PATCH 1/1 ksmbd: Fix dangling pointer in krb_authenticate

From: Sean Heelan <[email protected]>

[ Upstream commit 1e440d5b25b7efccb3defe542a73c51005799a5f ]

krb_authenticate frees sess->user and does not set the pointer to NULL. It calls ksmbd_krb5_authenticate to reinitialise sess->user but that function may return without doing so. If that happens then smb2_sess_setup, which calls krb_authenticate, will be accessing free'd memory when it later uses sess->user.

---
 fs/ksmbd/smb2pdu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +3 -1
index b5ff4c855f9c..f40f065c2a4f 100644
@@ -1617,8 +1617,10 @@ static int krb5_authenticate(struct ksmbd_work *work,
 	if (prev_sess_id && prev_sess_id != sess->id)
 		destroy_previous_session(conn, sess->user, prev_sess_id);
 
-	if (sess->state == SMB2_SESSION_VALID)
+	if (sess->state == SMB2_SESSION_VALID) {
 		ksmbd_free_user(sess->user);
+		sess->user = NULL;
+	}
 
 	retval = ksmbd_krb5_authenticate(sess, in_blob, in_len,
 					 out_blob, &out_len);
Signature · 1 line
2.35.3