KCSAN: data-race in do_dentry_open / kernfs_iop_getattr

Status: moderation: reported on 2026/11/18 03:28
Subsystems: kernfs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+c4b5fe313700a93ec0bc@syzkaller.appspotmail.com
First crash: 1d01h, last: 1d01h
✨ AI-generated root cause summary:

In kernfs, inode metadata is authoritatively stored on struct kernfs_node (and kn->iattr) and lazily synchronized to the associated struct inode. During fstat/stat queries, kernfs_iop_getattr() acquires only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) and calls kernfs_refresh_inode(), which unconditionally executes an unsynchronized 2-byte plain store (inode->i_mode = kn->mode). Concurrently, file open operations via do_dentry_open() perform an unsynchronized 2-byte plain read of inode->i_mode (e.g., checking S_ISREG/S_ISDIR) without holding the kernfs-internal rwsem, triggering a KCSAN data race.

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

Technical Root Cause Analysis

1. Involved Files, Functions, Structs, and Fields

  • Source Files:
    • fs/kernfs/inode.c: contains kernfs_iop_getattr(), kernfs_refresh_inode(), and kernfs_iop_permission().
    • fs/open.c: contains do_dentry_open().
  • Structures and Fields:
    • struct inode::i_mode (umode_t, 16-bit unsigned short): the VFS file mode and permissions.
    • struct kernfs_node::mode (umode_t): the kernfs node’s persistent mode representation.
    • struct kernfs_root::kernfs_iattr_rwsem (struct rw_semaphore): the per-kernfs-tree read-write semaphore used for attribute protection in kernfs.

2. Bug Mechanism and Invariant Violation

In kernfs (used by sysfs, cgroupfs, etc.), the filesystem tree and file attributes exist independently of whether a VFS struct inode is currently allocated. The authoritative metadata is tracked in struct kernfs_node (kn->mode, and dynamically allocated kn->iattr for UID, GID, and timestamps).

When a VFS inode exists for a kernfs_node, kernfs lazily synchronizes attributes from kn to struct inode in several operation callbacks:

Specifically, in kernfs_iop_getattr():

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;
}

And in kernfs_refresh_inode() (fs/kernfs/inode.c:165-180):

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);
...

This violates kernel concurrency expectations in two ways:

  1. Unsynchronized mutation of live VFS inode fields: In generic VFS, inode->i_mode is normally modified under inode_lock(inode) (e.g., via notify_change() -> setattr_copy()). During standard read-only operations such as stat(2), VFS assumes the inode is not being actively mutated. kernfs_refresh_inode() unconditionally performs a plain store inode->i_mode = kn->mode on every stat invocation, even when kn->mode hasn't changed.
  2. Missing reader/writer locking contract with VFS consumers: Generic VFS operations such as do_dentry_open() (fs/open.c:968 and fs/open.c:960) read inode->i_mode without acquiring kernfs_iattr_rwsem (a kernfs-internal rwsem unknown to the VFS core):
    if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))
        f->f_mode |= FMODE_ATOMIC_POS;
    
    Furthermore, kernfs_iop_getattr() only holds kernfs_iattr_rwsem as a reader (down_read), which permits multiple threads running getattr concurrently to race writing inode->i_mode at the same time.

3. Trigger Path and Failure Manifestation

When:

  • Task 1 (CPU 0) performs a fstat() / stat() syscall on a kernfs file: vfs_fstat() -> vfs_getattr() -> vfs_getattr_nosec() -> kernfs_iop_getattr() -> kernfs_refresh_inode() performs an unmarked 16-bit store to inode->i_mode (fs/kernfs/inode.c:169).
  • Task 2 (CPU 1, e.g. udevd) concurrently opens the same file: sys_openat() -> do_file_open() -> path_openat() -> vfs_open_consume() -> do_dentry_open() performs an unmarked 16-bit read from inode->i_mode (fs/open.c:968).

Because neither access uses atomic primitives or shared locking, KCSAN detects the simultaneous load and store to 0xffff888106dceb18 (&inode->i_mode) and reports a data race.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
809f310c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in do_dentry_open / kernfs_iop_getattr 2026/11/18 03:15 2026/11/18 03:15 2026/11/18 03:22 ca622473
91dda91d assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in do_dentry_open / kernfs_iop_getattr 2026/11/18 03:07 2026/11/18 03:07 2026/11/18 03:32 ca622473

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

write to 0xffff888106dceb18 of 2 bytes by task 2977 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

read to 0xffff888106dceb18 of 2 bytes by task 3334 on cpu 1:
 do_dentry_open+0x153/0xab0 fs/open.c:968
 vfs_open_consume+0x47/0x210 fs/open.c:1131
 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: 3334 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 02:04 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in do_dentry_open / kernfs_iop_getattr
* Struck through repros no longer work on HEAD.