Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] SUNRPC: preserve RQ_SECURE across request deferral
@ 2026-10-02 13:50 Mike Snitzer
  2026-10-05 15:06 ` Chuck Lever
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Snitzer @ 2026-10-02 13:50 UTC (permalink / raw)
  To: Chuck Lever, Jeff Layton; +Cc: linux-nfs

Commit 319951eba0fc ("SUNRPC: Remove ->xpo_secure_port()") moved the
setting of RQ_SECURE from svc_recv() into each transport's
->xpo_recvfrom(). But a deferred request is replayed through
svc_deferred_recv(), which bypasses ->xpo_recvfrom(), so RQ_SECURE is
no longer recomputed for it. The replaying thread instead carries
whatever RQ_SECURE value was left behind by the last request it
processed, and svc_defer() does not save the original value.

An AUTH_SYS request from a privileged port can therefore be deferred
on an ip_map or export cache upcall and then replayed by a thread
whose RQ_SECURE is clear (e.g. a newly created nfsd thread, whose
svc_rqst is zero-allocated). nfsd_setuser_and_check_port() then
rejects it with nfserr_perm on an export that lacks "insecure".
Conversely, a request from an unprivileged port can be replayed with
a stale RQ_SECURE set and pass that check.

Deferral is most likely right after an NFS server restart, when the
auth caches are empty and every client reconnects at once: if a pool
has no idle threads, cache_wait_req() waits only one second for the
upcall before deferring. This was observed as NFSv3 clients getting
EPERM shortly after a server reboot.

Save RQ_SECURE in struct svc_deferred_req when the request is first
deferred and restore it in svc_deferred_recv(). Restoring the saved
bit, rather than recomputing it from the peer address, keeps it
correct for transports such as RDMA that set RQ_SECURE
unconditionally.

Fixes: 319951eba0fc ("SUNRPC: Remove ->xpo_secure_port()")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 include/linux/sunrpc/svc.h | 1 +
 net/sunrpc/svc_xprt.c      | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index bdff8ccb92c77..2906481644f7a 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -382,6 +382,7 @@ struct svc_deferred_req {
 	struct sockaddr_storage	daddr;	/* where reply must come from */
 	size_t			daddrlen;
 	void			*xprt_ctxt;
+	bool			secure;	/* RQ_SECURE of the original request */
 	struct cache_deferred_req handle;
 	int			argslen;
 	__be32			args[];
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 0de613b36fffc..bf5b2cdad35ea 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -1343,6 +1343,7 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req)
 		memcpy(&dr->addr, &rqstp->rq_addr, rqstp->rq_addrlen);
 		dr->addrlen = rqstp->rq_addrlen;
 		dr->daddr = rqstp->rq_daddr;
+		dr->secure = test_bit(RQ_SECURE, &rqstp->rq_flags);
 		dr->argslen = rqstp->rq_arg.len >> 2;
 
 		memcpy(dr->args, rqstp->rq_arg.head[0].iov_base,
@@ -1377,6 +1378,12 @@ static noinline int svc_deferred_recv(struct svc_rqst *rqstp)
 	rqstp->rq_addrlen     = dr->addrlen;
 	rqstp->rq_daddr       = dr->daddr;
 	rqstp->rq_xprt_ctxt   = dr->xprt_ctxt;
+	/*
+	 * ->xpo_recvfrom() is bypassed for a deferred request, so the
+	 * replaying thread's RQ_SECURE is stale from whatever request
+	 * it handled last. Restore the value computed at receive time.
+	 */
+	assign_bit(RQ_SECURE, &rqstp->rq_flags, dr->secure);
 
 	dr->xprt_ctxt = NULL;
 	svc_xprt_received(rqstp->rq_xprt);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] SUNRPC: preserve RQ_SECURE across request deferral
  2026-10-02 13:50 [PATCH] SUNRPC: preserve RQ_SECURE across request deferral Mike Snitzer
@ 2026-10-05 15:06 ` Chuck Lever
  0 siblings, 0 replies; 2+ messages in thread
From: Chuck Lever @ 2026-10-05 15:06 UTC (permalink / raw)
  To: Jeff Layton, Mike Snitzer; +Cc: linux-nfs


On Fri, 02 Oct 2026 09:50:27 -0400, Mike Snitzer wrote:
> Commit 319951eba0fc ("SUNRPC: Remove ->xpo_secure_port()") moved the
> setting of RQ_SECURE from svc_recv() into each transport's
> ->xpo_recvfrom(). But a deferred request is replayed through
> svc_deferred_recv(), which bypasses ->xpo_recvfrom(), so RQ_SECURE is
> no longer recomputed for it. The replaying thread instead carries
> whatever RQ_SECURE value was left behind by the last request it
> processed, and svc_defer() does not save the original value.
> 
> [...]

Applied, thanks!

[1/1] SUNRPC: preserve RQ_SECURE across request deferral
      commit: ed7e67821acbbf7508d816d78c5a2b062f5eaf96

Best regards,
-- 
Chuck Lever <cel@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-05 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-02 13:50 [PATCH] SUNRPC: preserve RQ_SECURE across request deferral Mike Snitzer
2026-10-05 15:06 ` Chuck Lever

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox