Skip to content

Commit 2fe58d9

Browse files
Paulo AlcantaraSteve French
authored andcommitted
cifs: fix potential memory leaks in session setup
Make sure to free cifs_ses::auth_key.response before allocating it as we might end up leaking memory in reconnect or mounting. Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 22aeb01 commit 2fe58d9

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ build_avpair_blob(struct cifs_ses *ses, const struct nls_table *nls_cp)
278278
* ( for NTLMSSP_AV_NB_DOMAIN_NAME followed by NTLMSSP_AV_EOL ) +
279279
* unicode length of a netbios domain name
280280
*/
281+
kfree_sensitive(ses->auth_key.response);
281282
ses->auth_key.len = size + 2 * dlen;
282283
ses->auth_key.response = kzalloc(ses->auth_key.len, GFP_KERNEL);
283284
if (!ses->auth_key.response) {

fs/cifs/sess.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
815815
return -EINVAL;
816816
}
817817
if (tilen) {
818+
kfree_sensitive(ses->auth_key.response);
818819
ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
819820
GFP_KERNEL);
820821
if (!ses->auth_key.response) {
@@ -1428,6 +1429,7 @@ sess_auth_kerberos(struct sess_data *sess_data)
14281429
goto out_put_spnego_key;
14291430
}
14301431

1432+
kfree_sensitive(ses->auth_key.response);
14311433
ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
14321434
GFP_KERNEL);
14331435
if (!ses->auth_key.response) {

fs/cifs/smb2pdu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
14531453

14541454
/* keep session key if binding */
14551455
if (!is_binding) {
1456+
kfree_sensitive(ses->auth_key.response);
14561457
ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
14571458
GFP_KERNEL);
14581459
if (!ses->auth_key.response) {

0 commit comments

Comments
 (0)