ipvs: wait for RCU callbacks before dst_ops teardown
Subsystems (5)
PATCH 1/1 ipvs: wait for RCU callbacks before dst_ops teardown
From: Yalagada Pavan Kumar <[email protected]>
During network namespace cleanup, IPVS releases cached destinations using RCU callbacks. However, ip6_route_net_exit() destroys the per-CPU destination counters before these callbacks complete. The RCU callbacks call dst_release(), which updates the destroyed counters and causes a NULL pointer dereference in percpu_counter_add_batch().
Call rcu_barrier() at the end of __ip_vs_cleanup_batch() to make sure all pending IPVS RCU callbacks finish before the destination counters are destroyed.
--- net/netfilter/ipvs/ip_vs_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/ipvs/ip_vs_core.c +5 -0
@@ -2553,6 +2553,11 @@ static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)IP_VS_DBG (2 ,"ipvs netns %d released\n" , ipvs->gen); net->ipvs =NULL ; } + +/* +* Wait for ip_vs_dest_dst_rcu_free() callbacks before dst_ops teardown +*/ +rcu_barrier (); } static void __net_exit __ip_vs_dev_cleanup_batch(struct list_head *net_list)
Signature · 1 line
2.43.0
Julian Anastasov
maintainerHello,
Adding Wei Wang to the CC list...
Quoted 9 lines · On Sun, 15 Nov 2026, [email protected] wrote:
From: Yalagada Pavan Kumar <[email protected]>
During network namespace cleanup, IPVS releases cached destinations using RCU callbacks. However,
ip6_route_net_exit()destroys the per-CPU destination counters before these callbacks complete. The RCU callbacks calldst_release(), which updates the destroyed counters and causes a NULL pointer dereference inpercpu_counter_add_batch().
Quoted 3 lines
Call
rcu_barrier()at the end of__ip_vs_cleanup_batch()to make sure all pending IPVS RCU callbacks finish before the destination counters are destroyed.
What you see is a result of more fundamental problem.
IPVS is supposed to catch all NETDEV_DOWN events coming from the pernet device phase which come before the pernet subsys phase. So, on cleanup_net IPVS is supposed to run its subsys cleanup with no traffic, no devs, no cached dsts, no netfilter hooks, etc.
But in my tests free_fib_info_rcu -> fib_nh_release ->
fib_nh_common_release -> rt_fibinfo_free_cpus calls dst_dev_put() where the dst device that IPVS listens for is replaced with a blackhole_netdev. This happens before the NETDEV_DOWN event and as result IPVS misses the event because dst->dev is already replaced and does not match. When such dst_cache remains for the pernet subsys cleanup you see these crashes because IPVS has another problem that it does not call dst_release immediately but from RCU callback.
I now created a change to call dst_release immediately
but the problem with the blackholing before NETDEV_DOWN remains. It can hurt other event listeners.
My tests were with tools/testing/selftests/net/netfilter/ipvs.sh
where I modify it to run only the NAT test. What I see is veth12 to be blackholed before its NETDEV_DOWN event and ip_vs_forget_dev() missed it. Trying to find more information...
Quoted 29 lines
Reported-by [email protected]Fixes 026ace060dfe ("ipvs: optimize dst usage for real server")Signed-off-by Yalagada Pavan Kumar <[email protected]>--- net/netfilter/ipvs/ip_vs_core.c | 5 +++++ 1 file changed, 5 insertions(+)net/netfilter/ipvs/ip_vs_core.c +5
-0@@ -2553,6 +2553,11 @@ static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)IP_VS_DBG (2 ,"ipvs netns %d released\n" , ipvs->gen); net->ipvs =NULL ; } + +/* +* Wait for ip_vs_dest_dst_rcu_free() callbacks before dst_ops teardown +*/ +rcu_barrier (); } static void __net_exit __ip_vs_dev_cleanup_batch(struct list_head *net_list)Signature · 1 line
2.43.0
Regards
--
Julian Anastasov <[email protected]>