Skip to contentSkip to conversation

ipv6: reject released nexthop object routes in ip6_dst_check()

PATCH Applied Qiliang Yuan 4 participants 5 messages Nov 23 – Nov 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: reject released nexthop object routes in ip6_dst_check()

A per-cpu IPv6 route through a nexthop object records the fib6_sernum of its netns, and ip6_dst_check() accepts it as long as that value matches the fib6_sernum of the netns of its device, without looking at dst->obsolete as it does for per-cpu routes without a nexthop object.

When such a route is released with dst_dev_put(), for example when its nexthop is deleted from a group or replaced in place and the old nexthop is freed, it is pointed to blackhole_netdev, which belongs to init_net. For a socket in init_net the recorded fib6_sernum stays current until something else changes the IPv6 routes there, so the socket keeps sending into blackhole_netdev: send() succeeds and every datagram is dropped.

Reject routes that dst_dev_put() marked DST_OBSOLETE_DEAD in rt6_is_valid(), as ipv4_dst_check() does, so that the socket looks up its route again.

A connected UDP socket in init_net sends 3000 datagrams, one per ms, to a route through group {nh 1, nh 2} taking nh 1, and nh 1 is deleted, or replaced in place by one through the gateway of nh 2, after 1 s, with no other IPv6 route change in init_net. Datagrams that arrived through neither nexthop, 5 trials, median and range:

before (datagrams) after (datagrams) change

  delete         2060 (2049-2064)                   0    -100%
  replace        2061 (2059-2065)                   0    -100%
Fixes 8f34e53b60b33 ("ipv6: Use global sernum for dst validation with nexthop objects")
---
 net/ipv6/route.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/route.c +2 -1
index 1b2dcc066e198..dbc878c09b870 100644
@@ -1466,7 +1466,8 @@ static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
 
 static bool rt6_is_valid(const struct rt6_info *rt6)
 {
-	return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
+	return READ_ONCE(rt6->dst.obsolete) == DST_OBSOLETE_FORCE_CHK &&
+	       rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
 }
 
 /* It should be called with rcu_read_lock() acquired */

---
base-commit: af6737b9066832a2017c281159950ba92385ce00
change-id: 20261123-bug-net-ipv6-dst-check-released-91ceae12f8e6

Best regards,

Signature · 1 line
Qiliang Yuan <[email protected]>
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw
Quoted 3 lines · On Mon, Nov 23, 2026 at 07:02:23AM +0000, [email protected] wrote:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

The Sashiko review of v5 3/4 of my netns move series [1] pointed out that a socket in init_net keeps sending into blackhole_netdev once the routes of a removed group member are released. I reproduced it in a VM on net-next with the test described in the commit message and confirmed that it happens without that series too, which is why the fix goes to net on its own.

[1] https://lore.kernel.org/r/[email protected]

Thanks,
Qiliang

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Qiliang Yuan
Quoted 23 lines · Qiliang Yuan

A per-cpu IPv6 route through a nexthop object records the fib6_sernum of its netns, and ip6_dst_check() accepts it as long as that value matches the fib6_sernum of the netns of its device, without looking at dst->obsolete as it does for per-cpu routes without a nexthop object.

When such a route is released with dst_dev_put(), for example when its nexthop is deleted from a group or replaced in place and the old nexthop is freed, it is pointed to blackhole_netdev, which belongs to init_net. For a socket in init_net the recorded fib6_sernum stays current until something else changes the IPv6 routes there, so the socket keeps sending into blackhole_netdev: send() succeeds and every datagram is dropped.

Reject routes that dst_dev_put() marked DST_OBSOLETE_DEAD in rt6_is_valid(), as ipv4_dst_check() does, so that the socket looks up its route again.

A connected UDP socket in init_net sends 3000 datagrams, one per ms, to a route through group {nh 1, nh 2} taking nh 1, and nh 1 is deleted, or replaced in place by one through the gateway of nh 2, after 1 s, with no other IPv6 route change in init_net. Datagrams that arrived through neither nexthop, 5 trials, median and range:

Quoted 6 lines

before (datagrams) after (datagrams) change

  delete         2060 (2049-2064)                   0    -100%
  replace        2061 (2059-2065)                   0    -100%
Fixes 8f34e53b60b33 ("ipv6: Use global sernum for dst validation with nexthop objects")
#4 lore raw
In reply to Qiliang Yuan
This patch was applied to netdev/net.git (main) by Willem de Bruijn <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <[email protected]>:

Quoted 13 lines · On Mon, 23 Nov 2026 01:59:13 -0500 you wrote:

A per-cpu IPv6 route through a nexthop object records the fib6_sernum of its netns, and ip6_dst_check() accepts it as long as that value matches the fib6_sernum of the netns of its device, without looking at dst->obsolete as it does for per-cpu routes without a nexthop object.

When such a route is released with dst_dev_put(), for example when its nexthop is deleted from a group or replaced in place and the old nexthop is freed, it is pointed to blackhole_netdev, which belongs to init_net. For a socket in init_net the recorded fib6_sernum stays current until something else changes the IPv6 routes there, so the socket keeps sending into blackhole_netdev: send() succeeds and every datagram is dropped.

Quoted 1 line

[...]

Here is the summary with links:
- [net] ipv6: reject released nexthop object routes in ip6_dst_check()

    https://git.kernel.org/netdev/net/c/86b669b1d3f0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html