syzbot
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: 16h53m, last: 5h39m
✨ 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
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
-
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.
-
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.
-
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).
-
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.
Sample crash report:
* Struck through repros no longer work on HEAD.