KCSAN: data-race in _raw_spin_lock / do_exit

Status: moderation: reported on 2026/11/18 00:03
Subsystems: kernel
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+9a0dc729f3c2d4bae1d8@syzkaller.appspotmail.com
First crash: 4h57m, last: 4h57m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  15dd3a948855 hrtimer: Push reprogramming timers into the interrupt return path
  0e98eb14814e entry: Prepare for deferred hrtimer rearming
  e18eecb8b357 Add generic exit-time stack-depth checking to CONFIG_DEBUG_STACK_USAGE
  7c9f8861e6c9 stackprotector: use canary at end of stack to indicate overruns at oops time
  
✨ AI-generated root cause summary:

Under CONFIG_DEBUG_STACK_USAGE, stack_not_used() in kernel/exit.c scans the task's kernel stack from end_of_stack(p) upward using a plain, unannotated C dereference while (!*n) to determine the lowest unused stack slot. When invoked on current in check_stack_usage() during do_exit() while interrupts and preemption remain enabled, KCSAN instruments the read of an unused zeroed stack word and sets a watchpoint. An asynchronous timer interrupt (sysvec_apic_timer_interrupt) occurring on the same CPU during KCSAN's delay executes irqentry_exit() on the task stack, pushing stack frames and writing local variables (such as val = 0 in queued_spin_lock()), triggering a benign same-task data race on the task stack.

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

Technical Mechanism and Root Cause

1. Functions, Structs, and Files Involved


2. Triggering Sequence and Invariant Violation

  1. Unannotated Stack Scan: During task termination in do_exit() (kernel/exit.c:1015), check_stack_usage() calls stack_not_used(current) while preemption and interrupts are still enabled (preempt_disable() is only called on line 1016). On architectures where the stack grows downward (!CONFIG_STACK_GROWSUP), stack_not_used() iterates over stack addresses:

    unsigned long *n = end_of_stack(p);
    
    do {    /* Skip over canary */
        n++;
    } while (!*n);
    

    Because *n is a plain, unannotated C pointer dereference rather than marked with READ_ONCE_NOCHECK(*n), data_race(*n), or defined with __no_kcsan, KCSAN treats accesses to *n as regular shared-memory reads and instruments them.

  2. KCSAN Watchpoint Setup and Delay: While scanning an unused, zeroed stack word at 0xffffc9000448fc20, KCSAN sets up a watchpoint covering [0xffffc9000448fc20, 0xffffc9000448fc28) via kcsan_setup_watchpoint() and pauses the CPU in delay_access() -> udelay() -> delay_tsc() -> native_pause().

  3. Asynchronous Interrupt on the Same Task and CPU: While paused in native_pause(), an asynchronous APIC timer interrupt (sysvec_apic_timer_interrupt) is delivered to CPU 1. Under DEFINE_IDTENTRY_SYSVEC (arch/x86/include/asm/idtentry.h:256-265), irqentry_enter() creates a trap frame (struct pt_regs) on the interrupted task's stack. Although the main interrupt handler runs on the per-CPU interrupt stack via run_sysvec_on_irqstack_cond(), control switches back to the task stack before calling irqentry_exit(regs, state).

  4. Task Stack Growth into the Watched Memory: On the task stack, irqentry_exit() -> irqentry_exit_to_kernel_mode() -> irqentry_exit_to_kernel_mode_after_preempt() -> irqentry_hrtimer_rearm_deferred() calls __hrtimer_rearm_deferred() (kernel/time/hrtimer.c:2193), which acquires a raw spinlock via guard(raw_spinlock)(&cpu_base->lock). In queued_spin_lock() (include/asm-generic/qspinlock.h:108-116):

    static __always_inline void queued_spin_lock(struct qspinlock *lock)
    {
        int val = 0;
    
        if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val, _Q_LOCKED_VAL)))
            return;
    ...
    

    The local variable int val = 0 is allocated on the stack and has its address passed to atomic_try_cmpxchg_acquire(). Because its address escapes to an atomic helper, the compiler emits an instrumented store for val = 0 at address 0xffffc9000448fc24 (4 bytes). This address falls directly inside the watchpoint window [0xffffc9000448fc20, 0xffffc9000448fc28) previously registered by stack_not_used(). When the interrupt unwinds, return addresses (e.g. 0xffffffff815205b9) are left in that stack region, changing the memory from 0x0000000000000000 to non-zero and tripping KCSAN's watchpoint detection.


3. Root Cause Summary

The root cause is that stack_not_used() reads its argument's kernel stack memoryβ€”which can legally be modified asynchronously by interrupt handlers executing on the same task stack or concurrently by another task when queried from sched_show_task()β€”using a plain, unannotated memory dereference (while (!*n)). Because compiler instrumentation is active, KCSAN detects the concurrent stack write from the nested interrupt handler as a data race. Marking the read as a known diagnostic race (e.g., using READ_ONCE_NOCHECK(*n) or data_race(*n)) or annotating stack_not_used() with __no_kcsan prevents KCSAN from setting watchpoints on volatile stack regions.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
a5247c66 assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in _raw_spin_lock / do_exit 2026/11/17 21:19 2026/11/17 21:19 2026/11/17 21:38 ca622473
767709e7 bisect-cause ❓ KCSAN: data-race in _raw_spin_lock / do_exit 2026/11/17 21:17 2026/11/17 21:17 2026/11/17 21:55 ca622473
0466bb75 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in _raw_spin_lock / do_exit 2026/11/17 21:17 2026/11/17 21:17 2026/11/17 21:24 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in _raw_spin_lock / do_exit

write to 0xffffc9000448fc24 of 4 bytes by task 4867 on cpu 1:
 queued_spin_lock include/asm-generic/qspinlock.h:110 [inline]
 do_raw_spin_lock include/linux/spinlock.h:188 [inline]
 __raw_spin_lock include/linux/spinlock_api_smp.h:191 [inline]
 _raw_spin_lock+0x31/0xc0 kernel/locking/spinlock.c:173
 class_raw_spinlock_constructor include/linux/spinlock.h:559 [inline]
 __hrtimer_rearm_deferred+0x4a/0x660 kernel/time/hrtimer.c:2193
 hrtimer_rearm_deferred_tif include/linux/hrtimer_rearm.h:58 [inline]
 hrtimer_rearm_deferred include/linux/hrtimer_rearm.h:67 [inline]
 irqentry_hrtimer_rearm_deferred include/linux/irq-entry-common.h:471 [inline]
 irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:509 [inline]
 irqentry_exit_to_kernel_mode include/linux/irq-entry-common.h:546 [inline]
 irqentry_exit+0x5bc/0x640 kernel/entry/common.c:154
 sysvec_apic_timer_interrupt+0x44/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
 stack_not_used kernel/exit.c:804 [inline]
 check_stack_usage kernel/exit.c:853 [inline]
 do_exit+0xf39/0x1530 kernel/exit.c:1015
 kthread+0x250/0x2a0 kernel/kthread.c:438
 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 to 0xffffc9000448fc20 of 8 bytes by task 4867 on cpu 1:
 stack_not_used kernel/exit.c:804 [inline]
 check_stack_usage kernel/exit.c:853 [inline]
 do_exit+0xf39/0x1530 kernel/exit.c:1015
 kthread+0x250/0x2a0 kernel/kthread.c:438
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

value changed: 0x0000000000000000 -> 0xffffffff815205b9

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 4867 Comm: kworker/R-ext4- Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 19:54 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _raw_spin_lock / do_exit
* Struck through repros no longer work on HEAD.