From: Lukas Wunner <lukas@wunner.de>
To: wufan@kernel.org
Cc: keyrings@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, dhowells@redhat.com,
ignat@cloudflare.com, herbert@gondor.apana.org.au,
davem@davemloft.net, jarkko@kernel.org, zohar@linux.ibm.com,
eric.snowberg@oracle.com
Subject: Re: [PATCH v2] KEYS: X.509: Fix Basic Constraints CA flag parsing
Date: Tue, 16 Sep 2025 16:52:44 +0200 [thread overview]
Message-ID: <aMl5vAB1qmRw6eZT@wunner.de> (raw)
In-Reply-To: <20250915211550.2610-1-wufan@kernel.org>
On Mon, Sep 15, 2025 at 09:15:50PM +0000, wufan@kernel.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@kernel.org>
Reviewed-by: Lukas Wunner <lukas@wunner.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
next prev parent reply other threads:[~2025-09-16 14:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 22:53 [PATCH] KEYS: X.509: Fix Basic Constraints CA flag parsing wufan
2025-09-12 13:14 ` Lukas Wunner
2025-09-12 21:14 ` Fan Wu
2025-09-13 4:38 ` Lukas Wunner
2025-09-13 5:37 ` Fan Wu
2025-09-15 21:15 ` [PATCH v2] " wufan
2025-09-16 14:52 ` Lukas Wunner [this message]
2025-09-28 3:56 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aMl5vAB1qmRw6eZT@wunner.de \
--to=lukas@wunner.de \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=eric.snowberg@oracle.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@cloudflare.com \
--cc=jarkko@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wufan@kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).