Commit 690447a2 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'vrf-fix-address-binding-with-icmp-socket'

Nicolas Dichtel says:

====================
vrf: fix address binding with icmp socket

The first patch fixes the issue.
The second patch adds related tests in selftests.
====================

Link: https://lore.kernel.org/r/20220504090739.21821-1-nicolas.dichtel@6wind.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 15f03ffe e71b7f1f
...@@ -305,6 +305,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk, ...@@ -305,6 +305,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
if (sk->sk_family == AF_INET) { if (sk->sk_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *) uaddr; struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
u32 tb_id = RT_TABLE_LOCAL;
int chk_addr_ret; int chk_addr_ret;
if (addr_len < sizeof(*addr)) if (addr_len < sizeof(*addr))
...@@ -318,7 +319,8 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk, ...@@ -318,7 +319,8 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
pr_debug("ping_check_bind_addr(sk=%p,addr=%pI4,port=%d)\n", pr_debug("ping_check_bind_addr(sk=%p,addr=%pI4,port=%d)\n",
sk, &addr->sin_addr.s_addr, ntohs(addr->sin_port)); sk, &addr->sin_addr.s_addr, ntohs(addr->sin_port));
chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr); tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
if (!inet_addr_valid_or_nonlocal(net, inet_sk(sk), if (!inet_addr_valid_or_nonlocal(net, inet_sk(sk),
addr->sin_addr.s_addr, addr->sin_addr.s_addr,
...@@ -355,6 +357,14 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk, ...@@ -355,6 +357,14 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
return -ENODEV; return -ENODEV;
} }
} }
if (!dev && sk->sk_bound_dev_if) {
dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
if (!dev) {
rcu_read_unlock();
return -ENODEV;
}
}
has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev, has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
scoped); scoped);
rcu_read_unlock(); rcu_read_unlock();
......
...@@ -810,10 +810,16 @@ ipv4_ping() ...@@ -810,10 +810,16 @@ ipv4_ping()
setup setup
set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null set_sysctl net.ipv4.raw_l3mdev_accept=1 2>/dev/null
ipv4_ping_novrf ipv4_ping_novrf
setup
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
ipv4_ping_novrf
log_subsection "With VRF" log_subsection "With VRF"
setup "yes" setup "yes"
ipv4_ping_vrf ipv4_ping_vrf
setup "yes"
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
ipv4_ping_vrf
} }
################################################################################ ################################################################################
...@@ -2348,10 +2354,16 @@ ipv6_ping() ...@@ -2348,10 +2354,16 @@ ipv6_ping()
log_subsection "No VRF" log_subsection "No VRF"
setup setup
ipv6_ping_novrf ipv6_ping_novrf
setup
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
ipv6_ping_novrf
log_subsection "With VRF" log_subsection "With VRF"
setup "yes" setup "yes"
ipv6_ping_vrf ipv6_ping_vrf
setup "yes"
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
ipv6_ping_vrf
} }
################################################################################ ################################################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment