KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (7)

Status: moderation: reported on 2026/11/17 20:37
Subsystems: fs
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+e1ff0d66bdeab5bbc071@syzkaller.appspotmail.com
First crash: 15h54m, last: 15h54m
✨ AI cause bisection: introduced by (AI job) :
commit 38035c04f5865c4ef9597d6beed6a7178f90f64a
Author: Amir Goldstein <amir73il@gmail.com>
Date: Fri Apr 22 12:03:13 2022 +0000

  inotify: move control flags from mask to mark flags

  
✨ AI-generated root cause summary:

A data race occurs on struct fsnotify_mark::flags (offset 0x44) between concurrent event handling and mark destruction. During file close, fsnotify_handle_inode_event() traverses mark lists under fsnotify_mark_srcu without acquiring mark->lock and performs a plain C read of inode_mark->flags to test FSNOTIFY_MARK_FLAG_EXCL_UNLINK. Concurrently, inotify_rm_watch() calls fsnotify_destroy_mark() -> fsnotify_free_mark(), which acquires mark->lock and executes a plain C read-modify-write to clear FSNOTIFY_MARK_FLAG_ALIVE (mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE). Because both operations access the same 32-bit flags field without READ_ONCE/WRITE_ONCE or atomic operations, KCSAN reports a data race.

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

Technical Root Cause Analysis

1. Involved Files, Functions, Structs, and Fields


2. Detailed Technical Mechanism

A. Reader Path (fsnotify_handle_inode_event):

During file closure (close() -> __fput() -> fsnotify_close() -> fsnotify()), the notification engine walks registered mark lists for watched objects:

  1. fsnotify() acquires srcu_read_lock(&fsnotify_mark_srcu) (fs/notify/fsnotify.c:568) to iterate over attached struct fsnotify_mark entries without taking per-mark spinlocks.
  2. In send_to_group() and fsnotify_handle_event(), fsnotify_handle_inode_event() is called to evaluate event delivery rules.
  3. At fs/notify/fsnotify.c:267, it performs an unannotated, plain C read of inode_mark->flags:
    if ((inode_mark->flags & FSNOTIFY_MARK_FLAG_EXCL_UNLINK) &&
        path && d_unlinked(path->dentry))
            return 0;
    
B. Writer Path (fsnotify_free_mark):

Concurrently, a user-space task removes a watch via inotify_rm_watch(fd, wd):

  1. inotify_rm_watch() locates the mark via inotify_idr_find() and invokes fsnotify_destroy_mark().
  2. fsnotify_destroy_mark() detaches the mark from the group and calls fsnotify_free_mark().
  3. In fsnotify_free_mark() (fs/notify/mark.c:644-651), the function takes spin_lock(&mark->lock) and modifies the lifecycle state by clearing FSNOTIFY_MARK_FLAG_ALIVE:
    spin_lock(&mark->lock);
    if (!(mark->flags & FSNOTIFY_MARK_FLAG_ALIVE)) {
        spin_unlock(&mark->lock);
        return;
    }
    mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
    spin_unlock(&mark->lock);
    

3. Invariant Violation and Root Cause

In include/linux/fsnotify_backend.h:

struct fsnotify_mark {
    ...
    spinlock_t lock; /* Protects inode / mnt pointers, flags, masks */
    ...
    unsigned int flags; /* flags [mark->lock] */
};

Per fsnotify's locking architecture, mark->lock serializes all modifications to mark->flags. The lifetime of the fsnotify_mark allocation itself during event iteration is protected by SRCU (fsnotify_mark_srcu), which guarantees the mark memory is not freed until an SRCU grace period finishes.

Inotify control flags (FSNOTIFY_MARK_FLAG_EXCL_UNLINK and FSNOTIFY_MARK_FLAG_IN_ONESHOT) were placed into the same flags field as internal mark lifecycle flags (FSNOTIFY_MARK_FLAG_ALIVE and FSNOTIFY_MARK_FLAG_ATTACHED). Because the SRCU event-delivery reader inspects inode_mark->flags locklessly via a plain C read while the writer modifies mark->flags via a plain C read-modify-write under mark->lock, the concurrent access constitutes a data race under the Linux Kernel Memory Model, as flagged by KCSAN.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
efdb72f4 bisect-cause ❓ KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (7) 2026/11/17 20:36 2026/11/17 20:36 2026/11/17 20:43 ca622473
5507c2ba assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (7) 2026/11/17 20:29 2026/11/17 20:29 2026/11/17 20:36 ca622473
5e4153fd assessment-kcsan 🏃 KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (7) 2026/11/17 20:27 2026/11/17 20:27 ca622473
▶ ▼ Similar bugs (6)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (4) fs 6 1 1084d 1071d 0/29 auto-obsoleted due to no activity on 2024/01/03 04:57
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (5) fs 6 2 994d 1012d 0/29 auto-obsoleted due to no activity on 2024/04/02 20:17
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event fs 6 1 1227d 1227d 0/29 auto-obsoleted due to no activity on 2023/08/13 07:22
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (3) fs 6 2 1142d 1145d 0/29 auto-obsoleted due to no activity on 2023/11/05 21:43
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (2) fs 6 1 1185d 1185d 0/29 auto-obsoleted due to no activity on 2023/09/24 11:29
upstream KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event (6) fs 6 1 832d 832d 0/29 auto-obsoleted due to no activity on 2024/09/11 02:06

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

read to 0xffff888104a7b544 of 4 bytes by task 6187 on cpu 1:
 fsnotify_handle_inode_event+0x13d/0x230 fs/notify/fsnotify.c:267
 fsnotify_handle_event fs/notify/fsnotify.c:330 [inline]
 send_to_group fs/notify/fsnotify.c:378 [inline]
 fsnotify+0x16d9/0x18b0 fs/notify/fsnotify.c:597
 __fsnotify_parent+0x2f8/0x3a0 fs/notify/fsnotify.c:241
 fsnotify_parent include/linux/fsnotify.h:96 [inline]
 fsnotify_path include/linux/fsnotify.h:113 [inline]
 fsnotify_file include/linux/fsnotify.h:127 [inline]
 fsnotify_close include/linux/fsnotify.h:461 [inline]
 __fput+0x1d9/0x660 fs/file_table.c:498
 fput_close_sync+0xd5/0x1d0 fs/file_table.c:618
 filp_close_sync fs/open.c:1574 [inline]
 __do_sys_close fs/open.c:1597 [inline]
 __se_sys_close fs/open.c:1584 [inline]
 __x64_sys_close+0x55/0xf0 fs/open.c:1584
 x64_sys_call+0x812/0x2550 arch/x86/include/generated/asm/syscalls_64.h:4
 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

write to 0xffff888104a7b544 of 4 bytes by task 3287 on cpu 0:
 fsnotify_free_mark fs/notify/mark.c:650 [inline]
 fsnotify_destroy_mark+0xe6/0x140 fs/notify/mark.c:668
 __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: 3287 Comm: udevd 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 05:01 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fsnotify_destroy_mark / fsnotify_handle_inode_event
* Struck through repros no longer work on HEAD.