syzbot
KCSAN: data-race in queue_delayed_work_on / queue_delayed_work_on
Status:
moderation: reported on 2026/11/22 00:48
Subsystems:
net
Labels:
prio:high
race:benign
[Documentation on labels]
Reported-by: syzbot+4d949380380b54ef4564@syzkaller.appspotmail.com
First crash: 4d20h, last: 3h13m
✨ AI-generated root cause summary:
When queueing a work item via queue_delayed_work_on() or queue_work_on(), the caller atomically sets WORK_STRUCT_PENDING_BIT using test_and_set_bit(..., work_data_bits(work)). If the bit was previously clear, the winner calls clear_pending_if_disabled(), which performs an unmarked plain load (*work_data_bits(work)) from work->data instead of using an atomic accessor (e.g. atomic_long_read). If another thread concurrently calls queue_delayed_work_on() on the same work item, its test_and_set_bit() performs an atomic RMW on work->data concurrently with the unmarked load, triggering a KCSAN data-race report.
▶
▼
✨ Full AI root cause analysis
Technical Analysis of Root Cause
1. Involved Files, Functions, and Data Structures
- Source Files:
- Functions:
kernel/workqueue.c: clear_pending_if_disabled() (line 2560), queue_delayed_work_on() (line 2755), queue_work_on() (line 2589)
drivers/net/bonding/bond_main.c: bond_netdev_notify_work() (line 1805), bond_queue_slave_event() (line 1822), bond_enslave() (line 1888)
- Structures and Fields:
2. Detailed Mechanism and Trigger Sequence
-
Workqueue Disabling Feature (clear_pending_if_disabled):
Commit 86898fa6b8cd ("workqueue: Implement disable/enable for (delayed) work items") introduced disable/enable semantics for work items by encoding a 16-bit disable depth within work->data while the work item is off-queue. To enforce this when queueing a work item, queue_work_on() and queue_delayed_work_on() perform:
if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) &&
!clear_pending_if_disabled(work)) {
__queue_delayed_work(cpu, wq, dwork, delay);
ret = true;
}
Inside clear_pending_if_disabled():
static bool clear_pending_if_disabled(struct work_struct *work)
{
unsigned long data = *work_data_bits(work); // Line 2562: Unmarked plain read
...
Unlike other places in kernel/workqueue.c that inspect work->data (e.g., get_work_pwq() and get_work_pool(), which use atomic_long_read(&work->data)), line 2562 dereferences work_data_bits(work) directly with a plain, unmarked C read (*work_data_bits(work)).
-
Triggering the Concurrent Access via Bonding:
Concurrent invocations of queue_work() or queue_delayed_work() on the same work item from different contexts are legal and supported by workqueue semantics, designed to be synchronized via test_and_set_bit(WORK_STRUCT_PENDING_BIT, ...).
- In
bond_enslave(), new_slave->notify_work is queued on CPU 0 while holding the rtnl_lock (e.g., via bond_set_slave_link_state() or bond_set_slave_inactive_flags()).
- A worker thread (Task 13 on CPU 1) picks up
notify_work. Before calling the worker callback, workqueue infrastructure clears the WORK_STRUCT_PENDING_BIT. The callback bond_netdev_notify_work() executes and attempts rtnl_trylock(), which fails because CPU 0 is still executing bond_enslave() holding rtnl_lock.
- Failing
rtnl_trylock(), Task 13 calls queue_delayed_work(slave->bond->wq, &slave->notify_work, 1) at line 1818. Task 13 successfully transitions WORK_STRUCT_PENDING_BIT from 0 -> 1 in test_and_set_bit() and proceeds to execute clear_pending_if_disabled(work), performing the unmarked read *work_data_bits(work).
- Concurrently, CPU 0 reaches the end of
bond_enslave() at line 2347 and calls bond_queue_slave_event(new_slave), which executes queue_delayed_work(slave->bond->wq, &slave->notify_work, 0).
- In
queue_delayed_work_on() at line 2765, CPU 0 invokes test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)), executing an atomic read-modify-write (LOCK BTS) on the exact same 8-byte word (work->data).
-
Violation and Sanitizer Detection:
KCSAN detects that clear_pending_if_disabled() performs an uninstrumented, non-atomic plain read from work->data (*work_data_bits(work)) concurrently with another thread executing an atomic read-modify-write (test_and_set_bit()) to the same word. Using atomic_long_read(&work->data) or READ_ONCE(*work_data_bits(work)) in clear_pending_if_disabled() marks the access and avoids the data race report.
Sample crash report:
* Struck through repros no longer work on HEAD.