KCSAN: data-race in 0x0 / fsnotify_destroy_mark

Status: moderation: reported on 2026/11/20 00:01
Subsystems: fs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+887981c8c035f12de9f3@syzkaller.appspotmail.com
First crash: 2d21h, last: 2d08h
✨ AI-generated root cause summary:

With CONFIG_KCSAN_STRICT=y, KCSAN does not ignore accesses to &current->flags and sets up a write watchpoint in kcsan_setup_watchpoint() on the plain RMW current->flags |= PF_MEMALLOC_NOFS in memalloc_flags_save() during fsnotify_destroy_mark(). Because kcsan_setup_watchpoint() leaves current->kcsan_ctx enabled and delay_tsc() re-enables preemption during delay_access(), task 3284 can be preempted into __schedule() on CPU 0 while its watchpoint is live and in_task() still reports true. A KCSAN-instrumented 4-byte read of task_3284->flags during that preemption/context-switch window consumes the watchpoint while %rsp has already switched to the next task's stack before current_task is updated in __switch_to(), causing __unwind_start() to fail stack validation and report 0x0 / fsnotify_destroy_mark with an empty stack trace.

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

Root Cause Analysis

The KCSAN report is a same-task self-race on task_struct::flags triggered when task 3284 (udevd) is preempted inside KCSAN's own watchpoint delay window:

  1. Watched write (fsnotify_destroy_mark -> memalloc_flags_save):

    • SYSCALL_DEFINE2(inotify_rm_watch) (fs/notify/inotify/inotify_user.c:793) calls fsnotify_destroy_mark() (fs/notify/mark.c:665), which acquires the group lock via fsnotify_group_lock() (include/linux/fsnotify_backend.h:290).
    • fsnotify_group_lock() calls memalloc_nofs_save() -> memalloc_flags_save(PF_MEMALLOC_NOFS) (include/linux/sched/mm.h:335), which performs a plain C read-modify-write:
      current->flags |= flags;
      
    • struct task_struct::flags is a 4-byte (unsigned int) field at offset 352 bits (0x2c bytes), matching the watched address 0xffff88810487c52c (4 bytes).
    • Although kcsan_ignore_address() (kernel/kcsan/permissive.h:22-32) normally ignores &current->flags ("Data-racy bitops on current->flags are too common, ignore completely for now"), that rule is gated on CONFIG_KCSAN_PERMISSIVE. This kernel is built with CONFIG_KCSAN_STRICT=y, so kcsan_ignore_address() returns false.
  2. Why kcsan_setup_watchpoint() allows preemption with KCSAN still active on current:

    • The instrumentation on current->flags |= flags enters kcsan_setup_watchpoint() (kernel/kcsan/core.c:528), inserts a write watchpoint on 0xffff88810487c52c, and waits in delay_access() (kernel/kcsan/core.c:322) -> udelay().
    • kcsan_setup_watchpoint() does not increment current->kcsan_ctx.disable_count, and with CONFIG_KCSAN_INTERRUPT_WATCHER=y, it keeps interrupts enabled during delay_access().
    • On x86 (CONFIG_PREEMPT_LAZY=y / CONFIG_PREEMPTION=y), delay_tsc() (arch/x86/lib/delay.c:75) explicitly executes preempt_enable(); native_pause(); preempt_disable(); inside its delay loop (and an interrupt during udelay() can also invoke irqentry_exit_cond_resched() -> preempt_schedule_irq() in kernel/entry/common.c:144-145).
    • Consequently, task 3284 can be preempted into preempt_schedule() / preempt_schedule_irq() -> __schedule(SM_PREEMPT) on CPU 0 while its watchpoint on &task_3284->flags is still active.
  3. Why the conflicting read is attributed to task 3284 on cpu 0:

    • in_task() (include/linux/preempt.h:160) checks only NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET, not PREEMPT_MASK.
    • Therefore, during __schedule() / context switch, in_task() remains true. get_ctx() (kernel/kcsan/core.c:206) returns &current->kcsan_ctx (where disable_count == 0), and prepare_access_info() (kernel/kcsan/report.c:649) records task_pid_nr(current) (3284) and raw_smp_processor_id() (0).
  4. Why the first access has an empty stack trace and 0x0 in the bug title:

    • During context switch on x86-64, __switch_to_asm switches %rsp to next_p's stack before jumping to __switch_to(prev_p, next_p) (arch/x86/kernel/process_64.c:610), whereas current_task is still prev_p (task 3284) until raw_cpu_write(current_task, next_p) (arch/x86/kernel/process_64.c:670).
    • When a KCSAN-instrumented 4-byte read of task_3284->flags executes in this window and hits kcsan_found_watchpoint() -> kcsan_report_set_info() -> prepare_report_producer() (kernel/kcsan/report.c:598), stack_trace_save() calls arch_stack_walk() -> __unwind_start() (arch/x86/kernel/unwind_orc.c:740-769).
    • Because task == current (prev_p), __unwind_start() reads the live %rsp (which is already on next_p's stack) and validates it against prev_p via get_stack_info(). That check fails immediately (state->stack_info.type = STACK_TYPE_UNKNOWN), so stack_trace_save() records num_stack_entries = 0.
    • print_report() (kernel/kcsan/report.c:416, 436, 455) then reads other_info->stack_entries[0] == 0x0 and prints 0 frames, producing BUG: KCSAN: data-race in 0x0 / fsnotify_destroy_mark.

Verification Scope / What Remains Inconclusive

  • kernel/sched/Makefile:16 and arch/x86/kernel/Makefile:31 both set KCSAN_SANITIZE := n, so __schedule() and __switch_to() themselves are not KCSAN-instrumented.
  • Out-of-line callees invoked from __switch_to() before raw_cpu_write(current_task, next_p) can live in KCSAN-instrumented compilation units (for example, arch/x86/kernel/fpu/Makefile does not disable KCSAN_SANITIZE, though switch_fpu()'s direct old->flags read in arch/x86/include/asm/fpu/sched.h:37 is inlined into process_64.c, and update_fpu_state_and_flag() in arch/x86/kernel/fpu/core.c:223 does not directly read task->flags). The exact out-of-line instrumented callee between %rsp switching in __switch_to_asm and raw_cpu_write(current_task, next_p) that performed the 4-byte read of task_3284->flags was not exhaustively pinpointed.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
27a59a33 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in 0x0 / fsnotify_destroy_mark 2026/11/19 19:35 2026/11/19 19:35 2026/11/19 19:49 229865fb
8ae3fe30 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in 0x0 / fsnotify_destroy_mark 2026/11/19 19:34 2026/11/19 19:34 2026/11/19 19:39 229865fb

Sample crash report:
==================================================================
BUG: KCSAN: data-race in 0x0 / fsnotify_destroy_mark

read to 0xffff88810487c52c of 4 bytes by task 3284 on cpu 0:

read-write to 0xffff88810487c52c of 4 bytes by task 3284 on cpu 0:
 memalloc_flags_save include/linux/sched/mm.h:335 [inline]
 memalloc_nofs_save include/linux/sched/mm.h:388 [inline]
 fsnotify_group_lock include/linux/fsnotify_backend.h:290 [inline]
 fsnotify_destroy_mark+0x4e/0x140 fs/notify/mark.c:665
 __do_sys_inotify_rm_watch fs/notify/inotify/inotify_user.c:793 [inline]
 __se_sys_inotify_rm_watch+0x97/0x110 fs/notify/inotify/inotify_user.c:774
 __x64_sys_inotify_rm_watch+0x31/0x40 fs/notify/inotify/inotify_user.c:774
 x64_sys_call+0x1f51/0x2550 arch/x86/include/generated/asm/syscalls_64.h:256
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

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

Crashes (18):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 17:15 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 16:24 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 16:18 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 15:54 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 15:46 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 15:33 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 15:10 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 15:02 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 14:51 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 13:25 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 13:23 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 13:17 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 12:54 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 12:48 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 12:46 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 12:08 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 04:15 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
2026/11/17 03:44 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / fsnotify_destroy_mark
* Struck through repros no longer work on HEAD.