[moderation] [mm?] KCSAN: data-race in shmem_add_to_page_cache / shmem_recalc_inode (3)

0 views
Skip to first unread message

syzbot

unread,
7:04 PM (1 hour ago) 7:04 PM
to syzkaller-upst...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 4405c18c95d2 Merge tag 'mm-nonmm-hotfixes-stable-2026-11-1..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=162184bd580000
kernel config: https://syzkaller.appspot.com/x/.config?x=886d2ddd2d6b664e
dashboard link: https://syzkaller.appspot.com/bug?extid=5e144c78a31a24f3faf6
compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8
CC: [linux-...@vger.kernel.org linu...@kvack.org]

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/bc2915167a4c/disk-4405c18c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/cdf4152506d9/vmlinux-4405c18c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/04690243718a/bzImage-4405c18c.xz

AI-generated root cause summary:
`shmem_recalc_inode()` reads `inode->i_mapping->nrpages` using `READ_ONCE()`
while holding `SHMEM_I(inode)->lock`, whereas `shmem_add_to_page_cache()`
updates `mapping->nrpages += nr` with a plain (unmarked) read-modify-write while
holding `mapping->i_pages.xa_lock`. Because these two functions hold different
locks, KCSAN reports a data race between the marked read at `mm/shmem.c:454` and
the unmarked write at `mm/shmem.c:1151`. On 64-bit systems this race is benign:
`nrpages` is an aligned `unsigned long` serialized among writers by `xa_lock`,
and `shmem_recalc_inode()` handles transient mismatches before the caller
updates `info->alloced` or `info->swapped`. Missing `WRITE_ONCE()` annotations
on `mapping->nrpages` updates (also present in `shmem_delete_from_page_cache()`,
`shmem_charge()`, and `mm/filemap.c` helpers) trigger the KCSAN report.

full analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=5e144c78a31a24f3faf6

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+5e144c...@syzkaller.appspotmail.com

==================================================================
BUG: KCSAN: data-race in shmem_add_to_page_cache / shmem_recalc_inode

read (marked) to 0xffff888118c3cfd0 of 8 bytes by task 6760 on cpu 1:
shmem_recalc_inode+0x6e/0x1f0 mm/shmem.c:454
shmem_writeout+0x46e/0x9b0 mm/shmem.c:1936
pageout mm/vmscan.c:730 [inline]
shrink_folio_list+0x1fb5/0x2d70 mm/vmscan.c:1505
evict_folios+0x1fa4/0x2990 mm/vmscan.c:5097
try_to_shrink_lruvec+0x9fb/0xd60 mm/vmscan.c:5271
lru_gen_shrink_lruvec mm/vmscan.c:5422 [inline]
shrink_lruvec mm/vmscan.c:6199 [inline]
shrink_node_memcgs mm/vmscan.c:6438 [inline]
shrink_node+0x97e/0x4600 mm/vmscan.c:6482
shrink_zones mm/vmscan.c:6701 [inline]
do_try_to_free_pages+0x310/0xb80 mm/vmscan.c:6763
try_to_free_mem_cgroup_pages+0x201/0x450 mm/vmscan.c:7044
mem_cgroup_force_empty mm/memcontrol-v1.c:1502 [inline]
mem_cgroup_force_empty_write+0x6b/0x160 mm/memcontrol-v1.c:1518
cgroup_file_write+0x197/0x350 kernel/cgroup/cgroup.c:4426
kernfs_fop_write_iter+0x1d2/0x2e0 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:575 [inline]
vfs_write+0x57a/0x9b0 fs/read_write.c:667
ksys_write+0xdc/0x1a0 fs/read_write.c:719
__do_sys_write fs/read_write.c:730 [inline]
__se_sys_write fs/read_write.c:727 [inline]
__x64_sys_write+0x40/0x50 fs/read_write.c:727
x64_sys_call+0x154e/0x2550 arch/x86/include/generated/asm/syscalls_64.h:2
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 0xffff888118c3cfd0 of 8 bytes by task 6656 on cpu 0:
shmem_add_to_page_cache+0x53a/0x650 mm/shmem.c:1151
shmem_alloc_and_add_folio mm/shmem.c:2252 [inline]
shmem_get_folio_gfp+0x4f0/0xcb0 mm/shmem.c:2792
shmem_get_folio mm/shmem.c:2891 [inline]
shmem_write_begin+0xfc/0x210 mm/shmem.c:3526
generic_perform_write+0x198/0x510 mm/filemap.c:4407
shmem_file_write_iter+0xc5/0xf0 mm/shmem.c:3701
__kernel_write_iter+0x30d/0x5a0 fs/read_write.c:601
dump_write_iter fs/coredump.c:1360 [inline]
dump_emit_page fs/coredump.c:1533 [inline]
dump_user_range+0x78e/0x950 fs/coredump.c:1601
elf_core_dump+0x2183/0x2310 fs/binfmt_elf.c:2106
coredump_write fs/coredump.c:1150 [inline]
do_coredump+0x3abb/0x4040 fs/coredump.c:1237
vfs_coredump+0x757/0x990 fs/coredump.c:1312
get_signal+0xb41/0xd30 kernel/signal.c:3098
arch_do_signal_or_restart+0x96/0x480 arch/x86/kernel/signal.c:337
__exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
exit_to_user_mode_loop kernel/entry/common.c:101 [inline]
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
irqentry_exit_to_user_mode_prepare include/linux/irq-entry-common.h:244 [inline]
irqentry_exit_to_user_mode include/linux/irq-entry-common.h:315 [inline]
irqentry_exit+0x15f/0x640 kernel/entry/common.c:152
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 6656 Comm: syz.0.622 Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
batman_adv: batadv0: Interface deactivated: syz_tun
batman_adv: batadv0: Removing interface: syz_tun


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup
Reply all
Reply to author
Forward
0 new messages