diff mbox series

ipv4: Correct/silence an endian warning in __ip_do_redirect

Message ID 20231117152728.2286551-1-chentao@kylinos.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ipv4: Correct/silence an endian warning in __ip_do_redirect | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1130 this patch: 1129
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1155 this patch: 1155
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1157 this patch: 1156
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kunwu Chan Nov. 17, 2023, 3:27 p.m. UTC
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(-)

Comments

Eric Dumazet Nov. 17, 2023, 5:15 p.m. UTC | #1
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
Kunwu Chan Nov. 19, 2023, 2:04 p.m. UTC | #2
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
diff mbox series

Patch

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