Commit c5794709 authored by Eric Biggers's avatar Eric Biggers Committed by Steve French
Browse files

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: e2f34481 ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarEric Biggers <ebiggers@kernel.org>
Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 6de23f81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ config SMB_SERVER
	select CRYPTO_LIB_MD5
	select CRYPTO_LIB_SHA256
	select CRYPTO_LIB_SHA512
	select CRYPTO_LIB_UTILS
	select CRYPTO_CMAC
	select CRYPTO_AEAD2
	select CRYPTO_CCM
+3 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <crypto/aead.h>
#include <crypto/md5.h>
#include <crypto/sha2.h>
#include <crypto/utils.h>
#include <linux/random.h>
#include <linux/scatterlist.h>

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

	if (memcmp(ntlmv2->ntlmv2_hash, ntlmv2_rsp, CIFS_HMAC_MD5_HASH_SIZE) != 0)
	if (crypto_memneq(ntlmv2->ntlmv2_hash, ntlmv2_rsp,
			  CIFS_HMAC_MD5_HASH_SIZE))
		return -EINVAL;
	return 0;
}
+3 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
 */

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

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

	if (memcmp(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
	if (crypto_memneq(signature, signature_req, SMB2_SIGNATURE_SIZE)) {
		pr_err("bad smb2 signature\n");
		return 0;
	}