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
Based on kernel commit 666539eecdf4:

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

  1. 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 &current->flags and delays execution (delay_access() / udelay()).

  2. 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().

  3. 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.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
016dff71 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in kthread_data / loop_process_work 2026/11/18 15:27 2026/11/18 15:27 2026/11/18 15:36 2006bdcc
15c20102 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in kthread_data / loop_process_work 2026/11/18 15:19 2026/11/18 15:19 2026/11/18 15:42 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in kthread_data / loop_process_work

read (marked) to 0xffff888101c5c52c of 4 bytes by interrupt on cpu 0:
 to_kthread kernel/kthread.c:84 [inline]
 kthread_data+0x17/0x70 kernel/kthread.c:236
 wq_worker_tick+0x2f/0x3c0 kernel/workqueue.c:1569
 sched_tick+0xc8/0x200 kernel/sched/core.c:5876
 update_process_times+0x162/0x190 kernel/time/timer.c:2481
 tick_sched_handle kernel/time/tick-sched.c:296 [inline]
 tick_nohz_handler+0x241/0x3d0 kernel/time/tick-sched.c:317
 __run_hrtimer kernel/time/hrtimer.c:2079 [inline]
 __hrtimer_run_queues+0x1f8/0x540 kernel/time/hrtimer.c:2136
 hrtimer_interrupt+0x27b/0x870 kernel/time/hrtimer.c:2255
 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1051 [inline]
 __sysvec_apic_timer_interrupt+0x5f/0x1f0 arch/x86/kernel/apic/apic.c:1068
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x6f/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 native_pause arch/x86/include/asm/vdso/processor.h:13 [inline]
 delay_tsc+0x43/0xa0 arch/x86/lib/delay.c:76
 udelay include/asm-generic/delay.h:64 [inline]
 delay_access kernel/kcsan/core.c:332 [inline]
 kcsan_setup_watchpoint+0x255/0x3f0 kernel/kcsan/core.c:622
 loop_process_work+0x55/0xb00 drivers/block/loop.c:1874
 loop_workfn+0x31/0x40 drivers/block/loop.c:1906
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

read-write to 0xffff888101c5c52c of 4 bytes by task 576 on cpu 0:
 loop_process_work+0x55/0xb00 drivers/block/loop.c:1874
 loop_workfn+0x31/0x40 drivers/block/loop.c:1906
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 576 Comm: kworker/u8:8 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue: loop1 loop_workfn
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 17:04 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in kthread_data / loop_process_work
2026/11/17 10:24 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in kthread_data / loop_process_work
2026/11/17 02:30 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in kthread_data / loop_process_work
* Struck through repros no longer work on HEAD.