syzbot
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 ¤t->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
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:
-
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 ¤t->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.
-
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.
-
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 ¤t->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).
-
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.
Sample crash report:
* Struck through repros no longer work on HEAD.