Skip to content

Commit 06ec313

Browse files
idoschdavem330
authored andcommitted
vxlan: Do not assume RTNL is held in vxlan_fdb_info()
vxlan_fdb_info() is not always called with RTNL held or from an RCU read-side critical section. For example, in the following call path: vxlan_cleanup() vxlan_fdb_destroy() vxlan_fdb_notify() __vxlan_fdb_notify() vxlan_fdb_info() The use of rtnl_dereference() can therefore result in the following splat [1]. Fix this by dereferencing the nexthop under RCU read-side critical section. [1] [May24 22:56] ============================= [ +0.004676] WARNING: suspicious RCU usage [ +0.004614] 5.7.0-rc5-custom-16219-g201392003491 #2772 Not tainted [ +0.007116] ----------------------------- [ +0.004657] drivers/net/vxlan.c:276 suspicious rcu_dereference_check() usage! [ +0.008164] other info that might help us debug this: [ +0.009126] rcu_scheduler_active = 2, debug_locks = 1 [ +0.007504] 5 locks held by bash/6892: [ +0.004392] #0: ffff8881d47e3410 (&sig->cred_guard_mutex){+.+.}-{3:3}, at: __do_execve_file.isra.27+0x392/0x23c0 [ +0.011795] #1: ffff8881d47e34b0 (&sig->exec_update_mutex){+.+.}-{3:3}, at: flush_old_exec+0x510/0x2030 [ +0.010947] #2: ffff8881a141b0b0 (ptlock_ptr(page)#2){+.+.}-{2:2}, at: unmap_page_range+0x9c0/0x2590 [ +0.010585] #3: ffff888230009d50 ((&vxlan->age_timer)){+.-.}-{0:0}, at: call_timer_fn+0xe8/0x800 [ +0.010192] #4: ffff888183729bc8 (&vxlan->hash_lock[h]){+.-.}-{2:2}, at: vxlan_cleanup+0x133/0x4a0 [ +0.010382] stack backtrace: [ +0.005103] CPU: 1 PID: 6892 Comm: bash Not tainted 5.7.0-rc5-custom-16219-g201392003491 #2772 [ +0.009675] Hardware name: Mellanox Technologies Ltd. MSN2100-CB2FO/SA001017, BIOS 5.6.5 06/07/2016 [ +0.010155] Call Trace: [ +0.002775] <IRQ> [ +0.002313] dump_stack+0xfd/0x178 [ +0.003895] lockdep_rcu_suspicious+0x14a/0x153 [ +0.005157] vxlan_fdb_info+0xe39/0x12a0 [ +0.004775] __vxlan_fdb_notify+0xb8/0x160 [ +0.004672] vxlan_fdb_notify+0x8e/0xe0 [ +0.004370] vxlan_fdb_destroy+0x117/0x330 [ +0.004662] vxlan_cleanup+0x1aa/0x4a0 [ +0.004329] call_timer_fn+0x1c4/0x800 [ +0.004357] run_timer_softirq+0x129d/0x17e0 [ +0.004762] __do_softirq+0x24c/0xaef [ +0.004232] irq_exit+0x167/0x190 [ +0.003767] smp_apic_timer_interrupt+0x1dd/0x6a0 [ +0.005340] apic_timer_interrupt+0xf/0x20 [ +0.004620] </IRQ> Fixes: 1274e1c ("vxlan: ecmp support for mac fdb entries") Signed-off-by: Ido Schimmel <[email protected]> Reported-by: Amit Cohen <[email protected]> Acked-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f36221e commit 06ec313

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/net/vxlan.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
263263
struct nlmsghdr *nlh;
264264
struct nexthop *nh;
265265
struct ndmsg *ndm;
266+
int nh_family;
267+
u32 nh_id;
266268

267269
nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
268270
if (nlh == NULL)
@@ -273,13 +275,20 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
273275

274276
send_eth = send_ip = true;
275277

276-
nh = rcu_dereference_rtnl(fdb->nh);
278+
rcu_read_lock();
279+
nh = rcu_dereference(fdb->nh);
280+
if (nh) {
281+
nh_family = nexthop_get_family(nh);
282+
nh_id = nh->id;
283+
}
284+
rcu_read_unlock();
285+
277286
if (type == RTM_GETNEIGH) {
278287
if (rdst) {
279288
send_ip = !vxlan_addr_any(&rdst->remote_ip);
280289
ndm->ndm_family = send_ip ? rdst->remote_ip.sa.sa_family : AF_INET;
281290
} else if (nh) {
282-
ndm->ndm_family = nexthop_get_family(nh);
291+
ndm->ndm_family = nh_family;
283292
}
284293
send_eth = !is_zero_ether_addr(fdb->eth_addr);
285294
} else
@@ -299,7 +308,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
299308
if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr))
300309
goto nla_put_failure;
301310
if (nh) {
302-
if (nla_put_u32(skb, NDA_NH_ID, nh->id))
311+
if (nla_put_u32(skb, NDA_NH_ID, nh_id))
303312
goto nla_put_failure;
304313
} else if (rdst) {
305314
if (send_ip && vxlan_nla_put_addr(skb, NDA_DST,

0 commit comments

Comments
 (0)