[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aMl5vAB1qmRw6eZT@wunner.de>
Date: Tue, 16 Sep 2025 16:52:44 +0200
From: Lukas Wunner <lukas@...ner.de>
To: wufan@...nel.org
Cc: keyrings@...r.kernel.org, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, dhowells@...hat.com,
ignat@...udflare.com, herbert@...dor.apana.org.au,
davem@...emloft.net, jarkko@...nel.org, zohar@...ux.ibm.com,
eric.snowberg@...cle.com
Subject: Re: [PATCH v2] KEYS: X.509: Fix Basic Constraints CA flag parsing
On Mon, Sep 15, 2025 at 09:15:50PM +0000, wufan@...nel.org wrote:
> Fix the X.509 Basic Constraints CA flag parsing to correctly handle
> the ASN.1 DER encoded structure. The parser was incorrectly treating
> the length field as the boolean value.
[...]
> Link: https://datatracker.ietf.org/doc/html/rfc5280
> Link: https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
> Fixes: 30eae2b037af ("KEYS: X.509: Parse Basic Constraints for CA")
> Signed-off-by: Fan Wu <wufan@...nel.org>
Reviewed-by: Lukas Wunner <lukas@...ner.de>
> @@ -623,8 +626,13 @@ int x509_process_extension(void *context, size_t hdrlen,
> return -EBADMSG;
> if (v[1] != vlen - 2)
> return -EBADMSG;
> - if (vlen >= 4 && v[1] != 0 && v[2] == ASN1_BOOL && v[3] == 1)
> + /* Empty SEQUENCE means CA:FALSE (default value omitted per DER) */
> + if (v[1] == 0)
> + return 0;
> + if (vlen >= 5 && v[2] == ASN1_BOOL && v[3] == 1 && v[4] == 0xFF)
> ctx->cert->pub->key_eflags |= 1 << KEY_EFLAG_CA;
> + else
> + return -EBADMSG;
> return 0;
> }
For anyone who didn't follow the discussion and/or isn't familiar
with ASN.1, the patch first checks for a well-formed "CA:FALSE",
then checks for a well-formed "CA:TRUE", finally rejects anything
else as malformed.
Thanks,
Lukas
Powered by blists - more mailing lists