]> git.hungrycats.org Git - linux/commitdiff
SUNRPC: Copy the deferred RPC Call from the head buffer
authorChuck Lever <cel@kernel.org>
Wed, 2 Sep 2026 13:31:01 +0000 (09:31 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:07 +0000 (12:06 -0500)
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.

Fixes: 260c1d1298f6 ("svc: Add transport hdr size for defer/revisit")
Cc: stable@vger.kernel.org
Reported-by: Kimi Security Team <bug-report@moonshot.ai>
Reported-by: Yilin Zhang <yilinzhang@moonshot.ai>
Link: https://patch.msgid.link/20260902133101.48914-1-cel@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/sunrpc/svc_xprt.c

index 6973184ff6675211b4338fac80105894e9c8d4df..34f97009e85696efbcaeb2bf299d6fbe1779899b 100644 (file)
@@ -1173,13 +1173,8 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
 }
 
 /*
- * Save the request off for later processing. The request buffer looks
- * like this:
- *
- * <xprt-header><rpc-header><rpc-pagelist><rpc-tail>
- *
- * This code can only handle requests that consist of an xprt-header
- * and rpc-header.
+ * Save the request off for later processing. Only a Call that fits
+ * entirely in rq_arg.head[0] can be deferred.
  */
 static struct cache_deferred_req *svc_defer(struct cache_req *req)
 {
@@ -1192,8 +1187,11 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req)
                dr = rqstp->rq_deferred;
                rqstp->rq_deferred = NULL;
        } else {
-               size_t skip;
                size_t size;
+
+               if (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);
@@ -1207,9 +1205,7 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req)
                dr->daddr = rqstp->rq_daddr;
                dr->argslen = rqstp->rq_arg.len >> 2;
 
-               /* back up head to the start of the buffer and copy */
-               skip = rqstp->rq_arg.len - rqstp->rq_arg.head[0].iov_len;
-               memcpy(dr->args, rqstp->rq_arg.head[0].iov_base - skip,
+               memcpy(dr->args, rqstp->rq_arg.head[0].iov_base,
                       dr->argslen << 2);
        }
        dr->xprt_ctxt = rqstp->rq_xprt_ctxt;
@@ -1232,17 +1228,13 @@ static noinline int svc_deferred_recv(struct svc_rqst *rqstp)
 
        trace_svc_defer_recv(dr);
 
-       /* setup iov_base past transport header */
        rqstp->rq_arg.head[0].iov_base = dr->args;
-       /* The iov_len does not include the transport header bytes */
        rqstp->rq_arg.head[0].iov_len = dr->argslen << 2;
        rqstp->rq_arg.page_len = 0;
-       /* The rq_arg.len includes the transport header bytes */
        rqstp->rq_arg.len     = dr->argslen << 2;
        rqstp->rq_prot        = dr->prot;
        memcpy(&rqstp->rq_addr, &dr->addr, dr->addrlen);
        rqstp->rq_addrlen     = dr->addrlen;
-       /* Save off transport header len in case we get deferred again */
        rqstp->rq_daddr       = dr->daddr;
        rqstp->rq_respages    = rqstp->rq_pages;
        rqstp->rq_xprt_ctxt   = dr->xprt_ctxt;