mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 08:15:07 -04:00
smb: client: Clear sensitive stack data in cifsencrypt.c
Make sure to not leak hash data via the stack, clear it with memzero_explicit() before leaving the function. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Paulo Alcantara <pc@manguebit.org>
This commit is contained in:
committed by
Paulo Alcantara
parent
55a1ad8413
commit
1a6bd74a27
@@ -249,12 +249,13 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
|
||||
E_md4hash(ses->password, nt_hash, nls_cp);
|
||||
|
||||
hmac_md5_init_usingrawkey(&hmac_ctx, nt_hash, CIFS_NTHASH_SIZE);
|
||||
memzero_explicit(nt_hash, sizeof(nt_hash));
|
||||
|
||||
/* convert ses->user_name to unicode */
|
||||
len = ses->user_name ? strlen(ses->user_name) : 0;
|
||||
user = kmalloc(2 + (len * 2), GFP_KERNEL);
|
||||
if (user == NULL)
|
||||
return -ENOMEM;
|
||||
goto out_nomem;
|
||||
|
||||
if (len) {
|
||||
len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);
|
||||
@@ -272,7 +273,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
|
||||
|
||||
domain = kmalloc(2 + (len * 2), GFP_KERNEL);
|
||||
if (domain == NULL)
|
||||
return -ENOMEM;
|
||||
goto out_nomem;
|
||||
|
||||
len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,
|
||||
nls_cp);
|
||||
@@ -284,7 +285,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
|
||||
|
||||
server = kmalloc(2 + (len * 2), GFP_KERNEL);
|
||||
if (server == NULL)
|
||||
return -ENOMEM;
|
||||
goto out_nomem;
|
||||
|
||||
len = cifs_strtoUTF16((__le16 *)server, ses->ip_addr, len, nls_cp);
|
||||
hmac_md5_update(&hmac_ctx, (const u8 *)server, 2 * len);
|
||||
@@ -293,6 +294,10 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
|
||||
|
||||
hmac_md5_final(&hmac_ctx, ntlmv2_hash);
|
||||
return 0;
|
||||
|
||||
out_nomem:
|
||||
memzero_explicit(&hmac_ctx, sizeof(hmac_ctx));
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static void CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
|
||||
@@ -463,6 +468,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
|
||||
rc = 0;
|
||||
unlock:
|
||||
cifs_server_unlock(ses->server);
|
||||
memzero_explicit(ntlmv2_hash, sizeof(ntlmv2_hash));
|
||||
setup_ntlmv2_rsp_ret:
|
||||
kfree_sensitive(tiblob);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user