KCSAN: data-race in xa_set_mark / xas_find_marked

Status: moderation: reported on 2026/11/26 11:31
Subsystems: net
Labels: prio:low race:harmful
[Documentation on labels]
Reported-by: syzbot+67feb1aa88152240c158@syzkaller.appspotmail.com
First crash: 2h12m, last: 2h12m
✨ AI-generated root cause summary:

KCSAN reports a data race on xa_node->marks between xa_set_mark() (lib/xarray.c) and xas_find_marked() / xas_find_chunk() (include/linux/xarray.h). While writers hold xa_lock and update node->marks using the non-atomic bitop __test_and_set_bit() in node_set_mark(), lockless RCU readers in xa_find() -> xas_find_marked() call xas_find_chunk(), which performs an unmarked plain read (*addr & (~0UL << offset)) without READ_ONCE() or data_race(). Because CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC is disabled, KCSAN flags the concurrent unmarked read against the non-atomic read-modify-write bitop.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit ebb7a8dc1e74:

Root Cause

This is a KCSAN-reported data race in the XArray mark-tracking code between a locked mark update (xa_set_mark()) and a lockless RCU marked search (xa_find() -> xas_find_marked() -> xas_find_chunk()), triggered concurrently through devlink registration and netlink lookup/dump paths.

Involved Structures, Functions, and Files

Trigger Mechanism

  1. Task 3329 (CPU 1) creates a netdevsim device via sysfs (new_device_store -> nsim_drv_probe -> devl_register at net/devlink/core.c:413). The devlink instance was previously inserted into the devlinks XArray in __devlink_alloc() (net/devlink/core.c:468), and devl_register() sets DEVLINK_REGISTERED (XA_MARK_1) via xa_set_mark(&devlinks, devlink->index, DEVLINK_REGISTERED).
  2. Task 3324 (CPU 0) concurrently executes a netlink dump (devlink_nl_port_get_dumpit -> devlink_nl_dumpit -> devlink_get_from_attrs_lock -> devlinks_xa_find_get -> __devlinks_xa_find_get at net/devlink/core.c:375), which calls xa_find(&devlinks, indexp, end, DEVLINK_REGISTERED) under rcu_read_lock().
  3. While Task 3329 executes __test_and_set_bit() on node->marks[DEVLINK_REGISTERED][0] under xa_lock(&devlinks), Task 3324 reads the same 8-byte node->marks[DEVLINK_REGISTERED][0] word in xas_find_chunk() without xa_lock.

Violated Invariant / Concurrency Rule

Although all writers to xa_node->marks are mutually serialized by xa_lock (and xa_node freeing is RCU-deferred via xa_node_free() -> call_rcu()), lockless RCU readers access node->marks concurrently with xa_lock-protected writers. xas_find_chunk() uses an unmarked plain read (*addr) instead of a marked/atomic read (READ_ONCE()), and node_set_mark() (along with node_clear_mark()) uses non-atomic bitops (__test_and_set_bit() / __test_and_clear_bit()) rather than marked writes or data_race() annotations compatible with KCSAN. Without READ_ONCE() on the reader and atomic/marked updates (or WRITE_ONCE() / set_bit() / data_race()) on the writer, C-level data-race rules are violated, causing KCSAN to flag the concurrent access (and theoretically permitting compiler load/store tearing or reloading across *addr on the reader path).

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
3a29e16c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in xa_set_mark / xas_find_marked 2026/11/26 10:03 2026/11/26 10:03 2026/11/26 10:10 9a575fe5
824d2f96 assessment-kcsan Benign: ❌ ❓ KCSAN: data-race in xa_set_mark / xas_find_marked 2026/11/26 10:02 2026/11/26 10:02 2026/11/26 11:30 9a575fe5

Sample crash report:
==================================================================
BUG: KCSAN: data-race in xa_set_mark / xas_find_marked

