All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sunrpc: fix xs_read_xdr_buf for partial pages receive
@ 2020-12-04 18:34 Dan Aloni
  2020-12-04 20:52 ` Trond Myklebust
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Aloni @ 2020-12-04 18:34 UTC (permalink / raw)
  To: linux-nfs; +Cc: Trond Myklebust

When receiving pages data, return value 'ret' when positive includes
`buf->page_base`, so we should subtract it similarly to how it is done
for `offset`.

This was discovered on the very rare cases where the server returned a
chunk of bytes that when added to the already received amount of bytes
for the pages happened to match the current `recv.len`, for example
on this case:

     buf->page_base : 258356
     actually received from socket: 1740
     ret : 260096
     want : 260096

In this case neither of the two 'if ... goto out' trigger, and we
continue to tail parsing.

Worth to mention that the ensuing EMSGSIZE from the continued execution of
`xs_read_xdr_buf` may be observed by an application due to 4 superfluous
bytes being added to the pages data.

Fixes: 277e4ab7d53 ("SUNRPC: Simplify TCP receive code by switching to
using iterators")
Signed-off-by: Dan Aloni <dan@kernelim.com>
---
 net/sunrpc/xprtsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 7090bbee0ec5..42b680a60d38 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -436,7 +436,7 @@ xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
 		offset += ret - buf->page_base;
 		if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
 			goto out;
-		if (ret != want)
+		if (ret - buf->page_base != want)
 			goto out;
 		seek = 0;
 	} else {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sunrpc: fix xs_read_xdr_buf for partial pages receive
  2020-12-04 18:34 [PATCH] sunrpc: fix xs_read_xdr_buf for partial pages receive Dan Aloni
@ 2020-12-04 20:52 ` Trond Myklebust
  2020-12-05  9:28   ` [PATCH v2] " Dan Aloni
  2020-12-05  9:29   ` [PATCH] " Dan Aloni
  0 siblings, 2 replies; 4+ messages in thread
From: Trond Myklebust @ 2020-12-04 20:52 UTC (permalink / raw)
  To: dan, linux-nfs

On Fri, 2020-12-04 at 20:34 +0200, Dan Aloni wrote:
> When receiving pages data, return value 'ret' when positive includes
> `buf->page_base`, so we should subtract it similarly to how it is
> done
> for `offset`.
> 
> This was discovered on the very rare cases where the server returned
> a
> chunk of bytes that when added to the already received amount of
> bytes
> for the pages happened to match the current `recv.len`, for example
> on this case:
> 
>      buf->page_base : 258356
>      actually received from socket: 1740
>      ret : 260096
>      want : 260096
> 
> In this case neither of the two 'if ... goto out' trigger, and we
> continue to tail parsing.
> 
> Worth to mention that the ensuing EMSGSIZE from the continued
> execution of
> `xs_read_xdr_buf` may be observed by an application due to 4
> superfluous
> bytes being added to the pages data.
> 
> Fixes: 277e4ab7d53 ("SUNRPC: Simplify TCP receive code by switching
> to
> using iterators")
> Signed-off-by: Dan Aloni <dan@kernelim.com>
> ---
>  net/sunrpc/xprtsock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> index 7090bbee0ec5..42b680a60d38 100644
> --- a/net/sunrpc/xprtsock.c
> +++ b/net/sunrpc/xprtsock.c
> @@ -436,7 +436,7 @@ xs_read_xdr_buf(struct socket *sock, struct
> msghdr *msg, int flags,
>                 offset += ret - buf->page_base;
>                 if (offset == count || msg->msg_flags &
> (MSG_EOR|MSG_TRUNC))
>                         goto out;
> -               if (ret != want)
> +               if (ret - buf->page_base != want)
>                         goto out;
>                 seek = 0;
>         } else {

Ouch... Well spotted!

Hmm... I think we want to just subtract out the buf->page_base from the
value of 'ret' after we call xs_flush_bvec() and then adjust the
calculation of 'offset' in the next line. That's more efficient.

Can you please resend with that change?

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] sunrpc: fix xs_read_xdr_buf for partial pages receive
  2020-12-04 20:52 ` Trond Myklebust
@ 2020-12-05  9:28   ` Dan Aloni
  2020-12-05  9:29   ` [PATCH] " Dan Aloni
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Aloni @ 2020-12-05  9:28 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

When receiving pages data, return value 'ret' when positive includes
`buf->page_base`, so we should subtract that before it is used for
changing `offset` and comparing against `want`.

This was discovered on the very rare cases where the server returned a
chunk of bytes that when added to the already received amount of bytes
for the pages happened to match the current `recv.len`, for example
on this case:

     buf->page_base : 258356
     actually received from socket: 1740
     ret : 260096
     want : 260096

In this case neither of the two 'if ... goto out' trigger, and we
continue to tail parsing.

Worth to mention that the ensuing EMSGSIZE from the continued execution of
`xs_read_xdr_buf` may be observed by an application due to 4 superfluous
bytes being added to the pages data.

Fixes: 277e4ab7d53 ("SUNRPC: Simplify TCP receive code by switching to
using iterators")
Signed-off-by: Dan Aloni <dan@kernelim.com>
---
 net/sunrpc/xprtsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 7090bbee0ec5..9a4300f07e4c 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -433,7 +433,8 @@ xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
 		if (ret <= 0)
 			goto sock_err;
 		xs_flush_bvec(buf->bvec, ret, seek + buf->page_base);
-		offset += ret - buf->page_base;
+		ret -= buf->page_base;
+		offset += ret;
 		if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
 			goto out;
 		if (ret != want)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sunrpc: fix xs_read_xdr_buf for partial pages receive
  2020-12-04 20:52 ` Trond Myklebust
  2020-12-05  9:28   ` [PATCH v2] " Dan Aloni
@ 2020-12-05  9:29   ` Dan Aloni
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Aloni @ 2020-12-05  9:29 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

On Fri, Dec 04, 2020 at 08:52:55PM +0000, Trond Myklebust wrote:
> On Fri, 2020-12-04 at 20:34 +0200, Dan Aloni wrote:
[..]
> > --- a/net/sunrpc/xprtsock.c
> > +++ b/net/sunrpc/xprtsock.c
> > @@ -436,7 +436,7 @@ xs_read_xdr_buf(struct socket *sock, struct
> > msghdr *msg, int flags,
> >                 offset += ret - buf->page_base;
> >                 if (offset == count || msg->msg_flags &
> > (MSG_EOR|MSG_TRUNC))
> >                         goto out;
> > -               if (ret != want)
> > +               if (ret - buf->page_base != want)
> >                         goto out;
> >                 seek = 0;
> >         } else {
> 
> Ouch... Well spotted!
> 
> Hmm... I think we want to just subtract out the buf->page_base from the
> value of 'ret' after we call xs_flush_bvec() and then adjust the
> calculation of 'offset' in the next line. That's more efficient.

Yes, it works out, though after being aware that the positive value of
`ret` when returned from `xs_read_xdr_buf` and propagated upward has no
effect except on traces.

-- 
Dan Aloni

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-05  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04 18:34 [PATCH] sunrpc: fix xs_read_xdr_buf for partial pages receive Dan Aloni
2020-12-04 20:52 ` Trond Myklebust
2020-12-05  9:28   ` [PATCH v2] " Dan Aloni
2020-12-05  9:29   ` [PATCH] " Dan Aloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.