syzbot


KASAN: slab-use-after-free Read in mas_next_entry

Status: fixed on 2023/06/08 14:41
Subsystems: mm
[Documentation on labels]
Reported-by: syzbot+a7c1ec5b1d71ceaa5186@syzkaller.appspotmail.com
Fix commit: f4e9e0e69468 mm/mempolicy: fix use-after-free of VMA iterator
First crash: 554d, last: 551d
Cause bisection: failed (error log, bisect log)
  
Discussions (2)
Title Replies (including bot) Last reply
[PATCH] mm/mempolicy: Fix use-after-free of VMA iterator 5 (5) 2023/05/01 18:24
[syzbot] [mm?] KASAN: slab-use-after-free Read in mas_next_entry 0 (2) 2023/04/07 16:36
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in mas_next_entry fs C error 16 704d 717d 22/28 fixed on 2023/02/24 13:50
Last patch testing requests (2)
Created Duration User Patch Repo Result
2023/04/10 13:16 18m liam.howlett@oracle.com git://git.infradead.org/users/jedix/linux-maple.git mempolicy_fix OK log
2023/04/10 13:05 0m liam.howlett@oracle.com http://git.infradead.org/users/jedix/linux-maple.git mempolicy_fix error

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in mas_safe_min lib/maple_tree.c:727 [inline]
BUG: KASAN: slab-use-after-free in mas_next_nentry lib/maple_tree.c:4664 [inline]
BUG: KASAN: slab-use-after-free in mas_next_entry+0x12b3/0x1690 lib/maple_tree.c:4760
Read of size 8 at addr ffff8880782e0440 by task syz-executor.3/5331

CPU: 0 PID: 5331 Comm: syz-executor.3 Not tainted 6.3.0-rc5-syzkaller-00137-gf2afccfefe7b #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/30/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:319
 print_report mm/kasan/report.c:430 [inline]
 kasan_report+0x11c/0x130 mm/kasan/report.c:536
 mas_safe_min lib/maple_tree.c:727 [inline]
 mas_next_nentry lib/maple_tree.c:4664 [inline]
 mas_next_entry+0x12b3/0x1690 lib/maple_tree.c:4760
 mas_find+0x7d/0x200 lib/maple_tree.c:6025
 vma_find include/linux/mm.h:736 [inline]
 __do_sys_set_mempolicy_home_node+0x1ef/0x480 mm/mempolicy.c:1524
 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:0x7f730dc8c169
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:00007f730ea05168 EFLAGS: 00000246 ORIG_RAX: 00000000000001c2
RAX: ffffffffffffffda RBX: 00007f730ddabf80 RCX: 00007f730dc8c169
RDX: 0000000000000000 RSI: 0000000000003000 RDI: 0000000020ffd000
RBP: 00007f730dce7ca1 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f730decfb1f R14: 00007f730ea05300 R15: 0000000000022000
 </TASK>

Allocated by task 5335:
 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:769 [inline]
 kmem_cache_alloc_bulk+0x424/0x860 mm/slub.c:4034
 mt_alloc_bulk lib/maple_tree.c:164 [inline]
 mas_alloc_nodes+0x276/0x8a0 lib/maple_tree.c:1263
 mas_node_count_gfp lib/maple_tree.c:1318 [inline]
 mas_preallocate+0x1bb/0x360 lib/maple_tree.c:5717
 vma_iter_prealloc mm/internal.h:972 [inline]
 __split_vma+0x1b7/0x810 mm/mmap.c:2177
 do_vmi_align_munmap+0x34a/0xf60 mm/mmap.c:2320
 do_vmi_munmap+0x26e/0x2c0 mm/mmap.c:2452
 mmap_region+0x1ee/0x2620 mm/mmap.c:2500
 do_mmap+0x831/0xf60 mm/mmap.c:1364
 vm_mmap_pgoff+0x1af/0x280 mm/util.c:542
 ksys_mmap_pgoff+0x41f/0x5a0 mm/mmap.c:1410
 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

