linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID
@ 2021-03-12 20:08 Alexander Lobakin
  2021-03-14 20:21 ` Jakub Sitnicki
  2021-03-14 22:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Lobakin @ 2021-03-12 20:08 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: Jakub Sitnicki, Alexei Starovoitov, Andrii Nakryiko,
	Vladimir Oltean, Davide Caratti, Guillaume Nault, wenxu,
	Eran Ben Elisha, Matteo Croce, netdev, linux-kernel,
	Alexander Lobakin

flow_dissector_key_icmp::id is of type u16 (CPU byteorder),
ICMP header has its ID field in network byteorder obviously.
Sparse says:

net/core/flow_dissector.c:178:43: warning: restricted __be16 degrades to integer

Convert ID value to CPU byteorder when storing it into
flow_dissector_key_icmp.

Fixes: 5dec597e5cd0 ("flow_dissector: extract more ICMP information")
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 net/core/flow_dissector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 2ef2224b3bff..a96a4f5de0ce 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -176,7 +176,7 @@ void skb_flow_get_icmp_tci(const struct sk_buff *skb,
 	 * avoid confusion with packets without such field
 	 */
 	if (icmp_has_id(ih->type))
-		key_icmp->id = ih->un.echo.id ? : 1;
+		key_icmp->id = ih->un.echo.id ? ntohs(ih->un.echo.id) : 1;
 	else
 		key_icmp->id = 0;
 }
--
2.30.2



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

* Re: [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID
  2021-03-12 20:08 [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID Alexander Lobakin
@ 2021-03-14 20:21 ` Jakub Sitnicki
  2021-03-14 20:44   ` Vladimir Oltean
  2021-03-14 22:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Jakub Sitnicki @ 2021-03-14 20:21 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: David S. Miller, Jakub Kicinski, Alexei Starovoitov,
	Andrii Nakryiko, Vladimir Oltean, Davide Caratti,
	Guillaume Nault, wenxu, Eran Ben Elisha, Matteo Croce, netdev,
	linux-kernel

On Fri, Mar 12, 2021 at 09:08 PM CET, Alexander Lobakin wrote:
> flow_dissector_key_icmp::id is of type u16 (CPU byteorder),
> ICMP header has its ID field in network byteorder obviously.
> Sparse says:
>
> net/core/flow_dissector.c:178:43: warning: restricted __be16 degrades to integer
>
> Convert ID value to CPU byteorder when storing it into
> flow_dissector_key_icmp.
>
> Fixes: 5dec597e5cd0 ("flow_dissector: extract more ICMP information")
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>
> ---
>  net/core/flow_dissector.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
> index 2ef2224b3bff..a96a4f5de0ce 100644
> --- a/net/core/flow_dissector.c
> +++ b/net/core/flow_dissector.c
> @@ -176,7 +176,7 @@ void skb_flow_get_icmp_tci(const struct sk_buff *skb,
>  	 * avoid confusion with packets without such field
>  	 */
>  	if (icmp_has_id(ih->type))
> -		key_icmp->id = ih->un.echo.id ? : 1;
> +		key_icmp->id = ih->un.echo.id ? ntohs(ih->un.echo.id) : 1;
>  	else
>  		key_icmp->id = 0;
>  }

Smells like a breaking change for existing consumers of this value.

How about we change the type of flow_dissector_key_icmp{}.id to __be16
instead to make sparse happy?

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

* Re: [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID
  2021-03-14 20:21 ` Jakub Sitnicki
