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: 17h28m
✨ 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
Based on kernel commit 20eef29b7c84:

Root Cause Analysis

1. Involved Structs, Fields, and Functions


2. Mechanism and Lifecycle Violation

  1. 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).
  2. Unmarked Concurrent Access:

    • In include/linux/fs.h (lines 2153–2183), the VFS macros accessing i_flags are defined as plain, unmarked pointer dereferences:
      #define IS_APPEND(inode)     ((inode)->i_flags & S_APPEND)
      #define IS_PRIVATE(inode)    ((inode)->i_flags & S_PRIVATE)
      
    • While writers update inode->i_flags using marked atomic operations (try_cmpxchg), the readers read inode->i_flags concurrently using plain C memory loads without holding inode->i_rwsem.
    • Under the Linux Kernel Memory Model (LKMM), any memory location that can be updated concurrently without locking must be read using marked accessors like READ_ONCE() (analogous to how inode->i_state uses inode_state_read_once()). Because IS_APPEND() and IS_PRIVATE() lack READ_ONCE(), KCSAN detects a concurrent marked atomic read-write and plain read, reporting a data race.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
55a83566 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in inode_set_flags / may_open 2026/11/18 18:00 2026/11/18 18:00 2026/11/18 18:35 2006bdcc
c446a2c5 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in inode_set_flags / may_open 2026/11/18 17:51 2026/11/18 17:51 2026/11/18 18:00 2006bdcc

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

read-write (marked) to 0xffff8881092c2694 of 4 bytes by task 13256 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:4422
 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 0xffff8881092c2694 of 4 bytes by task 3298 on cpu 0:
 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: 0 UID: 0 PID: 3298 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 0xffff8881092c2694 of 4 bytes by task 13256 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:4422
 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 0xffff8881092c2694 of 4 bytes by task 3298 on cpu 0:
 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: 0 UID: 0 PID: 3298 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 0xffff8881092c2694 of 4 bytes by task 13256 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:4422
 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 0xffff8881092c2694 of 4 bytes by task 3298 on cpu 1:
 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: 1 UID: 0 PID: 3298 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/18 07:14 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in inode_set_flags / may_open
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 inode_set_flags / may_open
* Struck through repros no longer work on HEAD.