Freed by task 5331:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 kasan_save_free_info+0x2e/0x40 mm/kasan/generic.c:521
 ____kasan_slab_free mm/kasan/common.c:236 [inline]
 ____kasan_slab_free+0x160/0x1c0 mm/kasan/common.c:200
 kasan_slab_free include/linux/kasan.h:162 [inline]
 slab_free_hook mm/slub.c:1781 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1807
 slab_free mm/slub.c:3787 [inline]
 kmem_cache_free_bulk.part.0+0x20c/0x680 mm/slub.c:3905
 mt_free_bulk lib/maple_tree.c:169 [inline]
 mas_destroy+0x3e0/0x650 lib/maple_tree.c:5771
 mas_store_prealloc+0xf0/0x150 lib/maple_tree.c:5702
 vma_iter_store mm/internal.h:1013 [inline]
 vma_complete+0xad9/0x1170 mm/mmap.c:572
 __split_vma+0x523/0x810 mm/mmap.c:2214
 split_vma+0xc6/0x110 mm/mmap.c:2242
 mbind_range+0x4d2/0x760 mm/mempolicy.c:829
 __do_sys_set_mempolicy_home_node+0x323/0x480 mm/mempolicy.c:1546
 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 ffff8880782e0400
 which belongs to the cache maple_node of size 256
The buggy address is located 64 bytes inside of
 freed 256-byte region [ffff8880782e0400, ffff8880782e0500)

The buggy address belongs to the physical page:
page:ffffea0001e0b800 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x782e0
head:ffffea0001e0b800 order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffff8880124cd000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0x1d20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 5335, tgid 5329 (syz-executor.3), ts 114724293643, free_ts 114618496841
 prep_new_page mm/page_alloc.c:2553 [inline]
 get_page_from_freelist+0x1190/0x2e20 mm/page_alloc.c:4326
 __alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:5592
 alloc_pages+0x1aa/0x270 mm/mempolicy.c:2283
 alloc_slab_page mm/slub.c:1851 [inline]
 allocate_slab+0x25f/0x390 mm/slub.c:1998
 new_slab mm/slub.c:2051 [inline]
 ___slab_alloc+0xa91/0x1400 mm/slub.c:3193
 __kmem_cache_alloc_bulk mm/slub.c:3952 [inline]
 kmem_cache_alloc_bulk+0x270/0x860 mm/slub.c:4027
 mt_alloc_bulk lib/maple_tree.c:164 [inline]
 mas_alloc_nodes+0x276/0x8a0 lib/maple_tree.c:1263
 mas_node_count_gfp lib/maple_tree.c:1318 [inline]
 mas_preallocate+0x1bb/0x360 lib/maple_tree.c:5717
 vma_iter_prealloc mm/internal.h:972 [inline]
 __split_vma+0x1b7/0x810 mm/mmap.c:2177
 do_vmi_align_munmap+0x34a/0xf60 mm/mmap.c:2320
 do_vmi_munmap+0x26e/0x2c0 mm/mmap.c:2452
 mmap_region+0x1ee/0x2620 mm/mmap.c:2500
 do_mmap+0x831/0xf60 mm/mmap.c:1364
 vm_mmap_pgoff+0x1af/0x280 mm/util.c:542
 ksys_mmap_pgoff+0x41f/0x5a0 mm/mmap.c:1410
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1454 [inline]
 free_pcp_prepare+0x5d5/0xa50 mm/page_alloc.c:1504
 free_unref_page_prepare mm/page_alloc.c:3388 [inline]
 free_unref_page+0x1d/0x490 mm/page_alloc.c:3483
 qlink_free mm/kasan/quarantine.c:168 [inline]
 qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x192/0x220 mm/kasan/quarantine.c:294
 __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:769 [inline]
 slab_alloc_node mm/slub.c:3452 [inline]
 slab_alloc mm/slub.c:3460 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3467 [inline]
 kmem_cache_alloc+0x17c/0x3b0 mm/slub.c:3476
 __mpol_dup+0x76/0x390 mm/mempolicy.c:2407
 mpol_dup include/linux/mempolicy.h:88 [inline]
 vma_replace_policy mm/mempolicy.c:773 [inline]
 mbind_range+0x132/0x760 mm/mempolicy.c:839
 __do_sys_set_mempolicy_home_node+0x323/0x480 mm/mempolicy.c:1546
 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:
 ffff8880782e0300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880782e0380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880782e0400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                           ^
 ffff8880782e0480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880782e0500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/04/07 16:36 upstream f2afccfefe7b f7ba566d .config console log report syz ci-upstream-kasan-gce KASAN: slab-use-after-free Read in mas_next_entry
2023/04/07 13:38 upstream f2afccfefe7b f7ba566d .config console log report info ci-upstream-kasan-gce KASAN: slab-use-after-free Read in mas_next_entry
2023/04/04 00:58 upstream 148341f0a2f5 7db618d0 .config console log report info ci-upstream-kasan-gce KASAN: slab-use-after-free Read in mas_next_entry
* Struck through repros no longer work on HEAD.