[moderation] [mm?] KCSAN: data-race in shmem_recalc_inode / shmem_writeout

0 views
Skip to first unread message

syzbot

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

syzbot found the following issue on:

HEAD commit: 8dac6df92a2e Merge tag 'nfsd-7.4-1' of git://git.kernel.or..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=15634dea580000
kernel config: https://syzkaller.appspot.com/x/.config?x=886d2ddd2d6b664e
dashboard link: https://syzkaller.appspot.com/bug?extid=d982dbed29a35e0e6571
compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8
CC: [ak...@linux-foundation.org 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/dfc787d10469/disk-8dac6df9.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/db7a8e4799da/vmlinux-8dac6df9.xz
kernel image: https://storage.googleapis.com/syzbot-assets/169073a123bc/bzImage-8dac6df9.xz

AI-generated root cause summary:
In mm/shmem.c, shmem_recalc_inode() (invoked from shmem_writeout()) reads
inode->i_mapping->nrpages using READ_ONCE() while holding only the shmem inode
info->lock, without holding the mapping->i_pages lock. Concurrently, writeout of
another folio for the same inode in shmem_delete_from_page_cache() decrements
mapping->nrpages under xa_lock_irq(&mapping->i_pages) using an unmarked
read-modify-write operation (mapping->nrpages -= nr). Because the write
operation is unmarked and executed without a common lock shared with the reader,
KCSAN flags this access pattern as a data race between a marked read and an
unmarked write under the Linux Kernel Memory Model.

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

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

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

read (marked) to 0xffff88811b5f7898 of 8 bytes by task 4921 on cpu 0:
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
try_charge_memcg+0x460/0xc50 mm/memcontrol.c:2776
charge_memcg+0xca/0x190 mm/memcontrol.c:5378
__mem_cgroup_charge+0x28/0xc0 mm/memcontrol.c:5395
mem_cgroup_charge include/linux/memcontrol.h:682 [inline]
shmem_alloc_and_add_folio mm/shmem.c:2236 [inline]
shmem_get_folio_gfp+0x478/0xcb0 mm/shmem.c:2792
shmem_fault+0xf4/0x260 mm/shmem.c:2986
__do_fault mm/memory.c:5691 [inline]
do_read_fault mm/memory.c:6136 [inline]
do_fault mm/memory.c:6270 [inline]
do_pte_missing mm/memory.c:4797 [inline]
handle_pte_fault mm/memory.c:6689 [inline]
__handle_mm_fault mm/memory.c:6841 [inline]
handle_mm_fault+0x2183/0x3880 mm/memory.c:7008
faultin_page mm/gup.c:1140 [inline]
__get_user_pages+0xf69/0x19e0 mm/gup.c:1442
__get_user_pages_locked mm/gup.c:1706 [inline]
get_dump_page+0xc9/0x250 mm/gup.c:2221
dump_user_range+0x15c/0x950 fs/coredump.c:1595
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

read-write to 0xffff88811b5f7898 of 8 bytes by task 4922 on cpu 1:
shmem_delete_from_page_cache mm/shmem.c:1177 [inline]
shmem_writeout+0x6d6/0x9b0 mm/shmem.c:1962
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
try_charge_memcg+0x460/0xc50 mm/memcontrol.c:2776
charge_memcg+0xca/0x190 mm/memcontrol.c:5378
__mem_cgroup_charge+0x28/0xc0 mm/memcontrol.c:5395
mem_cgroup_charge include/linux/memcontrol.h:682 [inline]
shmem_alloc_and_add_folio mm/shmem.c:2236 [inline]
shmem_get_folio_gfp+0x478/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: 1 UID: 0 PID: 4922 Comm: syz.1.412 Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
syz.1.412 (4922) used greatest stack depth: 6800 bytes left


---
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