]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
X.509: Fix validation of ASN.1 certificate header
authorLukas Wunner <lukas@wunner.de>
Thu, 14 May 2026 06:55:58 +0000 (08:55 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 May 2026 12:25:29 +0000 (20:25 +0800)
x509_load_certificate_list() seeks to enforce that a certificate starts
with 0x30 0x82 (ASN.1 SEQUENCE tag followed by a length of more than 256
and less than 65535 bytes).

But it only enforces that *either* of those two byte values are present,
instead of checking for the *conjunction* of the two values.  Fix it.

Fixes: 631cc66eb9ea ("MODSIGN: Provide module signing public keys to the kernel")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/20260508033917.B5873C2BCB0@smtp.kernel.org/
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: stable@vger.kernel.org # v3.7+
Reviewed-by: Ignat Korchagin <ignat@linux.win>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/asymmetric_keys/x509_loader.c

index a417413269989fe75858d9590c175832dd4c4ab7..0d516c77cc26ac51873d96528df6d9633970c717 100644 (file)
@@ -20,7 +20,7 @@ int x509_load_certificate_list(const u8 cert_list[],
                 */
                if (end - p < 4)
                        goto dodgy_cert;
-               if (p[0] != 0x30 &&
+               if (p[0] != 0x30 ||
                    p[1] != 0x82)
                        goto dodgy_cert;
                plen = (p[2] << 8) | p[3];