Skip to contentSkip to conversation

flow_dissector: fix byteorder of dissected ICMP ID

PATCH Applied Alexander Lobakin 5 participants 5 messages Mar 12, 2021 – Mar 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 flow_dissector: fix byteorder of dissected ICMP ID

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")
---
 net/core/flow_dissector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/flow_dissector.c +1 -1
index 2ef2224b3bff..a96a4f5de0ce 100644
@@ -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

#1 lore raw
Quoted 20 lines · 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")
---
 net/core/flow_dissector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/flow_dissector.c +0 -0
index 2ef2224b3bff..a96a4f5de0ce 100644

net/core/flow_dissector.c void skb_flow_get_icmp_tci(const struct sk_buff *skb, · line 182

Quoted 8 lines
net/core/flow_dissector.c +1 -1
@@ -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?

#2 lore raw
Quoted 32 lines · Jakub Sitnicki
Quoted 20 lines · 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")
---
 net/core/flow_dissector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/flow_dissector.c +0 -0
index 2ef2224b3bff..a96a4f5de0ce 100644

net/core/flow_dissector.c void skb_flow_get_icmp_tci(const struct sk_buff *skb, · line 182

Quoted 8 lines
net/core/flow_dissector.c +1 -1
@@ -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.

Quoted 2 lines

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.

maintainer
#3 lore raw

From: Vladimir Oltean <[email protected]>
Date: Sun, 14 Mar 2021 20:44:49 +0000

Quoted 8 lines · Jakub Sitnicki
Quoted 6 lines · Alexander Lobakin

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?

Quoted 6 lines

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.

#4 lore raw
In reply to Alexander Lobakin
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

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

Quoted 10 lines · 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