From: Chuck Lever <cel@kernel.org>
To: Donald Hunter <donald.hunter@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Sabrina Dubroca <sd@queasysnail.net>,
Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>,
Chuck Lever <cel@kernel.org>, Jeff Layton <jlayton@kernel.org>,
NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Eric Dumazet <edumazet@kernel.org>
Cc: kernel-tls-handshake@lists.linux.dev, netdev@vger.kernel.org,
linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org
Subject: [PATCH net-next v3 08/10] SUNRPC: Copy the TLS session tags when they are available
Date: Fri, 13 Nov 2026 14:22:06 -0500 [thread overview]
Message-ID: <20261113-tls-session-tags-v3-8-91271964cdb0@kernel.org> (raw)
In-Reply-To: <20261113-tls-session-tags-v3-0-91271964cdb0@kernel.org>
When a server handshake completes successfully, tlshd might provide
a set of TLS session tags. SUNRPC can save these within the svc_xprt.
NFSD can later use them to authorize or reject operations that target
NFS exports whose allow_tags list intersects those tags.
A second handshake on the same transport would destroy the saved tags
while other workers read them. svcauth_tls_accept() refuses AUTH_TLS
on a transport that already carries a TLS session, and
svc_tcp_handshake() rechecks the session flag under XPT_BUSY to close
the race with a handshake that completes concurrently.
Signed-off-by: Chuck Lever <cel@kernel.org>
---
include/linux/sunrpc/svc_xprt.h | 7 ++++-
net/sunrpc/Kconfig | 1 +
net/sunrpc/svc_xprt.c | 11 +++++---
net/sunrpc/svcauth_unix.c | 14 +++++++++-
net/sunrpc/svcsock.c | 59 ++++++++++++++++++++++++++++++++++-------
5 files changed, 78 insertions(+), 14 deletions(-)
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index 2af222f3ea2c..e52d5d4e7941 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -9,6 +9,7 @@
#define SUNRPC_SVC_XPRT_H
#include <linux/sunrpc/svc.h>
+#include <linux/stringset.h>
struct module;
@@ -82,6 +83,7 @@ struct svc_xprt {
const struct cred *xpt_cred;
struct rpc_xprt *xpt_bc_xprt; /* NFSv4.1 backchannel */
struct rpc_xprt_switch *xpt_bc_xps; /* NFSv4.1 backchannel */
+ struct stringset xpt_handshake_tags; /* TLS session tags */
};
/* flag bits for xpt_flags */
@@ -101,7 +103,10 @@ enum {
XPT_KILL_TEMP, /* call xpo_kill_temp_xprt before closing */
XPT_CONG_CTRL, /* has congestion control */
XPT_HANDSHAKE, /* xprt requests a handshake */
- XPT_TLS_SESSION, /* transport-layer security established */
+ XPT_TLS_SESSION, /* transport-layer security established;
+ * also gates xpt_handshake_tags
+ * visibility and destruction
+ */
XPT_PEER_AUTH, /* peer has been authenticated */
XPT_PEER_VALID, /* peer has presented a filehandle that
* it has access to. It is NOT counted
diff --git a/net/sunrpc/Kconfig b/net/sunrpc/Kconfig
index e7808e5714dc..5a7250b42a24 100644
--- a/net/sunrpc/Kconfig
+++ b/net/sunrpc/Kconfig
@@ -2,6 +2,7 @@
config SUNRPC
tristate
depends on MULTIUSER
+ select STRINGSET
config SUNRPC_GSS
tristate
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 08cfe8a31189..7a8cfc7c3d75 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -170,6 +170,8 @@ static void svc_xprt_free(struct kref *kref)
struct svc_xprt *xprt =
container_of(kref, struct svc_xprt, xpt_ref);
struct module *owner = xprt->xpt_class->xcl_owner;
+
+ stringset_destroy(&xprt->xpt_handshake_tags);
if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags))
svcauth_unix_info_release(xprt);
put_cred(xprt->xpt_cred);
@@ -190,9 +192,12 @@ void svc_xprt_put(struct svc_xprt *xprt)
}
EXPORT_SYMBOL_GPL(svc_xprt_put);
-/*
- * Called by transport drivers to initialize the transport independent
- * portion of the transport instance.
+/**
+ * svc_xprt_init - initialize transport-independent fields of an xprt
+ * @net: Network namespace
+ * @xcl: Transport class
+ * @xprt: Transport to be initialized
+ * @serv: RPC service
*/
void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
struct svc_xprt *xprt, struct svc_serv *serv)
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 1380d0946401..f5ed20e267b9 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -1100,7 +1100,8 @@ struct auth_ops svcauth_null = {
*
* Return values:
* %SVC_OK: Both credential and verifier are valid
- * %SVC_DENIED: Credential or verifier is not valid
+ * %SVC_DENIED: Credential or verifier is not valid, or a TLS
+ * session already exists on this transport
* %SVC_GARBAGE: Failed to decode credential or verifier
* %SVC_CLOSE: Temporary failure
*
@@ -1138,6 +1139,17 @@ svcauth_tls_accept(struct svc_rqst *rqstp)
return SVC_DENIED;
}
+ /*
+ * AUTH_TLS initiates a handshake, and a second handshake
+ * would destroy xpt_handshake_tags while other workers read
+ * them. This test can pass before a concurrent handshake
+ * completes; svc_tcp_handshake() rechecks under XPT_BUSY.
+ */
+ if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags)) {
+ rqstp->rq_auth_stat = rpc_autherr_badcred;
+ return SVC_DENIED;
+ }
+
/* Signal that mapping to nobody uid/gid is required */
cred->cr_uid = INVALID_UID;
cred->cr_gid = INVALID_GID;
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index f21522dd51f2..96a84b51328b 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -416,10 +416,10 @@ static void svc_tcp_kill_temp_xprt(struct svc_xprt *xprt)
* @peerid: serial number of key containing the remote peer's identity
* @tags: session tags assigned by the handshake agent
*
- * If a security policy is specified as an export option, we don't
- * have a specific export here to check. So we set a "TLS session
- * is present" flag on the xprt and let an upper layer enforce local
- * security policy.
+ * No export is available here to check against a security policy
+ * specified as an export option. The callback copies the session
+ * tags, sets a "TLS session is present" flag on the xprt, and
+ * leaves enforcement of local security policy to an upper layer.
*/
static void svc_tcp_handshake_done(void *data, int status, key_serial_t peerid,
const struct stringset *tags)
@@ -428,9 +428,35 @@ static void svc_tcp_handshake_done(void *data, int status, key_serial_t peerid,
struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
if (!status) {
- if (peerid != TLS_NO_PEERID)
- set_bit(XPT_PEER_AUTH, &xprt->xpt_flags);
- set_bit(XPT_TLS_SESSION, &xprt->xpt_flags);
+ /*
+ * The tag copy can sleep. The xprt is pinned, and
+ * svc_tcp_handshake() waits for sk_handshake_done
+ * when it cannot cancel the handshake.
+ *
+ * XPT_TLS_SESSION left clear on copy failure makes
+ * svc_tcp_handshake() close the connection; a
+ * reconnect retries both the handshake and the copy.
+ */
+ if (stringset_copy(&xprt->xpt_handshake_tags, tags, GFP_KERNEL)) {
+ /*
+ * XPT_PEER_AUTH is set first so no reader
+ * observes XPT_TLS_SESSION without it:
+ * check_xprtsec_policy() would read that
+ * combination as anonymous TLS. The reverse
+ * is harmless; it reads as plaintext.
+ */
+ if (peerid != TLS_NO_PEERID)
+ set_bit(XPT_PEER_AUTH, &xprt->xpt_flags);
+ /*
+ * Order the tag stores and XPT_PEER_AUTH
+ * before XPT_TLS_SESSION. Pairs with the
+ * reader's test_bit_acquire(XPT_TLS_SESSION).
+ */
+ smp_wmb();
+ set_bit(XPT_TLS_SESSION, &xprt->xpt_flags);
+ } else {
+ pr_warn_ratelimited("svc: failed to copy TLS session tags\n");
+ }
}
clear_bit(XPT_HANDSHAKE, &xprt->xpt_flags);
complete_all(&svsk->sk_handshake_done);
@@ -441,6 +467,8 @@ static void svc_tcp_handshake_done(void *data, int status, key_serial_t peerid,
* svc_tcp_handshake - Perform a transport-layer security handshake
* @xprt: connected transport endpoint
*
+ * The handshake request is declined if the transport already
+ * carries a TLS session.
*/
static void svc_tcp_handshake(struct svc_xprt *xprt)
{
@@ -453,9 +481,21 @@ static void svc_tcp_handshake(struct svc_xprt *xprt)
};
int ret;
+ /*
+ * svcauth_tls_accept()'s XPT_TLS_SESSION test can race a
+ * handshake that completes just after it; recheck under
+ * XPT_BUSY before destroying the saved tags.
+ */
+ if (test_bit(XPT_TLS_SESSION, &xprt->xpt_flags)) {
+ clear_bit(XPT_HANDSHAKE, &xprt->xpt_flags);
+ set_bit(XPT_DATA, &xprt->xpt_flags);
+ svc_xprt_enqueue(xprt);
+ return;
+ }
+
trace_svc_tls_upcall(xprt);
- clear_bit(XPT_TLS_SESSION, &xprt->xpt_flags);
+ stringset_destroy(&xprt->xpt_handshake_tags);
init_completion(&svsk->sk_handshake_done);
/* Pin the transport across the asynchronous handshake callback. */
@@ -477,7 +517,8 @@ static void svc_tcp_handshake(struct svc_xprt *xprt)
goto out_close;
}
/* Cancellation lost to handshake_complete(): the
- * callback is in flight and should finish quickly.
+ * callback is in flight. Its tag copy can sleep in
+ * the allocator before the completion fires.
*/
wait_for_completion(&svsk->sk_handshake_done);
}
--
2.56.0
next prev parent reply other threads:[~2026-11-13 19:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:21 [PATCH net-next v3 00/10] Deliver TLS session tags to upper-layer consumers (NFSD) Chuck Lever
2026-11-13 19:21 ` [PATCH net-next v3 01/10] handshake: Add tags to "done" downcall Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 02/10] lib: Add a "stringset" data structure Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 03/10] lib: Add KUnit tests for the stringset " Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 04/10] handshake: Add a session-tags argument to the TLS done callback Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 05/10] handshake: Pick up session tags passed during the DONE downcall Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 06/10] handshake: Add a kunit test for the completion gate Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 07/10] handshake: Advertise the session-tag cap to user space Chuck Lever
2026-11-13 19:22 ` Chuck Lever [this message]
2026-11-13 19:22 ` [PATCH net-next v3 09/10] NFSD: Implement export tagging Chuck Lever
2026-11-13 19:22 ` [PATCH net-next v3 10/10] NFSD: Add allow_tags to the netlink export interface 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=20261113-tls-session-tags-v3-8-91271964cdb0@kernel.org \
--to=cel@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=axboe@kernel.dk \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@kernel.org \
--cc=hch@lst.de \
--cc=horms@kernel.org \
--cc=jlayton@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=neil@brown.name \
--cc=netdev@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=pabeni@redhat.com \
--cc=sagi@grimberg.me \
--cc=sd@queasysnail.net \
--cc=tom@talpey.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox