[syzbot] [mm?] KASAN: slab-out-of-bounds Read in shrink_folio_list

9 views
Skip to first unread message

syzbot

unread,
Jul 9, 2023, 1:33:41 AM7/9/23
to ak...@linux-foundation.org, linux-...@vger.kernel.org, linu...@kvack.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 123212f53f3e Add linux-next specific files for 20230707
git tree: linux-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=1542771ca80000
kernel config: https://syzkaller.appspot.com/x/.config?x=15ec80b62f588543
dashboard link: https://syzkaller.appspot.com/bug?extid=c19a171264b968bf389b
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1284666aa80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12b142bca80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/098f7ee2237c/disk-123212f5.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/88defebbfc49/vmlinux-123212f5.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d5e9343ec16a/bzImage-123212f5.xz

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

==================================================================
BUG: KASAN: slab-out-of-bounds in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-out-of-bounds in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: slab-out-of-bounds in mapping_release_always include/linux/pagemap.h:279 [inline]
BUG: KASAN: slab-out-of-bounds in folio_needs_release mm/internal.h:187 [inline]
BUG: KASAN: slab-out-of-bounds in shrink_folio_list+0x2dbf/0x3e60 mm/vmscan.c:2067
Read of size 8 at addr ffff888078d2bda1 by task syz-executor321/5029

CPU: 1 PID: 5029 Comm: syz-executor321 Not tainted 6.4.0-next-20230707-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/03/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:364
print_report mm/kasan/report.c:475 [inline]
kasan_report+0x11d/0x130 mm/kasan/report.c:588
check_region_inline mm/kasan/generic.c:181 [inline]
kasan_check_range+0xf0/0x190 mm/kasan/generic.c:187
instrument_atomic_read include/linux/instrumented.h:68 [inline]
_test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
mapping_release_always include/linux/pagemap.h:279 [inline]
folio_needs_release mm/internal.h:187 [inline]
shrink_folio_list+0x2dbf/0x3e60 mm/vmscan.c:2067
reclaim_folio_list+0xd0/0x390 mm/vmscan.c:2801
reclaim_pages+0x442/0x670 mm/vmscan.c:2837
madvise_cold_or_pageout_pte_range+0x100e/0x1ee0 mm/madvise.c:533
walk_pmd_range mm/pagewalk.c:140 [inline]
walk_pud_range mm/pagewalk.c:218 [inline]
walk_p4d_range mm/pagewalk.c:253 [inline]
walk_pgd_range+0x9e7/0x1470 mm/pagewalk.c:290
__walk_page_range+0x651/0x780 mm/pagewalk.c:392
walk_page_range+0x311/0x4a0 mm/pagewalk.c:490
madvise_pageout_page_range mm/madvise.c:591 [inline]
madvise_pageout+0x2fe/0x560 mm/madvise.c:618
madvise_vma_behavior+0x61a/0x21a0 mm/madvise.c:1039
madvise_walk_vmas+0x1c7/0x2b0 mm/madvise.c:1268
do_madvise.part.0+0x276/0x490 mm/madvise.c:1448
do_madvise mm/madvise.c:1461 [inline]
__do_sys_madvise mm/madvise.c:1461 [inline]
__se_sys_madvise mm/madvise.c:1459 [inline]
__x64_sys_madvise+0x117/0x150 mm/madvise.c:1459
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f0290b79c29
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe42da7dc8 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 00007f0290be7ed0 RCX: 00007f0290b79c29
RDX: 0000000000000015 RSI: 0000000000600003 RDI: 0000000020000000
RBP: 00007ffe42da7dd8 R08: 00007f0290be7e40 R09: 00007f0290be7e40
R10: 00007ffe42da7840 R11: 0000000000000246 R12: 00007ffe42da7de0
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
</TASK>

Allocated by task 5019:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
anon_vma_fork+0xe2/0x630 mm/rmap.c:361
dup_mmap+0xc0f/0x14b0 kernel/fork.c:732
dup_mm kernel/fork.c:1694 [inline]
copy_mm kernel/fork.c:1743 [inline]
copy_process+0x6663/0x75c0 kernel/fork.c:2509
kernel_clone+0xeb/0x890 kernel/fork.c:2917
__do_sys_clone+0xba/0x100 kernel/fork.c:3060
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff888078d2bcc0
which belongs to the cache anon_vma of size 208
The buggy address is located 17 bytes to the right of
allocated 208-byte region [ffff888078d2bcc0, ffff888078d2bd90)

