KCSAN: data-race in __se_sys_inotify_add_watch / fsnotify (2)

Status: moderation: reported on 2026/12/03 04:37
Subsystems: fs
Labels: race:harmful prio:low
[Documentation on labels]
Reported-by: syzbot+4731eb69a41a54ed8401@syzkaller.appspotmail.com
First crash: 37m, last: 37m
✨ AI-generated root cause summary:

A KCSAN data race occurs on fsnotify_mark::mask (__u32) between inotify_update_existing_watch() in fs/notify/inotify/inotify_user.c and lockless SRCU event delivery in send_to_group() in fs/notify/fsnotify.c. inotify_update_existing_watch() updates fsn_mark->mask under fsn_mark->lock using two plain writes (fsn_mark->mask = 0; followed by fsn_mark->mask |= ...;), while send_to_group() runs under fsnotify_mark_srcu without holding fsn_mark->lock and reads mark->mask via a plain access. As a result, concurrent event delivery can race with the mask update and even observe the intermediate zeroed mask, potentially dropping an inotify event.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 0810bd27d7bb:

Root Cause Analysis

The KCSAN report identifies a data race on the 4-byte mask field (__u32) of struct fsnotify_mark (defined in include/linux/fsnotify_backend.h) between an inotify watch update and concurrent filesystem event delivery.

1. Writer side (fs/notify/inotify/inotify_user.c)

When inotify_add_watch() updates an existing watch on an inode, it calls: __do_sys_inotify_add_watch() -> inotify_update_watch() -> inotify_update_existing_watch().

inotify_update_watch() holds group->mark_mutex (fsnotify_group_lock(group)), and inotify_update_existing_watch() acquires fsn_mark->lock before updating fsn_mark->mask and fsn_mark->flags:

spin_lock(&fsn_mark->lock);
if (replace) {
	fsn_mark->mask = 0;
	fsn_mark->flags &= ~INOTIFY_MARK_FLAGS;
}
fsn_mark->mask |= inotify_arg_to_mask(inode, arg);
fsn_mark->flags |= inotify_arg_to_flags(arg);
spin_unlock(&fsn_mark->lock);

Two issues exist here:

  1. When replace is true (!(arg & IN_MASK_ADD)), fsn_mark->mask is updated in two separate stepsβ€”first zeroed at line 558 (fsn_mark->mask = 0;), and then populated with the new mask at line 561 (fsn_mark->mask |= inotify_arg_to_mask(inode, arg);).
  2. Both writes to fsn_mark->mask (as well as the writes to fsn_mark->flags) are plain memory accesses rather than WRITE_ONCE() of a single computed value.

2. Reader side (fs/notify/fsnotify.c)

During openat() (vfs_open_consume() -> fsnotify_open() -> fsnotify()), fsnotify() enters an SRCU read-side critical section (srcu_read_lock(&fsnotify_mark_srcu)), which protects the lifetime of struct fsnotify_mark and its connector, and iterates over attached marks without acquiring group->mark_mutex or mark->lock.

Inside the loop, fsnotify() calls send_to_group() (fs/notify/fsnotify.c:361), which reads mark->mask via a plain access:

fsnotify_foreach_iter_mark_type(iter_info, mark, type) {
	group = mark->group;
	marks_mask |= mark->mask;
	marks_ignore_mask |=
		fsnotify_effective_ignore_mask(mark, is_dir, type);
}

(The same lockless plain read pattern on mark->mask also occurs in fsnotify_iter_select_report_types() at fs/notify/fsnotify.c:442 and fsnotify_handle_inode_event() at fs/notify/fsnotify.c:272, and analogously for mark->flags at fs/notify/fsnotify.c:267 and fs/notify/inotify/inotify_fsnotify.c:132.)

3. Violated Invariant & Mechanism

Although fsnotify_mark::mask is documented as protected by [mark->lock, group->mark_mutex] for writers, the fsnotify() event-delivery path intentionally reads mark->mask locklessly under fsnotify_mark_srcu. Because inotify_update_existing_watch() performs non-WRITE_ONCE() storesβ€”and explicitly stores 0 before storing the new mask when replacing a watchβ€”and send_to_group() performs a plain read without READ_ONCE(), KCSAN flags the concurrent unsynchronized 4-byte access. In addition, a concurrent fsnotify() call can observe the transient fsn_mark->mask == 0 state between lines 558 and 561 and spuriously drop an event that both the old and new watch masks requested.

Computing the new mask (and flags) in a local variable and publishing it with a single WRITE_ONCE() in inotify_update_existing_watch(), paired with READ_ONCE() on the lockless SRCU read paths in fs/notify/fsnotify.c (and fs/notify/inotify/inotify_fsnotify.c), resolves both the data race and the transient zero-mask window.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
1ca4622b assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __se_sys_inotify_add_watch / fsnotify (2) 2026/12/03 04:11 2026/12/03 04:11 2026/12/03 04:36 35891725
04ad45a4 assessment-kcsan Benign: ❌ ❓ KCSAN: data-race in __se_sys_inotify_add_watch / fsnotify (2) 2026/12/03 04:10 2026/12/03 04:10 2026/12/03 04:17 35891725
▶ ▼ Similar bugs (1)
Kernel Title Rank πŸ›ˆ Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in __se_sys_inotify_add_watch / fsnotify fs 6 1 1788d 1788d 0/30 auto-closed as invalid on 2022/02/13 14:37

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

write to 0xffff888103bb00f0 of 4 bytes by task 5315 on cpu 0:
 inotify_update_existing_watch fs/notify/inotify/inotify_user.c:558 [inline]
 inotify_update_watch fs/notify/inotify/inotify_user.c:632 [inline]
 __do_sys_inotify_add_watch fs/notify/inotify/inotify_user.c:769 [inline]
 __se_sys_inotify_add_watch+0x2ea/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

read to 0xffff888103bb00f0 of 4 bytes by task 5316 on cpu 1:
 send_to_group fs/notify/fsnotify.c:361 [inline]
 fsnotify+0xf70/0x18b0 fs/notify/fsnotify.c:597
 fsnotify_parent include/linux/fsnotify.h:99 [inline]
 fsnotify_path include/linux/fsnotify.h:113 [inline]
 fsnotify_file include/linux/fsnotify.h:127 [inline]
 fsnotify_open include/linux/fsnotify.h:450 [inline]
 vfs_open_consume+0x1ee/0x210 fs/open.c:1133
 do_open fs/namei.c:4851 [inline]
 path_openat+0xc16/0x11e0 fs/namei.c:5016
 do_file_open+0x16c/0x290 fs/namei.c:5045
 do_sys_openat2+0xa1/0x140 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0xf2/0x120 fs/open.c:1460
 x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
 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: 5316 Comm: syz.0.348 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/12/03 04:10 upstream 0810bd27d7bb 35891725 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __se_sys_inotify_add_watch / fsnotify
* Struck through repros no longer work on HEAD.