SUNRPC: Fix svcxdr_init_encode's buflen calculation
authorChuck Lever <chuck.lever@oracle.com>
Thu, 1 Sep 2022 19:09:59 +0000 (15:09 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 26 Sep 2022 18:02:26 +0000 (14:02 -0400)
Commit 2825a7f90753 ("nfsd4: allow encoding across page boundaries")
added an explicit computation of the remaining length in the rq_res
XDR buffer.

The computation appears to suffer from an "off-by-one" bug. Because
buflen is too large by one page, XDR encoding can run off the end of
the send buffer by eventually trying to use the struct page address
in rq_page_end, which always contains NULL.

Fixes: bddfdbcddbe2 ("NFSD: Extract the svcxdr_init_encode() helper")
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
include/linux/sunrpc/svc.h

index 5a830b66f0592c078b4b2b0e656622be7a133fb5..0ca8a8ffb47e4a0acfea9e27d5e2595a30085fa4 100644 (file)
@@ -587,7 +587,7 @@ static inline void svcxdr_init_encode(struct svc_rqst *rqstp)
        xdr->end = resv->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
        buf->len = resv->iov_len;
        xdr->page_ptr = buf->pages - 1;
-       buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages);
+       buf->buflen = PAGE_SIZE * (rqstp->rq_page_end - buf->pages);
        buf->buflen -= rqstp->rq_auth_slack;
        xdr->rqst = NULL;
 }