Skip to contentSkip to conversation

cifs: fix double free on failed kerberos auth

PATCH In review Paulo Alcantara 2 participants 2 messages Jan 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix double free on failed kerberos auth

If session setup failed with kerberos auth, we ended up freeing cifs_ses::auth_key.response twice in SMB2_auth_kerberos() and sesInfoFree().

Fix this by zeroing out cifs_ses::auth_key.response after freeing it in SMB2_auth_kerberos().

Fixes a4e430c8c8ba ("cifs: replace kfree() with kfree_sensitive() for sensitive data")
---
 fs/cifs/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +4 -1
index 2c484d47c592..727f16b426be 100644
@@ -1482,8 +1482,11 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
 out_put_spnego_key:
 	key_invalidate(spnego_key);
 	key_put(spnego_key);
-	if (rc)
+	if (rc) {
 		kfree_sensitive(ses->auth_key.response);
+		ses->auth_key.response = NULL;
+		ses->auth_key.len = 0;
+	}
 out:
 	sess_data->result = rc;
 	sess_data->func = NULL;
Signature · 1 line
2.39.0
#1 lore raw

merged into cifs-2.6.git for-next pending testing

Xioli,
Let me know if you want me to add your reported-by and/or tested-by

Quoted 35 lines · Paulo Alcantara

If session setup failed with kerberos auth, we ended up freeing cifs_ses::auth_key.response twice in SMB2_auth_kerberos() and sesInfoFree().

Fix this by zeroing out cifs_ses::auth_key.response after freeing it in SMB2_auth_kerberos().

Fixes a4e430c8c8ba ("cifs: replace kfree() with kfree_sensitive() for sensitive data")
---
 fs/cifs/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +4 -2
index 2c484d47c592..727f16b426be 100644
@@ -1482,8 +1482,11 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
 out_put_spnego_key:
        key_invalidate(spnego_key);
        key_put(spnego_key);
-       if (rc)
+       if (rc) {
                kfree_sensitive(ses->auth_key.response);
+               ses->auth_key.response = NULL;
+               ses->auth_key.len = 0;
+       }
 out:
        sess_data->result = rc;
        sess_data->func = NULL;
--

2.39.0

Signature · 3 lines
Thanks,

Steve