syzbot
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
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
-
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.
-
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.
-
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).
-
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.
Sample crash report:
* Struck through repros no longer work on HEAD.