* [PATCH 1/8] tlshd: Unlink keyrings that a reload removes from the configuration
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 2/8] tlshd: Escape client PSK identities before logging them Chuck Lever
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd(8) documents that SIGHUP and SIGUSR1 update keyring
associations. tlshd_config_apply() only adds links to the session
keyring, and nothing removes them. A keyring that the administrator
deletes from the keyrings option stays linked until tlshd restarts.
The server PSK callbacks still search it, so a peer whose PSK is held
only in that keyring continues to authenticate.
Record the serial numbers of the keyrings that each apply links. Link
the keyrings in the new configuration first, then unlink the recorded
serials that are no longer in the set, so that a keyring present in
both configurations stays linked throughout.
Also correct tlshd.conf(5), which states that changes to the file
take effect only after a restart.
Fixes: b2d4d2f144c2 ("tlshd: Add a SIGHUP handler")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
man/man5/tlshd.conf.5 | 8 +++---
src/tlshd/config.c | 58 ++++++++++++++++++++++++++++++++++++++++---
src/tlshd/keyring.c | 7 +++---
src/tlshd/tlshd.h | 2 +-
4 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/man/man5/tlshd.conf.5 b/man/man5/tlshd.conf.5
index d946496ad7c4..92b5d9dcd19d 100644
--- a/man/man5/tlshd.conf.5
+++ b/man/man5/tlshd.conf.5
@@ -39,10 +39,10 @@ The configuration file is considered a trusted source of information.
.P
The
.B tlshd
-program reads this file once when it is launched.
-Thus changes made in this file take effect only when the
-.B tlshd
-program is restarted.
+program reads this file when it is launched, and reads it again
+when it receives SIGHUP or SIGUSR1.
+See
+.BR tlshd (8).
If this file does not exist, the
.B tlshd
program exits immediately.
diff --git a/src/tlshd/config.c b/src/tlshd/config.c
index e62830daec63..79ec46165aa3 100644
--- a/src/tlshd/config.c
+++ b/src/tlshd/config.c
@@ -73,17 +73,57 @@ static GKeyFile *tlshd_configuration;
*/
static gchar *tlshd_config_pathname;
+/**
+ * @var GArray *tlshd_session_keyrings
+ * Serial numbers of the configured keyrings on the session keyring
+ */
+static GArray *tlshd_session_keyrings;
+
+/**
+ * @brief Unlink keyrings that the configuration no longer lists
+ * @param[in] old serial numbers linked by the previous apply
+ * @param[in] new serial numbers linked by the current apply
+ */
+static void tlshd_config_unlink_keyrings(const GArray *old, const GArray *new)
+{
+ guint i, j;
+
+ for (i = 0; i < old->len; i++) {
+ key_serial_t serial = g_array_index(old, key_serial_t, i);
+
+ for (j = 0; j < new->len; j++)
+ if (g_array_index(new, key_serial_t, j) == serial)
+ break;
+ if (j < new->len)
+ continue;
+
+ /*
+ * ENOENT: linking a new keyring with the same description
+ * has already displaced this one.
+ */
+ if (keyctl_unlink(serial, KEY_SPEC_SESSION_KEYRING) < 0 &&
+ errno != ENOENT)
+ tlshd_log_error("Failed to unlink keyring %x: %s",
+ serial, strerror(errno));
+ else
+ tlshd_log_debug("Keyring %x unlinked from our session keyring.",
+ serial);
+ }
+}
+
/**
* @brief Apply settings from the current configuration
*
- * Updates debug levels and links keyrings based on the current
+ * Updates debug levels and keyring links based on the current
* tlshd_configuration. Called after loading or reloading the
* configuration file.
*/
static void tlshd_config_apply(void)
{
+ key_serial_t serial;
gchar **keyrings;
gsize i, length;
+ GArray *linked;
gint tmp;
/*
@@ -100,6 +140,7 @@ static void tlshd_config_apply(void)
"delay_done", NULL);
tlshd_delay_done = tmp > 0 ? (unsigned int)tmp : 0;
+ linked = g_array_new(FALSE, FALSE, sizeof(key_serial_t));
keyrings = g_key_file_get_string_list(tlshd_configuration,
"authenticate",
"keyrings", &length, NULL);
@@ -111,11 +152,18 @@ static void tlshd_config_apply(void)
continue;
if (!strcmp(keyrings[i], ".nfsd"))
continue;
- tlshd_keyring_link(keyrings[i],
- KEY_SPEC_SESSION_KEYRING);
+ serial = tlshd_keyring_link(keyrings[i],
+ KEY_SPEC_SESSION_KEYRING);
+ if (serial != -1)
+ g_array_append_val(linked, serial);
}
g_strfreev(keyrings);
}
+ if (tlshd_session_keyrings) {
+ tlshd_config_unlink_keyrings(tlshd_session_keyrings, linked);
+ g_array_free(tlshd_session_keyrings, TRUE);
+ }
+ tlshd_session_keyrings = linked;
/*
* The ".nvme" keyring cannot be disabled. The ".nfs" and ".nfsd"
* keyrings are linked by each handshake child that needs them.
@@ -293,6 +341,10 @@ bool tlshd_config_init(const gchar *pathname)
*/
void tlshd_config_shutdown(void)
{
+ if (tlshd_session_keyrings) {
+ g_array_free(tlshd_session_keyrings, TRUE);
+ tlshd_session_keyrings = NULL;
+ }
g_key_file_free(tlshd_configuration);
g_free(tlshd_config_pathname);
tlshd_config_pathname = NULL;
diff --git a/src/tlshd/keyring.c b/src/tlshd/keyring.c
index 570540b43eeb..1055c746e597 100644
--- a/src/tlshd/keyring.c
+++ b/src/tlshd/keyring.c
@@ -282,10 +282,9 @@ static bool tlshd_keyring_owned_by_root(key_serial_t serial)
* shares the session. A link into the process keyring is private to
* the calling process and is released when the process exits.
*
- * @retval 0 Success
- * @retval -1 Failure
+ * @returns the serial number of the linked keyring, or -1 on failure.
*/
-int tlshd_keyring_link(const char *keyring, key_serial_t dest)
+key_serial_t tlshd_keyring_link(const char *keyring, key_serial_t dest)
{
key_serial_t serial;
long ret;
@@ -316,5 +315,5 @@ int tlshd_keyring_link(const char *keyring, key_serial_t dest)
tlshd_log_debug("Keyring '%s' linked into our %s keyring.\n", keyring,
dest == KEY_SPEC_SESSION_KEYRING ? "session" : "process");
- return 0;
+ return serial;
}
diff --git a/src/tlshd/tlshd.h b/src/tlshd/tlshd.h
index bc86bcebd05b..1a8a4419d4c2 100644
--- a/src/tlshd/tlshd.h
+++ b/src/tlshd/tlshd.h
@@ -111,7 +111,7 @@ extern bool tlshd_keyring_get_certs(key_serial_t serial, gnutls_pcert_st *certs,
unsigned int *certs_len);
extern key_serial_t tlshd_keyring_create_cert(gnutls_x509_crt_t cert,
const char *peername);
-extern int tlshd_keyring_link(const char *keyring, key_serial_t dest);
+extern key_serial_t tlshd_keyring_link(const char *keyring, key_serial_t dest);
/* ktls.c */
extern unsigned int tlshd_initialize_ktls(gnutls_session_t session);
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/8] tlshd: Escape client PSK identities before logging them
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
2026-12-05 18:27 ` [PATCH 1/8] tlshd: Unlink keyrings that a reload removes from the configuration Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 3/8] tlshd: Escape the client certificate description before logging it Chuck Lever
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
The PSK identity in a ClientHello is chosen by the remote client and
arrives before any authentication. When no key matches it, both
server PSK callbacks pass the identity unmodified to syslog at
LOG_ERR in the LOG_AUTH facility. A client can embed newlines or
terminal escape sequences in the identity to add what look like
separate records to the authentication log, or to disturb a terminal
that displays the log.
Pass the identity through g_strescape() before logging it.
Fixes: 4632eb9bba64 ("tlshd: improve error logging for tlshd_server_psk_cb()")
Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/server.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 206fb9a45401..34965b0b036b 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -543,8 +543,11 @@ static int tlshd_server_psk_cb(gnutls_session_t session,
ret = tlshd_server_psk_search(TLS_DEFAULT_PSK_TYPE, username);
if (ret < 0) {
+ gchar *identity = g_strescape(username, NULL);
+
tlshd_log_error("failed to search '%s' key '%s'",
- TLS_DEFAULT_PSK_TYPE, username);
+ TLS_DEFAULT_PSK_TYPE, identity);
+ g_free(identity);
return -1;
}
@@ -731,7 +734,11 @@ static int tlshd_quic_server_psk_cb(gnutls_session_t session, const char *userna
ret = tlshd_server_psk_search(TLS_DEFAULT_PSK_TYPE, username);
if (ret < 0) {
- tlshd_log_error("key search error %d %s", errno, username);
+ int err = errno;
+ gchar *identity = g_strescape(username, NULL);
+
+ tlshd_log_error("key search error %d %s", err, identity);
+ g_free(identity);
return -1;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/8] tlshd: Escape the client certificate description before logging it
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
2026-12-05 18:27 ` [PATCH 1/8] tlshd: Unlink keyrings that a reload removes from the configuration Chuck Lever
2026-12-05 18:27 ` [PATCH 2/8] tlshd: Escape client PSK identities before logging them Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 4/8] tlshd: Limit the number of concurrent handshake processes Chuck Lever
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
When the debug loglevel is nonzero, tlshd_tls13_server_x509_handshake()
logs the one-line description of each certificate the client presented,
including certificates that failed verification. The subject and
issuer names in that description are chosen by whoever created the
certificate, and any network client can present a self-signed one. A
newline or terminal escape sequence in a name reaches the LOG_AUTH
facility unmodified, where it can look like a separate authentication
record.
Pass the description through g_strescape() before logging it. As a
side effect, non-ASCII characters in a name appear as octal escapes,
and the backslashes of RFC 4514 escaping appear doubled.
Fixes: 2f68c313c9a9 ("tlshd: Show ingress certificate on successful handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/server.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 34965b0b036b..19266054999c 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -480,7 +480,12 @@ static void tlshd_tls13_server_x509_handshake(struct tlshd_handshake_parms *parm
GNUTLS_X509_FMT_DER);
if (gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_ONELINE,
&cinfo) == 0) {
- tlshd_log_debug("Peer certificate: %s", cinfo.data);
+ gchar *desc;
+
+ desc = g_strescape((const gchar *)cinfo.data,
+ NULL);
+ tlshd_log_debug("Peer certificate: %s", desc);
+ g_free(desc);
gnutls_free(cinfo.data);
}
gnutls_x509_crt_deinit(cert);
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/8] tlshd: Limit the number of concurrent handshake processes
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
` (2 preceding siblings ...)
2026-12-05 18:27 ` [PATCH 3/8] tlshd: Escape the client certificate description before logging it Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 5/8] tlshd: Enforce the QUIC handshake timeout in the event loop Chuck Lever
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
tlshd forks a root child for every handshake notification and does not
count the children that are still running. Each connection to an
in-kernel TLS server produces one notification, so a remote host that
opens connections and then stalls accumulates children until their
handshakes time out, consuming memory and PIDs.
Run at most 256 children at a time. The kernel multicasts one
notification for each request and does not repeat it, so tlshd cannot
simply drop a notification at the limit. Count those notifications and
fork for them as running children exit. In the meantime the requests
wait on the kernel's queue, and the kernel refuses new requests once
that queue is full. A peer that stalls 256 handshakes therefore delays
all other handshakes until some of the stalled ones end.
Replace the SIG_IGN disposition of SIGCHLD with a case in the signalfd
loop that reaps children. Record the PIDs of the forked children, and
lower the count only when a recorded PID is reaped. tlshd can also
reap a child that it did not fork, such as one inherited across
exec(2). Also log a failed fork(), which tlshd currently ignores, and
keep the notification for a retry on a later event.
Fixes: a4fd25b872bd ("tlshd: Introduce infrastructure for using netlink")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/netlink.c | 121 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 102 insertions(+), 19 deletions(-)
diff --git a/src/tlshd/netlink.c b/src/tlshd/netlink.c
index a14fddc885ce..d7b8f9ba2162 100644
--- a/src/tlshd/netlink.c
+++ b/src/tlshd/netlink.c
@@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/signalfd.h>
+#include <sys/wait.h>
#include <netinet/in.h>
#include <stdbool.h>
@@ -71,7 +72,7 @@
* The event loop in tlshd_genl_dispatch() waits on two file
* descriptors:
* - Netlink socket for handshake requests from the kernel
- * - signalfd for SIGINT, SIGTERM, SIGHUP, and SIGUSR1
+ * - signalfd for SIGINT, SIGTERM, SIGHUP, SIGUSR1, and SIGCHLD
*
* Signals are delivered synchronously through signalfd rather than
* asynchronous signal handlers, ensuring that signal processing
@@ -84,8 +85,9 @@
*
* When a handshake request arrives via netlink, the parent process
* forks a child to service that request. This occurs in
- * tlshd_genl_accept_handler() at the call to fork(2). The child
- * process:
+ * tlshd_start_children() at the call to fork(2). At most
+ * TLSHD_MAX_CHILDREN children run at once; further requests wait
+ * until a child exits. The child process:
* - Closes the signalfd and unblocks signals
* - Closes the netlink socket
* - Calls tlshd_service_socket() to perform the TLS handshake
@@ -93,7 +95,7 @@
*
* The parent process:
* - Continues running the event loop
- * - Ignores SIGCHLD (children are reaped automatically)
+ * - Reaps children when SIGCHLD arrives
* - Remains responsive to new handshake requests
* - Handles configuration reload requests
*
@@ -446,6 +448,92 @@ static sigset_t tlshd_sig_poll_mask;
*/
static int tlshd_sig_poll_fd;
+/**
+ * @def TLSHD_MAX_CHILDREN
+ * @brief Maximum number of concurrent handshake processes
+ */
+#define TLSHD_MAX_CHILDREN (256)
+
+/**
+ * @def TLSHD_MAX_PENDING
+ * @brief Maximum number of notifications remembered at the child limit
+ *
+ * The kernel queues at most 50 unaccepted requests. Notifications
+ * beyond that number belong to requests it has since cancelled.
+ */
+#define TLSHD_MAX_PENDING (256)
+
+/**
+ * @var unsigned int tlshd_nr_children
+ * Number of handshake processes not yet reaped
+ */
+static unsigned int tlshd_nr_children;
+
+/**
+ * @var pid_t tlshd_child_pids
+ * PIDs of unreaped handshake processes, in the first tlshd_nr_children
+ * elements
+ */
+static pid_t tlshd_child_pids[TLSHD_MAX_CHILDREN];
+
+/**
+ * @var unsigned int tlshd_nr_pending
+ * Number of notifications for which no process has been forked
+ */
+static unsigned int tlshd_nr_pending;
+
+/**
+ * @brief Fork handshake processes for pending notifications
+ */
+static void tlshd_start_children(void)
+{
+ pid_t pid;
+
+ while (tlshd_nr_pending && tlshd_nr_children < TLSHD_MAX_CHILDREN) {
+ pid = fork();
+ if (pid < 0) {
+ tlshd_log_perror("fork");
+ return;
+ }
+ if (!pid) {
+ /* child */
+ close(tlshd_sig_poll_fd);
+ sigprocmask(SIG_UNBLOCK, &tlshd_sig_poll_mask, NULL);
+
+ tlshd_genl_sock_close(tlshd_notification_nls);
+
+ tlshd_service_socket();
+
+ tlshd_gnutls_priority_deinit();
+ tlshd_config_shutdown();
+ exit(EXIT_SUCCESS);
+ }
+ tlshd_nr_pending--;
+ tlshd_child_pids[tlshd_nr_children++] = pid;
+ }
+}
+
+/**
+ * @brief Reap handshake processes that have exited
+ */
+static void tlshd_reap_children(void)
+{
+ unsigned int i;
+ pid_t pid;
+
+ /* One SIGCHLD can report several exited children */
+ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
+ /* A child inherited across exec(2) is not counted */
+ for (i = 0; i < tlshd_nr_children; i++) {
+ if (tlshd_child_pids[i] == pid) {
+ tlshd_child_pids[i] =
+ tlshd_child_pids[--tlshd_nr_children];
+ break;
+ }
+ }
+ }
+}
+
/**
* @brief Process one netlink notification event
* @param[in] msg A netlink event to be handled
@@ -472,20 +560,8 @@ static int tlshd_genl_event_handler(struct nl_msg *msg,
HANDSHAKE_HANDLER_CLASS_TLSHD)
return NL_SKIP;
- if (!fork()) {
- /* child */
- close(tlshd_sig_poll_fd);
- sigprocmask(SIG_UNBLOCK, &tlshd_sig_poll_mask, NULL);
-
- nlmsg_free(msg);
- tlshd_genl_sock_close(tlshd_notification_nls);
-
- tlshd_service_socket();
-
- tlshd_gnutls_priority_deinit();
- tlshd_config_shutdown();
- exit(EXIT_SUCCESS);
- }
+ if (tlshd_nr_pending < TLSHD_MAX_PENDING)
+ tlshd_nr_pending++;
return NL_SKIP;
}
@@ -504,6 +580,7 @@ void tlshd_genl_dispatch(void)
sigaddset(&tlshd_sig_poll_mask, SIGTERM);
sigaddset(&tlshd_sig_poll_mask, SIGHUP);
sigaddset(&tlshd_sig_poll_mask, SIGUSR1);
+ sigaddset(&tlshd_sig_poll_mask, SIGCHLD);
err = tlshd_genl_sock_open(&tlshd_notification_nls);
if (err)
@@ -528,7 +605,8 @@ void tlshd_genl_dispatch(void)
/* Detect which optional netlink attributes the kernel supports */
tlshd_detect_kernel_caps();
- if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
+ /* An inherited SIG_IGN would reap children without notice */
+ if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
tlshd_log_perror("signal");
goto out_close;
}
@@ -580,6 +658,10 @@ void tlshd_genl_dispatch(void)
case SIGUSR1:
tlshd_config_reload();
continue;
+ case SIGCHLD:
+ tlshd_reap_children();
+ tlshd_start_children();
+ break;
default:
/* SIGINT or SIGTERM: exit */
goto out_sig;
@@ -592,6 +674,7 @@ void tlshd_genl_dispatch(void)
tlshd_log_nl_error("nl_recvmsgs", err);
break;
}
+ tlshd_start_children();
}
}
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/8] tlshd: Enforce the QUIC handshake timeout in the event loop
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
` (3 preceding siblings ...)
2026-12-05 18:27 ` [PATCH 4/8] tlshd: Limit the number of concurrent handshake processes Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 6/8] tlshd: Strip whitespace from keyring names Chuck Lever
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
The QUIC handshake timeout is a SIGEV_THREAD timer whose handler
writes conn->errcode from a separate thread.
tlshd_quic_conn_destroy() calls timer_delete() and then frees conn,
but timer_delete() does not wait for a handler that has already
started. If the timer expires as the handshake ends, the handler can
still be inside its log call while conn is freed, and the handler
then writes ETIMEDOUT into freed memory. A remote peer can aim for
that window by delaying its last message until the timeout is near.
Replace the timer with a CLOCK_MONOTONIC deadline that the handshake
loop checks, and shorten the select() timeout when less than a second
remains. A deadline that passes during the wait for a session ticket,
after the handshake has completed, no longer sets conn->errcode.
Fixes: 43a15fed2f33 ("tlshd: add support for quic handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/quic.c | 84 ++++++++++++++++++++---------------------------
src/tlshd/tlshd.h | 2 +-
2 files changed, 36 insertions(+), 50 deletions(-)
diff --git a/src/tlshd/quic.c b/src/tlshd/quic.c
index f845b21540f6..801a7d777a94 100644
--- a/src/tlshd/quic.c
+++ b/src/tlshd/quic.c
@@ -36,54 +36,37 @@
#ifdef HAVE_GNUTLS_QUIC
/**
- * @brief Callback to handle a timer expiry
- * @param[in,out] arg user data
- */
-static void quic_timer_handler(union sigval arg)
-{
- struct tlshd_quic_conn *conn = arg.sival_ptr;
-
- tlshd_log_error("conn timeout error %d", ETIMEDOUT);
- conn->errcode = ETIMEDOUT;
-}
-
-/**
- * @brief Set a handshake timer
+ * @brief Set the handshake deadline
* @param[in,out] conn QUIC handshake context
*
- * @retval 0 Timer configured successfully
- * @retval -1 Failed to configure timer
+ * A timeout of zero leaves the handshake without a deadline.
*/
-static int quic_conn_setup_timer(struct tlshd_quic_conn *conn)
+static void quic_conn_set_deadline(struct tlshd_quic_conn *conn)
{
- uint64_t msec = conn->parms->timeout_ms;
- struct itimerspec its = {};
- struct sigevent sev = {};
+ gint64 msec = conn->parms->timeout_ms;
- sev.sigev_notify = SIGEV_THREAD;
- sev.sigev_notify_function = quic_timer_handler;
- sev.sigev_value.sival_ptr = conn;
- if (timer_create(CLOCK_REALTIME, &sev, &conn->timer)) {
- tlshd_log_error("timer creation error %d", errno);
- return -1;
- }
-
- its.it_value.tv_sec = msec / 1000;
- its.it_value.tv_nsec = (msec % 1000) * 1000000;
- if (timer_settime(conn->timer, 0, &its, NULL)) {
- tlshd_log_error("timer setup error %d", errno);
- return -1;
- }
- return 0;
+ if (msec)
+ conn->deadline = g_get_monotonic_time() + msec * 1000;
}
/**
- * @brief Delete a handshake timer
- * @param[in,out] conn QUIC handshake context
+ * @brief Compute how long to wait for the next handshake message
+ * @param[in] conn QUIC handshake context
+ * @param[out] tv One second, or less if the deadline is nearer
*/
-static void quic_conn_delete_timer(struct tlshd_quic_conn *conn)
+static void quic_conn_wait_time(const struct tlshd_quic_conn *conn,
+ struct timeval *tv)
{
- timer_delete(conn->timer);
+ gint64 usec = G_USEC_PER_SEC;
+
+ if (conn->deadline) {
+ /* CLAMP() evaluates its arguments more than once */
+ gint64 left = conn->deadline - g_get_monotonic_time();
+
+ usec = CLAMP(left, 0, G_USEC_PER_SEC);
+ }
+ tv->tv_sec = usec / G_USEC_PER_SEC;
+ tv->tv_usec = usec % G_USEC_PER_SEC;
}
/**
@@ -537,13 +520,21 @@ static int quic_handshake_recvmsg(int sockfd, struct tlshd_quic_msg *msg)
/**
* @brief Predicate: Has the QUIC handshake completed
- * @param[in] conn QUIC handshake context
+ * @param[in,out] conn QUIC handshake context
*
- * @retval true The handshake completed
- * @retval false The handshake has not completed
+ * Sets conn->errcode to ETIMEDOUT if the deadline has passed on an
+ * unfinished handshake.
+ *
+ * @retval true The handshake completed or failed
+ * @retval false The handshake is still in progress
*/
-static bool quic_handshake_completed(const struct tlshd_quic_conn *conn)
+static bool quic_handshake_completed(struct tlshd_quic_conn *conn)
{
+ if (!conn->completed && !conn->errcode && conn->deadline &&
+ g_get_monotonic_time() >= conn->deadline) {
+ tlshd_log_error("conn timeout error %d", ETIMEDOUT);
+ conn->errcode = ETIMEDOUT;
+ }
return conn->completed || conn->errcode;
}
@@ -613,10 +604,7 @@ int tlshd_quic_conn_create(struct tlshd_quic_conn **conn_p, struct tlshd_handsha
goto err;
}
- if (quic_conn_setup_timer(conn)) {
- ret = -errno;
- goto err;
- }
+ quic_conn_set_deadline(conn);
*conn_p = conn;
return 0;
@@ -639,7 +627,6 @@ void tlshd_quic_conn_destroy(struct tlshd_quic_conn *conn)
msg = conn->send_list;
}
- quic_conn_delete_timer(conn);
gnutls_deinit(conn->session);
free(conn);
}
@@ -775,8 +762,7 @@ void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)
/* select() modifies readfds and tv on return */
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
- tv.tv_sec = 1;
- tv.tv_usec = 0;
+ quic_conn_wait_time(conn, &tv);
ret = select(sockfd + 1, &readfds, NULL, NULL, &tv);
if (ret < 0) {
conn->errcode = errno;
diff --git a/src/tlshd/tlshd.h b/src/tlshd/tlshd.h
index 1a8a4419d4c2..28c0c44f3bf1 100644
--- a/src/tlshd/tlshd.h
+++ b/src/tlshd/tlshd.h
@@ -231,7 +231,7 @@ struct tlshd_quic_conn {
uint8_t cert_req:2;
uint8_t is_serv:1;
uint32_t errcode;
- timer_t timer;
+ gint64 deadline; /* g_get_monotonic_time() units, 0 if none */
struct tlshd_quic_msg *send_list;
struct tlshd_quic_msg *send_last;
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 6/8] tlshd: Strip whitespace from keyring names
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
` (4 preceding siblings ...)
2026-12-05 18:27 ` [PATCH 5/8] tlshd: Enforce the QUIC handshake timeout in the event loop Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 7/8] tlshd: Escape certificate names before logging tag filter results Chuck Lever
2026-12-05 18:27 ` [PATCH 8/8] tlshd: Skip the session ticket after a failed QUIC handshake Chuck Lever
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
GKeyFile does not strip the whitespace around a list separator, so
"keyrings=a; b" yields the name " b". The lookup of " b" fails and
tlshd does not link keyring "b". A reload after an edit that only adds
the space also unlinks a previously linked "b".
Strip each name before using it, as is already done for the
dane.resolver list.
Fixes: 58741f474fb5 ("tlshd: add 'keyrings' configuration option")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/config.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/tlshd/config.c b/src/tlshd/config.c
index 79ec46165aa3..1cfcb8283799 100644
--- a/src/tlshd/config.c
+++ b/src/tlshd/config.c
@@ -146,6 +146,7 @@ static void tlshd_config_apply(void)
"keyrings", &length, NULL);
if (keyrings) {
for (i = 0; i < length; i++) {
+ g_strstrip(keyrings[i]);
if (!strcmp(keyrings[i], ".nvme"))
continue;
if (!strcmp(keyrings[i], ".nfs"))
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 7/8] tlshd: Escape certificate names before logging tag filter results
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
` (5 preceding siblings ...)
2026-12-05 18:27 ` [PATCH 6/8] tlshd: Strip whitespace from keyring names Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
2026-12-05 18:27 ` [PATCH 8/8] tlshd: Skip the session ticket after a failed QUIC handshake Chuck Lever
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
When the debug loglevel is nonzero, the x.509 issuer and subject tag
filters log the issuer or subject DN of the peer's certificate.
Whoever created the certificate chose the names in both DNs.
gnutls_x509_crt_get_dn3() and gnutls_x509_crt_get_issuer_dn3() can
return a DN that contains a raw newline or escape character, and such
a DN passes the UTF-8 check. A newline logged this way can make part
of a name look like a separate log record.
Pass each DN through g_strescape() before logging it. The filters
still match against the unescaped DN. Non-ASCII characters in a logged
name now appear as octal escapes, and the backslashes of RFC 4514
escaping appear doubled.
Fixes: f11519ab4a45 ("tlshd: Match ingress certificates with defined TLS session tags")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/tags.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/tlshd/tags.c b/src/tlshd/tags.c
index 1863f4b34510..ed83062433b1 100644
--- a/src/tlshd/tags.c
+++ b/src/tlshd/tags.c
@@ -1505,6 +1505,7 @@ tlshd_tags_filter_type_match_x509_tbs_issuer(struct tlshd_tags_filter *filter,
gnutls_x509_crt_t peercert;
gnutls_datum_t dn;
bool res = false;
+ gchar *desc;
int ret;
if (!tlshd_tags_get_peer_x509_cert(session, &peercert))
@@ -1530,10 +1531,12 @@ tlshd_tags_filter_type_match_x509_tbs_issuer(struct tlshd_tags_filter *filter,
(const gchar *)dn.data, NULL);
#endif
+ desc = g_strescape((const gchar *)dn.data, NULL);
tlshd_log_debug("Filter '%s' %s issuer '%s'",
filter->fi_name,
res ? "matched" : "did not match",
- dn.data);
+ desc);
+ g_free(desc);
gnutls_free(dn.data);
deinit:
gnutls_x509_crt_deinit(peercert);
@@ -1627,6 +1630,7 @@ tlshd_tags_filter_type_match_x509_tbs_subject(struct tlshd_tags_filter *filter,
gnutls_x509_crt_t peercert;
gnutls_datum_t dn;
bool res = false;
+ gchar *desc;
int ret;
if (!tlshd_tags_get_peer_x509_cert(session, &peercert))
@@ -1652,10 +1656,12 @@ tlshd_tags_filter_type_match_x509_tbs_subject(struct tlshd_tags_filter *filter,
(const gchar *)dn.data, NULL);
#endif
+ desc = g_strescape((const gchar *)dn.data, NULL);
tlshd_log_debug("Filter '%s' %s subject '%s'",
filter->fi_name,
res ? "matched" : "did not match",
- dn.data);
+ desc);
+ g_free(desc);
gnutls_free(dn.data);
deinit:
gnutls_x509_crt_deinit(peercert);
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 8/8] tlshd: Skip the session ticket after a failed QUIC handshake
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
` (6 preceding siblings ...)
2026-12-05 18:27 ` [PATCH 7/8] tlshd: Escape certificate names before logging tag filter results Chuck Lever
@ 2026-12-05 18:27 ` Chuck Lever
7 siblings, 0 replies; 9+ messages in thread
From: Chuck Lever @ 2026-12-05 18:27 UTC (permalink / raw)
To: kernel-tls-handshake
The handshake loop in tlshd_quic_start_handshake() exits on completion
and also when conn->errcode has been set. After a failure, a client
configured to receive a session ticket still waits for one, which
delays the report of the failure. An error while fetching or
processing a ticket also replaces the original value of
conn->errcode.
Return from tlshd_quic_recv_session_ticket() at once when the
handshake has failed.
Fixes: 22e0f96d059f ("tlshd: receive new session ticket msg after completing quic handshake")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
src/tlshd/quic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tlshd/quic.c b/src/tlshd/quic.c
index 801a7d777a94..454c68855d2e 100644
--- a/src/tlshd/quic.c
+++ b/src/tlshd/quic.c
@@ -677,7 +677,7 @@ static void tlshd_quic_recv_session_ticket(struct tlshd_quic_conn *conn)
unsigned int len;
size_t size;
- if (conn->is_serv || !conn->recv_ticket)
+ if (conn->errcode || conn->is_serv || !conn->recv_ticket)
return;
for (i = 0; i < 10 * conn->recv_ticket; i++) { /* wait and try for conn->recv_ticket secs */
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread