Skip to content

Commit 163f970

Browse files
idoschvijay-suman
authored andcommitted
vxlan: Annotate FDB data races
[ Upstream commit f6205f8 ] The 'used' and 'updated' fields in the FDB entry structure can be accessed concurrently by multiple threads, leading to reports such as [1]. Can be reproduced using [2]. Suppress these reports by annotating these accesses using READ_ONCE() / WRITE_ONCE(). [1] BUG: KCSAN: data-race in vxlan_xmit / vxlan_xmit write to 0xffff942604d263a8 of 8 bytes by task 286 on cpu 0: vxlan_xmit+0xb29/0x2380 dev_hard_start_xmit+0x84/0x2f0 __dev_queue_xmit+0x45a/0x1650 packet_xmit+0x100/0x150 packet_sendmsg+0x2114/0x2ac0 __sys_sendto+0x318/0x330 __x64_sys_sendto+0x76/0x90 x64_sys_call+0x14e8/0x1c00 do_syscall_64+0x9e/0x1a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f read to 0xffff942604d263a8 of 8 bytes by task 287 on cpu 2: vxlan_xmit+0xadf/0x2380 dev_hard_start_xmit+0x84/0x2f0 __dev_queue_xmit+0x45a/0x1650 packet_xmit+0x100/0x150 packet_sendmsg+0x2114/0x2ac0 __sys_sendto+0x318/0x330 __x64_sys_sendto+0x76/0x90 x64_sys_call+0x14e8/0x1c00 do_syscall_64+0x9e/0x1a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f value changed: 0x00000000fffbac6e -> 0x00000000fffbac6f Reported by Kernel Concurrency Sanitizer on: CPU: 2 UID: 0 PID: 287 Comm: mausezahn Not tainted 6.13.0-rc7-01544-gb4b270f11a02 #5 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-3.fc41 04/01/2014 [2] #!/bin/bash set +H echo whitelist > /sys/kernel/debug/kcsan echo !vxlan_xmit > /sys/kernel/debug/kcsan ip link add name vx0 up type vxlan id 10010 dstport 4789 local 192.0.2.1 bridge fdb add 00:11:22:33:44:55 dev vx0 self static dst 198.51.100.1 taskset -c 0 mausezahn vx0 -a own -b 00:11:22:33:44:55 -c 0 -q & taskset -c 2 mausezahn vx0 -a own -b 00:11:22:33:44:55 -c 0 -q & Reviewed-by: Petr Machata <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit e033da39fc6abbddab6c29624acef80757f273fa) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent af8835a commit 163f970

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
335335
be32_to_cpu(fdb->vni)))
336336
goto nla_put_failure;
337337

338-
ci.ndm_used = jiffies_to_clock_t(now - fdb->used);
338+
ci.ndm_used = jiffies_to_clock_t(now - READ_ONCE(fdb->used));
339339
ci.ndm_confirmed = 0;
340-
ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated);
340+
ci.ndm_updated = jiffies_to_clock_t(now - READ_ONCE(fdb->updated));
341341
ci.ndm_refcnt = 0;
342342

343343
if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
@@ -543,8 +543,8 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan,
543543
struct vxlan_fdb *f;
544544

545545
f = __vxlan_find_mac(vxlan, mac, vni);
546-
if (f && f->used != jiffies)
547-
f->used = jiffies;
546+
if (f && READ_ONCE(f->used) != jiffies)
547+
WRITE_ONCE(f->used, jiffies);
548548

549549
return f;
550550
}
@@ -1074,12 +1074,12 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
10741074
!(f->flags & NTF_VXLAN_ADDED_BY_USER)) {
10751075
if (f->state != state) {
10761076
f->state = state;
1077-
f->updated = jiffies;
1077+
WRITE_ONCE(f->updated, jiffies);
10781078
notify = 1;
10791079
}
10801080
if (f->flags != fdb_flags) {
10811081
f->flags = fdb_flags;
1082-
f->updated = jiffies;
1082+
WRITE_ONCE(f->updated, jiffies);
10831083
notify = 1;
10841084
}
10851085
}
@@ -1113,7 +1113,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
11131113
}
11141114

11151115
if (ndm_flags & NTF_USE)
1116-
f->used = jiffies;
1116+
WRITE_ONCE(f->used, jiffies);
11171117

11181118
if (notify) {
11191119
if (rd == NULL)
@@ -1526,7 +1526,7 @@ static bool vxlan_snoop(struct net_device *dev,
15261526
src_mac, &rdst->remote_ip.sa, &src_ip->sa);
15271527

15281528
rdst->remote_ip = *src_ip;
1529-
f->updated = jiffies;
1529+
WRITE_ONCE(f->updated, jiffies);
15301530
vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL);
15311531
} else {
15321532
u32 hash_index = fdb_head_index(vxlan, src_mac, vni);
@@ -2981,7 +2981,7 @@ static void vxlan_cleanup(struct timer_list *t)
29812981
if (f->flags & NTF_EXT_LEARNED)
29822982
continue;
29832983

2984-
timeout = f->used + vxlan->cfg.age_interval * HZ;
2984+
timeout = READ_ONCE(f->used) + vxlan->cfg.age_interval * HZ;
29852985
if (time_before_eq(timeout, jiffies)) {
29862986
netdev_dbg(vxlan->dev,
29872987
"garbage collect %pM\n",

0 commit comments

Comments
 (0)