2022-06-30 20:49:49

by Chuck Lever III

[permalink] [raw]
Subject: [PATCH v2] SUNRPC: Fix READ_PLUS crasher

Looks like there are still cases when "space_left - frag1bytes" can
legitimately exceed PAGE_SIZE. Ensure that xdr->end always remains
within the current encode buffer.

Reported-by: Bruce Fields <[email protected]>
Reported-by: Zorro Lang <[email protected]>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216151
Fixes: 6c254bf3b637 ("SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer()")
Signed-off-by: Chuck Lever <[email protected]>
---
net/sunrpc/xdr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index f87a2d8f23a7..5d2b3e6979fb 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -984,7 +984,7 @@ static noinline __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
p = page_address(*xdr->page_ptr);
xdr->p = p + frag2bytes;
space_left = xdr->buf->buflen - xdr->buf->len;
- if (space_left - nbytes >= PAGE_SIZE)
+ if (space_left - frag1bytes >= PAGE_SIZE)
xdr->end = p + PAGE_SIZE;
else
xdr->end = p + space_left - frag1bytes;



2022-07-01 14:19:54

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH v2] SUNRPC: Fix READ_PLUS crasher

This also gets through my tests without a crash.--b.

On Thu, Jun 30, 2022 at 04:48:18PM -0400, Chuck Lever wrote:
> Looks like there are still cases when "space_left - frag1bytes" can
> legitimately exceed PAGE_SIZE. Ensure that xdr->end always remains
> within the current encode buffer.
>
> Reported-by: Bruce Fields <[email protected]>
> Reported-by: Zorro Lang <[email protected]>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216151
> Fixes: 6c254bf3b637 ("SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer()")
> Signed-off-by: Chuck Lever <[email protected]>
> ---
> net/sunrpc/xdr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
> index f87a2d8f23a7..5d2b3e6979fb 100644
> --- a/net/sunrpc/xdr.c
> +++ b/net/sunrpc/xdr.c
> @@ -984,7 +984,7 @@ static noinline __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
> p = page_address(*xdr->page_ptr);
> xdr->p = p + frag2bytes;
> space_left = xdr->buf->buflen - xdr->buf->len;
> - if (space_left - nbytes >= PAGE_SIZE)
> + if (space_left - frag1bytes >= PAGE_SIZE)
> xdr->end = p + PAGE_SIZE;
> else
> xdr->end = p + space_left - frag1bytes;
>

2022-07-04 07:00:45

by Zorro Lang

[permalink] [raw]
Subject: Re: [PATCH v2] SUNRPC: Fix READ_PLUS crasher

On Thu, Jun 30, 2022 at 04:48:18PM -0400, Chuck Lever wrote:
> Looks like there are still cases when "space_left - frag1bytes" can
> legitimately exceed PAGE_SIZE. Ensure that xdr->end always remains
> within the current encode buffer.
>
> Reported-by: Bruce Fields <[email protected]>
> Reported-by: Zorro Lang <[email protected]>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216151
> Fixes: 6c254bf3b637 ("SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer()")
> Signed-off-by: Chuck Lever <[email protected]>
> ---

I can't reproduce this bug by merging this patch:

FSTYP -- nfs
PLATFORM -- Linux/x86_64 ibm-xxxxx-08 5.19.0-rc4+ #1 SMP PREEMPT_DYNAMIC Sat Jul 2 09:59:50 EDT 2022
MKFS_OPTIONS -- ibm-xxxxx-xx.xxx.xxx.xxx.xxxxxx.com:/mnt/xfstests/scratch/nfs-server
MOUNT_OPTIONS -- -o vers=4.2 -o context=system_u:object_r:root_t:s0 ibm-x3650m4-08.rhts.eng.pek2.redhat.com:/mnt/xfstests/scratch/nfs-server /mnt/xfstests/scratch/nfs-client

generic/465 12s
Ran: generic/465
Passed all 1 tests

> net/sunrpc/xdr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
> index f87a2d8f23a7..5d2b3e6979fb 100644
> --- a/net/sunrpc/xdr.c
> +++ b/net/sunrpc/xdr.c
> @@ -984,7 +984,7 @@ static noinline __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
> p = page_address(*xdr->page_ptr);
> xdr->p = p + frag2bytes;
> space_left = xdr->buf->buflen - xdr->buf->len;
> - if (space_left - nbytes >= PAGE_SIZE)
> + if (space_left - frag1bytes >= PAGE_SIZE)
> xdr->end = p + PAGE_SIZE;
> else
> xdr->end = p + space_left - frag1bytes;
>
>

2022-07-04 16:18:42

by Chuck Lever III

[permalink] [raw]
Subject: Re: [PATCH v2] SUNRPC: Fix READ_PLUS crasher



> On Jul 4, 2022, at 2:55 AM, Zorro Lang <[email protected]> wrote:
>
> On Thu, Jun 30, 2022 at 04:48:18PM -0400, Chuck Lever wrote:
>> Looks like there are still cases when "space_left - frag1bytes" can
>> legitimately exceed PAGE_SIZE. Ensure that xdr->end always remains
>> within the current encode buffer.
>>
>> Reported-by: Bruce Fields <[email protected]>
>> Reported-by: Zorro Lang <[email protected]>
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216151
>> Fixes: 6c254bf3b637 ("SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer()")
>> Signed-off-by: Chuck Lever <[email protected]>
>> ---
>
> I can't reproduce this bug by merging this patch:
>
> FSTYP -- nfs
> PLATFORM -- Linux/x86_64 ibm-xxxxx-08 5.19.0-rc4+ #1 SMP PREEMPT_DYNAMIC Sat Jul 2 09:59:50 EDT 2022
> MKFS_OPTIONS -- ibm-xxxxx-xx.xxx.xxx.xxx.xxxxxx.com:/mnt/xfstests/scratch/nfs-server
> MOUNT_OPTIONS -- -o vers=4.2 -o context=system_u:object_r:root_t:s0 ibm-x3650m4-08.rhts.eng.pek2.redhat.com:/mnt/xfstests/scratch/nfs-server /mnt/xfstests/scratch/nfs-client
>
> generic/465 12s
> Ran: generic/465
> Passed all 1 tests

Thanks for testing!


>> net/sunrpc/xdr.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
>> index f87a2d8f23a7..5d2b3e6979fb 100644
>> --- a/net/sunrpc/xdr.c
>> +++ b/net/sunrpc/xdr.c
>> @@ -984,7 +984,7 @@ static noinline __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
>> p = page_address(*xdr->page_ptr);
>> xdr->p = p + frag2bytes;
>> space_left = xdr->buf->buflen - xdr->buf->len;
>> - if (space_left - nbytes >= PAGE_SIZE)
>> + if (space_left - frag1bytes >= PAGE_SIZE)
>> xdr->end = p + PAGE_SIZE;
>> else
>> xdr->end = p + space_left - frag1bytes;
>>
>>
>

--
Chuck Lever