From: Chuck Lever <cel@kernel.org>
To: <kernel-tls-handshake@lists.linux.dev>
Subject: [PATCH 1/8] tlshd: Unlink keyrings that a reload removes from the configuration
Date: Sat, 5 Dec 2026 13:27:36 -0500 [thread overview]
Message-ID: <20261205182743.79220-2-cel@kernel.org> (raw)
In-Reply-To: <20261205182743.79220-1-cel@kernel.org>
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
next prev parent reply other threads:[~2026-12-05 18:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 18:27 [PATCH 0/8] More security-related fixes Chuck Lever
2026-12-05 18:27 ` Chuck Lever [this message]
2026-12-05 18:27 ` [PATCH 2/8] tlshd: Escape client PSK identities before logging them Chuck Lever
2026-12-05 18:27 ` [PATCH 3/8] tlshd: Escape the client certificate description before logging it Chuck Lever
2026-12-05 18:27 ` [PATCH 4/8] tlshd: Limit the number of concurrent handshake processes Chuck Lever
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 ` [PATCH 6/8] tlshd: Strip whitespace from keyring names 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
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=20261205182743.79220-2-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.