KCSAN: data-race in kernfs_iop_getattr / may_open

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

In fs/kernfs/inode.c, kernfs_iop_getattr() acquires the kernfs root iattr rwsem in shared read mode and invokes kernfs_refresh_inode(), which unconditionally executes an unmarked plain write to inode->i_mode (inode->i_mode = kn->mode). Because inode->i_lock is not held and getattr is a read-only operation, this store races against concurrent readers of inode->i_mode such as may_open() in fs/namei.c (which checks inode->i_mode & S_IFMT locklessly during openat). This unsynchronized read-write access to inode->i_mode violates the Linux Kernel Memory Model, triggering the KCSAN data-race report.

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

Root Cause Analysis

1. Functions, Structs, and Files Involved

  • fs/kernfs/inode.c:
    • kernfs_iop_getattr(): Implements the .getattr VFS inode operation for kernfs.
    • kernfs_refresh_inode(): Synchronizes cached attributes from struct kernfs_node into the shared VFS struct inode.
  • fs/namei.c:
    • may_open(): Checks inode mode and permissions during path open (openat / openat2).
  • Data Structures and Fields:
    • struct inode::i_mode (umode_t, 2 bytes at offset 0).
    • struct kernfs_node::mode (umode_t).
    • struct kernfs_root::kernfs_iattr_rwsem (struct rw_semaphore).

2. Technical Mechanism and Triggering Flow

  1. Lazy Inode Refresh in kernfs: In kernfs (used by sysfs, cgroupfs, etc.), the persistent filesystem hierarchy is represented in memory by struct kernfs_node. The VFS struct inode is allocated on demand and may be evicted independently of the kernfs_node. Because attributes (such as permissions or UID/GID) can be altered on a kernfs_node via kernel APIs (kernfs_setattr() / sysfs_chmod_file()) without tracking or immediately updating every associated VFS struct inode, kernfs performs lazy synchronization of inode attributes.

  2. Unsynchronized Store in kernfs_iop_getattr: When a user process issues a stat(), fstatat(), or statx() syscall on a kernfs path:

    vfs_fstatat() -> vfs_statx() -> vfs_statx_path() -> vfs_getattr() -> vfs_getattr_nosec() -> kernfs_iop_getattr()
    

    In kernfs_iop_getattr():

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

    Notice that root->kernfs_iattr_rwsem is held only in shared read mode, and inode->i_lock is not held. kernfs_refresh_inode() performs an unconditional plain store to inode->i_mode:

    static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
    {
        ...
        inode->i_mode = kn->mode;
        ...
    }
    

    This write executes every time getattr is invokedβ€”even when kn->mode has not changed at all.

  3. Concurrent Lockless Read in may_open: Concurrently, another task opening the same file executes:

    do_sys_openat2() -> do_file_open() -> path_openat() -> do_open() -> may_open()
    

    In fs/namei.c:

    static int may_open(const struct mnt_idmap *idmap, const struct path *path,
                        int acc_mode, int flag)
    {
        ...
        switch (inode->i_mode & S_IFMT) {
        ...
    

    may_open() performs a plain, lockless read of inode->i_mode to determine the file type (S_IFMT).

  4. The Violation: Under the Linux Kernel Memory Model (LKMM) and ISO C concurrency rules, an unmarked write (inode->i_mode = kn->mode;) executed concurrently with an unmarked read (inode->i_mode & S_IFMT) constitutes a data race. Because kernfs_iop_getattr() takes only a shared read lock and does not acquire inode->i_lock, concurrent getattr operations race with lockless readers like may_open() (and against each other), triggering the KCSAN report.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
9b81a5fe assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in kernfs_iop_getattr / may_open 2026/11/18 23:12 2026/11/18 23:12 2026/11/18 23:40 2006bdcc
80c53e7f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in kernfs_iop_getattr / may_open 2026/11/18 23:02 2026/11/18 23:02 2026/11/18 23:20 2006bdcc

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

write to 0xffff888107608f88 of 2 bytes by task 5446 on cpu 1:
 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+0x48/0x60 fs/stat.c:266
 vfs_statx_path+0x28/0x140 fs/stat.c:303
 vfs_statx+0xc4/0x170 fs/stat.c:360
 vfs_fstatat+0x118/0x170 fs/stat.c:377
 __do_sys_newfstatat fs/stat.c:542 [inline]
 __se_sys_newfstatat+0x55/0x3e0 fs/stat.c:536
 __x64_sys_newfstatat+0x55/0x70 fs/stat.c:536
 x64_sys_call+0xee6/0x2550 arch/x86/include/generated/asm/syscalls_64.h:263
 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 0xffff888107608f88 of 2 bytes by task 4067 on cpu 0:
 may_open+0x43/0x350 fs/namei.c:4247
 do_open fs/namei.c:4849 [inline]
 path_openat+0xb71/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: 0 UID: 0 PID: 4067 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:30 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in kernfs_iop_getattr / may_open
* Struck through repros no longer work on HEAD.