strparser: Fix sign of err codes
Subsystems (2)
PATCH 1/1 strparser: Fix sign of err codes
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.
--- net/strparser/strparser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/strparser/strparser.c +2 -2
@@ -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); }
Signature · 1 line
2.9.5
Quoted 5 lines · Dave Watson
strp_parser_erris called with a negative code everywhere, which then callsabort_parserwith a negative code.strp_msg_timeoutcallsabort_parserdirectly with a positive code. Negate ETIMEDOUT to match signed-ness of other calls.
Quoted 8 lines
The default
abort_parsercallback,strp_abort_strp, setssk->sk_errto err. Also negate the error here sosk_erralways holds a positive value, as the rest of the net code expects. Currently a negativesk_errcan result in endless loops, or user code that thinks it actually sent/received err bytes.Found while testing
net/tls_swrecv 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
Quoted 31 lines
Fixes 43a0c6751a322847 ("strparser: Stream parser for messages")Signed-off-by Dave Watson <[email protected]>--- net/strparser/strparser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/strparser/strparser.c +2
-3@@ -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
Quoted 12 lines · Tom Herbert
Quoted 11 lines · Dave Watson
strp_parser_erris called with a negative code everywhere, which then callsabort_parserwith a negative code.strp_msg_timeoutcallsabort_parserdirectly with a positive code. Negate ETIMEDOUT to match signed-ness of other calls.The default
abort_parsercallback,strp_abort_strp, setssk->sk_errto err. Also negate the error here sosk_erralways holds a positive value, as the rest of the net code expects. Currently a negativesk_errcan result in endless loops, or user code that thinks it actually sent/received err bytes.
Quoted 7 lines
Quoted 2 lines
Found while testing
net/tls_swrecv path.Nice catch!
It might be nice to have a comment at
strp_parser_errandabort_parserdescription inDocumentation/networking/strparser.txtshould also be updated that err is a negative error value.
Sure I can update the docs also.