syzbot
KCSAN: data-race in kthread_data / loop_process_work
Status:
moderation: reported on 2026/11/19 00:04
Subsystems:
kernel
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+4593b8da5f17144fd293@syzkaller.appspotmail.com
First crash: 1d22h, last: 1d07h
✨ AI-generated root cause summary:
In loop_process_work() (drivers/block/loop.c:1874), a kworker task performs an unmarked read-modify-write on its flags field (current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO) with interrupts enabled. An interrupt occurring on the same CPU (such as the scheduler tick invoking wq_worker_tick() -> kthread_data() -> to_kthread()) reads k->flags using READ_ONCE(k->flags) in kernel/kthread.c:84. Because commit fd00a46e36a1 annotated the read in to_kthread() with READ_ONCE() rather than data_race() while kernel-wide task flag updates remain plain unmarked operations, KCSAN detects and reports a data race between the unmarked write and the marked read.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Files Involved
drivers/block/loop.c (loop_process_work): Updates current->flags in a loop work item using an unmarked bitwise OR operation.
kernel/kthread.c (to_kthread, kthread_data): Reads k->flags under to_kthread() to assert PF_KTHREAD using READ_ONCE(k->flags).
kernel/workqueue.c (wq_worker_tick): Calls kthread_data(task) during scheduler ticks to obtain the struct worker * associated with a kworker.
struct task_struct::flags (include/linux/sched.h): The 32-bit unsigned int field storing task attributes (PF_*).
2. Technical Mechanism and Trigger Condition
-
Unmarked Write in loop_process_work() (drivers/block/loop.c:1874):
When processing queued commands for a loop device, loop_process_work() sets memory allocation and writeback flags on the current worker thread:
current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO;
At this point, local interrupts are enabled (the driver does not disable IRQs until spin_lock_irq(&lo->lo_work_lock) on line 1875). Under KCSAN, this unmarked read-modify-write sets up a watchpoint on ¤t->flags and delays execution (delay_access() / udelay()).
-
Concurrent Marked Read in IRQ Context (kernel/kthread.c:84):
While task 576 delays on CPU 0 with interrupts enabled, an APIC timer interrupt fires on CPU 0:
sysvec_apic_timer_interrupt()
-> hrtimer_interrupt()
-> update_process_times()
-> sched_tick()
In sched_tick(), the scheduler checks if (curr->flags & PF_WQ_WORKER) and calls wq_worker_tick(curr):
void wq_worker_tick(struct task_struct *task)
{
struct worker *worker = kthread_data(task);
...
}
kthread_data() in turn invokes to_kthread(task):
static inline struct kthread *to_kthread(struct task_struct *k)
{
WARN_ON(!(READ_ONCE(k->flags) & PF_KTHREAD));
return k->worker_private;
}
to_kthread() performs a marked 4-byte read (READ_ONCE(k->flags)) of the exact same memory word (0xffff888101c5c52c) that is currently being modified by loop_process_work().
-
Why KCSAN Reports a Bug:
Commit fd00a46e36a1 ("kthread: Annotate lockless to_kthread() flags access") changed k->flags & PF_KTHREAD in to_kthread() to READ_ONCE(k->flags) & PF_KTHREAD to annotate that to_kthread() can locklessly inspect k->flags because PF_KTHREAD is immutable across the task lifecycle.
However, across the kernel (loop_process_work(), memalloc_flags_save(), etc.), task flag updates are written using plain, unmarked operations (current->flags |= ...). In KCSAN's concurrency model, pairing an unmarked write or read-modify-write with a marked read (READ_ONCE()) still constitutes a reportable data race. Because to_kthread() intentionally reads k->flags locklessly while writers do not use WRITE_ONCE(), the read in to_kthread() requires data_race() (e.g. data_race(READ_ONCE(k->flags)) or data_race(k->flags)), or the writers would need atomic/marked updates.
Sample crash report:
* Struck through repros no longer work on HEAD.