KCSAN: data-race in generic_fillattr / shmem_rename2 (4)

Status: moderation: reported on 2026/11/17 05:51
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+438c03e34805baaacd50@syzkaller.appspotmail.com
First crash: 4h52m, last: 4h52m
✨ AI-generated root cause summary:

A data race occurs in tmpfs between generic_fillattr() and shmem_rename2() on inode->i_size. While directory modifications in shmem_rename2() hold the directory's i_rwsem lock, vfs_getattr() / generic_fillattr() reads inode->i_size locklessly using i_size_read(). shmem_rename2() updates directory sizes via direct plain read-modify-write operations (old_dir->i_size -= BOGO_DIRENT_SIZE and new_dir->i_size += BOGO_DIRENT_SIZE) rather than through the standard i_size_write() helper, causing KCSAN to detect a conflict between the unmarked writes and the marked acquire load in i_size_read().

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

Root Cause Analysis

Involved Subsystem, Files, Functions, and Fields


Technical Mechanism and Trigger Conditions

In Linux VFS, attribute retrieval (stat(), statx(), fstatat()) via vfs_getattr() does not acquire the inode's i_rwsem. To allow safe lockless inspection of file and directory sizes, VFS provides the i_size_read() and i_size_write() helpers defined in include/linux/fs.h:

  • i_size_read(inode) reads inode->i_size using smp_load_acquire() on 64-bit architectures (or under inode->i_size_seqcount seqlock on 32-bit SMP architectures).
  • i_size_write(inode, size) updates inode->i_size using smp_store_release() on 64-bit architectures (and brackets the write with write_seqcount_begin() / write_seqcount_end(&inode->i_size_seqcount) on 32-bit SMP).

In tmpfs (mm/shmem.c), directory entries pretend to occupy a synthetic size (#define BOGO_DIRENT_SIZE 20). When creating, removing, or renaming directory entries, tmpfs increments or decrements the parent directory's inode->i_size.

In shmem_rename2() (mm/shmem.c:4284-4285):

	old_dir->i_size -= BOGO_DIRENT_SIZE;
	new_dir->i_size += BOGO_DIRENT_SIZE;

Instead of invoking i_size_write(), shmem_rename2() directly reads and writes old_dir->i_size and new_dir->i_size as plain, unmarked memory operations. (Similar direct modifications exist in other tmpfs directory helpers like shmem_mknod(), shmem_link(), and shmem_unlink()).

While shmem_rename2() holds lock_rename(old_dir, new_dir) protecting against concurrent directory modifications, concurrent readers executing stat() on either directory run locklessly through:

vfs_fstatat() -> vfs_statx() -> vfs_getattr() -> shmem_getattr() -> generic_fillattr() -> i_size_read()

generic_fillattr() calls i_size_read(), performing a marked acquire load of inode->i_size. Concurrently, shmem_rename2() executes an unmarked read-modify-write on the same 8-byte field. Kernel Concurrency Sanitizer (KCSAN) flags this discrepancy as a data race between a marked read and an unmarked write.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
68857698 bisect-cause 💥 KCSAN: data-race in generic_fillattr / shmem_rename2 (4) 2026/11/17 06:11 2026/11/17 06:11 2026/11/17 06:13 a3e64cfc
33fcfb8b assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in generic_fillattr / shmem_rename2 (4) 2026/11/17 05:35 2026/11/17 05:35 2026/11/17 05:40 f5be7dee
78d05ccf assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in generic_fillattr / shmem_rename2 (4) 2026/11/17 05:26 2026/11/17 05:26 2026/11/17 05:44 f5be7dee
▶ ▼ Similar bugs (3)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 (2) fs 6 82 2342d 2414d 0/29 auto-closed as invalid on 2020/07/23 12:50
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 fs 6 1 2591d 2591d 0/29 closed as invalid on 2019/10/18 14:11
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 (3) mm 6 1 1213d 1213d 0/29 auto-obsoleted due to no activity on 2023/08/26 22:55

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

read (marked) to 0xffff888103949eb8 of 8 bytes by task 3982 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 0xffff888103949eb8 of 8 bytes by task 3545 on cpu 0:
 shmem_rename2+0x2ab/0x310 mm/shmem.c:4284
 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: 3545 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
udevd[3545]: inotify_add_watch(7, /dev/loop1p244, 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 02:02 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in generic_fillattr / shmem_rename2
* Struck through repros no longer work on HEAD.