diff mbox series

[net] net: ping6: Fix ping -6 with interface name

Message ID 20220510172739.30823-1-tariqt@nvidia.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] net: ping6: Fix ping -6 with interface name | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 3 maintainers not CCed: yoshfuji@linux-ipv6.org edumazet@google.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tariq Toukan May 10, 2022, 5:27 p.m. UTC
From: Aya Levin <ayal@nvidia.com>

When passing interface parameter to ping -6:
$ ping -6 ::11:141:84:9 -I eth2
Results in:
PING ::11:141:84:10(::11:141:84:10) from ::11:141:84:9 eth2: 56 data bytes
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument

Initialize the fl6's outgoing interface (OIF) before triggering
ip6_datagram_send_ctl.

Fixes: 13651224c00b ("net: ping6: support setting basic SOL_IPV6 options via cmsg")
Signed-off-by: Aya Levin <ayal@nvidia.com>
Reviewed-by: Gal Pressman <gal@nvidia.com>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 net/ipv6/ping.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Ahern May 10, 2022, 8:27 p.m. UTC | #1
On 5/10/22 11:27 AM, Tariq Toukan wrote:
> From: Aya Levin <ayal@nvidia.com>
> 
> When passing interface parameter to ping -6:
> $ ping -6 ::11:141:84:9 -I eth2
> Results in:
> PING ::11:141:84:10(::11:141:84:10) from ::11:141:84:9 eth2: 56 data bytes
> ping: sendmsg: Invalid argument
> ping: sendmsg: Invalid argument
> 
> Initialize the fl6's outgoing interface (OIF) before triggering
> ip6_datagram_send_ctl.
> 
> Fixes: 13651224c00b ("net: ping6: support setting basic SOL_IPV6 options via cmsg")
> Signed-off-by: Aya Levin <ayal@nvidia.com>
> Reviewed-by: Gal Pressman <gal@nvidia.com>
> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---
>  net/ipv6/ping.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
> index ff033d16549e..83f014559c0d 100644
> --- a/net/ipv6/ping.c
> +++ b/net/ipv6/ping.c
> @@ -106,6 +106,8 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>  
>  		opt.tot_len = sizeof(opt);
>  		ipc6.opt = &opt;
> +		memset(&fl6, 0, sizeof(fl6));
> +		fl6.flowi6_oif = oif;
>  
>  		err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, &ipc6);
>  		if (err < 0)

I agree that fl6 is used unitialized here, but right after this is:

        memset(&fl6, 0, sizeof(fl6));

        fl6.flowi6_proto = IPPROTO_ICMPV6;
        fl6.saddr = np->saddr;
        fl6.daddr = *daddr;
        fl6.flowi6_oif = oif;

so adding a memset before the call to ip6_datagram_send_ctl duplicates
the existing one. Best to move the memset before the 'if
(msg->msg_controllen) {'
Aya Levin May 12, 2022, 1:02 p.m. UTC | #2
On 5/10/2022 11:27 PM, David Ahern wrote:
> On 5/10/22 11:27 AM, Tariq Toukan wrote:
>> From: Aya Levin <ayal@nvidia.com>
>>
>> When passing interface parameter to ping -6:
>> $ ping -6 ::11:141:84:9 -I eth2
>> Results in:
>> PING ::11:141:84:10(::11:141:84:10) from ::11:141:84:9 eth2: 56 data bytes
>> ping: sendmsg: Invalid argument
>> ping: sendmsg: Invalid argument
>>
>> Initialize the fl6's outgoing interface (OIF) before triggering
>> ip6_datagram_send_ctl.
>>
>> Fixes: 13651224c00b ("net: ping6: support setting basic SOL_IPV6 options via cmsg")
>> Signed-off-by: Aya Levin <ayal@nvidia.com>
>> Reviewed-by: Gal Pressman <gal@nvidia.com>
>> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
>> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
>> ---
>>   net/ipv6/ping.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
>> index ff033d16549e..83f014559c0d 100644
>> --- a/net/ipv6/ping.c
>> +++ b/net/ipv6/ping.c
>> @@ -106,6 +106,8 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>>   
>>   		opt.tot_len = sizeof(opt);
>>   		ipc6.opt = &opt;
>> +		memset(&fl6, 0, sizeof(fl6));
>> +		fl6.flowi6_oif = oif;
>>   
>>   		err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, &ipc6);
>>   		if (err < 0)
> 
> I agree that fl6 is used unitialized here, but right after this is:
> 
>          memset(&fl6, 0, sizeof(fl6));
> 
>          fl6.flowi6_proto = IPPROTO_ICMPV6;
>          fl6.saddr = np->saddr;
>          fl6.daddr = *daddr;
>          fl6.flowi6_oif = oif;
> 
> so adding a memset before the call to ip6_datagram_send_ctl duplicates
> the existing one. Best to move the memset before the 'if
> (msg->msg_controllen) {'
Hi,

Thanks for your comment. As far as I understand the flow, any changes 
done to fl6 inside ip6_datagram_send_ctl is to be disregarded. That's 
how I understand the comment:
/* Changes to txoptions and flow info are not implemented, yet.
  * Drop the options, fl6 is wiped below.
  */

Thanks,
Aya
diff mbox series

Patch

diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index ff033d16549e..83f014559c0d 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -106,6 +106,8 @@  static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 		opt.tot_len = sizeof(opt);
 		ipc6.opt = &opt;
+		memset(&fl6, 0, sizeof(fl6));
+		fl6.flowi6_oif = oif;
 
 		err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, &ipc6);
 		if (err < 0)