netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] strparser: Fix sign of err codes
@ 2018-03-26 19:31 Dave Watson
  2018-03-26 20:44 ` Tom Herbert
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Watson @ 2018-03-26 19:31 UTC (permalink / raw)
  To: David S. Miller, Tom Herbert, netdev

strp_parser_err is called with a negative code everywhere, which then
calls abort_parser with a negative code.  strp_msg_timeout calls
abort_parser directly with a positive code.  Negate ETIMEDOUT
to match signed-ness of other calls.

The default abort_parser callback, strp_abort_strp, sets
sk->sk_err to err.  Also negate the error here so sk_err always
holds a positive value, as the rest of the net code expects.  Currently
a negative sk_err can result in endless loops, or user code that
thinks it actually sent/received err bytes.

Found while testing net/tls_sw recv path.

Fixes: 43a0c6751a322847 ("strparser: Stream parser for messages")
Signed-off-by: Dave Watson <davejwatson@fb.com>
---
 net/strparser/strparser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index 1fdab5c..b9283ce 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -60,7 +60,7 @@ static void strp_abort_strp(struct strparser *strp, int err)
 		struct sock *sk = strp->sk;
 
 		/* Report an error on the lower socket */
-		sk->sk_err = err;
+		sk->sk_err = -err;
 		sk->sk_error_report(sk);
 	}
 }
@@ -458,7 +458,7 @@ static void strp_msg_timeout(struct work_struct *w)
 	/* Message assembly timed out */
 	STRP_STATS_INCR(strp->stats.msg_timeouts);
 	strp->cb.lock(strp);
-	strp->cb.abort_parser(strp, ETIMEDOUT);
+	strp->cb.abort_parser(strp, -ETIMEDOUT);
 	strp->cb.unlock(strp);
 }
 
-- 
2.9.5

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

* Re: [PATCH net] strparser: Fix sign of err codes
  2018-03-26 19:31 [PATCH net] strparser: Fix sign of err codes Dave Watson
@ 2018-03-26 20:44 ` Tom Herbert
  2018-03-27 15:05   ` Dave Watson
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Herbert @ 2018-03-26 20:44 UTC (permalink / raw)
  To: Dave Watson; +Cc: David S. Miller, Linux Kernel Network Developers

On Mon, Mar 26, 2018 at 12:31 PM, Dave Watson <davejwatson@fb.com> wrote:
> strp_parser_err is called with a negative code everywhere, which then
> calls abort_parser with a negative code.  strp_msg_timeout calls
> abort_parser directly with a positive code.  Negate ETIMEDOUT
> to match signed-ness of other calls.
>
> The default abort_parser callback, strp_abort_strp, sets
> sk->sk_err to err.  Also negate the error here so sk_err always
> holds a positive value, as the rest of the net code expects.  Currently
> a negative sk_err can result in endless loops, or user code that
> thinks it actually sent/received err bytes.
>
> Found while testing net/tls_sw recv path.
>
Nice catch!

It might be nice to have a comment at strp_parser_err and abort_parser
description in Documentation/networking/strparser.txt should also be
updated that err is a negative error value.

Tom


> Fixes: 43a0c6751a322847 ("strparser: Stream parser for messages")
> Signed-off-by: Dave Watson <davejwatson@fb.com>
> ---
>  net/strparser/strparser.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
> index 1fdab5c..b9283ce 100644
> --- a/net/strparser/strparser.c
> +++ b/net/strparser/strparser.c
> @@ -60,7 +60,7 @@ static void strp_abort_strp(struct strparser *strp, int err)
>                 struct sock *sk = strp->sk;
>
>                 /* Report an error on the lower socket */
> -               sk->sk_err = err;
> +               sk->sk_err = -err;
>                 sk->sk_error_report(sk);
>         }
>  }
> @@ -458,7 +458,7 @@ static void strp_msg_timeout(struct work_struct *w)
>         /* Message assembly timed out */
>         STRP_STATS_INCR(strp->stats.msg_timeouts);
>         strp->cb.lock(strp);
> -       strp->cb.abort_parser(strp, ETIMEDOUT);
> +       strp->cb.abort_parser(strp, -ETIMEDOUT);
>         strp->cb.unlock(strp);
>  }
>
> --
> 2.9.5
>

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

* Re: [PATCH net] strparser: Fix sign of err codes
  2018-03-26 20:44 ` Tom Herbert
@ 2018-03-27 15:05   ` Dave Watson
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Watson @ 2018-03-27 15:05 UTC (permalink / raw)
  To: Tom Herbert; +Cc: David S. Miller, Linux Kernel Network Developers

On 03/26/18 01:44 PM, Tom Herbert wrote:
> On Mon, Mar 26, 2018 at 12:31 PM, Dave Watson <davejwatson@fb.com> wrote:
> > strp_parser_err is called with a negative code everywhere, which then
> > calls abort_parser with a negative code.  strp_msg_timeout calls
> > abort_parser directly with a positive code.  Negate ETIMEDOUT
> > to match signed-ness of other calls.
> >
> > The default abort_parser callback, strp_abort_strp, sets
> > sk->sk_err to err.  Also negate the error here so sk_err always
> > holds a positive value, as the rest of the net code expects.  Currently
> > a negative sk_err can result in endless loops, or user code that
> > thinks it actually sent/received err bytes.
> >
> > Found while testing net/tls_sw recv path.
> >
> Nice catch!
> 
> It might be nice to have a comment at strp_parser_err and abort_parser
> description in Documentation/networking/strparser.txt should also be
> updated that err is a negative error value.

Sure I can update the docs also.

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

end of thread, other threads:[~2018-03-27 15:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-26 19:31 [PATCH net] strparser: Fix sign of err codes Dave Watson
2018-03-26 20:44 ` Tom Herbert
2018-03-27 15:05   ` Dave Watson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).