KCSAN: data-race in __se_sys_inotify_add_watch / selinux_inode_permission

Status: closed as invalid on 2026/11/17 09:42
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+1b1e8d87e69ffe7b88b3@syzkaller.appspotmail.com
First crash: 7h52m, last: 7h52m
✨ AI-generated root cause summary:

The report stems from two interrelated issues: first, an unmarked read-modify-write access to current->flags in memalloc_flags_restore() (include/linux/sched/mm.h) during fsnotify_group_unlock() sets up a KCSAN watchpoint on current->flags. With CONFIG_KCSAN_INTERRUPT_WATCHER=y, local interrupts remain enabled during delay_access() without current->kcsan_ctx.disable_count being incremented, allowing a subsequent access in the same task/CPU context to trigger and consume its own watchpoint. Finally, because the triggered stack trace was empty or completely filtered, other_skipnr matched other_info->num_stack_entries, causing sanitize_stack_entries() in kernel/kcsan/report.c to read past the end of other_info->stack_entries[] into a stale entry (selinux_inode_permission) left over from a previous report.

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

Technical Root Cause Analysis

1. The Racing Memory Access and Invariants Involved

The memory address reported by KCSAN (0xffff888103c4c52c, 4 bytes) corresponds to current->flags (struct task_struct::flags at byte offset 0x2c).

In inotify_update_watch() (fs/notify/inotify/inotify_user.c:636), fsnotify_group_unlock() calls memalloc_nofs_restore(group->owner_flags), which in turn invokes memalloc_flags_restore() (include/linux/sched/mm.h:341):

static inline void memalloc_flags_restore(unsigned flags)
{
    current->flags &= ~flags;
}

This compound read-modify-write (&= ~flags) on current->flags is unmarked (unlike other accessors such as current_gfp_context() which explicitly uses READ_ONCE(current->flags)).

2. Why Task 7132 Hit Its Own Watchpoint on CPU 1

When memalloc_flags_restore() executed the read-modify-write on current->flags, KCSAN selected this write to set up a watchpoint in kcsan_setup_watchpoint() (kernel/kcsan/core.c:528).

Under CONFIG_KCSAN_INTERRUPT_WATCHER=y:

  • kcsan_setup_watchpoint() leaves interrupts enabled (local_irq_save() is skipped).
  • It increments ctx->disable_scoped, but does not increment current->kcsan_ctx.disable_count or the CPU's disable count.
  • Consequently, while task 7132 pauses inside delay_access() via udelay(), an interrupt or IRQ exit path executes with in_task() == true on CPU 1.
  • During this interrupt/exit or rescheduling execution on the same CPU, an instrumented read of current->flags occurred.
  • Because current->kcsan_ctx.disable_count was zero, kcsan_is_enabled() returned true, and check_access() located the watchpoint that task 7132 had just installed on its own task_struct::flags.
  • try_consume_watchpoint() succeeded, invoking kcsan_report_set_info() (kernel/kcsan/report.c:656), which recorded other_info with ai.task_pid = 7132 and ai.cpu_id = 1.

3. Why selinux_inode_permission Appeared in the Report with an Empty Stack Trace

In kcsan_report_set_info(), prepare_report_producer() calls:

other_info->num_stack_entries = stack_trace_save(other_info->stack_entries, NUM_STACK_ENTRIES, 2);

In this scenario, either num_stack_entries was 0 or all captured frames were KCSAN/entry runtime functions filtered by get_stack_skipnr(), resulting in:

other_skipnr == other_info->num_stack_entries

In print_report() (kernel/kcsan/report.c:413-416):

other_skipnr = sanitize_stack_entries(other_info->stack_entries,
                                      other_info->num_stack_entries,
                                      other_info->ai.ip, &other_reordered_to);
other_frame = other_info->stack_entries[other_skipnr];

When other_skipnr == other_info->num_stack_entries:

  1. other_frame reads other_info->stack_entries[other_skipnr], which indexes beyond num_stack_entries.
  2. release_report() only clears other_info->ai.size = 0 without zeroing other_info->stack_entries[].
  3. Thus, other_frame picked up a stale function address (selinux_inode_permission) from whatever previous report occupied slot watchpoint_idx in other_infos[].
  4. stack_trace_print(other_info->stack_entries + other_skipnr, other_info->num_stack_entries - other_skipnr, ...) was called with nr_entries = 0, printing zero stack frames under read to 0xffff888103c4c52c of 4 bytes by task 7132 on cpu 1:.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
64443f22 bisect-cause 🏃 KCSAN: data-race in __se_sys_inotify_add_watch / selinux_inode_permission 2026/11/17 09:08 2026/11/17 09:08 a3e64cfc
5c6f4715 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __se_sys_inotify_add_watch / selinux_inode_permission 2026/11/17 08:47 2026/11/17 08:47 2026/11/17 09:52 a3e64cfc
e764b1e1 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __se_sys_inotify_add_watch / selinux_inode_permission 2026/11/17 08:33 2026/11/17 08:33 2026/11/17 08:47 a3e64cfc

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

read to 0xffff888103c4c52c of 4 bytes by task 7132 on cpu 1:

read-write to 0xffff888103c4c52c of 4 bytes by task 7132 on cpu 1:
 memalloc_flags_restore include/linux/sched/mm.h:341 [inline]
 memalloc_nofs_restore include/linux/sched/mm.h:401 [inline]
 fsnotify_group_unlock include/linux/fsnotify_backend.h:295 [inline]
 inotify_update_watch fs/notify/inotify/inotify_user.c:636 [inline]
 __do_sys_inotify_add_watch fs/notify/inotify/inotify_user.c:769 [inline]
 __se_sys_inotify_add_watch+0x6f6/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: 7132 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
udevd[7132]: inotify_add_watch(7, /dev/loop0p3, 10) failed: No such file or directory

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