syzbot
KCSAN: data-race in assign_work / queue_work_on
Status:
moderation: reported on 2026/11/20 00:01
Subsystems:
block
Labels:
prio:high
race:benign
[Documentation on labels]
Reported-by: syzbot+eb6c66d8f130ac27fe3a@syzkaller.appspotmail.com
First crash: 2d22h, last: 4h16m
β¨ AI-generated root cause summary:
A KCSAN data race occurs between move_linked_works() and queue_work_on() when accessing struct work_struct::data. In move_linked_works(), WORK_STRUCT_LINKED is inspected via an unmarked plain load (*work_data_bits(work) & WORK_STRUCT_LINKED) while holding pool->lock. Concurrently, queue_work_on() locklessly executes test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)), performing an instrumented atomic read-modify-write on the same 8-byte word. In production kernels this race is benign, as WORK_STRUCT_PENDING_BIT is already set and test_and_set_bit() does not alter WORK_STRUCT_LINKED_BIT.
▶
▼
β¨ Full AI root cause analysis
Technical Root Cause Analysis
1. Functions, Structs, and Fields Involved
struct work_struct (include/linux/workqueue_types.h:16-23):
Contains atomic_long_t data (field at offset 0). The data field packs several status flags in its lowest bits (including WORK_STRUCT_PENDING_BIT at bit 0 and WORK_STRUCT_LINKED_BIT at bit 3) alongside pointer / color / pool metadata (include/linux/workqueue.h:26-74).
#define work_data_bits(work) (include/linux/workqueue.h:24):
Casts (unsigned long *)(&(work)->data).
move_linked_works() (kernel/workqueue.c:1200-1222), called by assign_work() (kernel/workqueue.c:1240-1274):
Invoked by worker threads (worker_thread() / bh_worker()) under pool->lock to transfer a work item and any associated barrier work items linked behind it from pool->worklist to worker->scheduled.
queue_work_on() (kernel/workqueue.c:2589-2605):
Invoked locklessly (here from WireGuard's transmit path: wg_xmit() -> wg_packet_create_data() -> wg_queue_enqueue_per_device_and_peer()).
2. Triggering Mechanism & Race Condition
- While a work item (here the per-CPU encryption work item of WireGuard's
encrypt_queue) is queued on pool->worklist, its WORK_STRUCT_PENDING_BIT is set to 1. This bit remains 1 until execution starts and set_work_pool_and_clear_pending() is invoked in process_one_work() (kernel/workqueue.c:3456).
- On CPU 1, a worker thread (
PID 3557) picks up this work item from pool->worklist and executes assign_work() -> move_linked_works(). At line 1211 of kernel/workqueue.c:
list_for_each_entry_safe_from(work, n, NULL, entry) {
list_move_tail(&work->entry, head);
if (!(*work_data_bits(work) & WORK_STRUCT_LINKED))
break;
}
The condition *work_data_bits(work) & WORK_STRUCT_LINKED performs an uninstrumented, unmarked plain load from work->data.
- Concurrently on CPU 0, task 6710 is handling network traffic and attempts to queue new encryption work on the same per-CPU work struct by calling
queue_work_on(). At line 2597:
if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) &&
!clear_pending_if_disabled(work)) {
__queue_work(cpu, wq, work);
ret = true;
}
test_and_set_bit() executes an instrumented atomic read-modify-write on the same 8-byte word work->data (0xffffe8ffffd391c0) without holding pool->lock.
- Because one CPU performs an atomic read-modify-write while the other CPU performs a plain, unmarked load to the exact same word, KCSAN detects a data race between
assign_work and queue_work_on.
3. Invariant & Lifecycle Analysis
- Under the Linux Kernel Memory Model, racing a plain load against a concurrent atomic write constitutes a data race.
- In core workqueue,
WORK_STRUCT_LINKED_BIT is modified solely under pool->lock (during insert_wq_barrier() and work processing).
- The concurrent
test_and_set_bit(WORK_STRUCT_PENDING_BIT, ...) sets bit 0, which is already 1, leaving all other bits (including WORK_STRUCT_LINKED_BIT) unchanged.
- Using an atomic or marked read primitiveβsuch as
test_bit(WORK_STRUCT_LINKED_BIT, work_data_bits(work)) or atomic_long_read(&work->data)βin move_linked_works() marks the access appropriately and eliminates the data race.
Sample crash report:
* Struck through repros no longer work on HEAD.