SUNRPC: preserve RQ_SECURE across request deferral
Subsystems (3)
PATCH 1/1 SUNRPC: preserve RQ_SECURE across request deferral
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.
--- include/linux/sunrpc/svc.h | 1 + net/sunrpc/svc_xprt.c | 7 +++++++ 2 files changed, 8 insertions(+)
include/linux/sunrpc/svc.h +1 -0
@@ -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[];
net/sunrpc/svc_xprt.c +7 -0
@@ -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);
Signature · 1 line
2.52.0
Quoted 9 lines · Mike Snitzer
Commit
319951eba0fc("SUNRPC: Remove ->xpo_secure_port()") moved the setting ofRQ_SECUREfromsvc_recv()into each transport's ->xpo_recvfrom(). But a deferred request is replayed throughsvc_deferred_recv(), which bypasses ->xpo_recvfrom(), soRQ_SECUREis no longer recomputed for it. The replaying thread instead carries whateverRQ_SECUREvalue was left behind by the last request it processed, andsvc_defer()does not save the original value.[...]
Applied, thanks!
[1/1] SUNRPC: preserve RQ_SECURE across request deferral
commit: ed7e67821acbbf7508d816d78c5a2b062f5eaf96
Best regards,
Signature · 1 line
Chuck Lever <[email protected]>