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: 6h27m, last: 6h27m
✨ 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
Based on kernel commit 666539eecdf4:

Root Cause Analysis

1. Functions, Structs, and Files Involved

2. Trigger Mechanism & Violated Invariants

  1. 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.
  2. 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().
  3. 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.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
3a106e4e assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __file_has_perm / inode_set_flags 2026/11/17 08:19 2026/11/17 08:19 2026/11/17 08:28 a3e64cfc
98bdec73 assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in __file_has_perm / inode_set_flags 2026/11/17 07:59 2026/11/17 07:59 2026/11/17 08:20 a3e64cfc
907ad80b bisect-cause πŸƒ KCSAN: data-race in __file_has_perm / inode_set_flags 2026/11/17 07:49 2026/11/17 07:49 a3e64cfc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in __file_has_perm / inode_set_flags

read-write (marked) to 0xffff88811c4dc33c of 4 bytes by task 3296 on cpu 1:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 inode_set_flags+0x81/0x110 fs/inode.c:2839
 shmem_set_inode_flags mm/shmem.c:3254 [inline]
 shmem_fileattr_set+0xe7/0x190 mm/shmem.c:4419
 vfs_fileattr_set+0x6a4/0x6f0 fs/file_attr.c:306
 ioctl_setflags+0x2c7/0x300 fs/file_attr.c:342
 do_vfs_ioctl+0x65d/0xe80 fs/ioctl.c:561
 __do_sys_ioctl fs/ioctl.c:596 [inline]
 __se_sys_ioctl+0x82/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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 0xffff88811c4dc33c of 4 bytes by task 3301 on cpu 1:
 inode_sid_has_perm security/selinux/hooks.c:1694 [inline]
 inode_has_perm security/selinux/hooks.c:1707 [inline]
 __file_has_perm+0x35b/0x430 security/selinux/hooks.c:1813
 file_has_perm security/selinux/hooks.c:1829 [inline]
 selinux_file_ioctl+0x1ab/0x3b0 security/selinux/hooks.c:-1
 security_file_ioctl+0x44/0x80 security/security.c:2534
 __do_sys_ioctl fs/ioctl.c:592 [inline]
 __se_sys_ioctl+0x47/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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: 1 UID: 0 PID: 3301 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
==================================================================
BUG: KCSAN: data-race in inode_set_flags / selinux_file_open

read-write (marked) to 0xffff88811c4dc33c of 4 bytes by task 3296 on cpu 0:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 inode_set_flags+0x81/0x110 fs/inode.c:2839
 shmem_set_inode_flags mm/shmem.c:3254 [inline]
 shmem_fileattr_set+0xe7/0x190 mm/shmem.c:4419
 vfs_fileattr_set+0x6a4/0x6f0 fs/file_attr.c:306
 ioctl_setflags+0x2c7/0x300 fs/file_attr.c:342
 do_vfs_ioctl+0x65d/0xe80 fs/ioctl.c:561
 __do_sys_ioctl fs/ioctl.c:596 [inline]
 __se_sys_ioctl+0x82/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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 0xffff88811c4dc33c of 4 bytes by task 3301 on cpu 1:
 inode_sid_has_perm security/selinux/hooks.c:1694 [inline]
 inode_has_perm security/selinux/hooks.c:1707 [inline]
 file_path_has_perm security/selinux/hooks.c:1757 [inline]
 selinux_file_open+0x26f/0x340 security/selinux/hooks.c:4408
 security_file_open+0x32/0x60 security/security.c:2761
 do_dentry_open+0x1fd/0xab0 fs/open.c:977
 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: 1 UID: 0 PID: 3301 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
==================================================================
BUG: KCSAN: data-race in inode_set_flags / security_inode_permission

read-write (marked) to 0xffff88811c4dc33c of 4 bytes by task 3296 on cpu 1:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 inode_set_flags+0x81/0x110 fs/inode.c:2839
 shmem_set_inode_flags mm/shmem.c:3254 [inline]
 shmem_fileattr_set+0xe7/0x190 mm/shmem.c:4419
 vfs_fileattr_set+0x6a4/0x6f0 fs/file_attr.c:306
 ioctl_setflags+0x2c7/0x300 fs/file_attr.c:342
 do_vfs_ioctl+0x65d/0xe80 fs/ioctl.c:561
 __do_sys_ioctl fs/ioctl.c:596 [inline]
 __se_sys_ioctl+0x82/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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 0xffff88811c4dc33c of 4 bytes by task 3301 on cpu 0:
 security_inode_permission+0x22/0xb0 security/security.c:1863
 inode_permission+0x1e3/0x3c0 fs/namei.c:661
 may_open+0x25b/0x350 fs/namei.c:4275
 do_open fs/namei.c:4849 [inline]
 path_openat+0xb71/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: 3301 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
==================================================================
BUG: KCSAN: data-race in inode_set_flags / selinux_file_open

read-write (marked) to 0xffff88811c4dc33c of 4 bytes by task 3296 on cpu 0:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 inode_set_flags+0x81/0x110 fs/inode.c:2839
 shmem_set_inode_flags mm/shmem.c:3254 [inline]
 shmem_fileattr_set+0xe7/0x190 mm/shmem.c:4419
 vfs_fileattr_set+0x6a4/0x6f0 fs/file_attr.c:306
 ioctl_setflags+0x2c7/0x300 fs/file_attr.c:342
 do_vfs_ioctl+0x65d/0xe80 fs/ioctl.c:561
 __do_sys_ioctl fs/ioctl.c:596 [inline]
 __se_sys_ioctl+0x82/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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 0xffff88811c4dc33c of 4 bytes by task 3301 on cpu 1:
 inode_sid_has_perm security/selinux/hooks.c:1694 [inline]
 inode_has_perm security/selinux/hooks.c:1707 [inline]
 file_path_has_perm security/selinux/hooks.c:1757 [inline]
 selinux_file_open+0x26f/0x340 security/selinux/hooks.c:4408
 security_file_open+0x32/0x60 security/security.c:2761
 do_dentry_open+0x1fd/0xab0 fs/open.c:977
 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: 1 UID: 0 PID: 3301 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
==================================================================
BUG: KCSAN: data-race in inode_set_flags / may_open

read-write (marked) to 0xffff88811c4dc33c of 4 bytes by task 3296 on cpu 1:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 inode_set_flags+0x81/0x110 fs/inode.c:2839
 shmem_set_inode_flags mm/shmem.c:3254 [inline]
 shmem_fileattr_set+0xe7/0x190 mm/shmem.c:4419
 vfs_fileattr_set+0x6a4/0x6f0 fs/file_attr.c:306
 ioctl_setflags+0x2c7/0x300 fs/file_attr.c:342
 do_vfs_ioctl+0x65d/0xe80 fs/ioctl.c:561
 __do_sys_ioctl fs/ioctl.c:596 [inline]
 __se_sys_ioctl+0x82/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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 0xffff88811c4dc33c of 4 bytes by task 3301 on cpu 1:
 may_open+0x282/0x350 fs/namei.c:4282
 do_open fs/namei.c:4849 [inline]
 path_openat+0xb71/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: 1 UID: 0 PID: 3301 Comm: syz-executor 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 02:24 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __file_has_perm / inode_set_flags
* Struck through repros no longer work on HEAD.