Skip to content

Commit

Permalink
sunrpc: Avoid a KASAN slab-out-of-bounds bug in xdr_set_page_base()
Browse files Browse the repository at this point in the history
[ Upstream commit 6d1c0f3 ]

This seems to happen fairly easily during READ_PLUS testing on NFS v4.2.
I found that we could end up accessing xdr->buf->pages[pgnr] with a pgnr
greater than the number of pages in the array. So let's just return
early if we're setting base to a point at the end of the page data and
let xdr_set_tail_base() handle setting up the buffer pointers instead.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Fixes: 8d86e37 ("SUNRPC: Clean up helpers xdr_set_iov() and xdr_set_page_base()")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
amschuma-ntap authored and gregkh committed Jul 20, 2021
1 parent 7aec9f8 commit a02357d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions net/sunrpc/xdr.c
Expand Up @@ -1230,10 +1230,9 @@ static unsigned int xdr_set_page_base(struct xdr_stream *xdr,
void *kaddr;

maxlen = xdr->buf->page_len;
if (base >= maxlen) {
base = maxlen;
maxlen = 0;
} else
if (base >= maxlen)
return 0;
else
maxlen -= base;
if (len > maxlen)
len = maxlen;
Expand Down

0 comments on commit a02357d

Please sign in to comment.