ipvs: do not delay the dst_release calls
Subsystems (4)
Julian Anastasov
maintainerPATCH v2 1/1 ipvs: do not delay the dst_release calls
syzbot is reporting [1] for a crash when IPVS initiates delayed dst_release calls from its pernet subsys cleanup handler.
Yalagada Pavan Kumar proposed a new rcu_barrier() to be added but the problem is different: the FIB layer started to replace the dst->dev with a blackhole_netdev before the NETDEV_DOWN event is delivered to the ip_vs_dst_event() handler. As ip_vs_forget_dev() matches the dst->dev and not the ifindex, IPVS can miss the event and to defer the dst_release() call from the pernet device phase to the pernet subsys phase where ip6_route_net_exit() already destroyed the per-CPU destination counters.
Fix the dst_release delays in two ways:
1. Cache the ifindex together with the dst and match it on NETDEV_DOWN event to protect against dst->dev being replaced with blackhole_netdev. As result, dst_release will not be left for the dest server removal. This problem can delay the dst_release for long time if the used device was marked down independently and not used actively in IPVS before the dest server is removed.
2. Do not call dst_release from our own RCU callback, dst_release uses its own RCU callback to destroy the dst, so we can call it immediately. This allows rcu_barrier to destroy the dst during the pernet device cleanup.
[1]
BUG: unable to handle page fault for address: ffff8880d456e000 PGD 1d131067 P4D 1d131067 PUD 0 Oops: Oops: 0000 [#1] SMP KASAN NOPTI CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Tainted: G L syzkaller #0 PREEMPT(full) Tainted: [L]=SOFTLOCKUP Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:percpu_counter_add_batch+0x4b/0x230 lib/percpu_counter.c:98 Code: 8d 45 58 48 89 c2 48 89 44 24 08 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 9f 01 00 00 4d 8b 65 58 4c 89 ff <65> 49 63 2c 24 4a 8d 54 35 00 48 89 6c 24 10 48 89 eb 48 89 d0 48 RSP: 0018:ffffc900006b0d68 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: ffff88803e0cf400 RCX: 0000000000000101 RDX: 1ffff11007045bab RSI: ffffffff85702e00 RDI: 0000000000000020 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000003 R11: 0000000000000001 R12: 0000000000000000 R13: ffff88803822dd00 R14: ffffffffffffffff R15: 0000000000000020 FS: 0000000000000000(0000) GS:ffff8880d456e000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff8880d456e000 CR3: 0000000025b53000 CR4: 0000000000352ef0 DR0: 0000000000000010 DR1: 00000000fffffffd DR2: 400000000001001d DR3: fffffffffffffff6 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Call Trace: <IRQ> dst_entries_add include/net/dst_ops.h:59 [inline] dst_count_dec net/core/dst.c:163 [inline] dst_count_dec net/core/dst.c:160 [inline] dst_release net/core/dst.c:177 [inline] dst_release+0x2aa/0x330 net/core/dst.c:166 ip_vs_dest_dst_rcu_free+0x32/0x50 net/netfilter/ipvs/ip_vs_ctl.c:1081 rcu_do_batch kernel/rcu/tree.c:2650 [inline] rcu_core+0x5f0/0x1220 kernel/rcu/tree.c:2919 handle_softirqs+0x216/0xa20 kernel/softirq.c:669 __do_softirq kernel/softirq.c:703 [inline] invoke_softirq kernel/softirq.c:542 [inline] __irq_exit_rcu+0x178/0x220 kernel/softirq.c:786 irq_exit_rcu+0x9/0x30 kernel/softirq.c:809 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline] sysvec_apic_timer_interrupt+0xa3/0xc0 arch/x86/kernel/apic/apic.c:1062 </IRQ> <TASK>
---
Changes in v2:
* no changes, just mention the prerequisite
Due to small collision in include/net/ip_vs.h this patch needs to be applied after "ipvs: pass correct sk to update_pmtu and on tunneling"
include/net/ip_vs.h | 3 ++- net/netfilter/ipvs/ip_vs_ctl.c | 14 ++++------ net/netfilter/ipvs/ip_vs_xmit.c | 45 +++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 20 deletions(-)
include/net/ip_vs.h +2 -1
@@ -964,6 +964,7 @@ struct ip_vs_service {struct ip_vs_dest_dst {struct dst_entry *dst_cache;/* destination cache entry */ u32 dst_cookie; +int dst_ifindex;/* dev ifindex or 0 */ union nf_inet_addr dst_saddr;struct rcu_head rcu_head; };
@@ -2007,7 +2008,7 @@ int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, unsigned int toff, const struct nf_hook_state *state, struct ip_vs_iphdr *ciph); -void ip_vs_dest_dst_rcu_free (struct rcu_head *head); +void ip_vs_dest_dst_rcu_free (struct ip_vs_dest_dst *dest_dst);#ifdef CONFIG_IP_VS_IPV6 int ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
net/netfilter/ipvs/ip_vs_ctl.c +5 -9
@@ -1072,14 +1072,10 @@ struct ip_vs_dest *ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int destreturn dest; } -void ip_vs_dest_dst_rcu_free (struct rcu_head *head) +void ip_vs_dest_dst_rcu_free (struct ip_vs_dest_dst *dest_dst) { -struct ip_vs_dest_dst *dest_dst =container_of (head, - struct ip_vs_dest_dst, - rcu_head); -dst_release (dest_dst->dst_cache); -kfree (dest_dst); +kfree_rcu (dest_dst, rcu_head); }/* Release dest_dst and dst_cache for dest in user context */
@@ -1090,7 +1086,7 @@ static void __ip_vs_dst_cache_reset(struct ip_vs_dest *dest) old =rcu_dereference_protected (dest->dest_dst,1 );if (old) {RCU_INIT_POINTER (dest->dest_dst,NULL ); -call_rcu (&old->rcu_head, ip_vs_dest_dst_rcu_free); +ip_vs_dest_dst_rcu_free (old); } }
@@ -2246,13 +2242,13 @@ void ip_vs_service_nets_cleanup(struct list_head *net_list)/* Put all references for device (dst_cache) */ static inline void -ip_vs_forget_dev (struct ip_vs_dest *dest,struct net_device *dev) +ip_vs_forget_dev (struct ip_vs_dest *dest,const struct net_device *dev) {struct ip_vs_dest_dst *dest_dst;spin_lock_bh (&dest->dst_lock); dest_dst =rcu_dereference_protected (dest->dest_dst,1 ); -if (dest_dst && dest_dst->dst_cache->dev == dev) { +if (dest_dst && dest_dst->dst_ifindex == dev->ifindex) { IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n", dev->name, IP_VS_DBG_ADDR(dest->af, &dest->addr),
net/netfilter/ipvs/ip_vs_xmit.c +35 -10
125 lines not on this page · raw message
Prerequisite-Message-Id: <[email protected]>
Signature · 1 line
2.56.1