From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796495265; b=s1OhZ39F8XL0b5Pnm3A+5TDKQI35p12vmUZ+RfUVzR/hfxr3cp5Q3EWF4UFM8yD1cx/7 XQALtpNOtk8bMlA5SZ9ceFcdxZDrgh98k/ZfyTS9cdBHHUCsVvGqTjEncNxzg68RIchuP SPmjMaPPqJY7i5uIHQ903rxy6Ho0bvA1efrA/O7Lh9qztlHbu/w7SLQJT10xxhSJ4tLWD FrdnzkDvhK5P/kfIZNPtF86OZ6I76B0tbAFG80XhPXRCB7N1Kmwzgstytc9yg7uwabsaz pb+84COM+mi3UwK5s+fAsl8kjH8toJjmSIuFtRTXQsHNVlD7fG8R4SXjuYk9vQg4SlQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796495265; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=0mHW+c7FqhWHkYolmUkrgQyJIBqwA6/tUCNhrTML4+k=; b=HVwkxPeN/FhXFyd6cidJfvE5Ku7Gr3P4qzrDeeUoLJph/dAFOT5zkecODi8qRumZ9p5J vG+EzrrV1zDYqiP9P/jGaMDMOW9gS9DsstHTjd604lqKvCTMCuBRwYEKXwK6XAfzdecVn mFDc/VmxiR6tQSYhvwQ9yboI5MoWK8nYMY9yu17zzlP85jFXxjFbCD4XgiPTRzgZywvn7 PAxE/b/fDFR9E0Co409y6Iltsfv6mA8Df/a6KRWikeZ3JayLDBnAYQxcjj0snsyW9NywK +MIJ8js+y/Dahf6wHv7MH0hXkYDh/0vWSP6B76FcmWLt6fVaYX6DtpkSM/JbO0n2Ivw== 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="OK5AOUr/"; 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 A2BC8606A32F for ; Sat, 5 Dec 2026 18:27:45 +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=OK5AOUr/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4403B1F00936 for ; Sat, 5 Dec 2026 18:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796495265; bh=0mHW+c7FqhWHkYolmUkrgQyJIBqwA6/tUCNhrTML4+k=; h=From:To:Subject:Date:In-Reply-To:References; b=OK5AOUr/dYiaWvPKTy3GAxgd0ccIXE7cWCmaGi/ZfO8jIM7i0iLdXxe4u9FRcO7KQ Jfy7bE4NHMbzT6uL11N/8UOr2FdfmaTPUXw6wCw0paANXppwq41b4BQlhCGWDP9HQi GVlgcK2tCUEoeSEvG2k746CdPUaG7x+kU+Ik7PKKPD9A+qywZjGoLcO5tg7Mz5xGF9 3z+3zcBDHpiUy//I4CDDhA49Awnp7vneRYm4h1Vaf36l7609+0CANC09m3g+WU8YHH aLkCN0iQweJk8quwDyj5gbgsB2Rk6wM8CmFddQu+GMzTfu/uDmBO6yrk09H6tze5xM d4WsEFVhkhCCA== From: Chuck Lever To: Subject: [PATCH 1/8] tlshd: Unlink keyrings that a reload removes from the configuration Date: Sat, 5 Dec 2026 13:27:36 -0500 Message-ID: <20261205182743.79220-2-cel@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261205182743.79220-1-cel@kernel.org> References: <20261205182743.79220-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 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 --- 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