]> www.infradead.org Git - users/willy/linux.git/commitdiff
sctp: Fix MAC comparison to be constant-time
authorEric Biggers <ebiggers@kernel.org>
Mon, 18 Aug 2025 20:54:23 +0000 (13:54 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 Aug 2025 02:36:25 +0000 (19:36 -0700)
To prevent timing attacks, MACs need to be compared in constant time.
Use the appropriate helper function for this.

Fixes: bbd0d59809f9 ("[SCTP]: Implement the receive and verification of AUTH chunk")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20250818205426.30222-3-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sctp/sm_make_chunk.c
net/sctp/sm_statefuns.c

index 3ead591c72fd3cb354bac266eb2d5e973af8f0d6..d099b605e44a7ff62067b8b9034b20debcabea26 100644 (file)
@@ -31,6 +31,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <crypto/hash.h>
+#include <crypto/utils.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/ip.h>
@@ -1788,7 +1789,7 @@ struct sctp_association *sctp_unpack_cookie(
                }
        }
 
-       if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
+       if (crypto_memneq(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
                *error = -SCTP_IERROR_BAD_SIG;
                goto fail;
        }
index a0524ba8d78781324a13dcbe1e1db776e267ae7a..d4d5b14b49b3f5f6d102c7b7df6e1d6ef030da67 100644 (file)
@@ -30,6 +30,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <crypto/utils.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/ip.h>
@@ -4416,7 +4417,7 @@ static enum sctp_ierror sctp_sf_authenticate(
                                 sh_key, GFP_ATOMIC);
 
        /* Discard the packet if the digests do not match */
-       if (memcmp(save_digest, digest, sig_len)) {
+       if (crypto_memneq(save_digest, digest, sig_len)) {
                kfree(save_digest);
                return SCTP_IERROR_BAD_SIG;
        }