read-write to 0xffff888106b77228 of 8 bytes by task 3329 on cpu 1:
 instrument_read_write include/linux/instrumented.h:56 [inline]
 __instrument_read_write_bitop include/asm-generic/bitops/instrumented-non-atomic.h:84 [inline]
 ___test_and_set_bit include/asm-generic/bitops/instrumented-non-atomic.h:99 [inline]
 node_set_mark lib/xarray.c:95 [inline]
 xas_set_mark lib/xarray.c:894 [inline]
 __xa_set_mark lib/xarray.c:2088 [inline]
 xa_set_mark+0xda/0x1b0 lib/xarray.c:2155
 devl_register+0x4c/0x70 net/devlink/core.c:413
 nsim_drv_probe+0x1e1/0x7c0 drivers/net/netdevsim/dev.c:1607
 nsim_bus_probe+0x15/0x20 drivers/net/netdevsim/bus.c:419
 call_driver_probe drivers/base/dd.c:-1 [inline]
 really_probe+0x1ba/0x600 drivers/base/dd.c:707
 __driver_probe_device+0x176/0x1e0 drivers/base/dd.c:869
 driver_probe_device+0x63/0x380 drivers/base/dd.c:899
 __device_attach_driver+0x24e/0x350 drivers/base/dd.c:1027
 bus_for_each_drv+0x1c0/0x230 drivers/base/bus.c:500
 __device_attach+0x1d1/0x2a0 drivers/base/dd.c:1131
 device_initial_probe+0x6a/0xb0 drivers/base/dd.c:1190
 __bus_probe_device+0xfd/0x1b0 drivers/base/bus.c:614
 bus_probe_device+0x15/0x20 drivers/base/bus.c:632
 device_add+0x601/0x7c0 drivers/base/core.c:3778
 device_register+0x1d/0x30 drivers/base/core.c:3860
 nsim_bus_dev_new drivers/net/netdevsim/bus.c:468 [inline]
 new_device_store+0x2b0/0x460 drivers/net/netdevsim/bus.c:191
 bus_attr_store+0x57/0x80 drivers/base/bus.c:172
 sysfs_kf_write+0xfe/0x120 fs/sysfs/file.c:145
 kernfs_fop_write_iter+0x1d2/0x2e0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x57a/0x9b0 fs/read_write.c:667
 ksys_write+0xdc/0x1a0 fs/read_write.c:719
 __do_sys_write fs/read_write.c:730 [inline]
 __se_sys_write fs/read_write.c:727 [inline]
 __x64_sys_write+0x40/0x50 fs/read_write.c:727
 x64_sys_call+0x154e/0x2550 arch/x86/include/generated/asm/syscalls_64.h:2
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff888106b77228 of 8 bytes by task 3324 on cpu 0:
 xas_find_chunk include/linux/xarray.h:1752 [inline]
 xas_find_marked+0x211/0x650 lib/xarray.c:1516
 xa_find+0xa4/0x140 lib/xarray.c:2204
 __devlinks_xa_find_get+0x99/0xe0 net/devlink/core.c:375
 devlinks_xa_find_get+0x24/0x30 net/devlink/core.c:396
 devlink_get_from_attrs_lock+0xd8/0x390 net/devlink/netlink.c:225
 devlink_nl_inst_single_dumpit net/devlink/netlink.c:397 [inline]
 devlink_nl_dumpit+0x26d/0x300 net/devlink/netlink.c:456
 devlink_nl_port_get_dumpit+0x24/0x30 net/devlink/port.c:631
 genl_dumpit+0xac/0x110 net/netlink/genetlink.c:1026
 netlink_dump+0x46a/0x880 net/netlink/af_netlink.c:2360
 __netlink_dump_start+0x483/0x570 net/netlink/af_netlink.c:2475
 genl_family_rcv_msg_dumpit+0x1a5/0x210 net/netlink/genetlink.c:1075
 genl_family_rcv_msg net/netlink/genetlink.c:1191 [inline]
 genl_rcv_msg+0x3fd/0x470 net/netlink/genetlink.c:1209
 netlink_rcv_skb+0x11e/0x220 net/netlink/af_netlink.c:2585
 genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
 netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
 netlink_unicast+0x6fd/0x7e0 net/netlink/af_netlink.c:1362
 netlink_sendmsg+0x605/0x760 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec net/socket.c:800 [inline]
 __sock_sendmsg net/socket.c:818 [inline]
 __sys_sendto+0x429/0x480 net/socket.c:2283
 __do_sys_sendto net/socket.c:2290 [inline]
 __se_sys_sendto net/socket.c:2286 [inline]
 __x64_sys_sendto+0x76/0x90 net/socket.c:2286
 x64_sys_call+0x200c/0x2550 arch/x86/include/generated/asm/syscalls_64.h:45
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3324 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
netdevsim netdevsim1 netdevsim0: renamed from eth0
8021q: adding VLAN 0 to HW filter on device netdevsim0
netdevsim netdevsim1 netdevsim1: renamed from eth1
8021q: adding VLAN 0 to HW filter on device netdevsim1
netdevsim netdevsim1 netdevsim2: renamed from eth2
8021q: adding VLAN 0 to HW filter on device netdevsim2
netdevsim netdevsim1 netdevsim3: renamed from eth3
8021q: adding VLAN 0 to HW filter on device netdevsim3
8021q: adding VLAN 0 to HW filter on device bond0
8021q: adding VLAN 0 to HW filter on device team0
hsr0: Slave A (hsr_slave_0) is not up; please bring it up to get a fully working HSR network
hsr0: Slave B (hsr_slave_1) is not up; please bring it up to get a fully working HSR network
8021q: adding VLAN 0 to HW filter on device batadv0
veth0_vlan: entered promiscuous mode
veth1_vlan: entered promiscuous mode
veth0_macvtap: entered promiscuous mode
veth1_macvtap: entered promiscuous mode
batman_adv: batadv0: Interface activated: batadv_slave_0
batman_adv: batadv0: Interface activated: batadv_slave_1
soft_limit_in_bytes is deprecated and will be removed. Writing any value to this file has no effect. Please report your usecase to linux-mm@kvack.org if you depend on this functionality.

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/26 09:38 upstream ebb7a8dc1e74 9a575fe5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in xa_set_mark / xas_find_marked
* Struck through repros no longer work on HEAD.