ipv6: account route exceptions to the netns of their dst
Subsystems (3)
Eric Dumazet
maintainerPATCH 1/1 ipv6: account route exceptions to the netns of their dst
rt6_insert_exception() and rt6_remove_exception() update rt6_stats->fib_rt_cache of dev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket.
This happens when the bucket is flushed from an RCU callback, for instance from nexthop_free_rcu() for the nh_info of a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in /proc/net/rt6_stats, while the counter of the original netns never goes back down.
Account exceptions to the netns their dst was allocated in, derived from dst->ops as ip6_dst_gc() already does, which does not depend on the device. The dst already relies on that netns' ip6_dst_ops being alive when it is destroyed, which happens after the exception is removed.
---
Discovered while reviewing https://lore.kernel.org/netdev/20261016-bug-net-netns-move-rcu-barrier-v1-1-4157d798658f@gmail.com/T/#m7f6763afc4dc72233969ae22567af09cfdb3923a
net/ipv6/route.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/ipv6/route.c +11 -2
@@ -1511,6 +1511,15 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,*/ static DEFINE_SPINLOCK (rt6_exception_lock); +/* Exceptions are accounted to the netns their dst was allocated in. +* Unlike dev_net(dst->dev), it does not change when the device moves to +* another netns or when dst_dev_put() points the dst to blackhole_netdev. +*/ +static struct net *rt6_exception_net (const struct rt6_info *rt) +{ + return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops); +} +/* Remove rt6_ex from hash table and free the memory * Caller must hold rt6_exception_lock */
@@ -1522,7 +1531,7 @@ static void rt6_remove_exception(struct rt6_exception_bucket *bucket,if (!bucket || !rt6_ex)return ; - net =dev_net (rt6_ex->rt6i->dst.dev); + net =rt6_exception_net (rt6_ex->rt6i); net->ipv6.rt6_stats->fib_rt_cache--;/* purge completely the exception to allow releasing the held resources:
@@ -1750,7 +1759,7 @@ static int rt6_insert_exception(struct rt6_info *nrt, rt6_ex->stamp = jiffies;hlist_add_head_rcu (&rt6_ex->hlist, &bucket->chain); bucket->depth++; - net->ipv6.rt6_stats->fib_rt_cache++; +rt6_exception_net (nrt)->ipv6.rt6_stats->fib_rt_cache++;/* Randomize max depth to avoid some side channels attacks. */ max_depth =FIB6_MAX_DEPTH +get_random_u32_below (FIB6_MAX_DEPTH );
Signature · 1 line
2.53.0
[email protected]
AI reviewThis 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:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
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. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Eric Dumazet
maintainerQuoted 10 lines · Le ven. 16 oct. 2026 à 11:19, <[email protected]> a écrit :
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
This is fixing a minor bug : fib_rt_cache is statistics only.
Quoted 8 lines
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. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 12 lines · Eric Dumazet
rt6_insert_exception()andrt6_remove_exception()updatert6_stats->fib_rt_cacheofdev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket.This happens when the bucket is flushed from an RCU callback, for instance from
nexthop_free_rcu()for thenh_infoof a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in/proc/net/rt6_stats, while the counter of the original netns never goes back down.
Quoted 7 lines
Account exceptions to the netns their dst was allocated in, derived from
dst->opsasip6_dst_gc()already does, which does not depend on the device. The dst already relies on that netns'ip6_dst_opsbeing alive when it is destroyed, which happens after the exception is removed.Fixes 81eb8447daae ("ipv6: take care of rt6_stats")Signed-off-by Eric Dumazet <[email protected]>
Quoted 12 lines · Eric Dumazet
rt6_insert_exception()andrt6_remove_exception()updatert6_stats->fib_rt_cacheofdev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket.This happens when the bucket is flushed from an RCU callback, for instance from
nexthop_free_rcu()for thenh_infoof a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in/proc/net/rt6_stats, while the counter of the original netns never goes back down.
Quoted 7 lines
Account exceptions to the netns their dst was allocated in, derived from
dst->opsasip6_dst_gc()already does, which does not depend on the device. The dst already relies on that netns'ip6_dst_opsbeing alive when it is destroyed, which happens after the exception is removed.Fixes 81eb8447daae ("ipv6: take care of rt6_stats")Signed-off-by Eric Dumazet <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Fri, 16 Oct 2026 11:15:56 +0200 you wrote:
rt6_insert_exception()andrt6_remove_exception()updatert6_stats->fib_rt_cacheofdev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket.
Quoted 8 lines
This happens when the bucket is flushed from an RCU callback, for instance from
nexthop_free_rcu()for thenh_infoof a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in/proc/net/rt6_stats, while the counter of the original netns never goes back down.[...]
Here is the summary with links:
- [net] ipv6: account route exceptions to the netns of their dst
https://git.kernel.org/netdev/net/c/8ff017b891e8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html