Skip to content

Commit c579470

Browse files
Eric Biggerssmfrench
authored andcommitted
ksmbd: Compare MACs in constant time
To prevent timing attacks, MAC comparisons need to be constant-time. Replace the memcmp() with the correct function, crypto_memneq(). Fixes: e2f3448 ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 6de23f8 commit c579470

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

fs/smb/server/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config SMB_SERVER
1313
select CRYPTO_LIB_MD5
1414
select CRYPTO_LIB_SHA256
1515
select CRYPTO_LIB_SHA512
16+
select CRYPTO_LIB_UTILS
1617
select CRYPTO_CMAC
1718
select CRYPTO_AEAD2
1819
select CRYPTO_CCM

fs/smb/server/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <crypto/aead.h>
1616
#include <crypto/md5.h>
1717
#include <crypto/sha2.h>
18+
#include <crypto/utils.h>
1819
#include <linux/random.h>
1920
#include <linux/scatterlist.h>
2021

@@ -165,7 +166,8 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,
165166
ntlmv2_rsp, CIFS_HMAC_MD5_HASH_SIZE,
166167
sess->sess_key);
167168

168-
if (memcmp(ntlmv2->ntlmv2_hash, ntlmv2_rsp, CIFS_HMAC_MD5_HASH_SIZE) != 0)
169+
if (crypto_memneq(ntlmv2->ntlmv2_hash, ntlmv2_rsp,
170+
CIFS_HMAC_MD5_HASH_SIZE))
169171
return -EINVAL;
170172
return 0;
171173
}

fs/smb/server/smb2pdu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
55
*/
66

7+
#include <crypto/utils.h>
78
#include <linux/inetdevice.h>
89
#include <net/addrconf.h>
910
#include <linux/syscalls.h>
@@ -8880,7 +8881,7 @@ int smb2_check_sign_req(struct ksmbd_work *work)
88808881
ksmbd_sign_smb2_pdu(work->conn, work->sess->sess_key, iov, 1,
88818882
signature);
88828883

8883-
if (memcmp(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
8884+
if (crypto_memneq(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
88848885
pr_err("bad smb2 signature\n");
88858886
return 0;
88868887
}
@@ -8968,7 +8969,7 @@ int smb3_check_sign_req(struct ksmbd_work *work)
89688969
if (ksmbd_sign_smb3_pdu(conn, signing_key, iov, 1, signature))
89698970
return 0;
89708971

8971-
if (memcmp(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
8972+
if (crypto_memneq(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
89728973
pr_err("bad smb2 signature\n");
89738974
return 0;
89748975
}

0 commit comments

Comments
 (0)