All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: <kernel-tls-handshake@lists.linux.dev>
Subject: [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching
Date: Tue,  1 Dec 2026 16:42:48 -0500	[thread overview]
Message-ID: <20261201214249.296675-10-cel@kernel.org> (raw)
In-Reply-To: <20261201214249.296675-1-cel@kernel.org>

The subject and issuer filters pass the DN that
gnutls_x509_crt_get_dn3() renders straight to
g_pattern_spec_match(), which takes a UTF-8 string. GnuTLS copies
the bytes of a UTF8String or PrintableString attribute through
without validating them, so a certificate can present a DN that ends
in the lead byte of a multibyte sequence.

GLib advances through the string by the length that each lead byte
declares. For a pattern with wildcards at both ends, such as
"*,OU=Example,*", g_utf8_next_char() steps over the terminating NUL
and the matcher reads past the end of the DN buffer. For a pattern
whose last wildcard is nearer the end, such as "CN=*,O=Example",
g_pattern_spec_match() first reverses the DN with
g_utf8_strreverse(). That function fails an assertion and aborts the
process, or, in a GLib built with G_DISABLE_ASSERT, writes up to five
bytes before the start of its result buffer.

Treat a DN that is not valid UTF-8 as not matching the filter.

Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined TLS session tags")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
 src/tlshd/tags.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/tlshd/tags.c b/src/tlshd/tags.c
index cd0004fce4f8..1863f4b34510 100644
--- a/src/tlshd/tags.c
+++ b/src/tlshd/tags.c
@@ -1515,6 +1515,12 @@ tlshd_tags_filter_type_match_x509_tbs_issuer(struct tlshd_tags_filter *filter,
 		tlshd_log_gnutls_error(ret);
 		goto deinit;
 	}
+	if (!g_utf8_validate((const gchar *)dn.data, dn.size, NULL)) {
+		tlshd_log_debug("Filter '%s' did not match: issuer is not valid UTF-8",
+				filter->fi_name);
+		gnutls_free(dn.data);
+		goto deinit;
+	}
 
 #ifdef HAVE_GLIB_G_PATTERN_SPEC_MATCH
 	res = g_pattern_spec_match(filter->fi_pattern_spec, dn.size,
@@ -1631,6 +1637,12 @@ tlshd_tags_filter_type_match_x509_tbs_subject(struct tlshd_tags_filter *filter,
 		tlshd_log_gnutls_error(ret);
 		goto deinit;
 	}
+	if (!g_utf8_validate((const gchar *)dn.data, dn.size, NULL)) {
+		tlshd_log_debug("Filter '%s' did not match: subject is not valid UTF-8",
+				filter->fi_name);
+		gnutls_free(dn.data);
+		goto deinit;
+	}
 
 #ifdef HAVE_GLIB_G_PATTERN_SPEC_MATCH
 	res = g_pattern_spec_match(filter->fi_pattern_spec, dn.size,
-- 
2.56.0


  parent reply	other threads:[~2026-12-01 21:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
2026-12-01 21:42 ` [PATCH v1 1/9] tlshd: Require the clientAuth key purpose on client certificates Chuck Lever
2026-12-02  0:38   ` Alistair
2026-12-01 21:42 ` [PATCH v1 2/9] tlshd: Require the serverAuth key purpose on server certificates Chuck Lever
2026-12-02  0:40   ` Alistair
2026-12-01 21:42 ` [PATCH v1 3/9] tlshd: Fail the handshake when a configured trust store is missing Chuck Lever
2026-12-02  0:42   ` Alistair
2026-12-01 21:42 ` [PATCH v1 4/9] tlshd: Accept only "psk" keys in the QUIC server PSK callback Chuck Lever
2026-12-02  0:46   ` Alistair
2026-12-01 21:42 ` [PATCH v1 5/9] tlshd: Match session tags only after the client certificate verifies Chuck Lever
2026-12-02  0:48   ` Alistair
2026-12-01 21:42 ` [PATCH v1 6/9] tlshd: Fix the direction of the certificate validity filters Chuck Lever
2026-12-02  0:59   ` Alistair
2026-12-01 21:42 ` [PATCH v1 7/9] tlshd: Re-arm select() on each pass of the QUIC handshake loop Chuck Lever
2026-12-02  1:02   ` Alistair
2026-12-01 21:42 ` [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it Chuck Lever
2026-12-02  1:03   ` Alistair
2026-12-01 21:42 ` Chuck Lever [this message]
2026-12-02  1:04   ` [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Alistair

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=20261201214249.296675-10-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=kernel-tls-handshake@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.