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

Status: moderation: reported on 2026/11/17 17:43
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+6980a31b1563ce48b977@syzkaller.appspotmail.com
First crash: 1h57m, last: 1h57m
✨ AI cause bisection: introduced by (AI job) :
commit 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2
Author: Linus Torvalds <torvalds@ppc970.osdl.org>
Date: Sat Apr 16 22:20:36 2005 +0000

  Linux-2.6.12-rc2

  
✨ AI-generated root cause summary:

In mm/shmem.c, shmem_rename2() mutates directory inode sizes using plain unmarked read-modify-write operations (old_dir->i_size -= BOGO_DIRENT_SIZE and new_dir->i_size += BOGO_DIRENT_SIZE) rather than the standard i_size_write() helper. VFS stat/getattr (vfs_getattr_nosec -> shmem_getattr -> generic_fillattr) runs locklessly without inode->i_rwsem and reads inode->i_size using i_size_read(), which performs an acquire load (smp_load_acquire). The plain writes lack release/seqcount synchronization, triggering a KCSAN data race detection. Furthermore, when old_dir == new_dir, shmem_rename2() unconditionally decrements and immediately re-increments the same directory's i_size, exposing a transient window where the directory size is undercounted.

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

Root Cause Analysis

1. Functions, Structs, and Files Involved

  • mm/shmem.c: shmem_rename2() (and similarly shmem_mknod(), shmem_link(), shmem_unlink(), shmem_symlink())
  • fs/stat.c: vfs_getattr_nosec(), generic_fillattr()
  • include/linux/fs.h: i_size_read(), i_size_write()
  • Structs & Fields: struct inode::i_size

2. Mechanism and Lifecycle Violation

  • Lockless Read in VFS Stat Path: In VFS, querying file/directory metadata via stat() (vfs_getattr_nosec() $\to$ shmem_getattr() $\to$ generic_fillattr()) deliberately executes locklessly without acquiring inode->i_rwsem. In generic_fillattr(), the size is retrieved via i_size_read(inode). On 64-bit architectures, i_size_read() performs an acquire load (smp_load_acquire(&inode->i_size)), which requires paired concurrent updates to use i_size_write() (smp_store_release(&inode->i_size, ...)). On 32-bit SMP architectures, i_size_read() relies on read_seqcount_begin(&inode->i_size_seqcount) and retries to read the 64-bit loff_t atomically.

  • Unmarked Read-Modify-Write in shmem_rename2(): In mm/shmem.c:4284-4285, shmem_rename2() updates the directory sizes directly:

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

    These modifications are executed as plain, unmarked C read-modify-write memory accesses rather than through i_size_write(). Because smp_load_acquire() in i_size_read() races with an unmarked write, KCSAN detects and reports a data race.

  • Same-Directory Inode Size Glitch: When renaming within the same directory (old_dir == new_dir), shmem_rename2() unconditionally subtracts BOGO_DIRENT_SIZE (20 bytes) from old_dir->i_size and immediately adds it back via new_dir->i_size. This creates an unnecessary write and a transient race window where a concurrent reader sees the directory's size temporarily undercounted by 20 bytes.

  • Related Sites: Other directory mutators in mm/shmem.c exhibit the same pattern of bypassing i_size_write():

    • shmem_mknod(): dir->i_size += BOGO_DIRENT_SIZE; (line 4089)
    • shmem_link(): dir->i_size += BOGO_DIRENT_SIZE; (line 4177)
    • shmem_unlink(): dir->i_size -= BOGO_DIRENT_SIZE; (line 4191)
    • shmem_symlink(): dir->i_size += BOGO_DIRENT_SIZE; (line 4342)

3. Recommended Fix

  1. In mm/shmem.c:shmem_rename2(), only adjust old_dir->i_size and new_dir->i_size when old_dir != new_dir.
  2. Update all directory i_size modifications in mm/shmem.c to use i_size_write(dir, dir->i_size +/- BOGO_DIRENT_SIZE).
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
da9e5940 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in generic_fillattr / shmem_rename2 (5) 2026/11/17 17:39 2026/11/17 17:39 2026/11/17 18:46 ca622473
eb085238 bisect-cause ❓ KCSAN: data-race in generic_fillattr / shmem_rename2 (5) 2026/11/17 17:31 2026/11/17 17:31 2026/11/17 18:00 ca622473
94871fa2 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in generic_fillattr / shmem_rename2 (5) 2026/11/17 17:26 2026/11/17 17:26 2026/11/17 17:43 ca622473
▶ ▼ Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 (4) fs prio:low race:benign 6 1 17h01m 13h11m 0/29 closed as invalid on 2026/11/17 09:42
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 (2) fs 6 82 2343d 2415d 0/29 auto-closed as invalid on 2020/07/23 12:50
upstream KCSAN: data-race in generic_fillattr / shmem_rename2 fs 6 1 2592d 2592d 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 0xffff888103909690 of 8 bytes by task 3545 on cpu 1:
 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 0xffff888103909690 of 8 bytes by task 3547 on cpu 1:
 shmem_rename2+0x2c0/0x310 mm/shmem.c:4285
 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: 1 UID: 0 PID: 3547 Comm: udevd 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 17:05 upstream 666539eecdf4 122f94d5 .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.