Skip to content

Commit c341cdf

Browse files
vwaxgregkh
authored andcommitted
cifs: fix crash due to race in hmac(md5) handling
commit bd975d1 upstream. The secmech hmac(md5) structures are present in the TCP_Server_Info struct and can be shared among multiple CIFS sessions. However, the server mutex is not currently held when these structures are allocated and used, which can lead to a kernel crashes, as in the scenario below: mount.cifs(8) tobetter#1 mount.cifs(8) tobetter#2 Is secmech.sdeschmaccmd5 allocated? // false Is secmech.sdeschmaccmd5 allocated? // false secmech.hmacmd = crypto_alloc_shash.. secmech.sdeschmaccmd5 = kzalloc.. sdeschmaccmd5->shash.tfm = &secmec.hmacmd; secmech.sdeschmaccmd5 = kzalloc // sdeschmaccmd5->shash.tfm // not yet assigned crypto_shash_update() deref NULL sdeschmaccmd5->shash.tfm Unable to handle kernel paging request at virtual address 00000030 epc : 8027ba34 crypto_shash_update+0x38/0x158 ra : 8020f2e8 setup_ntlmv2_rsp+0x4bc/0xa84 Call Trace: crypto_shash_update+0x38/0x158 setup_ntlmv2_rsp+0x4bc/0xa84 build_ntlmssp_auth_blob+0xbc/0x34c sess_auth_rawntlmssp_authenticate+0xac/0x248 CIFS_SessSetup+0xf0/0x178 cifs_setup_session+0x4c/0x84 cifs_get_smb_ses+0x2c8/0x314 cifs_mount+0x38c/0x76c cifs_do_mount+0x98/0x440 mount_fs+0x20/0xc0 vfs_kern_mount+0x58/0x138 do_mount+0x1e8/0xccc SyS_mount+0x88/0xd4 syscall_common+0x30/0x54 Fix this by locking the srv_mutex around the code which uses these hmac(md5) structures. All the other secmech algos already have similar locking. Fixes: 95dc8dd ("Limit allocation of crypto mechanisms to dialect which requires") Signed-off-by: Rabin Vincent <[email protected]> Acked-by: Sachin Prabhu <[email protected]> Signed-off-by: Steve French <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3abfd2c commit c341cdf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,24 +743,26 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
743743

744744
memcpy(ses->auth_key.response + baselen, tiblob, tilen);
745745

746+
mutex_lock(&ses->server->srv_mutex);
747+
746748
rc = crypto_hmacmd5_alloc(ses->server);
747749
if (rc) {
748750
cifs_dbg(VFS, "could not crypto alloc hmacmd5 rc %d\n", rc);
749-
goto setup_ntlmv2_rsp_ret;
751+
goto unlock;
750752
}
751753

752754
/* calculate ntlmv2_hash */
753755
rc = calc_ntlmv2_hash(ses, ntlmv2_hash, nls_cp);
754756
if (rc) {
755757
cifs_dbg(VFS, "could not get v2 hash rc %d\n", rc);
756-
goto setup_ntlmv2_rsp_ret;
758+
goto unlock;
757759
}
758760

759761
/* calculate first part of the client response (CR1) */
760762
rc = CalcNTLMv2_response(ses, ntlmv2_hash);
761763
if (rc) {
762764
cifs_dbg(VFS, "Could not calculate CR1 rc: %d\n", rc);
763-
goto setup_ntlmv2_rsp_ret;
765+
goto unlock;
764766
}
765767

766768
/* now calculate the session key for NTLMv2 */
@@ -769,28 +771,30 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
769771
if (rc) {
770772
cifs_dbg(VFS, "%s: Could not set NTLMV2 Hash as a key\n",
771773
__func__);
772-
goto setup_ntlmv2_rsp_ret;
774+
goto unlock;
773775
}
774776

775777
rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
776778
if (rc) {
777779
cifs_dbg(VFS, "%s: Could not init hmacmd5\n", __func__);
778-
goto setup_ntlmv2_rsp_ret;
780+
goto unlock;
779781
}
780782

781783
rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
782784
ntlmv2->ntlmv2_hash,
783785
CIFS_HMAC_MD5_HASH_SIZE);
784786
if (rc) {
785787
cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
786-
goto setup_ntlmv2_rsp_ret;
788+
goto unlock;
787789
}
788790

789791
rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
790792
ses->auth_key.response);
791793
if (rc)
792794
cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
793795

796+
unlock:
797+
mutex_unlock(&ses->server->srv_mutex);
794798
setup_ntlmv2_rsp_ret:
795799
kfree(tiblob);
796800

0 commit comments

Comments
 (0)