diff mbox series

sunrpc: Avoid a KASAN slab-out-of-bounds bug in xdr_set_page_base()

Message ID 20210609210729.254578-1-Anna.Schumaker@Netapp.com (mailing list archive)
State New
Headers show
Series sunrpc: Avoid a KASAN slab-out-of-bounds bug in xdr_set_page_base() | expand

Commit Message

Anna Schumaker June 9, 2021, 9:07 p.m. UTC
From: Anna Schumaker <Anna.Schumaker@Netapp.com>

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>
---
 net/sunrpc/xdr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

J. Bruce Fields June 14, 2021, 11:14 p.m. UTC | #1
On Wed, Jun 09, 2021 at 05:07:29PM -0400, schumaker.anna@gmail.com wrote:
> From: Anna Schumaker <Anna.Schumaker@Netapp.com>
> 
> This seems to happen fairly easily during READ_PLUS testing on NFS v4.2.

Yep, I hit a KASAN warning here every time, and this fixes it,
thanks.--b.

> 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>
> ---
>  net/sunrpc/xdr.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
> index 3964ff74ee51..ca10ba2626f2 100644
> --- a/net/sunrpc/xdr.c
> +++ b/net/sunrpc/xdr.c
> @@ -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;
> -- 
> 2.32.0
diff mbox series

Patch

diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 3964ff74ee51..ca10ba2626f2 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -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;