syzbot
KCSAN: data-race in __file_has_perm / inode_set_flags
Status:
moderation: reported on 2026/11/17 08:29
Subsystems:
fs
Labels:
race:benign
prio:low
[Documentation on labels]
Reported-by: syzbot+ae3b056439277b9b46f5@syzkaller.appspotmail.com
First crash: 6h21m, last: 6h21m
β¨ AI-generated root cause summary:
A KCSAN data race occurs between concurrent atomic writes and lockless plain reads of inode->i_flags. The writer in vfs_fileattr_set() -> inode_set_flags() modifies inode->i_flags using set_mask_bits(), which performs an atomic try_cmpxchg() RMW under inode_lock() (i_rwsem). Meanwhile, VFS path traversal, open, and LSM hooks (inode_sid_has_perm(), security_inode_permission(), and may_open()) intentionally inspect inode->i_flags locklessly via macros like IS_PRIVATE(inode) and IS_APPEND(inode) using plain unmarked C loads ((inode)->i_flags & S_*), violating LKMM concurrency rules by failing to use READ_ONCE().
▶
▼
β¨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Files Involved
struct inode::i_flags (include/linux/fs.h:766): 32-bit unsigned integer (unsigned int) storing VFS inode flags (S_IMMUTABLE, S_APPEND, S_PRIVATE, S_NOATIME, etc.).
- Writer Path (
fs/inode.c:2835-2841):
- Invoked during
FS_IOC_SETFLAGS (ioctl_setflags() in fs/file_attr.c:342) via vfs_fileattr_set() (fs/file_attr.c:306) $\rightarrow$ shmem_fileattr_set() (mm/shmem.c:4419) $\rightarrow$ shmem_set_inode_flags() (mm/shmem.c:3254).
vfs_fileattr_set() acquires inode_lock(inode) (inode->i_rwsem) and calls inode_set_flags(inode, flags, mask).
inode_set_flags() calls set_mask_bits(&inode->i_flags, mask, flags) (include/linux/bitops.h:364-375), which executes an atomic try_cmpxchg() loop. In KCSAN instrumentation, this atomic read-modify-write is recorded as a marked read-write access.
- Reader Paths (
include/linux/fs.h:2153-2179):
2. Trigger Mechanism & Violated Invariants
- Locking Invariant Asymmetry:
When modifying inode flags via
vfs_fileattr_set(), the caller holds inode_lock(inode) (exclusive i_rwsem). However, core VFS fast pathsβincluding path walk traversal, RCU-walk, permission checking (security_inode_permission(), inode_sid_has_perm()), and file opening (may_open())βmust execute locklessly for performance and scalability reasons. They intentionally do not acquire inode->i_rwsem.
- Unmarked Read vs. Atomic Update (LKMM Violation):
inode_set_flags() writes to inode->i_flags using set_mask_bits(), which performs atomic read-modify-writes via try_cmpxchg(). However, the helper macros in include/linux/fs.h (IS_PRIVATE, IS_APPEND, IS_IMMUTABLE, etc.) read (inode)->i_flags as a plain, unmarked C memory access (((inode)->i_flags & S_*)) without READ_ONCE().
- Data Race Detected by KCSAN:
When a thread executes
ioctl_setflags() (FS_IOC_SETFLAGS) on a file while another thread concurrently traverses or opens files, accesses file permissions, or performs an ioctl on that inode, KCSAN detects a concurrent marked atomic read-write and plain read to inode->i_flags. Under the Linux Kernel Memory Model (LKMM), concurrent lockless reads of variables that are modified concurrently must be annotated with READ_ONCE() to prevent compiler load-tearing, reordering, and fusion across multiple evaluations.
3. Proposed Fix
Updating the IS_* flag access macros in include/linux/fs.h (e.g., #define IS_APPEND(inode) (READ_ONCE((inode)->i_flags) & S_APPEND), #define IS_PRIVATE(inode) (READ_ONCE((inode)->i_flags) & S_PRIVATE)) or defining an inline helper inode_flags(const struct inode *inode) returning READ_ONCE(inode->i_flags) ensures all lockless readers properly annotate accesses to inode->i_flags.
Sample crash report:
* Struck through repros no longer work on HEAD.