* [PATCH net 0/2] ipv6: fix IPv6 scope check of the source address in a VRF
@ 2026-11-23 14:30 Vincent Jardin via B4 Relay
2026-11-23 14:30 ` [PATCH net 1/2] ipv6: check the scope of the best source address candidate " Vincent Jardin via B4 Relay
2026-11-23 14:30 ` [PATCH net 2/2] selftests: fib_tests: test IPv6 source address of " Vincent Jardin via B4 Relay
0 siblings, 2 replies; 4+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-23 14:30 UTC (permalink / raw)
To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Nicolas Dichtel, Shuah Khan
Cc: netdev, linux-kselftest, Vincent Jardin, stable
When a packet is sent through a device of a VRF, ipv6_dev_get_saddr()
first checks the addresses of that device and of the VRF device,
and stops when the best of them has a scope that fits the destination.
Since the commit abb9a68d2c64 ("ipv6: take care of scope when
choosing the src addr"), the check reads the scopedist of the best
candidate, which is an issue:
- with a single candidate, scopedist is not written: when the stack is
zero-initialized, a device that only has a link-local address sends
to global destinations with it, although another device of the VRF
has a global address
- with more candidates, scopedist is negative, whether the scope fits
or not: all the devices of the VRF are looked at, and one of their
addresses can win over the address of the VRF device
Changes:
- patch 1 compares the scope of the best candidate with the scope
of the destination
- patch 2 adds test cases to fib_tests.sh
Note: abb9a68d2c64 is in every kernel since v6.11 and was backported down
to 4.19, so the bug is in all the maintained trees (5.10, 5.15, 6.1, 6.6,
6.12, 6.18 and 7.3), hence this series for net.
Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
Vincent Jardin (2):
ipv6: check the scope of the best source address candidate in a VRF
selftests: fib_tests: test IPv6 source address of a VRF
net/ipv6/addrconf.c | 6 ++--
tools/testing/selftests/net/fib_tests.sh | 47 +++++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 3 deletions(-)
---
base-commit: af6737b9066832a2017c281159950ba92385ce00
change-id: 20261123-for-upstream-ipv6-vrf-saddr-scope-v1-4e0165804d43
Best regards,
--
Vincent Jardin <vjardin@free.fr>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net 1/2] ipv6: check the scope of the best source address candidate in a VRF
2026-11-23 14:30 [PATCH net 0/2] ipv6: fix IPv6 scope check of the source address in a VRF Vincent Jardin via B4 Relay
@ 2026-11-23 14:30 ` Vincent Jardin via B4 Relay
2026-11-24 13:55 ` Nicolas Dichtel
2026-11-23 14:30 ` [PATCH net 2/2] selftests: fib_tests: test IPv6 source address of " Vincent Jardin via B4 Relay
1 sibling, 1 reply; 4+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-23 14:30 UTC (permalink / raw)
To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Nicolas Dichtel, Shuah Khan
Cc: netdev, linux-kselftest, Vincent Jardin, stable
From: Vincent Jardin <vjardin@free.fr>
When a packet is sent through a device of a VRF, ipv6_dev_get_saddr()
first checks the addresses of that device and of the VRF device.
It stops there when the best of them has a scope that fits the
destination.
Since the commit abb9a68d2c64 ("ipv6: take care of scope when
choosing the src addr"), that is what the scopedist of the best
candidate is tested for.
scopedist is only written when the rule scope compares 2 candidates.
With a single candidate, the rules stop at the first one, which only
tells that there was no candidate yet, then scopedist is read without
having been written.
It is 0 with CONFIG_INIT_STACK_ALL_ZERO, which passes the test:
a device that only has an IPv6 link-local address sends to
global destinations with that link-local address,
although another device of the VRF has a global address.
# ip link add site2 type vrf table 30
# ip link set site2 up
# ip link add dummy0 type dummy
# ip link set dummy0 master site2 up
# ip addr add fd00:91::1/64 dev dummy0 nodad
# ip link add dummy1 type dummy
# ip link set dummy1 master site2 up
# ip -6 route add fd00:93::/64 vrf site2 dev dummy1
# ip -6 route get fd00:93::1 vrf site2
fd00:93::1 dev dummy1 table 30 src fe80::5cb7:13ff:fe96:87ac metric 1024 pref medium
When the scope rule does run, scopedist is negative, whether the scope
fits or not: the test fails, and the other devices of the VRF are
checked too. One of their addresses can then win on a later rule,
the longest matching prefix for instance, over the address of the VRF
device, which the first lookup is meant to prefer.
So let's compare the scope of the best candidate with the scope of the
destination instead.
This issue was found for a development of a UDP tunnel device with
IPv6 addresses in a VRF selecting an IPv6 link-local source
address for a global destination: then it was confirmed with the
fib_tests.sh case of the next commit, whose first two checks fail without
this fix on a CONFIG_INIT_STACK_ALL_ZERO=y kernel.
Fixes: abb9a68d2c64 ("ipv6: take care of scope when choosing the src addr")
Cc: stable@vger.kernel.org
Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
net/ipv6/addrconf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d9d13e78bf13b..656bf1ea26da8 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1902,8 +1902,10 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
master, &dst,
scores, hiscore_idx);
- if (scores[hiscore_idx].ifa &&
- scores[hiscore_idx].scopedist >= 0)
+ hiscore = &scores[hiscore_idx];
+ if (hiscore->ifa &&
+ __ipv6_addr_src_scope(hiscore->addr_type) >=
+ dst.scope)
goto out;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net 2/2] selftests: fib_tests: test IPv6 source address of a VRF
2026-11-23 14:30 [PATCH net 0/2] ipv6: fix IPv6 scope check of the source address in a VRF Vincent Jardin via B4 Relay
2026-11-23 14:30 ` [PATCH net 1/2] ipv6: check the scope of the best source address candidate " Vincent Jardin via B4 Relay
@ 2026-11-23 14:30 ` Vincent Jardin via B4 Relay
1 sibling, 0 replies; 4+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-23 14:30 UTC (permalink / raw)
To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Nicolas Dichtel, Shuah Khan
Cc: netdev, linux-kselftest, Vincent Jardin
From: Vincent Jardin <vjardin@free.fr>
Check the IPv6 source address of a route of a VRF through a device
that only has an IPv6 link-local address:
- the address of another device of the VRF
- then the one of the VRF device once it has one
- then the one of the output device
Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
tools/testing/selftests/net/fib_tests.sh | 47 +++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index d7ac3c727f704..e211ea5a945ef 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -14,7 +14,7 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \
ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \
ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \
- fib6_ra_to_static fib6_temp_addr_renewal"
+ ipv6_saddr_vrf fib6_ra_to_static fib6_temp_addr_renewal"
VERBOSE=0
PAUSE_ON_FAIL=no
@@ -3228,6 +3228,50 @@ ipv6_mpath_oif_vrf_test()
cleanup
}
+ipv6_saddr_vrf_check()
+{
+ local saddr="$1"
+ local desc="$2"
+ local route_get="$IP -6 route get 2001:db8:10::1 vrf vrf-123"
+
+ run_cmd "$route_get | grep -q 'src $saddr '"
+ log_test $? 0 "$desc"
+}
+
+ipv6_saddr_vrf_test()
+{
+ echo
+ echo "IPv6 source address selection with VRF test"
+
+ setup
+
+ if ! $IP link add name vrf-123 up type vrf table 123 &> /dev/null; then
+ echo "SKIP: Could not add a VRF device."
+ cleanup
+ return
+ fi
+
+ set -e
+ $NS_EXEC sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
+ $IP link set dev dummy0 master vrf-123
+ $IP link add dummy1 up master vrf-123 type dummy
+ $IP -6 route add 2001:db8:10::/64 vrf vrf-123 dev dummy1
+ set +e
+
+ ipv6_saddr_vrf_check "2001:db8:1::1" \
+ "Output device with a link-local address only"
+
+ $IP address add 2001:db8:100::1/128 dev vrf-123 nodad
+ ipv6_saddr_vrf_check "2001:db8:100::1" \
+ "Address of the VRF device before those of other devices"
+
+ $IP address add 2001:db8:2::1/64 dev dummy1 nodad
+ ipv6_saddr_vrf_check "2001:db8:2::1" \
+ "Address of the output device first"
+
+ cleanup
+}
+
################################################################################
# usage
@@ -3320,6 +3364,7 @@ do
ipv6_mpath_oif) ipv6_mpath_oif_test;;
ipv6_mpath_oif_nh) ipv6_mpath_oif_nh_test;;
ipv6_mpath_oif_vrf) ipv6_mpath_oif_vrf_test;;
+ ipv6_saddr_vrf) ipv6_saddr_vrf_test;;
fib6_ra_to_static) fib6_ra_to_static;;
fib6_temp_addr_renewal) fib6_temp_addr_renewal;;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] ipv6: check the scope of the best source address candidate in a VRF
2026-11-23 14:30 ` [PATCH net 1/2] ipv6: check the scope of the best source address candidate " Vincent Jardin via B4 Relay
@ 2026-11-24 13:55 ` Nicolas Dichtel
0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2026-11-24 13:55 UTC (permalink / raw)
To: vjardin, David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Shuah Khan
Cc: netdev, linux-kselftest, stable
Le 23/11/2026 à 15:30, Vincent Jardin via B4 Relay a écrit :
> From: Vincent Jardin <vjardin@free.fr>
>
> When a packet is sent through a device of a VRF, ipv6_dev_get_saddr()
> first checks the addresses of that device and of the VRF device.
> It stops there when the best of them has a scope that fits the
> destination.
>
> Since the commit abb9a68d2c64 ("ipv6: take care of scope when
> choosing the src addr"), that is what the scopedist of the best
> candidate is tested for.
>
> scopedist is only written when the rule scope compares 2 candidates.
> With a single candidate, the rules stop at the first one, which only
> tells that there was no candidate yet, then scopedist is read without
> having been written.
>
> It is 0 with CONFIG_INIT_STACK_ALL_ZERO, which passes the test:
> a device that only has an IPv6 link-local address sends to
> global destinations with that link-local address,
> although another device of the VRF has a global address.
>
> # ip link add site2 type vrf table 30
> # ip link set site2 up
> # ip link add dummy0 type dummy
> # ip link set dummy0 master site2 up
> # ip addr add fd00:91::1/64 dev dummy0 nodad
> # ip link add dummy1 type dummy
> # ip link set dummy1 master site2 up
> # ip -6 route add fd00:93::/64 vrf site2 dev dummy1
> # ip -6 route get fd00:93::1 vrf site2
> fd00:93::1 dev dummy1 table 30 src fe80::5cb7:13ff:fe96:87ac metric 1024 pref medium
>
> When the scope rule does run, scopedist is negative, whether the scope
> fits or not: the test fails, and the other devices of the VRF are
> checked too. One of their addresses can then win on a later rule,
> the longest matching prefix for instance, over the address of the VRF
> device, which the first lookup is meant to prefer.
>
> So let's compare the scope of the best candidate with the scope of the
> destination instead.
>
> This issue was found for a development of a UDP tunnel device with
> IPv6 addresses in a VRF selecting an IPv6 link-local source
> address for a global destination: then it was confirmed with the
> fib_tests.sh case of the next commit, whose first two checks fail without
> this fix on a CONFIG_INIT_STACK_ALL_ZERO=y kernel.
>
> Fixes: abb9a68d2c64 ("ipv6: take care of scope when choosing the src addr")
> Cc: stable@vger.kernel.org
> Signed-off-by: Vincent Jardin <vjardin@free.fr>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 13:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:30 [PATCH net 0/2] ipv6: fix IPv6 scope check of the source address in a VRF Vincent Jardin via B4 Relay
2026-11-23 14:30 ` [PATCH net 1/2] ipv6: check the scope of the best source address candidate " Vincent Jardin via B4 Relay
2026-11-24 13:55 ` Nicolas Dichtel
2026-11-23 14:30 ` [PATCH net 2/2] selftests: fib_tests: test IPv6 source address of " Vincent Jardin via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox