KCSAN: data-race in generic_fillattr / shmem_unlink (5)

Status: moderation: reported on 2026/11/17 13:39
Subsystems: fs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+bc78d191849d03756b4f@syzkaller.appspotmail.com
First crash: 3h40m, last: 3h40m
✨ AI-generated root cause summary:

In tmpfs (mm/shmem.c), directory inode size is updated directly with plain, unmarked arithmetic (such as dir->i_size -= BOGO_DIRENT_SIZE in shmem_unlink) rather than via i_size_write(). Meanwhile, stat operations (generic_fillattr() via shmem_getattr()) read inode->i_size locklessly using i_size_read(), which expects writers to use i_size_write() to pair smp_store_release() with smp_load_acquire() on 64-bit systems and maintain i_size_seqcount on 32-bit systems. This unsynchronized plain store vs. acquire load triggers a KCSAN data race report between concurrent directory modification and stat syscalls.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Root Cause Analysis

Involved Functions, Structs, and Files


Technical Mechanism & Failure Chain

  1. Lockless Reader Path (generic_fillattr / i_size_read):

    • When user space invokes newfstatat(2) / statx(2), the VFS path executes vfs_getattr_nosec() $\to$ inode->i_op->getattr() (shmem_getattr()), which delegates to generic_fillattr().
    • generic_fillattr() does not hold directory mutexes (inode->i_rwsem) and fetches the inode size via stat->size = i_size_read(inode).
    • On 64-bit architectures, i_size_read() relies on smp_load_acquire(&inode->i_size) to pair with smp_store_release() in i_size_write(). On 32-bit SMP architectures, i_size_read() loops reading inode->i_size_seqcount to prevent reading torn 32-bit halves of the 64-bit loff_t.
  2. Unmarked Concurrent Writer Path (shmem_unlink):

    • Concurrent directory operations (in the reported case, shmem_rename2() calling shmem_unlink() while holding new_dir's i_rwsem) update the directory inode's size to reflect added or removed entries.
    • In shmem_unlink() (mm/shmem.c:4191), tmpfs updates directory size with a plain read-modify-write:
      dir->i_size -= BOGO_DIRENT_SIZE;
      
    • Similar direct, unmarked modifications of dir->i_size occur across mm/shmem.c (shmem_mknod at line 4089, shmem_link at line 4177, shmem_rename2 at lines 4284–4285, and shmem_symlink at line 4342), instead of using i_size_write().
  3. Concurrency Invariant Violation:

    • The kernel concurrency protocol requires updates to inode->i_size that can race with lockless readers using i_size_read() to be executed through i_size_write(inode, new_size).
    • Because shmem_unlink() performs a plain, unmarked store to dir->i_size without smp_store_release() / i_size_write(), KCSAN detects a data race between the marked load in i_size_read() and the unmarked read-modify-write in shmem_unlink().
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
caf3f6b0 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in generic_fillattr / shmem_unlink (5) 2026/11/17 13:19 2026/11/17 13:19 2026/11/17 13:39 a3e64cfc
c463b238 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in generic_fillattr / shmem_unlink (5) 2026/11/17 13:16 2026/11/17 13:16 2026/11/17 13:32 a3e64cfc
ae7c6867 bisect-cause 🏃 KCSAN: data-race in generic_fillattr / shmem_unlink (5) 2026/11/17 12:59 2026/11/17 12:59 a3e64cfc
▶ ▼ Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in generic_fillattr / shmem_unlink (2) mm 6 51 2345d 2344d 0/29 auto-closed as invalid on 2020/07/21 00:44
upstream KCSAN: data-race in generic_fillattr / shmem_unlink (3) mm 6 654 916d 1303d 0/29 auto-obsoleted due to no activity on 2024/06/11 16:04
upstream KCSAN: data-race in generic_fillattr / shmem_unlink (4) mm 6 15 756d 876d 0/29 auto-obsoleted due to no activity on 2024/12/16 23:11
upstream KCSAN: data-race in generic_fillattr / shmem_unlink fs 6 3 2562d 2576d 0/29 closed as invalid on 2019/11/19 14:54

Sample crash report:
==================================================================
BUG: KCSAN: data-race in generic_fillattr / shmem_unlink

read (marked) to 0xffff888103a4a428 of 8 bytes by task 4209 on cpu 0:
 i_size_read include/linux/fs.h:1146 [inline]
 generic_fillattr+0x14a/0x340 fs/stat.c:95
 shmem_getattr+0x18b/0x210 mm/shmem.c:1539
 vfs_getattr_nosec+0x194/0x230 fs/stat.c:217
 vfs_getattr+0x48/0x60 fs/stat.c:266
 vfs_statx_path+0x28/0x140 fs/stat.c:303
 vfs_statx+0xc4/0x170 fs/stat.c:360
 vfs_fstatat+0x118/0x170 fs/stat.c:377
 __do_sys_newfstatat fs/stat.c:542 [inline]
 __se_sys_newfstatat+0x55/0x3e0 fs/stat.c:536
 __x64_sys_newfstatat+0x55/0x70 fs/stat.c:536
 x64_sys_call+0xee6/0x2550 arch/x86/include/generated/asm/syscalls_64.h:263
 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-write to 0xffff888103a4a428 of 8 bytes by task 3281 on cpu 0:
 shmem_unlink+0x111/0x140 mm/shmem.c:4191
 shmem_rename2+0x185/0x310 mm/shmem.c:4274
 vfs_rename+0x963/0xac0 fs/namei.c:6226
 filename_renameat2+0x3ab/0x6c0 fs/namei.c:6344
 __do_sys_rename fs/namei.c:6388 [inline]
 __se_sys_rename+0x4a/0x1c0 fs/namei.c:6384
 __x64_sys_rename+0x31/0x40 fs/namei.c:6384
 x64_sys_call+0x20fe/0x2550 arch/x86/include/generated/asm/syscalls_64.h:83
 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: 3281 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
udevd[3281]: inotify_add_watch(7, /dev/loop3p115, 10) failed: No such file or directory

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 10:10 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in generic_fillattr / shmem_unlink
* Struck through repros no longer work on HEAD.