* [PATCH] ksmbd: Compare MACs in constant time
@ 2026-02-18 4:28 Eric Biggers
2026-02-18 12:50 ` Namjae Jeon
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2026-02-18 4:28 UTC (permalink / raw)
To: Namjae Jeon, Steve French, linux-cifs
Cc: Sergey Senozhatsky, Tom Talpey, Ronnie Sahlberg, linux-crypto,
Eric Biggers, stable
To prevent timing attacks, MAC comparisons need to be constant-time.
Replace the memcmp() with the correct function, crypto_memneq().
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
fs/smb/server/Kconfig | 1 +
fs/smb/server/auth.c | 4 +++-
fs/smb/server/smb2pdu.c | 5 +++--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/smb/server/Kconfig b/fs/smb/server/Kconfig
index 2775162c535c..12594879cb64 100644
--- a/fs/smb/server/Kconfig
+++ b/fs/smb/server/Kconfig
@@ -11,10 +11,11 @@ config SMB_SERVER
select CRYPTO_LIB_ARC4
select CRYPTO_LIB_DES
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
select CRYPTO_GCM
select ASN1
diff --git a/fs/smb/server/auth.c b/fs/smb/server/auth.c
index 09af55b71153..a69e8694605a 100644
--- a/fs/smb/server/auth.c
+++ b/fs/smb/server/auth.c
@@ -13,10 +13,11 @@
#include <linux/xattr.h>
#include <crypto/hash.h>
#include <crypto/aead.h>
#include <crypto/md5.h>
#include <crypto/sha2.h>
+#include <crypto/utils.h>
#include <linux/random.h>
#include <linux/scatterlist.h>
#include "auth.h"
#include "glob.h"
@@ -163,11 +164,12 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,
/* Generate the session key */
hmac_md5_usingrawkey(ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE,
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;
}
/**
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index cbb31efdbaa2..7a88cf3bd29e 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2,10 +2,11 @@
/*
* Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
+#include <crypto/utils.h>
#include <linux/inetdevice.h>
#include <net/addrconf.h>
#include <linux/syscalls.h>
#include <linux/namei.h>
#include <linux/statfs.h>
@@ -8878,11 +8879,11 @@ int smb2_check_sign_req(struct ksmbd_work *work)
iov[0].iov_len = len;
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;
}
return 1;
@@ -8966,11 +8967,11 @@ int smb3_check_sign_req(struct ksmbd_work *work)
iov[0].iov_len = len;
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;
}
return 1;
base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ksmbd: Compare MACs in constant time
2026-02-18 4:28 [PATCH] ksmbd: Compare MACs in constant time Eric Biggers
@ 2026-02-18 12:50 ` Namjae Jeon
0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-02-18 12:50 UTC (permalink / raw)
To: Eric Biggers
Cc: Steve French, linux-cifs, Sergey Senozhatsky, Tom Talpey,
Ronnie Sahlberg, linux-crypto, stable
On Wed, Feb 18, 2026 at 1:29 PM Eric Biggers <ebiggers@kernel.org> wrote:
>
> To prevent timing attacks, MAC comparisons need to be constant-time.
> Replace the memcmp() with the correct function, crypto_memneq().
>
> Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Applied it to #ksmbd-for-next-next.
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-18 12:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 4:28 [PATCH] ksmbd: Compare MACs in constant time Eric Biggers
2026-02-18 12:50 ` Namjae Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox