KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (5)

Status: moderation: reported on 2026/11/18 00:00
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+f968afcac117a84b7f14@syzkaller.appspotmail.com
First crash: 17h09m, last: 10h17m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  08991e83b728 fsnotify: Free fsnotify_mark_connector when there is no mark attached
  9dd813c15b2c fsnotify: Move mark list head from object into dedicated structure
  
✨ AI-generated root cause summary:

In fsnotify(), an opportunistic lockless optimization checks whether any marks are attached to the relevant objects (sbinfo->sb_marks, mnt->mnt_fsnotify_marks, inode->i_fsnotify_marks, etc.) to avoid the memory barrier overhead of srcu_read_lock(). However, these __rcu-annotated connector pointers are read using plain C loads without rcu_access_pointer() or READ_ONCE(). When an inotify watch is concurrently removed via sys_inotify_rm_watch() -> fsnotify_put_mark() -> fsnotify_detach_connector_from_object(), the kernel clears inode->i_fsnotify_marks using rcu_assign_pointer(*connp, NULL), triggering a KCSAN data-race report against the plain read in fsnotify().

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

Root Cause Analysis

Involved Functions, Structs, and Fields


Bug Mechanism and Invariant Violation

  1. Write Side (fs/notify/mark.c:423): When an inotify watch is removed (e.g. via sys_inotify_rm_watch()), fsnotify_put_mark() destroys the mark. When detaching the last mark attached to the inode connector, fsnotify_detach_connector_from_object() clears the inode's connector pointer using RCU:

    fsnotify_connp_t *connp = fsnotify_object_connp(conn->obj, conn->type);
    ...
    rcu_assign_pointer(*connp, NULL);
    

    For an inode, *connp is inode->i_fsnotify_marks. rcu_assign_pointer() issues an 8-byte marked store (smp_store_release). After clearing *connp, line 427 calls fsnotify_update_sb_watchers(sb, conn). Because the superblock watcher count is updated after *connp is cleared, a concurrent notification path can still see fsnotify_sb_has_watchers(sb) == true and proceed into fsnotify().

  2. Read Side (fs/notify/fsnotify.c:540–545): Concurrently, a task closing a file enters close() $\to$ __fput() $\to$ fsnotify_close() $\to$ __fsnotify_parent() $\to$ fsnotify(). Before taking srcu_read_lock(&fsnotify_mark_srcu), fsnotify() executes an opportunistic fast-path optimization to avoid the memory barrier overhead of srcu_read_lock() if no objects on the notification path have any marks:

    if ((!sbinfo || !sbinfo->sb_marks) &&
        (!mnt || !mnt->mnt_fsnotify_marks) &&
        (!inode || !inode->i_fsnotify_marks) &&
        (!inode2 || !inode2->i_fsnotify_marks) &&
        (!mnt_data || !mnt_data->ns->n_fsnotify_marks))
            return 0;
    

    Although inode->i_fsnotify_marks (and the other connector pointers) is declared with __rcu, this check reads it as a plain, unmarked C load (!inode->i_fsnotify_marks) without using rcu_access_pointer() or READ_ONCE().

  3. KCSAN Detection: KCSAN detects the concurrent unmarked 8-byte read of inode->i_fsnotify_marks in fsnotify() racing against the marked 8-byte write (rcu_assign_pointer(*connp, NULL)) in fsnotify_detach_connector_from_object().


Invariants and Suggested Fix

The read in fsnotify() is only testing whether the __rcu pointer is non-NULL and does not dereference it at this point (if non-NULL, it enters srcu_read_lock(&fsnotify_mark_srcu) and later safely accesses *connp via srcu_dereference() inside fsnotify_first_mark()).

According to kernel concurrency rules, lockless NULL checks on __rcu pointers outside of an RCU/SRCU read-side critical section must be wrapped in rcu_access_pointer(). The fix is to wrap the connector pointer checks in fsnotify() (and similar checks like fsnotify_mnt() at fs/notify/fsnotify.c:713) with rcu_access_pointer():

--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -537,11 +537,11 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
 		 * However, if we do not walk the lists, we do not have to do
 		 * SRCU because we have no references to any objects and do not
 		 * need SRCU to keep them "alive".
 		 */
-		if ((!sbinfo || !sbinfo->sb_marks) &&
-		    (!mnt || !mnt->mnt_fsnotify_marks) &&
-		    (!inode || !inode->i_fsnotify_marks) &&
-		    (!inode2 || !inode2->i_fsnotify_marks) &&
-		    (!mnt_data || !mnt_data->ns->n_fsnotify_marks))
+		if ((!sbinfo || !rcu_access_pointer(sbinfo->sb_marks)) &&
+		    (!mnt || !rcu_access_pointer(mnt->mnt_fsnotify_marks)) &&
+		    (!inode || !rcu_access_pointer(inode->i_fsnotify_marks)) &&
+		    (!inode2 || !rcu_access_pointer(inode2->i_fsnotify_marks)) &&
+		    (!mnt_data || !rcu_access_pointer(mnt_data->ns->n_fsnotify_marks)))
 			return 0;
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
467dc9b3 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (5) 2026/11/17 23:56 2026/11/17 23:56 2026/11/18 00:11 ca622473
eb6a4f8d bisect-cause ❓ KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (5) 2026/11/17 23:55 2026/11/17 23:55 2026/11/18 00:20 ca622473
acc66abe assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (5) 2026/11/17 23:51 2026/11/17 23:51 2026/11/17 23:56 ca622473
▶ ▼ Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (2) fs 6 44 2344d 2514d 0/29 closed as invalid on 2020/06/18 14:24
upstream KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (4) fs 6 1 923d 923d 0/29 auto-obsoleted due to no activity on 2024/06/12 06:08
upstream KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object fs 6 2 2564d 2567d 0/29 closed as invalid on 2019/11/19 14:44
upstream KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object (3) fs 6 957 954d 1076d 0/29 auto-obsoleted due to no activity on 2024/05/05 06:09

Sample crash report:
loop5: detected capacity change from 0 to 33280
==================================================================
BUG: KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object

write (marked) to 0xffff888101711038 of 8 bytes by task 3334 on cpu 0:
 fsnotify_detach_connector_from_object+0x319/0x370 fs/notify/mark.c:423
 fsnotify_put_mark+0x1d8/0x590 fs/notify/mark.c:476
 __do_sys_inotify_rm_watch fs/notify/inotify/inotify_user.c:796 [inline]
 __se_sys_inotify_rm_watch+0x9f/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

read to 0xffff888101711038 of 8 bytes by task 6735 on cpu 1:
 fsnotify+0x339/0x18b0 fs/notify/fsnotify.c:542
 __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

value changed: 0xffff888104e192f8 -> 0x0000000000000000

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 6735 Comm: syz.5.1259 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
EXT4-fs (loop5): ext4_check_descriptors: Block bitmap for group 0 overlaps superblock
EXT4-fs (loop5): revision level too high, forcing read-only mode
EXT4-fs (loop5): too many log groups per flexible block group
EXT4-fs (loop5): failed to initialize mballoc (-12)
EXT4-fs (loop5): mount failed

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