netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ping6: Fix send to link-local addresses with VRF.
@ 2023-06-07 16:05 Guillaume Nault
  2023-06-07 16:11 ` David Ahern
  2023-06-09  2:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Guillaume Nault @ 2023-06-07 16:05 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
  Cc: netdev, David Ahern, Lorenzo Colitti, Mirsad Todorovac

Ping sockets can't send packets when they're bound to a VRF master
device and the output interface is set to a slave device.

For example, when net.ipv4.ping_group_range is properly set, so that
ping6 can use ping sockets, the following kind of commands fails:
  $ ip vrf exec red ping6 fe80::854:e7ff:fe88:4bf1%eth1

What happens is that sk->sk_bound_dev_if is set to the VRF master
device, but 'oif' is set to the real output device. Since both are set
but different, ping_v6_sendmsg() sees their value as inconsistent and
fails.

Fix this by allowing 'oif' to be a slave device of ->sk_bound_dev_if.

This fixes the following kselftest failure:
  $ ./fcnal-test.sh -t ipv6_ping
  [...]
  TEST: ping out, vrf device+address bind - ns-B IPv6 LLA        [FAIL]

Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Closes: https://lore.kernel.org/netdev/b6191f90-ffca-dbca-7d06-88a9788def9c@alu.unizg.hr/
Tested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Fixes: 5e457896986e ("net: ipv6: Fix ping to link-local addresses.")
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 net/ipv6/ping.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index c4835dbdfcff..f804c11e2146 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -114,7 +114,8 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	addr_type = ipv6_addr_type(daddr);
 	if ((__ipv6_addr_needs_scope_id(addr_type) && !oif) ||
 	    (addr_type & IPV6_ADDR_MAPPED) ||
-	    (oif && sk->sk_bound_dev_if && oif != sk->sk_bound_dev_if))
+	    (oif && sk->sk_bound_dev_if && oif != sk->sk_bound_dev_if &&
+	     l3mdev_master_ifindex_by_index(sock_net(sk), oif) != sk->sk_bound_dev_if))
 		return -EINVAL;
 
 	ipcm6_init_sk(&ipc6, np);
-- 
2.39.2


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

* Re: [PATCH net] ping6: Fix send to link-local addresses with VRF.
  2023-06-07 16:05 [PATCH net] ping6: Fix send to link-local addresses with VRF Guillaume Nault
@ 2023-06-07 16:11 ` David Ahern
  2023-06-09  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2023-06-07 16:11 UTC (permalink / raw)
  To: Guillaume Nault, David Miller, Jakub Kicinski, Paolo Abeni,
	Eric Dumazet
  Cc: netdev, Lorenzo Colitti, Mirsad Todorovac

On 6/7/23 10:05 AM, Guillaume Nault wrote:
> Ping sockets can't send packets when they're bound to a VRF master
> device and the output interface is set to a slave device.
> 
> For example, when net.ipv4.ping_group_range is properly set, so that
> ping6 can use ping sockets, the following kind of commands fails:
>   $ ip vrf exec red ping6 fe80::854:e7ff:fe88:4bf1%eth1
> 
> What happens is that sk->sk_bound_dev_if is set to the VRF master
> device, but 'oif' is set to the real output device. Since both are set
> but different, ping_v6_sendmsg() sees their value as inconsistent and
> fails.
> 
> Fix this by allowing 'oif' to be a slave device of ->sk_bound_dev_if.
> 
> This fixes the following kselftest failure:
>   $ ./fcnal-test.sh -t ipv6_ping
>   [...]
>   TEST: ping out, vrf device+address bind - ns-B IPv6 LLA        [FAIL]

Thank you for resolving that one.

> 
> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Closes: https://lore.kernel.org/netdev/b6191f90-ffca-dbca-7d06-88a9788def9c@alu.unizg.hr/
> Tested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Fixes: 5e457896986e ("net: ipv6: Fix ping to link-local addresses.")
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
>  net/ipv6/ping.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
> index c4835dbdfcff..f804c11e2146 100644
> --- a/net/ipv6/ping.c
> +++ b/net/ipv6/ping.c
> @@ -114,7 +114,8 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>  	addr_type = ipv6_addr_type(daddr);
>  	if ((__ipv6_addr_needs_scope_id(addr_type) && !oif) ||
>  	    (addr_type & IPV6_ADDR_MAPPED) ||
> -	    (oif && sk->sk_bound_dev_if && oif != sk->sk_bound_dev_if))
> +	    (oif && sk->sk_bound_dev_if && oif != sk->sk_bound_dev_if &&
> +	     l3mdev_master_ifindex_by_index(sock_net(sk), oif) != sk->sk_bound_dev_if))
>  		return -EINVAL;
>  
>  	ipcm6_init_sk(&ipc6, np);

Reviewed-by: David Ahern <dsahern@kernel.org>


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

* Re: [PATCH net] ping6: Fix send to link-local addresses with VRF.
  2023-06-07 16:05 [PATCH net] ping6: Fix send to link-local addresses with VRF Guillaume Nault
  2023-06-07 16:11 ` David Ahern
@ 2023-06-09  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-09  2:10 UTC (permalink / raw)
  To: Guillaume Nault
  Cc: davem, kuba, pabeni, edumazet, netdev, dsahern, lorenzo,
	mirsad.todorovac

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 7 Jun 2023 18:05:02 +0200 you wrote:
> Ping sockets can't send packets when they're bound to a VRF master
> device and the output interface is set to a slave device.
> 
> For example, when net.ipv4.ping_group_range is properly set, so that
> ping6 can use ping sockets, the following kind of commands fails:
>   $ ip vrf exec red ping6 fe80::854:e7ff:fe88:4bf1%eth1
> 
> [...]

Here is the summary with links:
  - [net] ping6: Fix send to link-local addresses with VRF.
    https://git.kernel.org/netdev/net/c/91ffd1bae1da

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] 3+ messages in thread

end of thread, other threads:[~2023-06-09  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-07 16:05 [PATCH net] ping6: Fix send to link-local addresses with VRF Guillaume Nault
2023-06-07 16:11 ` David Ahern
2023-06-09  2: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;
as well as URLs for NNTP newsgroup(s).