KCSAN: data-race in kernfs_iop_getattr / kernfs_iop_getattr

Status: moderation: reported on 2026/11/18 01:56
Subsystems: kernfs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+724e9963c8c41f811c76@syzkaller.appspotmail.com
First crash: 16h38m, last: 5h25m
✨ AI cause bisection: introduced by (AI job) :
commit aa1d058d48f292aa138e33ad12b7b4d18b5407cd
Author: Ian Kent <raven@themaw.net>
Date: Tue Oct 18 02:32:42 2022 +0000

  kernfs: dont take i_lock on inode attr read

  
✨ AI-generated root cause summary:

In kernfs, multiple tasks querying file attributes on the same inode (via getattr/stat syscalls) concurrently execute kernfs_iop_getattr(). While kernfs_iop_getattr() acquires root->kernfs_iattr_rwsem via down_read(), this shared lock permits multiple concurrent readers to simultaneously call kernfs_refresh_inode() on the same struct inode without any inode-level mutual exclusion. Within kernfs_refresh_inode() and set_inode_attr(), fields of struct inode (including inode->i_gid, inode->i_uid, inode->i_mode, and link count) are updated using plain, unsynchronized memory stores, resulting in a write-write data race detected by KCSAN.

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

Root Cause Analysis

Involved Components

  • Source File: fs/kernfs/inode.c
  • Functions:
    • kernfs_iop_getattr() (lines 182–196)
    • kernfs_refresh_inode() (lines 165–180)
    • set_inode_attr() (lines 155–163)
  • Structures & Fields:
    • struct kernfs_root::kernfs_iattr_rwsem
    • struct kernfs_node::iattr (struct kernfs_iattrs)
    • struct kernfs_iattrs::ia_gid, struct kernfs_iattrs::ia_uid, ia_atime, ia_mtime, ia_ctime
    • struct inode::i_gid, struct inode::i_uid, struct inode::i_mode, struct inode::__i_nlink

Mechanism & Triggering Sequence

  1. Concurrent VFS Attribute Queries (getattr): In the VFS layer, querying file attributes (e.g. via fstat, newfstatat, or statx) is treated as a read-only operation and does not acquire any inode-level mutex or lock (i_rwsem). Consequently, multiple threads querying attributes on the same file or directory in a kernfs-backed filesystem (such as sysfs or cgroup) can enter kernfs_iop_getattr() concurrently on the same struct inode.

  2. Shared Reader Lock on kernfs_iattr_rwsem: 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;
    }
    

    kernfs_iop_getattr() acquires root->kernfs_iattr_rwsem with down_read(). Because this lock is acquired in shared (read) mode across the entire kernfs_root, multiple tasks can hold down_read(&root->kernfs_iattr_rwsem) simultaneously.

  3. Unsynchronized Writes During Refresh: While holding down_read, each task invokes kernfs_refresh_inode(kn, inode) to synchronize the VFS inode attributes with the backing kernfs_node / kernfs_iattrs:

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

    And in set_inode_attr():

    static inline void set_inode_attr(struct inode *inode,
                                      struct kernfs_iattrs *attrs)
    {
            inode->i_uid = attrs->ia_uid;
            inode->i_gid = attrs->ia_gid;
            inode_set_atime_to_ts(inode, attrs->ia_atime);
            inode_set_mtime_to_ts(inode, attrs->ia_mtime);
            inode_set_ctime_to_ts(inode, attrs->ia_ctime);
    }
    

    Even though attrs and kn are protected from modification by root->kernfs_iattr_rwsem, there is no mutual exclusion protecting the destination struct inode. Multiple concurrent tasks execute plain memory stores to the same address (&inode->i_gid at offset 28 of struct inode, as well as inode->i_uid, inode->i_mode, and inode->__i_nlink).

  4. KCSAN Detection: KCSAN detects these concurrent, unannotated memory stores between two tasks (here, task 4305 running __do_sys_newfstat on CPU 1 and task 2977 running __do_sys_newfstatat on CPU 0) as a write-write data race on inode->i_gid at fs/kernfs/inode.c:159.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
cb25bb47 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in kernfs_iop_getattr / kernfs_iop_getattr 2026/11/18 01:57 2026/11/18 01:57 2026/11/18 02:15 ca622473
a17be34d bisect-cause ❓ KCSAN: data-race in kernfs_iop_getattr / kernfs_iop_getattr 2026/11/18 01:55 2026/11/18 01:55 2026/11/18 02:05 ca622473
b3200b99 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in kernfs_iop_getattr / kernfs_iop_getattr 2026/11/18 01:49 2026/11/18 01:49 2026/11/18 01:55 ca622473

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

write to 0xffff88810728a8fc of 4 bytes by task 4305 on cpu 1:
 set_inode_attr fs/kernfs/inode.c:159 [inline]
 kernfs_refresh_inode fs/kernfs/inode.c:176 [inline]
 kernfs_iop_getattr+0xf7/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

write to 0xffff88810728a8fc of 4 bytes by task 2977 on cpu 0:
 set_inode_attr fs/kernfs/inode.c:159 [inline]
 kernfs_refresh_inode fs/kernfs/inode.c:176 [inline]
 kernfs_iop_getattr+0xf7/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

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 2977 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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