@ 2021-03-14 20:44   ` Vladimir Oltean
  2021-03-14 21:31     ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Oltean @ 2021-03-14 20:44 UTC (permalink / raw)
  To: Jakub Sitnicki
  Cc: Alexander Lobakin, David S. Miller, Jakub Kicinski,
	Alexei Starovoitov, Andrii Nakryiko, Davide Caratti,
	Guillaume Nault, wenxu, Eran Ben Elisha, Matteo Croce, netdev,
	linux-kernel

On Sun, Mar 14, 2021 at 09:21:40PM +0100, Jakub Sitnicki wrote:
> On Fri, Mar 12, 2021 at 09:08 PM CET, Alexander Lobakin wrote:
> > flow_dissector_key_icmp::id is of type u16 (CPU byteorder),
> > ICMP header has its ID field in network byteorder obviously.
> > Sparse says:
> >
> > net/core/flow_dissector.c:178:43: warning: restricted __be16 degrades to integer
> >
> > Convert ID value to CPU byteorder when storing it into
> > flow_dissector_key_icmp.
> >
> > Fixes: 5dec597e5cd0 ("flow_dissector: extract more ICMP information")
> > Signed-off-by: Alexander Lobakin <alobakin@pm.me>
> > ---
> >  net/core/flow_dissector.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
> > index 2ef2224b3bff..a96a4f5de0ce 100644
> > --- a/net/core/flow_dissector.c
> > +++ b/net/core/flow_dissector.c
> > @@ -176,7 +176,7 @@ void skb_flow_get_icmp_tci(const struct sk_buff *skb,
> >  	 * avoid confusion with packets without such field
> >  	 */
> >  	if (icmp_has_id(ih->type))
> > -		key_icmp->id = ih->un.echo.id ? : 1;
> > +		key_icmp->id = ih->un.echo.id ? ntohs(ih->un.echo.id) : 1;
> >  	else
> >  		key_icmp->id = 0;
> >  }
> 
> Smells like a breaking change for existing consumers of this value.
> 
> How about we change the type of flow_dissector_key_icmp{}.id to __be16
> instead to make sparse happy?

The struct flow_dissector_key_icmp::id only appears to be used in
bond_xmit_hash, and there, the exact value doesn't seem to matter.

This appears to be a real bug and not just to appease sparse:
ih->un.echo.id has one endianness and "1" has another. Both cannot
be correct.

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

* Re: [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID
  2021-03-14 20:44   ` Vladimir Oltean
@ 2021-03-14 21:31     ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2021-03-14 21:31 UTC (permalink / raw)
  To: vladimir.oltean
  Cc: jakub, alobakin, kuba, ast, andriin, dcaratti, gnault, wenxu,
	eranbe, mcroce, netdev, linux-kernel

From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: Sun, 14 Mar 2021 20:44:49 +0000

> On Sun, Mar 14, 2021 at 09:21:40PM +0100, Jakub Sitnicki wrote:
>> On Fri, Mar 12, 2021 at 09:08 PM CET, Alexander Lobakin wrote:
>> 
>> Smells like a breaking change for existing consumers of this value.
>> 
>> How about we change the type of flow_dissector_key_icmp{}.id to __be16
>> instead to make sparse happy?
> 
> The struct flow_dissector_key_icmp::id only appears to be used in
> bond_xmit_hash, and there, the exact value doesn't seem to matter.
> 
> This appears to be a real bug and not just to appease sparse:
> ih->un.echo.id has one endianness and "1" has another. Both cannot
> be correct.

Agreed, so I will apply this, thanks.

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

* Re: [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID
  2021-03-12 20:08 [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID Alexander Lobakin
  2021-03-14 20:21 ` Jakub Sitnicki
@ 2021-03-14 22:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-03-14 22:40 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: davem, kuba, jakub, ast, andriin, vladimir.oltean, dcaratti,
	gnault, wenxu, eranbe, mcroce, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Fri, 12 Mar 2021 20:08:57 +0000 you wrote:
> flow_dissector_key_icmp::id is of type u16 (CPU byteorder),
> ICMP header has its ID field in network byteorder obviously.
> Sparse says:
> 
> net/core/flow_dissector.c:178:43: warning: restricted __be16 degrades to integer
> 
> Convert ID value to CPU byteorder when storing it into
> flow_dissector_key_icmp.
> 
> [...]

Here is the summary with links:
  - [net] flow_dissector: fix byteorder of dissected ICMP ID
    https://git.kernel.org/netdev/net/c/a25f82228542

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-03-14 22:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 20:08 [PATCH net] flow_dissector: fix byteorder of dissected ICMP ID Alexander Lobakin
2021-03-14 20:21 ` Jakub Sitnicki
2021-03-14 20:44   ` Vladimir Oltean
2021-03-14 21:31     ` David Miller
2021-03-14 22:40 ` patchwork-bot+netdevbpf

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).