syzbot
KCSAN: data-race in inode_set_flags / may_open
Status:
moderation: reported on 2026/11/19 00:05
Subsystems:
fs
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+ea5933cea0c776a2ef27@syzkaller.appspotmail.com
First crash: 1d22h, last: 17h33m
✨ AI-generated root cause summary:
A data race exists on inode->i_flags between inode_set_flags() (updating flags via an atomic try_cmpxchg() in set_mask_bits(), holding i_rwsem) and lockless readers such as may_open() and security_inode_permission(). Path resolution and permission checking intentionally run locklessly without acquiring inode->i_rwsem. However, the VFS macros IS_APPEND() and IS_PRIVATE() in include/linux/fs.h perform plain, unmarked C loads of (inode)->i_flags instead of using READ_ONCE(), violating the Linux Kernel Memory Model expectation for concurrent access and triggering KCSAN data-race reports.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Involved Structs, Fields, and Functions
- Raced Object:
struct inode::i_flags (an unsigned int, 4 bytes located at byte offset 4 of struct inode, referenced at address 0xffff8881092c2694 in the report).
- Writer Path:
- Reader Paths:
2. Mechanism and Lifecycle Violation
-
Locking Asymmetry between Inode Flag Writers and VFS Readers:
- Setting inode file attributes via
ioctl(fd, FS_IOC_SETFLAGS, ...) calls vfs_fileattr_set(), which acquires inode_lock(inode) (exclusive inode->i_rwsem) and calls into filesystem-specific attribute setters (e.g., shmem_set_inode_flags()).
shmem_set_inode_flags() calls inode_set_flags(inode, i_flags, mask), which uses set_mask_bits(&inode->i_flags, mask, flags). In include/linux/bitops.h, set_mask_bits() modifies inode->i_flags using an atomic try_cmpxchg() loop. This atomic RMW operation is instrumented by KCSAN as a marked read-write (instrument_atomic_read_write).
- Concurrently, other tasks open the same file via
openat() (do_sys_openat2() -> path_openat() -> do_open() -> may_open()). For performance and scalability, path traversal, file open checks, and permission validations intentionally run locklessly without taking inode_lock(inode).
- In
may_open(), the kernel checks whether security modules should bypass checks via security_inode_permission(), which inspects IS_PRIVATE(inode). Subsequently, may_open() verifies append-only constraints using IS_APPEND(inode).
-
Unmarked Concurrent Access:
Sample crash report:
* Struck through repros no longer work on HEAD.