* [PATCH v1 0/9] Security-related fixes
@ 2026-12-01 21:42 Chuck Lever
2026-12-01 21:42 ` [PATCH v1 1/9] tlshd: Require the clientAuth key purpose on client certificates Chuck Lever
` (8 more replies)
0 siblings, 9 replies; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
Address review findings from the new Claude security review tool.
Chuck Lever (9):
tlshd: Require the clientAuth key purpose on client certificates
tlshd: Require the serverAuth key purpose on server certificates
tlshd: Fail the handshake when a configured trust store is missing
tlshd: Accept only "psk" keys in the QUIC server PSK callback
tlshd: Match session tags only after the client certificate verifies
tlshd: Fix the direction of the certificate validity filters
tlshd: Re-arm select() on each pass of the QUIC handshake loop
tlshd: Link a configured keyring only when root owns it
tlshd: Validate DN strings as UTF-8 before glob matching
src/tlshd/client.c | 14 ++++++++++++--
src/tlshd/config.c | 10 ----------
src/tlshd/keyring.c | 34 ++++++++++++++++++++++++++++++++++
src/tlshd/quic.c | 10 ++++++----
src/tlshd/server.c | 25 ++++++++++++-------------
src/tlshd/tags.c | 16 ++++++++++++++--
6 files changed, 78 insertions(+), 31 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v1 1/9] tlshd: Require the clientAuth key purpose on client certificates
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
@ 2026-12-01 21:42 ` 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
` (7 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_server_x509_verify_function() checks a client's certificate
chain with gnutls_certificate_verify_peers3(). With a NULL hostname,
that call hands GnuTLS no typed data at all, so GnuTLS does not check
the extended key usage of the end-entity certificate. A certificate
issued only for TLS server authentication passes, and tlshd reports
the peer to the kernel as authenticated. When no server trust store
is configured, the trust anchors are the system's public CAs, which
now issue serverAuth-only certificates. Any holder of such a
certificate is then accepted as an mTLS client by NFSD.
Pass GNUTLS_KP_TLS_WWW_CLIENT to gnutls_certificate_verify_peers().
GnuTLS then rejects an end-entity certificate whose extended key
usage extension omits clientAuth and anyPurpose. A certificate that
carries no extended key usage extension is still accepted, as RFC
5280 Section 4.2.1.12 permits.
Fixes: 9d1b6a30d57c ("tlshd: Basic support for ServerHello")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/server.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 10a63c2a6a63..4cb97b03c4a1 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -330,11 +330,15 @@ static int tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)
static int tlshd_server_x509_verify_function(gnutls_session_t session,
struct tlshd_handshake_parms *parms)
{
+ gnutls_typed_vdata_st data = {
+ .type = GNUTLS_DT_KEY_PURPOSE_OID,
+ .data = (void *)GNUTLS_KP_TLS_WWW_CLIENT,
+ };
const gnutls_datum_t *peercerts;
unsigned int i, status, num_peercerts;
int ret;
- ret = gnutls_certificate_verify_peers3(session, NULL, &status);
+ ret = gnutls_certificate_verify_peers(session, &data, 1, &status);
switch (ret) {
case GNUTLS_E_SUCCESS:
break;
@@ -350,10 +354,6 @@ static int tlshd_server_x509_verify_function(gnutls_session_t session,
goto certificate_error;
}
- /* To do: Examine extended key usage information here, if we want
- * to get picky. Kernel would have to tell us what to look for
- * via a netlink attribute. */
-
peercerts = gnutls_certificate_get_peers(session, &num_peercerts);
if (!peercerts || num_peercerts == 0) {
tlshd_log_debug("The peer cert list is empty.");
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 2/9] tlshd: Require the serverAuth key purpose on server certificates
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-01 21:42 ` 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
` (6 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_client_verify_peer() checks the server's certificate chain with
gnutls_certificate_verify_peers3(), which passes GnuTLS the peer's
hostname and nothing else. GnuTLS therefore does not check the
extended key usage of the end-entity certificate, and a certificate
issued only for TLS client authentication is accepted as a server
certificate for a name it covers.
Pass GNUTLS_KP_TLS_WWW_SERVER alongside the hostname. GnuTLS then
rejects an end-entity certificate whose extended key usage extension
omits serverAuth and anyPurpose. A certificate that carries no
extended key usage extension is still accepted.
Fixes: 26b539227f24 ("tlshd: Add client-side certificate verification")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/client.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/tlshd/client.c b/src/tlshd/client.c
index b85b54c77269..eb4f9eacdda0 100644
--- a/src/tlshd/client.c
+++ b/src/tlshd/client.c
@@ -368,6 +368,16 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,
static int tlshd_client_verify_peer(gnutls_session_t session,
struct tlshd_handshake_parms *parms)
{
+ gnutls_typed_vdata_st data[2] = {
+ {
+ .type = GNUTLS_DT_KEY_PURPOSE_OID,
+ .data = (void *)GNUTLS_KP_TLS_WWW_SERVER,
+ },
+ {
+ .type = GNUTLS_DT_DNS_HOSTNAME,
+ .data = (void *)parms->peername,
+ },
+ };
unsigned int status;
int ret, dane;
@@ -377,8 +387,8 @@ static int tlshd_client_verify_peer(gnutls_session_t session,
if (dane > 0)
return GNUTLS_E_SUCCESS;
- ret = gnutls_certificate_verify_peers3(session, parms->peername,
- &status);
+ ret = gnutls_certificate_verify_peers(session, data,
+ parms->peername ? 2 : 1, &status);
if (ret != GNUTLS_E_SUCCESS) {
tlshd_log_gnutls_error(ret);
return GNUTLS_E_CERTIFICATE_ERROR;
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 3/9] tlshd: Fail the handshake when a configured trust store is missing
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-01 21:42 ` [PATCH v1 2/9] tlshd: Require the serverAuth key purpose on server certificates Chuck Lever
@ 2026-12-01 21:42 ` 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
` (5 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_config_get_truststore() returns false when the configured
x509.truststore file does not exist, which is the same result it
returns when the option is unset. Both callers then load the system
trust store in its place. On the server side, a typo in the path or
a file removed after configuration turns client authentication over
to every public CA, and the only sign is a debug-level message.
tlshd_config_get_crl() treats a missing x509.crl file the same way,
so revocation checking stops without notice.
Drop the access() checks so both functions return the configured
pathname whether or not the file exists. GnuTLS then fails to load
the missing file, and the handshake fails. Log that failure on the
server side, as the client side already does. An unset option still
selects the system trust store.
Fixes: ad57063880e1 ("config: supply meaningful error for non-existing pathnames")
Fixes: 88a93dc33f41 ("tlshd: Add server-side CRL checking")
Fixes: 9ab34c1b1054 ("Add client-side CRL checking")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/config.c | 10 ----------
src/tlshd/server.c | 4 +++-
2 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/src/tlshd/config.c b/src/tlshd/config.c
index b1fdd0c0e1b2..e62830daec63 100644
--- a/src/tlshd/config.c
+++ b/src/tlshd/config.c
@@ -465,11 +465,6 @@ bool tlshd_config_get_truststore(int peer_type, char **bundle)
"x509.truststore", NULL);
if (!pathname)
return false;
- if (access(pathname, F_OK)) {
- tlshd_log_debug("tlshd cannot access \"%s\"", pathname);
- g_free(pathname);
- return false;
- }
*bundle = strdup(pathname);
g_free(pathname);
@@ -502,11 +497,6 @@ bool tlshd_config_get_crl(int peer_type, char **result)
"x509.crl", NULL);
if (!pathname)
return false;
- if (access(pathname, F_OK)) {
- tlshd_log_debug("tlshd cannot access \"%s\"", pathname);
- g_free(pathname);
- return false;
- }
*result = strdup(pathname);
g_free(pathname);
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 4cb97b03c4a1..341b047cc894 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -294,8 +294,10 @@ static int tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)
free(pathname);
} else
ret = gnutls_certificate_set_x509_system_trust(cred);
- if (ret < 0)
+ if (ret < 0) {
+ tlshd_log_gnutls_error(ret);
return ret;
+ }
tlshd_log_debug("System trust: Loaded %d certificate(s).", ret);
if (tlshd_config_get_crl(PEER_TYPE_SERVER, &pathname)) {
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 4/9] tlshd: Accept only "psk" keys in the QUIC server PSK callback
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (2 preceding siblings ...)
2026-12-01 21:42 ` [PATCH v1 3/9] tlshd: Fail the handshake when a configured trust store is missing Chuck Lever
@ 2026-12-01 21:42 ` 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
` (4 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
When no "psk" key matches the identity a QUIC client offers,
tlshd_quic_server_psk_cb() searches for a "user" key with that
description and uses its payload as the PSK. Keys of type "user" are
not provisioned as PSKs, and some of them carry public data.
nfstlskey stores each certificate as a "user" key named
"<identity>:cert", and systemd puts an "invocation_id" key in the
session keyring of every service it starts. A client that offers one
of those descriptions as its identity, with the public payload as the
key, completes the handshake, and tlshd reports the key's serial
number to the kernel as the authenticated peer.
Search only for keys of type TLS_DEFAULT_PSK_TYPE, as
tlshd_server_psk_cb() already does on the TCP path.
Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/server.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 341b047cc894..ab6d7b3b93c2 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -727,17 +727,12 @@ static int tlshd_quic_server_psk_cb(gnutls_session_t session, const char *userna
key_serial_t psk;
long ret;
- ret = tlshd_server_psk_search("psk", username);
- if (ret >= 0)
- goto found;
-
- ret = tlshd_server_psk_search("user", username);
+ ret = tlshd_server_psk_search(TLS_DEFAULT_PSK_TYPE, username);
if (ret < 0) {
tlshd_log_error("key search error %d %s", errno, username);
return -1;
}
-found:
psk = (key_serial_t)ret;
if (!tlshd_keyring_get_psk_key(psk, key)) {
tlshd_log_error("key load error %d", errno);
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 5/9] tlshd: Match session tags only after the client certificate verifies
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (3 preceding siblings ...)
2026-12-01 21:42 ` [PATCH v1 4/9] tlshd: Accept only "psk" keys in the QUIC server PSK callback Chuck Lever
@ 2026-12-01 21:42 ` 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
` (3 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_tls13_server_x509_handshake() calls tlshd_tags_match_session()
after every handshake. The server only requests a client certificate,
so a client may complete the handshake without one. Every filter then
fails to match, because there is no certificate to examine, and a tag
whose filters are all negated, or that has no filters at all, is
marked as matched. tls-session-tags(7) describes tags as the server's
recognition of a peer whose certificate is trusted, but an anonymous
client receives them.
Match tags only when the handshake succeeded and the verify function
recorded a peer ID, which it does only for a verified certificate.
Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined TLS session tags")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/server.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index ab6d7b3b93c2..206fb9a45401 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -487,7 +487,9 @@ static void tlshd_tls13_server_x509_handshake(struct tlshd_handshake_parms *parm
}
}
- tlshd_tags_match_session(session);
+ /* Assign tags only to a peer whose certificate was verified */
+ if (!parms->session_status && parms->remote_peerids->len)
+ tlshd_tags_match_session(session);
out_deinit_session:
gnutls_deinit(session);
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 6/9] tlshd: Fix the direction of the certificate validity filters
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (4 preceding siblings ...)
2026-12-01 21:42 ` [PATCH v1 5/9] tlshd: Match session tags only after the client certificate verifies Chuck Lever
@ 2026-12-01 21:42 ` 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
` (2 subsequent siblings)
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tls-session-tags(7) documents that an x509.tbs.validity.notBefore
filter matches when the certificate's activation time is equal to or
later than the threshold, and that an x509.tbs.validity.notAfter
filter matches when the expiration time is equal to or earlier than
the threshold. Both match functions compare in the opposite
direction. A notBefore filter written to admit only certificates
issued after a CA key rotation instead admits only those issued
before it, and a notAfter filter meant to admit short-lived
certificates admits only long-lived ones.
Reverse both comparisons to match the documented behavior.
Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined TLS session tags")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/tags.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/tlshd/tags.c b/src/tlshd/tags.c
index 0491ca62b0d7..cd0004fce4f8 100644
--- a/src/tlshd/tags.c
+++ b/src/tlshd/tags.c
@@ -1559,7 +1559,7 @@ tlshd_tags_filter_type_match_x509_tbs_validity_notbefore(struct tlshd_tags_filte
goto deinit;
}
- res = (filter->fi_time >= activation_time);
+ res = (activation_time >= filter->fi_time);
tlshd_log_debug("Filter '%s' %s validity.notBefore '%s'",
filter->fi_name,
@@ -1595,7 +1595,7 @@ tlshd_tags_filter_type_match_x509_tbs_validity_notafter(struct tlshd_tags_filter
goto deinit;
}
- res = (filter->fi_time <= expiration_time);
+ res = (expiration_time <= filter->fi_time);
tlshd_log_debug("Filter '%s' %s validity.notAfter '%s'",
filter->fi_name,
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 7/9] tlshd: Re-arm select() on each pass of the QUIC handshake loop
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (5 preceding siblings ...)
2026-12-01 21:42 ` [PATCH v1 6/9] tlshd: Fix the direction of the certificate validity filters Chuck Lever
@ 2026-12-01 21:42 ` 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-01 21:42 ` [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Chuck Lever
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_quic_start_handshake() initializes readfds and tv once, before
its receive loop. On Linux, select() overwrites tv with the time
remaining and clears the socket from readfds when it times out. Once
a total of one second has elapsed waiting for the peer, every later
call has an empty set and a zero timeout and returns at once. The
loop then spins on EAGAIN from recvmsg() until the handshake timer
fires or the socket fails, so a peer that stalls mid-handshake keeps
a tlshd child at 100% CPU.
Reset readfds and tv before each call to select().
Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/quic.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/tlshd/quic.c b/src/tlshd/quic.c
index 25813e7385bd..f845b21540f6 100644
--- a/src/tlshd/quic.c
+++ b/src/tlshd/quic.c
@@ -741,13 +741,10 @@ static void tlshd_quic_recv_session_ticket(struct tlshd_quic_conn *conn)
void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)
{
int ret, sockfd = conn->parms->sockfd;
- struct timeval tv = {1, 0};
struct tlshd_quic_msg *msg;
+ struct timeval tv;
fd_set readfds;
- FD_ZERO(&readfds);
- FD_SET(sockfd, &readfds);
-
if (tlshd_quic_session_configure(conn)) {
conn->errcode = EACCES;
return;
@@ -775,6 +772,11 @@ void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)
}
while (!quic_handshake_completed(conn)) {
+ /* select() modifies readfds and tv on return */
+ FD_ZERO(&readfds);
+ FD_SET(sockfd, &readfds);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
ret = select(sockfd + 1, &readfds, NULL, NULL, &tv);
if (ret < 0) {
conn->errcode = errno;
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (6 preceding siblings ...)
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-01 21:42 ` Chuck Lever
2026-12-02 1:03 ` Alistair
2026-12-01 21:42 ` [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Chuck Lever
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd_keyring_link() looks up each keyring named by the keyrings
option in [authenticate] by type and description, then links the
result into the session keyring that every handshake child shares.
find_key_by_type_and_desc() falls back to scanning /proc/keys, and
any local user can create a keyring with a chosen description and
grant others permission to link it. If tlshd's own keyrings do not
reach the administrator's keyring, the scan can return the local
user's keyring instead. The server PSK callbacks then search that
keyring for the identity a client offers, so a PSK planted there
authenticates a remote peer.
Refuse to link a keyring that uid 0 does not own. Keyrings whose
names start with '.' skip the check, because add_key() and
keyctl_join_session_keyring() refuse such names from user space. The
kernel creates .nfs with the owner of the network namespace's user
namespace as its owner, and tlshd does not always see that owner as
uid 0.
Fixes: a70f14354543 ("keyring: merge keyring lookup in tlshd_keyring_link_session()")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/keyring.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/tlshd/keyring.c b/src/tlshd/keyring.c
index dd65d0c5b178..570540b43eeb 100644
--- a/src/tlshd/keyring.c
+++ b/src/tlshd/keyring.c
@@ -245,6 +245,34 @@ out:
return serial;
}
+/**
+ * @brief Check that root owns a key
+ * @param[in] serial serial number of the key to check
+ *
+ * Any user can create a keyring with a given description, so a
+ * keyring found by name is trusted only when root owns it.
+ *
+ * @retval true The key is owned by uid 0
+ * @retval false The key is owned by another user, or the check failed
+ */
+static bool tlshd_keyring_owned_by_root(key_serial_t serial)
+{
+ unsigned long uid;
+ char *desc, *p;
+ bool ret = false;
+
+ /* The description has the form "type;uid;gid;perm;description" */
+ if (keyctl_describe_alloc(serial, &desc) < 0)
+ return false;
+ p = strchr(desc, ';');
+ if (p) {
+ uid = strtoul(p + 1, &p, 10);
+ ret = (*p == ';' && uid == 0);
+ }
+ free(desc);
+ return ret;
+}
+
/**
* @brief Link a named keyring into one of the caller's keyrings
* @param[in] keyring name of the keyring to be linked
@@ -272,6 +300,12 @@ int tlshd_keyring_link(const char *keyring, key_serial_t dest)
tlshd_log_debug("Failed to find keyring '%s'\n", keyring);
return -1;
}
+ /* User space cannot create a keyring whose name starts with '.' */
+ if (keyring[0] != '.' && !tlshd_keyring_owned_by_root(serial)) {
+ tlshd_log_error("Keyring '%s' (%lx) is not owned by root\n",
+ keyring, serial);
+ return -1;
+ }
ret = keyctl_link(serial, dest);
if (ret < 0) {
--
2.56.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching
2026-12-01 21:42 [PATCH v1 0/9] Security-related fixes Chuck Lever
` (7 preceding siblings ...)
2026-12-01 21:42 ` [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it Chuck Lever
@ 2026-12-01 21:42 ` Chuck Lever
2026-12-02 1:04 ` Alistair
8 siblings, 1 reply; 19+ messages in thread
From: Chuck Lever @ 2026-12-01 21:42 UTC (permalink / raw)
To: kernel-tls-handshake
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
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v1 1/9] tlshd: Require the clientAuth key purpose on client certificates
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:38 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_server_x509_verify_function() checks a client's certificate
> chain with gnutls_certificate_verify_peers3(). With a NULL hostname,
> that call hands GnuTLS no typed data at all, so GnuTLS does not check
> the extended key usage of the end-entity certificate. A certificate
> issued only for TLS server authentication passes, and tlshd reports
> the peer to the kernel as authenticated. When no server trust store
> is configured, the trust anchors are the system's public CAs, which
> now issue serverAuth-only certificates. Any holder of such a
> certificate is then accepted as an mTLS client by NFSD.
>
> Pass GNUTLS_KP_TLS_WWW_CLIENT to gnutls_certificate_verify_peers().
> GnuTLS then rejects an end-entity certificate whose extended key
> usage extension omits clientAuth and anyPurpose. A certificate that
> carries no extended key usage extension is still accepted, as RFC
> 5280 Section 4.2.1.12 permits.
>
> Fixes: 9d1b6a30d57c ("tlshd: Basic support for ServerHello")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/server.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/src/tlshd/server.c b/src/tlshd/server.c
> index 10a63c2a6a63..4cb97b03c4a1 100644
> --- a/src/tlshd/server.c
> +++ b/src/tlshd/server.c
> @@ -330,11 +330,15 @@ static int
> tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)
> static int tlshd_server_x509_verify_function(gnutls_session_t
> session,
> struct
> tlshd_handshake_parms *parms)
> {
> + gnutls_typed_vdata_st data = {
> + .type = GNUTLS_DT_KEY_PURPOSE_OID,
> + .data = (void *)GNUTLS_KP_TLS_WWW_CLIENT,
> + };
> const gnutls_datum_t *peercerts;
> unsigned int i, status, num_peercerts;
> int ret;
>
> - ret = gnutls_certificate_verify_peers3(session, NULL,
> &status);
> + ret = gnutls_certificate_verify_peers(session, &data, 1,
> &status);
> switch (ret) {
> case GNUTLS_E_SUCCESS:
> break;
> @@ -350,10 +354,6 @@ static int
> tlshd_server_x509_verify_function(gnutls_session_t session,
> goto certificate_error;
> }
>
> - /* To do: Examine extended key usage information here, if we
> want
> - * to get picky. Kernel would have to tell us what to look
> for
> - * via a netlink attribute. */
> -
> peercerts = gnutls_certificate_get_peers(session,
> &num_peercerts);
> if (!peercerts || num_peercerts == 0) {
> tlshd_log_debug("The peer cert list is empty.");
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 2/9] tlshd: Require the serverAuth key purpose on server certificates
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:40 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_client_verify_peer() checks the server's certificate chain with
> gnutls_certificate_verify_peers3(), which passes GnuTLS the peer's
> hostname and nothing else. GnuTLS therefore does not check the
> extended key usage of the end-entity certificate, and a certificate
> issued only for TLS client authentication is accepted as a server
> certificate for a name it covers.
>
> Pass GNUTLS_KP_TLS_WWW_SERVER alongside the hostname. GnuTLS then
> rejects an end-entity certificate whose extended key usage extension
> omits serverAuth and anyPurpose. A certificate that carries no
> extended key usage extension is still accepted.
>
> Fixes: 26b539227f24 ("tlshd: Add client-side certificate
> verification")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/client.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/src/tlshd/client.c b/src/tlshd/client.c
> index b85b54c77269..eb4f9eacdda0 100644
> --- a/src/tlshd/client.c
> +++ b/src/tlshd/client.c
> @@ -368,6 +368,16 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t
> session,
> static int tlshd_client_verify_peer(gnutls_session_t session,
> struct tlshd_handshake_parms
> *parms)
> {
> + gnutls_typed_vdata_st data[2] = {
> + {
> + .type = GNUTLS_DT_KEY_PURPOSE_OID,
> + .data = (void *)GNUTLS_KP_TLS_WWW_SERVER,
> + },
> + {
> + .type = GNUTLS_DT_DNS_HOSTNAME,
> + .data = (void *)parms->peername,
> + },
> + };
> unsigned int status;
> int ret, dane;
>
> @@ -377,8 +387,8 @@ static int
> tlshd_client_verify_peer(gnutls_session_t session,
> if (dane > 0)
> return GNUTLS_E_SUCCESS;
>
> - ret = gnutls_certificate_verify_peers3(session, parms-
> >peername,
> - &status);
> + ret = gnutls_certificate_verify_peers(session, data,
> + parms->peername ? 2 :
> 1, &status);
> if (ret != GNUTLS_E_SUCCESS) {
> tlshd_log_gnutls_error(ret);
> return GNUTLS_E_CERTIFICATE_ERROR;
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 3/9] tlshd: Fail the handshake when a configured trust store is missing
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:42 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_config_get_truststore() returns false when the configured
> x509.truststore file does not exist, which is the same result it
> returns when the option is unset. Both callers then load the system
> trust store in its place. On the server side, a typo in the path or
> a file removed after configuration turns client authentication over
> to every public CA, and the only sign is a debug-level message.
> tlshd_config_get_crl() treats a missing x509.crl file the same way,
> so revocation checking stops without notice.
>
> Drop the access() checks so both functions return the configured
> pathname whether or not the file exists. GnuTLS then fails to load
> the missing file, and the handshake fails. Log that failure on the
> server side, as the client side already does. An unset option still
> selects the system trust store.
>
> Fixes: ad57063880e1 ("config: supply meaningful error for non-
> existing pathnames")
> Fixes: 88a93dc33f41 ("tlshd: Add server-side CRL checking")
> Fixes: 9ab34c1b1054 ("Add client-side CRL checking")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/config.c | 10 ----------
> src/tlshd/server.c | 4 +++-
> 2 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/src/tlshd/config.c b/src/tlshd/config.c
> index b1fdd0c0e1b2..e62830daec63 100644
> --- a/src/tlshd/config.c
> +++ b/src/tlshd/config.c
> @@ -465,11 +465,6 @@ bool tlshd_config_get_truststore(int peer_type,
> char **bundle)
> "x509.truststore", NULL);
> if (!pathname)
> return false;
> - if (access(pathname, F_OK)) {
> - tlshd_log_debug("tlshd cannot access \"%s\"",
> pathname);
> - g_free(pathname);
> - return false;
> - }
>
> *bundle = strdup(pathname);
> g_free(pathname);
> @@ -502,11 +497,6 @@ bool tlshd_config_get_crl(int peer_type, char
> **result)
> "x509.crl", NULL);
> if (!pathname)
> return false;
> - if (access(pathname, F_OK)) {
> - tlshd_log_debug("tlshd cannot access \"%s\"",
> pathname);
> - g_free(pathname);
> - return false;
> - }
>
> *result = strdup(pathname);
> g_free(pathname);
> diff --git a/src/tlshd/server.c b/src/tlshd/server.c
> index 4cb97b03c4a1..341b047cc894 100644
> --- a/src/tlshd/server.c
> +++ b/src/tlshd/server.c
> @@ -294,8 +294,10 @@ static int
> tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)
> free(pathname);
> } else
> ret =
> gnutls_certificate_set_x509_system_trust(cred);
> - if (ret < 0)
> + if (ret < 0) {
> + tlshd_log_gnutls_error(ret);
> return ret;
> + }
> tlshd_log_debug("System trust: Loaded %d certificate(s).",
> ret);
>
> if (tlshd_config_get_crl(PEER_TYPE_SERVER, &pathname)) {
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 4/9] tlshd: Accept only "psk" keys in the QUIC server PSK callback
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:46 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> When no "psk" key matches the identity a QUIC client offers,
> tlshd_quic_server_psk_cb() searches for a "user" key with that
> description and uses its payload as the PSK. Keys of type "user" are
> not provisioned as PSKs, and some of them carry public data.
> nfstlskey stores each certificate as a "user" key named
> "<identity>:cert", and systemd puts an "invocation_id" key in the
> session keyring of every service it starts. A client that offers one
> of those descriptions as its identity, with the public payload as the
> key, completes the handshake, and tlshd reports the key's serial
> number to the kernel as the authenticated peer.
>
> Search only for keys of type TLS_DEFAULT_PSK_TYPE, as
> tlshd_server_psk_cb() already does on the TCP path.
>
> Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/server.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/src/tlshd/server.c b/src/tlshd/server.c
> index 341b047cc894..ab6d7b3b93c2 100644
> --- a/src/tlshd/server.c
> +++ b/src/tlshd/server.c
> @@ -727,17 +727,12 @@ static int
> tlshd_quic_server_psk_cb(gnutls_session_t session, const char *userna
> key_serial_t psk;
> long ret;
>
> - ret = tlshd_server_psk_search("psk", username);
> - if (ret >= 0)
> - goto found;
> -
> - ret = tlshd_server_psk_search("user", username);
> + ret = tlshd_server_psk_search(TLS_DEFAULT_PSK_TYPE,
> username);
> if (ret < 0) {
> tlshd_log_error("key search error %d %s", errno,
> username);
> return -1;
> }
>
> -found:
> psk = (key_serial_t)ret;
> if (!tlshd_keyring_get_psk_key(psk, key)) {
> tlshd_log_error("key load error %d", errno);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 5/9] tlshd: Match session tags only after the client certificate verifies
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:48 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_tls13_server_x509_handshake() calls tlshd_tags_match_session()
> after every handshake. The server only requests a client certificate,
> so a client may complete the handshake without one. Every filter then
> fails to match, because there is no certificate to examine, and a tag
> whose filters are all negated, or that has no filters at all, is
> marked as matched. tls-session-tags(7) describes tags as the server's
> recognition of a peer whose certificate is trusted, but an anonymous
> client receives them.
>
> Match tags only when the handshake succeeded and the verify function
> recorded a peer ID, which it does only for a verified certificate.
>
> Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined
> TLS session tags")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/server.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/tlshd/server.c b/src/tlshd/server.c
> index ab6d7b3b93c2..206fb9a45401 100644
> --- a/src/tlshd/server.c
> +++ b/src/tlshd/server.c
> @@ -487,7 +487,9 @@ static void
> tlshd_tls13_server_x509_handshake(struct tlshd_handshake_parms *parm
> }
> }
>
> - tlshd_tags_match_session(session);
> + /* Assign tags only to a peer whose certificate was verified
> */
> + if (!parms->session_status && parms->remote_peerids->len)
> + tlshd_tags_match_session(session);
>
> out_deinit_session:
> gnutls_deinit(session);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 6/9] tlshd: Fix the direction of the certificate validity filters
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 0:59 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tls-session-tags(7) documents that an x509.tbs.validity.notBefore
> filter matches when the certificate's activation time is equal to or
> later than the threshold, and that an x509.tbs.validity.notAfter
> filter matches when the expiration time is equal to or earlier than
> the threshold. Both match functions compare in the opposite
> direction. A notBefore filter written to admit only certificates
> issued after a CA key rotation instead admits only those issued
> before it, and a notAfter filter meant to admit short-lived
> certificates admits only long-lived ones.
>
> Reverse both comparisons to match the documented behavior.
>
> Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined
> TLS session tags")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/tags.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/tlshd/tags.c b/src/tlshd/tags.c
> index 0491ca62b0d7..cd0004fce4f8 100644
> --- a/src/tlshd/tags.c
> +++ b/src/tlshd/tags.c
> @@ -1559,7 +1559,7 @@
> tlshd_tags_filter_type_match_x509_tbs_validity_notbefore(struct
> tlshd_tags_filte
> goto deinit;
> }
>
> - res = (filter->fi_time >= activation_time);
> + res = (activation_time >= filter->fi_time);
>
> tlshd_log_debug("Filter '%s' %s validity.notBefore '%s'",
> filter->fi_name,
> @@ -1595,7 +1595,7 @@
> tlshd_tags_filter_type_match_x509_tbs_validity_notafter(struct
> tlshd_tags_filter
> goto deinit;
> }
>
> - res = (filter->fi_time <= expiration_time);
> + res = (expiration_time <= filter->fi_time);
>
> tlshd_log_debug("Filter '%s' %s validity.notAfter '%s'",
> filter->fi_name,
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 7/9] tlshd: Re-arm select() on each pass of the QUIC handshake loop
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 1:02 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
ZOn Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_quic_start_handshake() initializes readfds and tv once, before
> its receive loop. On Linux, select() overwrites tv with the time
> remaining and clears the socket from readfds when it times out. Once
> a total of one second has elapsed waiting for the peer, every later
> call has an empty set and a zero timeout and returns at once. The
> loop then spins on EAGAIN from recvmsg() until the handshake timer
> fires or the socket fails, so a peer that stalls mid-handshake keeps
> a tlshd child at 100% CPU.
>
> Reset readfds and tv before each call to select().
>
> Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/quic.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/src/tlshd/quic.c b/src/tlshd/quic.c
> index 25813e7385bd..f845b21540f6 100644
> --- a/src/tlshd/quic.c
> +++ b/src/tlshd/quic.c
> @@ -741,13 +741,10 @@ static void
> tlshd_quic_recv_session_ticket(struct tlshd_quic_conn *conn)
> void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)
> {
> int ret, sockfd = conn->parms->sockfd;
> - struct timeval tv = {1, 0};
> struct tlshd_quic_msg *msg;
> + struct timeval tv;
> fd_set readfds;
>
> - FD_ZERO(&readfds);
> - FD_SET(sockfd, &readfds);
> -
> if (tlshd_quic_session_configure(conn)) {
> conn->errcode = EACCES;
> return;
> @@ -775,6 +772,11 @@ void tlshd_quic_start_handshake(struct
> tlshd_quic_conn *conn)
> }
>
> while (!quic_handshake_completed(conn)) {
> + /* select() modifies readfds and tv on return */
> + FD_ZERO(&readfds);
> + FD_SET(sockfd, &readfds);
> + tv.tv_sec = 1;
> + tv.tv_usec = 0;
> ret = select(sockfd + 1, &readfds, NULL, NULL,
> &tv);
> if (ret < 0) {
> conn->errcode = errno;
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it
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
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 1:03 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> tlshd_keyring_link() looks up each keyring named by the keyrings
> option in [authenticate] by type and description, then links the
> result into the session keyring that every handshake child shares.
> find_key_by_type_and_desc() falls back to scanning /proc/keys, and
> any local user can create a keyring with a chosen description and
> grant others permission to link it. If tlshd's own keyrings do not
> reach the administrator's keyring, the scan can return the local
> user's keyring instead. The server PSK callbacks then search that
> keyring for the identity a client offers, so a PSK planted there
> authenticates a remote peer.
>
> Refuse to link a keyring that uid 0 does not own. Keyrings whose
> names start with '.' skip the check, because add_key() and
> keyctl_join_session_keyring() refuse such names from user space. The
> kernel creates .nfs with the owner of the network namespace's user
> namespace as its owner, and tlshd does not always see that owner as
> uid 0.
>
> Fixes: a70f14354543 ("keyring: merge keyring lookup in
> tlshd_keyring_link_session()")
> Signed-off-by: Chuck Lever <cel@kernel.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> src/tlshd/keyring.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/src/tlshd/keyring.c b/src/tlshd/keyring.c
> index dd65d0c5b178..570540b43eeb 100644
> --- a/src/tlshd/keyring.c
> +++ b/src/tlshd/keyring.c
> @@ -245,6 +245,34 @@ out:
> return serial;
> }
>
> +/**
> + * @brief Check that root owns a key
> + * @param[in] serial serial number of the key to check
> + *
> + * Any user can create a keyring with a given description, so a
> + * keyring found by name is trusted only when root owns it.
> + *
> + * @retval true The key is owned by uid 0
> + * @retval false The key is owned by another user, or the check
> failed
> + */
> +static bool tlshd_keyring_owned_by_root(key_serial_t serial)
> +{
> + unsigned long uid;
> + char *desc, *p;
> + bool ret = false;
> +
> + /* The description has the form
> "type;uid;gid;perm;description" */
> + if (keyctl_describe_alloc(serial, &desc) < 0)
> + return false;
> + p = strchr(desc, ';');
> + if (p) {
> + uid = strtoul(p + 1, &p, 10);
> + ret = (*p == ';' && uid == 0);
> + }
> + free(desc);
> + return ret;
> +}
> +
> /**
> * @brief Link a named keyring into one of the caller's keyrings
> * @param[in] keyring name of the keyring to be linked
> @@ -272,6 +300,12 @@ int tlshd_keyring_link(const char *keyring,
> key_serial_t dest)
> tlshd_log_debug("Failed to find keyring '%s'\n",
> keyring);
> return -1;
> }
> + /* User space cannot create a keyring whose name starts with
> '.' */
> + if (keyring[0] != '.' &&
> !tlshd_keyring_owned_by_root(serial)) {
> + tlshd_log_error("Keyring '%s' (%lx) is not owned by
> root\n",
> + keyring, serial);
> + return -1;
> + }
>
> ret = keyctl_link(serial, dest);
> if (ret < 0) {
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching
2026-12-01 21:42 ` [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Chuck Lever
@ 2026-12-02 1:04 ` Alistair
0 siblings, 0 replies; 19+ messages in thread
From: Alistair @ 2026-12-02 1:04 UTC (permalink / raw)
To: Chuck Lever, kernel-tls-handshake
On Tue, 2026-12-01 at 16:42 -0500, Chuck Lever wrote:
> 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>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> 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,
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2026-12-02 1:04 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v1 9/9] tlshd: Validate DN strings as UTF-8 before glob matching Chuck Lever
2026-12-02 1:04 ` Alistair
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.