public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipv4: Correct/silence an endian warning in __ip_do_redirect
@ 2023-11-17 15:27 Kunwu Chan
  2023-11-17 17:15 ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Kunwu Chan @ 2023-11-17 15:27 UTC (permalink / raw)
  To: davem, dsahern, edumazet, kuba, pabeni
  Cc: kunwu.chan, netdev, linux-kernel, Kunwu Chan

net/ipv4/route.c:783:46: warning: incorrect type in argument 2 (different base types)
net/ipv4/route.c:783:46:    expected unsigned int [usertype] key
net/ipv4/route.c:783:46:    got restricted __be32 [usertype] new_gw

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 net/ipv4/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 3290a4442b4a..e8a542c6b031 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -780,7 +780,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
 			goto reject_redirect;
 	}
 
-	n = __ipv4_neigh_lookup(rt->dst.dev, new_gw);
+	n = __ipv4_neigh_lookup(rt->dst.dev, be32_to_cpu(new_gw));
 	if (!n)
 		n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev);
 	if (!IS_ERR(n)) {
-- 
2.34.1


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

* Re: [PATCH] ipv4: Correct/silence an endian warning in __ip_do_redirect
  2023-11-17 15:27 [PATCH] ipv4: Correct/silence an endian warning in __ip_do_redirect Kunwu Chan
@ 2023-11-17 17:15 ` Eric Dumazet
  2023-11-19 14:04   ` Kunwu Chan
  2023-11-19 14:17   ` [PATCH v2] " Kunwu Chan
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2023-11-17 17:15 UTC (permalink / raw)
  To: Kunwu Chan; +Cc: davem, dsahern, kuba, pabeni, kunwu.chan, netdev, linux-kernel

On Fri, Nov 17, 2023 at 6:07 PM Kunwu Chan <chentao@kylinos.cn> wrote:
>
> net/ipv4/route.c:783:46: warning: incorrect type in argument 2 (different base types)
> net/ipv4/route.c:783:46:    expected unsigned int [usertype] key
> net/ipv4/route.c:783:46:    got restricted __be32 [usertype] new_gw
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>

We need Fixes: tag for networking patches.

> ---
>  net/ipv4/route.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index 3290a4442b4a..e8a542c6b031 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -780,7 +780,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
>                         goto reject_redirect;
>         }
>
> -       n = __ipv4_neigh_lookup(rt->dst.dev, new_gw);
> +       n = __ipv4_neigh_lookup(rt->dst.dev, be32_to_cpu(new_gw));
>         if (!n)
>                 n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev);
>         if (!IS_ERR(n)) {
> --
> 2.34.1
>

How was this patch tested ?

You are 'fixing' sparse warnings by replacing them with real bugs.

be32_to_cpu() is going to swap bytes on x86, so the lookup will fail horribly.

Here, if you must silence sparse, you want (__force u32)new_gw

Look at this commit for a template.

commit 3c42b2019863b327caa233072c50739d4144dd16

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

* Re: [PATCH] ipv4: Correct/silence an endian warning in __ip_do_redirect
  2023-11-17 17:15 ` Eric Dumazet
@ 2023-11-19 14:04   ` Kunwu Chan
  2023-11-19 14:17   ` [PATCH v2] " Kunwu Chan
  1 sibling, 0 replies; 5+ messages in thread
From: Kunwu Chan @ 2023-11-19 14:04 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, dsahern, kuba, pabeni, kunwu.chan, netdev, linux-kernel

Hi Eric,
Thank you so much for taking the time to guide me, I'm a rookie who 
really wants to do my part for the kernel, and I can't get started, so I 
thought about eliminating some of the sparse warnings. I've looked at 
some other commits and thought I could resolve the alert this way, sorry 
for the trouble.
Follow your suggestion:
1. I will add a 'Fixes' tag as follows:
'Fixes: 969447f226b4 ("ipv4: use new_gw for redirect neigh lookup")'

2. Refer to the modification method of commit 
3c42b2019863b327caa233072c50739d4144dd16, and modify the patch to:
'n = __ipv4_neigh_lookup(rt->dst.dev, (__force u32)new_gw); '

On 2023/11/18 01:15, Eric Dumazet wrote:
> On Fri, Nov 17, 2023 at 6:07 PM Kunwu Chan <chentao@kylinos.cn> wrote:
>>
>> net/ipv4/route.c:783:46: warning: incorrect type in argument 2 (different base types)
>> net/ipv4/route.c:783:46:    expected unsigned int [usertype] key
>> net/ipv4/route.c:783:46:    got restricted __be32 [usertype] new_gw
>>
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> 
> We need Fixes: tag for networking patches.
> 
>> ---
>>   net/ipv4/route.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
>> index 3290a4442b4a..e8a542c6b031 100644
>> --- a/net/ipv4/route.c
>> +++ b/net/ipv4/route.c
>> @@ -780,7 +780,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
>>                          goto reject_redirect;
>>          }
>>
>> -       n = __ipv4_neigh_lookup(rt->dst.dev, new_gw);
>> +       n = __ipv4_neigh_lookup(rt->dst.dev, be32_to_cpu(new_gw));
>>          if (!n)
>>                  n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev);
>>          if (!IS_ERR(n)) {
>> --
>> 2.34.1
>>
> 
> How was this patch tested ?
> 
> You are 'fixing' sparse warnings by replacing them with real bugs.
> 
> be32_to_cpu() is going to swap bytes on x86, so the lookup will fail horribly.
> 
> Here, if you must silence sparse, you want (__force u32)new_gw
> 
> Look at this commit for a template.
> 
> commit 3c42b2019863b327caa233072c50739d4144dd16

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

* [PATCH v2] ipv4: Correct/silence an endian warning in __ip_do_redirect
  2023-11-17 17:15 ` Eric Dumazet
  2023-11-19 14:04   ` Kunwu Chan
@ 2023-11-19 14:17   ` Kunwu Chan
  2023-11-21 12:10     ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Kunwu Chan @ 2023-11-19 14:17 UTC (permalink / raw)
  To: edumazet
  Cc: chentao, davem, dsahern, kuba, kunwu.chan, linux-kernel, netdev,
	pabeni

net/ipv4/route.c:783:46: warning: incorrect type in argument 2 (different base types)
net/ipv4/route.c:783:46:    expected unsigned int [usertype] key
net/ipv4/route.c:783:46:    got restricted __be32 [usertype] new_gw

Fixes: 969447f226b4 ("ipv4: use new_gw for redirect neigh lookup")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 net/ipv4/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 3290a4442b4a..16615d107cf0 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -780,7 +780,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
 			goto reject_redirect;
 	}
 
-	n = __ipv4_neigh_lookup(rt->dst.dev, new_gw);
+	n = __ipv4_neigh_lookup(rt->dst.dev, (__force u32)new_gw);
 	if (!n)
 		n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev);
 	if (!IS_ERR(n)) {
-- 
2.34.1


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

* Re: [PATCH v2] ipv4: Correct/silence an endian warning in __ip_do_redirect
  2023-11-19 14:17   ` [PATCH v2] " Kunwu Chan
@ 2023-11-21 12:10     ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-21 12:10 UTC (permalink / raw)
  To: Kunwu Chan
  Cc: edumazet, davem, dsahern, kuba, kunwu.chan, linux-kernel, netdev,
	pabeni

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sun, 19 Nov 2023 22:17:59 +0800 you wrote:
> net/ipv4/route.c:783:46: warning: incorrect type in argument 2 (different base types)
> net/ipv4/route.c:783:46:    expected unsigned int [usertype] key
> net/ipv4/route.c:783:46:    got restricted __be32 [usertype] new_gw
> 
> Fixes: 969447f226b4 ("ipv4: use new_gw for redirect neigh lookup")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> 
> [...]

Here is the summary with links:
  - [v2] ipv4: Correct/silence an endian warning in __ip_do_redirect
    https://git.kernel.org/netdev/net/c/c0e2926266af

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:[~2023-11-21 12:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 15:27 [PATCH] ipv4: Correct/silence an endian warning in __ip_do_redirect Kunwu Chan
2023-11-17 17:15 ` Eric Dumazet
2023-11-19 14:04   ` Kunwu Chan
2023-11-19 14:17   ` [PATCH v2] " Kunwu Chan
2023-11-21 12:10     ` 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