From: Laveesh Bansal <laveeshb@laveeshbansal.com>
To: David Howells <dhowells@redhat.com>,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: Lukas Wunner <lukas@wunner.de>, Ignat Korchagin <ignat@linux.win>,
"David S . Miller" <davem@davemloft.net>,
Denis Kenzior <denkenz@gmail.com>,
Maximilian Stahlberg <maximilian.stahlberg@uni-bremen.de>,
keyrings@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] X.509: Accept a certificate with an empty subject
Date: Wed, 11 Nov 2026 23:42:45 -0800 [thread overview]
Message-ID: <20261112074246.99421-2-laveeshb@laveeshbansal.com> (raw)
In-Reply-To: <20261112074246.99421-1-laveeshb@laveeshbansal.com>
A certificate with an empty Subject, which RFC 5280 allows, fails to
load: add_key() returns -EBADMSG. iwd hits this with an eduroam server
certificate.
The subject is parsed with the Name rule. The ASN.1 compiler turns a
SEQUENCE OF into a loop that runs at least once, so the first RDN is
mandatory and an empty SEQUENCE runs out of data in the decoder.
Give the subject its own rule, a SEQUENCE OF a one-member CHOICE, so the
first RDN can be absent. Anything that is not a SET is still rejected.
The issuer keeps the Name rule, as RFC 5280 requires it to be non-empty.
Fixes: c26fd69fa009 ("X.509: Add a crypto key parser for binary (DER) X.509 certificates")
Cc: stable@vger.kernel.org # v3.7+
Reported-by: Maximilian Stahlberg <maximilian.stahlberg@uni-bremen.de>
Closes: https://lore.kernel.org/r/9b05b89cf296b8a6392bbe6327228c1bc2f05c49.camel@uni-bremen.de
Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---
Tested in QEMU/KVM guests on arm64 and x86_64 (cbbddb6b08cc, 7.3.0) with
KASAN, lockdep and debug lists on. Each cell is the add_key() result
before / after the patch, the same on both.
case before / after
empty Subject EBADMSG / ok
the reporter's certificate EBADMSG / ok
Subject with 1 or 4 RDNs ok / ok
empty Issuer, truncated, garbage EBADMSG / EBADMSG
malformed Subject (a member that is
not a SET, or an empty SET) EBADMSG / EBADMSG
chain: empty Subject, CA-restricted ring EBADMSG / ok
chain: empty Subject, signed by another CA EBADMSG / ENOKEY
The built-in keyring and PKCS#7 messages share this parser and now accept
such certificates too (tested on arm64). I didn't find any lookup that can
hit an empty Subject. The only one that compares Subjects is the dn:
fallback, and it would need an empty Issuer, which is still rejected.
Letting the compiler accept an empty SEQUENCE OF would need an opt-in,
since Extensions must stay non-empty. The CHOICE is that opt-in for the
subject alone; x509_akid.asn1 already uses the same shape for
GeneralNames.
crypto/asymmetric_keys/x509.asn1 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/crypto/asymmetric_keys/x509.asn1 b/crypto/asymmetric_keys/x509.asn1
index feb9573cacce..d22f7bad9721 100644
--- a/crypto/asymmetric_keys/x509.asn1
+++ b/crypto/asymmetric_keys/x509.asn1
@@ -17,7 +17,7 @@ TBSCertificate ::= SEQUENCE {
signature AlgorithmIdentifier ({ x509_note_sig_algo }),
issuer Name ({ x509_note_issuer }),
validity Validity,
- subject Name ({ x509_note_subject }),
+ subject SubjectName ({ x509_note_subject }),
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueID [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
subjectUniqueID [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
@@ -34,6 +34,12 @@ AlgorithmIdentifier ::= SEQUENCE {
Name ::= SEQUENCE OF RelativeDistinguishedName
+-- RFC 5280 4.1.2.6 allows an empty subject. The CHOICE lets the first RDN be
+-- absent, and its COND_FAIL still rejects a member that is not a SET.
+SubjectName ::= SEQUENCE OF CHOICE {
+ rdn RelativeDistinguishedName
+}
+
RelativeDistinguishedName ::= SET OF AttributeValueAssertion
AttributeValueAssertion ::= SEQUENCE {
--
2.54.0
next prev parent reply other threads:[~2026-11-12 7:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 7:42 [PATCH 0/2] " Laveesh Bansal
2026-11-12 7:42 ` Laveesh Bansal [this message]
2026-11-12 8:09 ` [PATCH 1/2] " Eric Biggers
2026-11-12 7:42 ` [PATCH 2/2] X.509: Add KUnit tests for the certificate parser Laveesh Bansal
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=20261112074246.99421-2-laveeshb@laveeshbansal.com \
--to=laveeshb@laveeshbansal.com \
--cc=davem@davemloft.net \
--cc=denkenz@gmail.com \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@linux.win \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=maximilian.stahlberg@uni-bremen.de \
/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
all inboxes | Powered by JetHome®