Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796161373; b=l3vQjHFHlkECLZBZNi+LdcUKJdXtBmWp8RGS9HwEc4+7iHfg7niTMxTa1A4rZkqnXUc2 upFPj3/PRxEMRfOkSstVPqjGwx+ztmZJUhMy4AH8iUu5MX0c8MH/ZuPry69pBl0KIZpEu i/uZJ/Oeq4xOGAoPDAbQduEBtLepeIdqpiHD9+jECEqOxbo7w950zUyUazlpH+cGEFT2w Tt0LcOqi/DpRSVZpvYRK1c9iRTEc8lEWRZwX2cNjCf5h9ULx2PdIrlX5GgKlRfQkzEGJE J3GJxSK410pnn+8Yt0vqe4I9TMUtSA/I8MwgyvLobUKCPWEbYb7QuzbEw4s4gZB9MPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796161373; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=jncDEbMBNonWkFGQAaXPkyvBab3rFaHjzzA3kcwhJlY=; b=j94kwUTk3IVvfKVUYXp0KFnB+PrvXdsyyrGh9d6iAHqP+iHFMlsZPdlQsiD6YGh+lS5B hljJ8x7b2E3reXfTqam/wCgtWthtyPocTw9AEnuGWi8arMGzoedpv7bIhu/KyTQr7biTm J45YFlZKuXU4/jDfdFpJArlV1vkgAH3dSwGPP6eWhOr5M10rSPUO/AuQMf49Tih+t1IPF Y/vVmtHFZFESo00QNgd8HHj2qIkcW6HgvN7n741DBHsFPlrQTTjC/Rqw/90+vV8gcHB97 2s0jg6hMKzmaxtskDXiHsdAYIPdXRvaIxK0GF+mf+tJULXlBmsI9DxgaT6Er69lcR0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gVBY1gIO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA146606A320 for ; Tue, 1 Dec 2026 21:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gVBY1gIO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 891271F000C1 for ; Tue, 1 Dec 2026 21:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796161373; bh=jncDEbMBNonWkFGQAaXPkyvBab3rFaHjzzA3kcwhJlY=; h=From:To:Subject:Date:In-Reply-To:References; b=gVBY1gIOULz7ZGjyX/Zp50/FZ2F+V8hXqbQBWS0KJo/PYU8rUFr7dwFLo++tpqQvE odFmrR+mKIgjYnNp18stYWBtcESKExonE3SPOlYSFySteUseOvllCG09M/UwLbzfam iY6KF2BM4T3nlHEF1JNLmNx3ZuDpxQbVqepiOY+P41WboN/q96nIAUciaRcHOALOaB +CFlYiAH5AAg9eYvqYLJbQuK6ODabZFp9y++1AllSUpQmCBM7X/TgT0m0P+7Zuo6c0 4khqcH0yh0owkzgnY2jwhnA2mf83yOattEh9W3fpibfg25Z89nDNRz9xSUqDCz7ptV 3fTQ79jk47UBw== From: Chuck Lever To: Subject: [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Date: Tue, 1 Dec 2026 16:42:48 -0500 Message-ID: <20261201214249.296675-10-cel@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261201214249.296675-1-cel@kernel.org> References: <20261201214249.296675-1-cel@kernel.org> X-Mailing-List: kernel-tls-handshake@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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