The buggy address belongs to the physical page:
page:ffffea0001e34ac0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x78d2b
ksm flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000200 ffff888014674140 ffffea0000ad6100 dead000000000003
raw: 0000000000000000 00000000800f000f 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 4694, tgid 4694 (dhcpcd), ts 64749636388, free_ts 46253751886
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2db/0x350 mm/page_alloc.c:1569
prep_new_page mm/page_alloc.c:1576 [inline]
get_page_from_freelist+0xfd9/0x2c40 mm/page_alloc.c:3256
__alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:4512
alloc_pages+0x1aa/0x270 mm/mempolicy.c:2279
alloc_slab_page mm/slub.c:1862 [inline]
allocate_slab+0x25f/0x390 mm/slub.c:2009
new_slab mm/slub.c:2062 [inline]
___slab_alloc+0xbc3/0x15d0 mm/slub.c:3215
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3314
__slab_alloc_node mm/slub.c:3367 [inline]
slab_alloc_node mm/slub.c:3460 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x371/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
anon_vma_fork+0xe2/0x630 mm/rmap.c:361
dup_mmap+0xc0f/0x14b0 kernel/fork.c:732
dup_mm kernel/fork.c:1694 [inline]
copy_mm kernel/fork.c:1743 [inline]
copy_process+0x6663/0x75c0 kernel/fork.c:2509
kernel_clone+0xeb/0x890 kernel/fork.c:2917
__do_sys_clone+0xba/0x100 kernel/fork.c:3060
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1160 [inline]
free_unref_page_prepare+0x62e/0xcb0 mm/page_alloc.c:2383
free_unref_page+0x33/0x370 mm/page_alloc.c:2478
__unfreeze_partials+0x1fe/0x220 mm/slub.c:2647
qlink_free mm/kasan/quarantine.c:166 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x195/0x220 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x63/0x90 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
getname_flags.part.0+0x50/0x4f0 fs/namei.c:140
getname_flags+0x9e/0xe0 include/linux/audit.h:319
vfs_fstatat+0x77/0xb0 fs/stat.c:275
__do_sys_newfstatat+0x8a/0x110 fs/stat.c:446
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
ffff888078d2bc80: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
ffff888078d2bd00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff888078d2bd80: 00 00 fc fc fc fc fc fc fc fc 00 00 00 00 00 00
^
ffff888078d2be00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff888078d2be80: 00 00 00 00 fc fc fc fc fc fc fc fc 00 00 00 00
==================================================================


---
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 bug is already fixed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

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

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

If you want to undo deduplication, reply with:
#syz undup

Hillf Danton

unread,
Jul 9, 2023, 4:50:18 AM7/9/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 08 Jul 2023 22:33:39 -0700
> HEAD commit: 123212f53f3e Add linux-next specific files for 20230707
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12b142bca80000

Lock parent upon forking.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 123212f53f3e

