KCSAN: data-race in kernfs_fop_open / kernfs_iop_getattr

Status: moderation: reported on 2026/11/18 02:03
Subsystems: kernfs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+727cca66b8415e905029@syzkaller.appspotmail.com
First crash: 16h16m, last: 16h16m
✨ 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 kernfs, VFS inode attributes are refreshed from the underlying kernfs_node (kn). During stat/fstat (kernfs_iop_getattr), kernfs acquires root->kernfs_iattr_rwsem in shared read mode and unconditionally executes an unmarked plain store (inode->i_mode = kn->mode) in kernfs_refresh_inode(). Concurrently, kernfs_fop_open() executes an unmarked plain read of inode->i_mode to perform DAC permission checks under KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK (used by sysfs and resctrl) without holding root->kernfs_iattr_rwsem. Because neither side uses synchronization locks or READ_ONCE()/WRITE_ONCE() access annotations, KCSAN detects a data race on inode->i_mode.

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

Root Cause Analysis: Data-Race in kernfs_fop_open / kernfs_iop_getattr

1. Functions, Structs, and Files Involved

  • fs/kernfs/inode.c:
    • kernfs_refresh_inode() (lines 165–180): Refreshes VFS inode attributes from the underlying struct kernfs_node.
    • kernfs_iop_getattr() (lines 182–196): inode_operations->getattr implementation for kernfs inodes.
  • fs/kernfs/file.c:
    • kernfs_fop_open() (lines 617–645): file_operations->open implementation for kernfs files.
  • include/linux/fs.h & include/linux/kernfs.h:
    • struct inode::i_mode: 16-bit (umode_t) permission and file-type field.
    • struct kernfs_node::mode: Canonical file mode and permissions stored in the kernfs hierarchy.
    • struct kernfs_root::flags: Flags such as KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK used by filesystems like sysfs and resctrl.

2. Technical Mechanism and Trigger Conditions

  1. Write Side (fs/kernfs/inode.c via stat / fstat):

    • In kernfs, authoritative attribute metadata (permissions, uid, gid, timestamps) resides in struct kernfs_node (kn).
    • When a task calls stat() / fstat() on a kernfs file or directory, VFS invokes kernfs_iop_getattr().
    • kernfs_iop_getattr() acquires root->kernfs_iattr_rwsem in shared read mode (down_read(&root->kernfs_iattr_rwsem)) and invokes kernfs_refresh_inode(kn, inode).
    • In kernfs_refresh_inode(), the function unconditionally executes:
      inode->i_mode = kn->mode;
      
    • This performs a plain, unmarked 2-byte store to inode->i_mode without holding any mutual-exclusion lock on struct inode (such as inode->i_rwsem or inode->i_lock, the latter having been previously removed on read paths). In fact, multiple concurrent stat() calls can execute this plain store simultaneously because they only hold kernfs_iattr_rwsem as readers.
  2. Read Side (fs/kernfs/file.c via open / openat):

    • Concurrently, when a process (e.g., udevd) opens a kernfs file via openat(), VFS invokes kernfs_fop_open().
    • For kernfs roots configured with KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK (such as /sys), kernfs_fop_open() performs additional DAC permission checks to verify that the file implements the requested read/write capabilities and that the inode mode has the corresponding permission bits (S_IRUGO / S_IWUGO):
      if (root->flags & KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK) {
          if ((file->f_mode & FMODE_WRITE) &&
              (!(inode->i_mode & S_IWUGO) || !has_write))
              goto err_out;
      
          if ((file->f_mode & FMODE_READ) &&
              (!(inode->i_mode & S_IRUGO) || !has_read))
              goto err_out;
      }
      
    • kernfs_fop_open() reads inode->i_mode using an unsynchronized, plain 2-byte load without holding root->kernfs_iattr_rwsem or any inode locks.
  3. Concurrency Conflict:

    • Because neither the store in kernfs_refresh_inode() nor the load in kernfs_fop_open() is guarded by a common mutual exclusion lock or marked with compiler barriers (READ_ONCE() / WRITE_ONCE()), concurrent execution on separate CPU cores triggers the KCSAN data-race report on &inode->i_mode.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
d68534e3 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in kernfs_fop_open / kernfs_iop_getattr 2026/11/18 01:46 2026/11/18 01:46 2026/11/18 02:03 ca622473
f74d77ea bisect-cause ❓ KCSAN: data-race in kernfs_fop_open / kernfs_iop_getattr 2026/11/18 01:44 2026/11/18 01:44 2026/11/18 02:24 ca622473
2145fd91 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in kernfs_fop_open / kernfs_iop_getattr 2026/11/18 01:26 2026/11/18 01:26 2026/11/18 01:57 ca622473

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

write to 0xffff888106dcb868 of 2 bytes by task 3341 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 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 0xffff888106dcb868 of 2 bytes by task 3586 on cpu 0:
 kernfs_fop_open+0x1ba/0x680 fs/kernfs/file.c:642
 do_dentry_open+0x4e0/0xab0 fs/open.c:1000
 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: 0 UID: 0 PID: 3586 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 17:05 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in kernfs_fop_open / kernfs_iop_getattr
* Struck through repros no longer work on HEAD.