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=1796161373; b=pGulUEt9a9qglCbFcvTDPI5nZJFtSa9VBSH50j22xB60KxbrINLrIFvYb8Q2GVPQ4vWZ ras5jJu388Yz8zL0iqOCwnZ63cci2MGMYXp+hCT536nm/afz+2sqnsFwqjYghlPzTLB20 kCibeded70Af8ueP7aUEfj7GHcBZA7ZyOgHbWFCg3b85e6uFH/ZetCPF17nvsZ993vGQw r+YiPS12mZ2pTWH8q484CHJGDOGbrdEN/cXSmAgHCvSAfU4NGYf2yFBlJomJ7SjpX+lPL 4ErTojs8zlwJt5zFotZn87xvpRRILWg22uxMUOlBTLwFyTo1Kz8l7R/zH490Q3C6LxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796161373; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JCYjGLLzO/w7n8xN3tDi4lkShrHSrBi51DaZyuU5ack=; b=2kKxQFVL+3HFy/qJduHK6Mlf9C5V241yk1smsvS0yuSU6AUxJZxi6E87dFBPGXNelLna OvvyIL0F5mTLVXCofZmAsvSNoGa1mxPeBzF7TSkHpcAq3EZSYTtw8K0DEsgRKlaXMOqVa XwDOntKn6dOndkowb7QPewN+6kGSFngAjNpcxe1qFRgod6Ys4fsSkRmsKF/ZunxKL/Bj0 S2H4Vu0yBsCbcTc5+HwfZFEN0YhIp1ysVrT4dFeXoeXLuubTAG4FYy3z0WIcJKADULPGa aABYrbGjJOSFHZ5/+g0tutMloFIHAHBv8fBQbpXFBhtst+DwXhWqydoe4Dbpgk+sqDw== 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=UwnYbZcv; 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 73FB7606A327 for ; Tue, 1 Dec 2026 21:42:53 +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=UwnYbZcv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2187C1F00898 for ; Tue, 1 Dec 2026 21:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796161373; bh=JCYjGLLzO/w7n8xN3tDi4lkShrHSrBi51DaZyuU5ack=; h=From:To:Subject:Date:In-Reply-To:References; b=UwnYbZcv6lMDFsW0OBqdARRNoFDXwMv1dPrPYCXG5h1+vGhMqefkMMzwWh0aX8JK+ Ao7RDvdKKhTWHGglulatNjSkaJWJqWapK09tbyeTjZToAG06iozEhZgA+wUFRN+cRH fc/T5WXpoWLf0FpqbjU3L2ktcltpQxtmf239O8A5ZF0w/qOcyWuRGmVKZ9qLr7pGUl 4KqkzWQuLeBi3e7vxsiPvuWNC+dX/xNV8TYF6nRn0J8ZR/Z5t4XiIcB47wwVaLz7CO uGQAQMdZo1qYSjtAeYH7sbYnarMwX445rKi4FBtQegi25f1mzG4AFEoNMvNZ+zGtxc HlgFSYAvzaHCQ== From: Chuck Lever To: Subject: [PATCH v1 8/9] tlshd: Link a configured keyring only when root owns it Date: Tue, 1 Dec 2026 16:42:47 -0500 Message-ID: <20261201214249.296675-9-cel@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261201214249.296675-1-cel@kernel.org> References: <20261201214249.296675-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_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 --- 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