]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb: client: Compare MACs in constant time
authorEric Biggers <ebiggers@kernel.org>
Wed, 18 Feb 2026 04:27:02 +0000 (20:27 -0800)
committerSteve French <stfrench@microsoft.com>
Wed, 4 Mar 2026 02:56:36 +0000 (20:56 -0600)
To prevent timing attacks, MAC comparisons need to be constant-time.
Replace the memcmp() with the correct function, crypto_memneq().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/smb1encrypt.c
fs/smb/client/smb2transport.c

index 0dbbce2431ff83c7b1cf68d263f2db0a2f17fd1e..bf10fdeeedcab58ecdcc7b271c28a4a91ecea6ad 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/fips.h>
 #include <crypto/md5.h>
+#include <crypto/utils.h>
 #include "cifsproto.h"
 #include "smb1proto.h"
 #include "cifs_debug.h"
@@ -131,7 +132,7 @@ int cifs_verify_signature(struct smb_rqst *rqst,
 /*     cifs_dump_mem("what we think it should be: ",
                      what_we_think_sig_should_be, 16); */
 
-       if (memcmp(server_response_sig, what_we_think_sig_should_be, 8))
+       if (crypto_memneq(server_response_sig, what_we_think_sig_should_be, 8))
                return -EACCES;
        else
                return 0;
index 8b9000a831816c8ab432834ff2c55c5372a02ab3..81be2b226e2644284b9b3b5284c95a9034ca049d 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/highmem.h>
 #include <crypto/aead.h>
 #include <crypto/sha2.h>
+#include <crypto/utils.h>
 #include "cifsglob.h"
 #include "cifsproto.h"
 #include "smb2proto.h"
@@ -617,7 +618,8 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
        if (rc)
                return rc;
 
-       if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE)) {
+       if (crypto_memneq(server_response_sig, shdr->Signature,
+                         SMB2_SIGNATURE_SIZE)) {
                cifs_dbg(VFS, "sign fail cmd 0x%x message id 0x%llx\n",
                        shdr->Command, shdr->MessageId);
                return -EACCES;