SUNRPC: Copy the deferred RPC Call from the head buffer
Subsystems (3)
PATCH 1/1 SUNRPC: Copy the deferred RPC Call from the head buffer
From: Chuck Lever <[email protected]>
commit 2192a56b0686599358909c3e12e9a366f5b5d452 upstream.
svc_defer() snapshots the RPC Call for replay once a pending cache upcall resolves. It copies the Call starting (rq_arg.len - head[0].iov_len) bytes before head[0].iov_base, a back-up that once covered a transport header. No transport has had one since commit 983084b2672c ("SUNRPC: Remove svc_rqst::rq_xprt_hlen"), so the two lengths are meant to be equal.
An RPCSEC_GSS Call breaks that assumption. Unwrapping the integrity service truncates rq_arg.len by the length of the trailing checksum, and unwrapping the privacy service leaves rq_arg.len short by an amount the client sets with trailing bytes after the wrap token. Neither adjusts head[0].iov_len. Both lengths are size_t, so the subtraction underflows and the copy starts past head[0].iov_base. Every deferred integrity Call replays a shifted snapshot.
A deferred replay skips GSS verification, so a shifted snapshot runs as an authenticated Call. With the privacy service the offset is client-chosen. A forged Call placed in that window, naming another user's GSS context handle, runs under that identity.
Copy the Call from head[0].iov_base. Refuse to defer a Call whose length runs past the head buffer, so the copy cannot read out of bounds.
[doebel: 5.15 backport. In this tree the RPC Call header is parsed
with svc_getnl(), which advances rq_arg.head[0].iov_base while rq_arg.len keeps measuring from the start of the receive buffer, so len > head[0].iov_len for every Call at svc_defer() time and the upstream guard and copy-from-iov_base cannot apply; keep the skip-based snapshot that svc_deferred_recv() expects. A GSS privacy unwrap breaks the len - iov_len invariant by resetting rq_arg.len (gss_unwrap_kerberos_v2()); refuse to defer after a GSS integrity/privacy unwrap (rq_auth_slack != 0) or when len < head[0].iov_len.]
--- net/sunrpc/svc_xprt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/sunrpc/svc_xprt.c +14 -0
@@ -1224,6 +1224,20 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req) }else {size_t skip;size_t size; + +/* +* A GSS integrity/privacy unwrap can reset rq_arg.len so +* it no longer measures from the start of the receive +* buffer (see gss_unwrap_kerberos_v2()). In that state +* len - iov_len does not locate the buffer start, and a +* snapshot taken here would be replayed without GSS +* verification. Refuse to defer; the caller fails the +* request and the client retries. +*/ +if (rqstp->rq_auth_slack || + rqstp->rq_arg.len < rqstp->rq_arg.head[0 ].iov_len) +return NULL ; +/* FIXME maybe discard if size too large */ size =sizeof (struct svc_deferred_req ) + rqstp->rq_arg.len; dr =kmalloc (size,GFP_KERNEL );
Signature · 1 line
2.50.1
Quoted 2 lines
svc_defer()snapshots the RPC Call for replay once a pending cache upcall resolves.
Queued for 6.1 and 5.15, thanks.
Signature · 2 lines
Thanks, Sasha