--- x/kernel/fork.c
+++ y/kernel/fork.c
@@ -692,6 +692,8 @@ static __latent_entropy int dup_mmap(str
for_each_vma(old_vmi, mpnt) {
struct file *file;

+ vma_start_write(mpnt);
+
if (mpnt->vm_flags & VM_DONTCOPY) {
vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt));
continue;
--

syzbot

unread,
Jul 9, 2023, 5:03:30 AM7/9/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-out-of-bounds Read in shrink_folio_list

==================================================================
BUG: KASAN: slab-out-of-bounds in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-out-of-bounds in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: slab-out-of-bounds in mapping_release_always include/linux/pagemap.h:279 [inline]
BUG: KASAN: slab-out-of-bounds in folio_needs_release mm/internal.h:187 [inline]
BUG: KASAN: slab-out-of-bounds in shrink_folio_list+0x2dbf/0x3e60 mm/vmscan.c:2067
Read of size 8 at addr ffff8880157b3c91 by task syz-executor.0/5445

CPU: 0 PID: 5445 Comm: syz-executor.0 Not tainted 6.4.0-next-20230707-syzkaller-dirty #0
RIP: 0033:0x7f38c8a8c389
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f38c9790168 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 00007f38c8babf80 RCX: 00007f38c8a8c389
RDX: 0000000000000015 RSI: 0000000000600003 RDI: 0000000020000000
RBP: 00007f38c8ad7493 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffd5dde0fbf R14: 00007f38c9790300 R15: 0000000000022000
</TASK>

Allocated by task 5368:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
__anon_vma_prepare+0x2c6/0x580 mm/rmap.c:203
anon_vma_prepare include/linux/rmap.h:159 [inline]
do_anonymous_page mm/memory.c:4112 [inline]
do_pte_missing mm/memory.c:3671 [inline]
handle_pte_fault mm/memory.c:4949 [inline]
__handle_mm_fault+0x39e6/0x3dd0 mm/memory.c:5089
handle_mm_fault+0x2a1/0x9e0 mm/memory.c:5254
do_user_addr_fault+0x435/0x10a0 arch/x86/mm/fault.c:1415
handle_page_fault arch/x86/mm/fault.c:1509 [inline]
exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1565
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570

The buggy address belongs to the object at ffff8880157b3bb0
which belongs to the cache anon_vma of size 208
The buggy address is located 17 bytes to the right of
allocated 208-byte region [ffff8880157b3bb0, ffff8880157b3c80)

The buggy address belongs to the physical page:
page:ffffea000055ecc0 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff8880157b3110 pfn:0x157b3
memcg:ffff88801ba5b401
ksm flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000200 ffff888014674140 ffffea0001ce4b40 dead000000000003
raw: ffff8880157b3110 00000000800f0009 00000001ffffffff ffff88801ba5b401
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 5296, tgid 5296 (dhcpcd-run-hook), ts 81876191202, free_ts 81861098399
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2db/0x350 mm/page_alloc.c:1569
prep_new_page mm/page_alloc.c:1576 [inline]
get_page_from_freelist+0xfd9/0x2c40 mm/page_alloc.c:3256
__alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:4512
alloc_pages+0x1aa/0x270 mm/mempolicy.c:2279
alloc_slab_page mm/slub.c:1862 [inline]
allocate_slab+0x25f/0x390 mm/slub.c:2009
new_slab mm/slub.c:2062 [inline]
___slab_alloc+0xbc3/0x15d0 mm/slub.c:3215
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3314
__slab_alloc_node mm/slub.c:3367 [inline]
slab_alloc_node mm/slub.c:3460 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x371/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
anon_vma_fork+0xe2/0x630 mm/rmap.c:361
dup_mmap+0xc0f/0x14b0 kernel/fork.c:734
dup_mm kernel/fork.c:1696 [inline]
copy_mm kernel/fork.c:1745 [inline]
copy_process+0x6663/0x75c0 kernel/fork.c:2511
kernel_clone+0xeb/0x890 kernel/fork.c:2919
__do_sys_clone+0xba/0x100 kernel/fork.c:3062
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1160 [inline]
free_unref_page_prepare+0x62e/0xcb0 mm/page_alloc.c:2383
free_unref_page+0x33/0x370 mm/page_alloc.c:2478
__unfreeze_partials+0x1fe/0x220 mm/slub.c:2647
qlink_free mm/kasan/quarantine.c:166 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x195/0x220 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x63/0x90 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
vm_area_dup+0x21/0x230 kernel/fork.c:500
__split_vma+0x199/0x810 mm/mmap.c:2339
do_vmi_align_munmap+0x3f3/0x10e0 mm/mmap.c:2477
do_vmi_munmap+0x266/0x300 mm/mmap.c:2619
mmap_region+0x1fb/0x20a0 mm/mmap.c:2669
do_mmap+0x837/0xea0 mm/mmap.c:1362
vm_mmap_pgoff+0x1b1/0x280 mm/util.c:543
ksys_mmap_pgoff+0x42b/0x5b0 mm/mmap.c:1408
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80

Memory state around the buggy address:
ffff8880157b3b80: fc fc fc fc fc fc 00 00 00 00 00 00 00 00 00 00
ffff8880157b3c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff8880157b3c80: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
^
ffff8880157b3d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8880157b3d80: 00 00 fc fc fc fc fc fc fc fc 00 00 00 00 00 00
==================================================================


Tested on:

commit: 123212f5 Add linux-next specific files for 20230707
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=135a15f8a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=15ec80b62f588543
dashboard link: https://syzkaller.appspot.com/bug?extid=c19a171264b968bf389b
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=13a4666aa80000

Hillf Danton

unread,
Jul 9, 2023, 5:23:03 AM7/9/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 08 Jul 2023 22:33:39 -0700
> HEAD commit: 123212f53f3e Add linux-next specific files for 20230707
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12b142bca80000

Lock parent upon forking.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 123212f53f3e

--- x/kernel/fork.c
+++ y/kernel/fork.c
@@ -692,6 +692,8 @@ static __latent_entropy int dup_mmap(str
for_each_vma(old_vmi, mpnt) {
struct file *file;

+ vma_start_write(mpnt);
+
if (mpnt->vm_flags & VM_DONTCOPY) {
vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt));
continue;
--- x/mm/mmap.c
+++ y/mm/mmap.c
@@ -2805,6 +2805,7 @@ cannot_expand:
if (vma_iter_prealloc(&vmi))
goto close_and_free_vma;

+ vma_start_write(vma);
if (vma->vm_file)
i_mmap_lock_write(vma->vm_file->f_mapping);

--

syzbot

unread,
Jul 9, 2023, 5:53:25 AM7/9/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-out-of-bounds Read in shrink_folio_list

==================================================================
BUG: KASAN: slab-out-of-bounds in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-out-of-bounds in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: slab-out-of-bounds in mapping_release_always include/linux/pagemap.h:279 [inline]
BUG: KASAN: slab-out-of-bounds in folio_needs_release mm/internal.h:187 [inline]
BUG: KASAN: slab-out-of-bounds in shrink_folio_list+0x2dbf/0x3e60 mm/vmscan.c:2067
Read of size 8 at addr ffff8880771f9411 by task syz-executor.0/5438

CPU: 0 PID: 5438 Comm: syz-executor.0 Not tainted 6.4.0-next-20230707-syzkaller-dirty #0
RIP: 0033:0x7f09fd48c389
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f09fe1fe168 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 00007f09fd5abf80 RCX: 00007f09fd48c389
RDX: 0000000000000015 RSI: 0000000000600003 RDI: 0000000020000000
RBP: 00007f09fd4d7493 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffcb3184d8f R14: 00007f09fe1fe300 R15: 0000000000022000
</TASK>

Allocated by task 5436:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
__anon_vma_prepare+0x2c6/0x580 mm/rmap.c:203
anon_vma_prepare include/linux/rmap.h:159 [inline]
do_cow_fault mm/memory.c:4573 [inline]
do_fault mm/memory.c:4682 [inline]
do_pte_missing mm/memory.c:3673 [inline]
handle_pte_fault mm/memory.c:4949 [inline]
__handle_mm_fault+0x304a/0x3dd0 mm/memory.c:5089
handle_mm_fault+0x2a1/0x9e0 mm/memory.c:5254
do_user_addr_fault+0x435/0x10a0 arch/x86/mm/fault.c:1415
handle_page_fault arch/x86/mm/fault.c:1509 [inline]
exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1565
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570

The buggy address belongs to the object at ffff8880771f9330
which belongs to the cache anon_vma of size 208
The buggy address is located 17 bytes to the right of
allocated 208-byte region [ffff8880771f9330, ffff8880771f9400)

The buggy address belongs to the physical page:
page:ffffea0001dc7e40 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff8880771f9aa0 pfn:0x771f9
memcg:ffff888015792801
ksm flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000200 ffff888014674140 ffffea00009b7300 0000000000000003
raw: ffff8880771f9aa0 00000000800f0009 00000001ffffffff ffff888015792801
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 5394, tgid 5394 (dhcpcd-run-hook), ts 87861312397, free_ts 85675041379
qlink_free mm/kasan/quarantine.c:166 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x195/0x220 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x63/0x90 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
kmem_cache_alloc_node+0x1cd/0x3f0 mm/slub.c:3515
__alloc_skb+0x288/0x330 net/core/skbuff.c:634
alloc_skb include/linux/skbuff.h:1289 [inline]
alloc_skb_with_frags+0x9a/0x6f0 net/core/skbuff.c:6228
sock_alloc_send_pskb+0x7a7/0x930 net/core/sock.c:2782
unix_dgram_sendmsg+0x422/0x1b70 net/unix/af_unix.c:1944
sock_sendmsg_nosec net/socket.c:725 [inline]
sock_sendmsg+0xde/0x190 net/socket.c:748
sock_write_iter+0x29b/0x3d0 net/socket.c:1129
call_write_iter include/linux/fs.h:1873 [inline]
do_iter_readv_writev+0x211/0x3b0 fs/read_write.c:735
do_iter_write+0x182/0x810 fs/read_write.c:860
vfs_writev+0x1b0/0x670 fs/read_write.c:933
do_writev+0x270/0x2f0 fs/read_write.c:976

Memory state around the buggy address:
ffff8880771f9300: fc fc fc fc fc fc 00 00 00 00 00 00 00 00 00 00
ffff8880771f9380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff8880771f9400: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
^
ffff8880771f9480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8880771f9500: 00 00 fc fc fc fc fc fc fc fc 00 00 00 00 00 00
==================================================================


Tested on:

commit: 123212f5 Add linux-next specific files for 20230707
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=16fb0fe2a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=15ec80b62f588543
dashboard link: https://syzkaller.appspot.com/bug?extid=c19a171264b968bf389b
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=153c3fa0a80000

Hillf Danton

unread,
Jul 9, 2023, 9:01:16 AM7/9/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 08 Jul 2023 22:33:39 -0700
> HEAD commit: 123212f53f3e Add linux-next specific files for 20230707
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12b142bca80000

Lock parent upon forking.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 123212f53f3e

--- x/kernel/fork.c
+++ y/kernel/fork.c
@@ -692,6 +692,8 @@ static __latent_entropy int dup_mmap(str
for_each_vma(old_vmi, mpnt) {
struct file *file;

+ vma_start_write(mpnt);
+
if (mpnt->vm_flags & VM_DONTCOPY) {
vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt));
continue;
--- x/mm/mmap.c
+++ y/mm/mmap.c
@@ -1977,6 +1977,7 @@ static int expand_upwards(struct vm_area
return -ENOMEM;
}

+ vma_start_write(vma);
/*
* vma->vm_start/vm_end cannot change under us because the caller
* is required to hold the mmap_lock in read mode. We need the
@@ -2064,6 +2065,7 @@ int expand_downwards(struct vm_area_stru
return -ENOMEM;
}

+ vma_start_write(vma);
/*
* vma->vm_start/vm_end cannot change under us because the caller
* is required to hold the mmap_lock in read mode. We need the
@@ -2805,6 +2807,7 @@ cannot_expand:

syzbot

unread,
Jul 9, 2023, 9:29:28 AM7/9/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-out-of-bounds Read in shrink_folio_list

==================================================================
BUG: KASAN: slab-out-of-bounds in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-out-of-bounds in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: slab-out-of-bounds in mapping_release_always include/linux/pagemap.h:279 [inline]
BUG: KASAN: slab-out-of-bounds in folio_needs_release mm/internal.h:187 [inline]
BUG: KASAN: slab-out-of-bounds in shrink_folio_list+0x2dbf/0x3e60 mm/vmscan.c:2067
Read of size 8 at addr ffff88802ba79521 by task syz-executor.0/5443

CPU: 1 PID: 5443 Comm: syz-executor.0 Not tainted 6.4.0-next-20230707-syzkaller-dirty #0
RIP: 0033:0x7ff6ee68c389
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ff6ef3c3168 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 00007ff6ee7abf80 RCX: 00007ff6ee68c389
RDX: 0000000000000015 RSI: 0000000000600003 RDI: 0000000020000000
RBP: 00007ff6ee6d7493 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffd8b088abf R14: 00007ff6ef3c3300 R15: 0000000000022000
</TASK>

Allocated by task 5441:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3470 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x173/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
__anon_vma_prepare+0x2c6/0x580 mm/rmap.c:203
anon_vma_prepare include/linux/rmap.h:159 [inline]
do_cow_fault mm/memory.c:4573 [inline]
do_fault mm/memory.c:4682 [inline]
do_pte_missing mm/memory.c:3673 [inline]
handle_pte_fault mm/memory.c:4949 [inline]
__handle_mm_fault+0x304a/0x3dd0 mm/memory.c:5089
handle_mm_fault+0x2a1/0x9e0 mm/memory.c:5254
do_user_addr_fault+0x435/0x10a0 arch/x86/mm/fault.c:1415
handle_page_fault arch/x86/mm/fault.c:1509 [inline]
exc_page_fault+0x98/0x170 arch/x86/mm/fault.c:1565
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570

The buggy address belongs to the object at ffff88802ba79440
which belongs to the cache anon_vma of size 208
The buggy address is located 17 bytes to the right of
allocated 208-byte region [ffff88802ba79440, ffff88802ba79510)

The buggy address belongs to the physical page:
page:ffffea0000ae9e40 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88802ba79bb0 pfn:0x2ba79
memcg:ffff888067eec601
ksm flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000200 ffff888014674140 ffffea0000aa3940 dead000000000003
raw: ffff88802ba79bb0 00000000800f0002 00000001ffffffff ffff888067eec601
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 5428, tgid 5428 (dhcpcd-run-hook), ts 90527418963, free_ts 90445288205
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2db/0x350 mm/page_alloc.c:1569
prep_new_page mm/page_alloc.c:1576 [inline]
get_page_from_freelist+0xfd9/0x2c40 mm/page_alloc.c:3256
__alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:4512
alloc_pages+0x1aa/0x270 mm/mempolicy.c:2279
alloc_slab_page mm/slub.c:1862 [inline]
allocate_slab+0x25f/0x390 mm/slub.c:2009
new_slab mm/slub.c:2062 [inline]
___slab_alloc+0xbc3/0x15d0 mm/slub.c:3215
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3314
__slab_alloc_node mm/slub.c:3367 [inline]
slab_alloc_node mm/slub.c:3460 [inline]
slab_alloc mm/slub.c:3478 [inline]
__kmem_cache_alloc_lru mm/slub.c:3485 [inline]
kmem_cache_alloc+0x371/0x390 mm/slub.c:3494
anon_vma_alloc mm/rmap.c:94 [inline]
__anon_vma_prepare+0x2c6/0x580 mm/rmap.c:203
anon_vma_prepare include/linux/rmap.h:159 [inline]
do_anonymous_page mm/memory.c:4112 [inline]
do_pte_missing mm/memory.c:3671 [inline]
handle_pte_fault mm/memory.c:4949 [inline]
__handle_mm_fault+0x39e6/0x3dd0 mm/memory.c:5089
handle_mm_fault+0x2a1/0x9e0 mm/memory.c:5254
faultin_page mm/gup.c:952 [inline]
__get_user_pages+0x4d3/0x10e0 mm/gup.c:1235
__get_user_pages_locked mm/gup.c:1500 [inline]
get_user_pages_remote+0x24f/0x980 mm/gup.c:2333
get_arg_page+0x12c/0x470 fs/exec.c:225
copy_string_kernel+0x1a3/0x260 fs/exec.c:643
do_execveat_common+0x4df/0x8e0 fs/exec.c:1937
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1160 [inline]
free_unref_page_prepare+0x62e/0xcb0 mm/page_alloc.c:2383
free_unref_page+0x33/0x370 mm/page_alloc.c:2478
vfree+0x180/0x7b0 mm/vmalloc.c:2842
delayed_vfree_work+0x57/0x70 mm/vmalloc.c:2763
process_one_work+0xa34/0x16f0 kernel/workqueue.c:2597
worker_thread+0x67d/0x10c0 kernel/workqueue.c:2748
kthread+0x344/0x440 kernel/kthread.c:389
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

Memory state around the buggy address:
ffff88802ba79400: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
ffff88802ba79480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88802ba79500: 00 00 fc fc fc fc fc fc fc fc 00 00 00 00 00 00
^
ffff88802ba79580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff88802ba79600: 00 00 00 00 fc fc fc fc fc fc fc fc 00 00 00 00
==================================================================


Tested on:

commit: 123212f5 Add linux-next specific files for 20230707
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=14985cf2a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=15ec80b62f588543
dashboard link: https://syzkaller.appspot.com/bug?extid=c19a171264b968bf389b
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=1505da54a80000

Hyeonggon Yoo

unread,
Jul 10, 2023, 5:21:22 AM7/10/23
to syzbot, ak...@linux-foundation.org, linux-...@vger.kernel.org, linu...@kvack.org, syzkall...@googlegroups.com
This should now be fixed:
https://lore.kernel.org/mm-commits/2023070718564...@smtp.kernel.org/T/#u

#syz fix: mm: call folio_mapping() inside folio_needs_release()

Hillf Danton

unread,
Jul 10, 2023, 9:35:38 AM7/10/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 08 Jul 2023 22:33:39 -0700
> HEAD commit: 123212f53f3e Add linux-next specific files for 20230707
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12b142bca80000

Use folio_mapping().
--- x/mm/internal.h
+++ y/mm/internal.h
@@ -181,7 +181,7 @@ static inline void set_page_refcounted(s
*/
static inline bool folio_needs_release(struct folio *folio)
{
- struct address_space *mapping = folio->mapping;
+ struct address_space *mapping = folio_mapping(folio);

return folio_has_private(folio) ||
(mapping && mapping_release_always(mapping));
--

syzbot

unread,
Jul 10, 2023, 9:55:26 AM7/10/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+c19a17...@syzkaller.appspotmail.com

Tested on:

commit: 123212f5 Add linux-next specific files for 20230707
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=150bf612a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=15ec80b62f588543
dashboard link: https://syzkaller.appspot.com/bug?extid=c19a171264b968bf389b
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=1204a004a80000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages