KCSAN: data-race in dnotify_flush / kernfs_iop_getattr

Status: moderation: reported on 2026/11/19 00:07
Subsystems: fs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+1c1295b3268bf2a49e46@syzkaller.appspotmail.com
First crash: 1d14h, last: 1d03h
✨ AI cause bisection: introduced by (AI job) :
commit e61ab4ae48fbf477f5b9fcbec9e1b8dc789920d0
Author: Eric W. Biederman <ebiederm@xmission.com>
Date: Sat Nov 21 00:08:53 2009 +0000

  sysfs: Implement sysfs_getattr & sysfs_permission

  
✨ AI-generated root cause summary:

In fs/kernfs/inode.c, kernfs_iop_getattr() calls kernfs_refresh_inode(), which unconditionally executes a plain store to inode->i_mode (inode->i_mode = kn->mode;) while holding only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) and no inode lock. Concurrently, during file close, filp_flush() invokes dnotify_flush() (fs/notify/dnotify/dnotify.c), which performs a standard lockless VFS read of !S_ISDIR(inode->i_mode). Because VFS callers assume file type bits (S_IFMT) on struct inode are immutable after initialization and do not take locks against read-only VFS operations like getattr(), KCSAN detects an unsynchronized 2-byte data race on inode->i_mode.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 63fdb511c27a:

Bug Mechanism and Technical Root Cause

1. Functions, Structs, and Fields Involved

  • fs/kernfs/inode.c: kernfs_iop_getattr(), kernfs_refresh_inode()
  • fs/notify/dnotify/dnotify.c: dnotify_flush()
  • struct inode: umode_t i_mode (at offset 0, 2 bytes)
  • struct kernfs_node: umode_t mode
  • struct kernfs_root: struct rw_semaphore kernfs_iattr_rwsem

2. Detailed Root Cause Analysis

In the VFS layer, querying file metadata via stat(), fstat(), or statx() invokes vfs_getattr_nosec(), which calls the filesystem's inode->i_op->getattr callback (kernfs_iop_getattr() in kernfs). A getattr call is fundamentally a read-only metadata retrieval operation and does not acquire inode->i_rwsem or any other VFS lock on struct inode.

In kernfs (fs/kernfs/inode.c), the backing kernfs_node stores persistent metadata, while struct inode is an ephemeral or cached VFS object created on demand. When getattr is invoked:

int kernfs_iop_getattr(const struct mnt_idmap *idmap,
		       const struct path *path, struct kstat *stat,
		       u32 request_mask, unsigned int query_flags)
{
	struct inode *inode = d_inode(path->dentry);
	struct kernfs_node *kn = inode->i_private;
	struct kernfs_root *root = kernfs_root(kn);

	down_read(&root->kernfs_iattr_rwsem);
	kernfs_refresh_inode(kn, inode);
	generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
	up_read(&root->kernfs_iattr_rwsem);

	return 0;
}

kernfs_refresh_inode() refreshes the VFS inode attributes from the kernfs_node so that generic_fillattr() can copy them into struct kstat *stat:

static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
{
	struct kernfs_iattrs *attrs;

	inode->i_mode = kn->mode;
	attrs = kernfs_iattrs_noalloc(kn);
	if (attrs)
		set_inode_attr(inode, attrs);

	if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING))
		set_nlink(inode, kn->dir.subdirs + 2);
}

Notice that kernfs_iop_getattr() only acquires a shared read lock (down_read(&root->kernfs_iattr_rwsem)). Previously, kernfs_refresh_inode() was protected by spin_lock(&inode->i_lock), but commit aa1d058d48f2 ("kernfs: dont take i_lock on inode attr read") dropped inode->i_lock on the assumption that concurrent callers always copy the same values from kn.

However, kernfs_refresh_inode() unconditionally performs a direct C assignment (inode->i_mode = kn->mode;), generating an unsynchronized 2-byte store instruction directly into inode->i_mode.


3. Concurrent Trigger and Invariant Violation

Concurrently, another task closing a file descriptor on the same inode calls close() -> __do_sys_close() -> filp_close_sync() -> filp_flush(), which executes dnotify_flush(filp, id):

void dnotify_flush(struct file *filp, fl_owner_t id)
{
	...
	inode = file_inode(filp);
	if (!S_ISDIR(inode->i_mode))
		return;
	...
}

dnotify_flush() performs a plain load from inode->i_mode at line 161 without holding any lock. In VFS, the file type bits (S_IFMT) of inode->i_mode are immutable after inode creation (a directory never changes its type to a non-directory, nor does a regular file become a directory). VFS callers throughout the kernel therefore routinely check S_ISDIR(inode->i_mode) locklessly.

Because kernfs_iop_getattr() performs an uninstrumented store to inode->i_mode without synchronization (or without checking if inode->i_mode != kn->mode / using WRITE_ONCE()), KCSAN detects the concurrent read and write to 0xffff88810632faa0 (&inode->i_mode) and reports a data race between dnotify_flush() and kernfs_refresh_inode().

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
b79a274f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in dnotify_flush / kernfs_iop_getattr 2026/11/18 07:28 2026/11/18 07:28 2026/11/18 07:37 eb4895d7
d96c4b46 bisect-cause ❓ KCSAN: data-race in dnotify_flush / kernfs_iop_getattr 2026/11/18 07:20 2026/11/18 07:20 2026/11/18 09:15 eb4895d7
14346798 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in dnotify_flush / kernfs_iop_getattr 2026/11/18 07:14 2026/11/18 07:14 2026/11/18 07:29 eb4895d7

Sample crash report:
==================================================================
BUG: KCSAN: data-race in dnotify_flush / kernfs_iop_getattr

read to 0xffff88810632faa0 of 2 bytes by task 3286 on cpu 1:
 dnotify_flush+0x32/0x380 fs/notify/dnotify/dnotify.c:161
 filp_flush+0xcd/0x130 fs/open.c:1549
 filp_close_sync fs/open.c:1573 [inline]
 __do_sys_close fs/open.c:1597 [inline]
 __se_sys_close fs/open.c:1584 [inline]
 __x64_sys_close+0x4b/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 0xffff88810632faa0 of 2 bytes by task 3283 on cpu 0:
 kernfs_refresh_inode fs/kernfs/inode.c:169 [inline]
 kernfs_iop_getattr+0xa1/0x220 fs/kernfs/inode.c:191
 vfs_getattr_nosec+0x194/0x230 fs/stat.c:217
 vfs_getattr fs/stat.c:266 [inline]
 vfs_fstat fs/stat.c:285 [inline]
 __do_sys_newfstat fs/stat.c:555 [inline]
 __se_sys_newfstat+0x96/0x460 fs/stat.c:550
 __x64_sys_newfstat+0x31/0x40 fs/stat.c:550
 x64_sys_call+0x1b5f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:6
 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: 3283 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 21:29 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in dnotify_flush / kernfs_iop_getattr
2026/11/17 10:11 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in dnotify_flush / kernfs_iop_getattr
* Struck through repros no longer work on HEAD.