syzbot
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: 1h45m, last: 1h45m
✨ 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
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
- In
mm/shmem.c:shmem_rename2(), only adjust old_dir->i_size and new_dir->i_size when old_dir != new_dir.
- Update all directory
i_size modifications in mm/shmem.c to use i_size_write(dir, dir->i_size +/- BOGO_DIRENT_SIZE).
Sample crash report:
* Struck through repros no longer work on HEAD.