Skip to content

Commit

Permalink
CIFS: zero sensitive data when freeing
Browse files Browse the repository at this point in the history
also replaces memset()+kfree() by kzfree().

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
Cc: <stable@vger.kernel.org>
  • Loading branch information
Aurelien Aptel authored and Steve French committed Jan 26, 2018
1 parent 2026b06 commit 97f4b72
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
3 changes: 1 addition & 2 deletions fs/cifs/cifsencrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,8 @@ int calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
{
int i;
int rc;
char password_with_pad[CIFS_ENCPWD_SIZE];
char password_with_pad[CIFS_ENCPWD_SIZE] = {0};

memset(password_with_pad, 0, CIFS_ENCPWD_SIZE);
if (password)
strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE);

Expand Down
6 changes: 3 additions & 3 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
tmp_end++;
if (!(tmp_end < end && tmp_end[1] == delim)) {
/* No it is not. Set the password to NULL */
kfree(vol->password);
kzfree(vol->password);
vol->password = NULL;
break;
}
Expand Down Expand Up @@ -1758,7 +1758,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
options = end;
}

kfree(vol->password);
kzfree(vol->password);
/* Now build new password string */
temp_len = strlen(value);
vol->password = kzalloc(temp_len+1, GFP_KERNEL);
Expand Down Expand Up @@ -4356,7 +4356,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
reset_cifs_unix_caps(0, tcon, NULL, vol_info);
out:
kfree(vol_info->username);
kfree(vol_info->password);
kzfree(vol_info->password);
kfree(vol_info);

return tcon;
Expand Down
14 changes: 4 additions & 10 deletions fs/cifs/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,11 @@ sesInfoFree(struct cifs_ses *buf_to_free)
kfree(buf_to_free->serverOS);
kfree(buf_to_free->serverDomain);
kfree(buf_to_free->serverNOS);
if (buf_to_free->password) {
memset(buf_to_free->password, 0, strlen(buf_to_free->password));
kfree(buf_to_free->password);
}
kzfree(buf_to_free->password);
kfree(buf_to_free->user_name);
kfree(buf_to_free->domainName);
kfree(buf_to_free->auth_key.response);
kfree(buf_to_free);
kzfree(buf_to_free->auth_key.response);
kzfree(buf_to_free);
}

struct cifs_tcon *
Expand Down Expand Up @@ -136,10 +133,7 @@ tconInfoFree(struct cifs_tcon *buf_to_free)
}
atomic_dec(&tconInfoAllocCount);
kfree(buf_to_free->nativeFileSystem);
if (buf_to_free->password) {
memset(buf_to_free->password, 0, strlen(buf_to_free->password));
kfree(buf_to_free->password);
}
kzfree(buf_to_free->password);
kfree(buf_to_free);
}

Expand Down

0 comments on commit 97f4b72

Please sign in to comment.