All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: <kernel-tls-handshake@lists.linux.dev>
Subject: [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it
Date: Tue,  1 Dec 2026 16:42:47 -0500	[thread overview]
Message-ID: <20261201214249.296675-9-cel@kernel.org> (raw)
In-Reply-To: <20261201214249.296675-1-cel@kernel.org>

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


  parent reply	other threads:[~2026-12-01 21:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Chuck Lever [this message]
2026-12-02  1:03   ` [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it 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

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=20261201214249.296675-9-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.