KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch

Status: moderation: reported on 2026/11/19 00:00
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+3ed9f2e4f2f870a82653@syzkaller.appspotmail.com
First crash: 1d14h, last: 1d03h
✨ AI-generated root cause summary:

KCSAN reported a data race on current->flags (task_struct::flags at offset 0x2c) between a read-write access in memalloc_flags_save() (called via fsnotify_group_lock() in inotify_add_watch()) and a concurrent read by the same task on the same CPU. With CONFIG_KCSAN_INTERRUPT_WATCHER=y enabled, kcsan_setup_watchpoint() sets a watchpoint on &current->flags and delays without disabling local interrupts. An interrupt or lazy preemption event occurring on the same CPU during this delay reads current->flags (e.g., during scheduler or tick accounting) and triggers the watchpoint, which KCSAN records as a data race against frame 0x0 because the nested stack frames are either empty or filtered out. In practice, task_struct::flags is modified only by the task itself, making this a benign data race on unmarked task flag accesses.

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

Root Cause Analysis

1. Involved Files, Functions, and Fields

2. Mechanism of the Report

The memory address referenced in the report (0xffff888103a9452c) corresponds to current->flags in struct task_struct (base 0xffff888103a94500 + offset 0x2c) of PID 9918 (udevd).

  1. Watchpoint Setup on Plain Read-Write: During the execution of inotify_add_watch, fsnotify_group_lock() calls memalloc_nofs_save(), which delegates to memalloc_flags_save(PF_MEMALLOC_NOFS):

    static inline unsigned memalloc_flags_save(unsigned flags)
    {
        unsigned oldflags = ~current->flags & flags;
        current->flags |= flags;
        return oldflags;
    }
    

    The statement current->flags |= flags; executes as a plain read-modify-write without atomic annotations or READ/WRITE_ONCE wrappers.

  2. KCSAN Watchpoint & Interrupt Watcher Interaction: Because CONFIG_KCSAN_INTERRUPT_WATCHER=y is enabled:

    • When memalloc_flags_save() accesses &current->flags, KCSAN's runtime sets up a watchpoint in kcsan_setup_watchpoint() (kernel/kcsan/core.c:528).
    • Because interrupt_watcher is true, KCSAN does not disable local IRQs via local_irq_save() before calling delay_access() (udelay()).
    • While the task delays in delay_access(), an asynchronous event (such as a timer interrupt or a lazy preemption check on return from interrupt) occurs on CPU 1 while current is still PID 9918.
  3. Racing Access by the Same Task Context: The interrupt/preemption path accesses current->flags (for instance, tick accounting checking p->flags & PF_VCPU in irqtime_account_process_tick(), or scheduler routines checking flags). This access hits the active watchpoint and invokes kcsan_found_watchpoint().

    • Because the access occurs on CPU 1 and in_task() is true (or retains current), KCSAN records the origin as task 9918 on cpu 1.
    • The stack unwinder or KCSAN stack sanitizer skips runtime frames, but cannot retrieve a valid calling stack across the interrupt boundary (other_info->num_stack_entries - other_skipnr <= 0), setting other_frame = 0 (0x0).
    • As a result, KCSAN prints: BUG: KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch with an empty stack for the read side.

3. Invariants and Evaluation

In the Linux kernel, task_struct::flags contains per-process PF_* bitfields. By design and kernel lifecycle invariants:

  • Writes to current->flags are performed exclusively by the current task itself.
  • Concurrent reads by interrupt/scheduler handlers on the same CPU or other cores inspect independent flags locklessly.
  • There is no inter-thread data race or corrupted state machine; the report is an artifact of KCSAN interrupt watching and unmarked accesses to task_struct::flags.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
7446f2b2 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch 2026/11/18 23:23 2026/11/18 23:23 2026/11/18 23:32 2006bdcc
51b3671f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch 2026/11/18 23:20 2026/11/18 23:20 2026/11/18 23:32 2006bdcc

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

read to 0xffff888103a9452c of 4 bytes by task 9918 on cpu 1:

read-write to 0xffff888103a9452c of 4 bytes by task 9918 on cpu 1:
 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]
 inotify_update_watch fs/notify/inotify/inotify_user.c:630 [inline]
 __do_sys_inotify_add_watch fs/notify/inotify/inotify_user.c:769 [inline]
 __se_sys_inotify_add_watch+0x285/0x720 fs/notify/inotify/inotify_user.c:717
 __x64_sys_inotify_add_watch+0x43/0x50 fs/notify/inotify/inotify_user.c:717
 x64_sys_call+0xa19/0x2550 arch/x86/include/generated/asm/syscalls_64.h:255
 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: 1 UID: 0 PID: 9918 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (23):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 21:00 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 20:18 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 20:05 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 19:41 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 19:16 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 19:11 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 16:25 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 15:50 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 15:50 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
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 / __se_sys_inotify_add_watch
2026/11/17 15:03 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 14:49 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 14:48 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 14:44 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 14:29 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 14:12 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 13:38 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 13:10 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 12:39 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 12:06 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 11:40 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 10:50 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
2026/11/17 10:25 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / __se_sys_inotify_add_watch
* Struck through repros no longer work on HEAD.