syzbot


KASAN: use-after-free Read in madvise_update_vma

Status: internal: reported C repro on 2022/02/07 20:29
Reported-by: syzbot+@syzkaller.appspotmail.com
Fix commit: 942341dcc574 mm: fix use-after-free when anon vma name is used after vma is freed
Patched on: [ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-leak ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce ci-upstream-kmsan-gce-386 ci-upstream-linux-next-kasan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-kcsan-gce ci2-upstream-usb], missing on: [ci-qemu2-riscv64]
First crash: 141d, last: 123d

Cause bisection: introduced by (bisect log) :
commit 9a10064f5625d5572c3626c1516e0bebc6c9fe9b
Author: Colin Cross <ccross@google.com>
Date: Fri Jan 14 22:05:59 2022 +0000

  mm: add a field to store names for private anonymous memory

Crash: KASAN: use-after-free Read in madvise_update_vma (log)
Repro: C syz .config

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in strcmp+0x9b/0xb0 lib/string.c:346
Read of size 1 at addr ffff88807f0711c4 by task syz-executor286/3588

CPU: 1 PID: 3588 Comm: syz-executor286 Not tainted 5.17.0-rc3-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0x8d/0x336 mm/kasan/report.c:255
 __kasan_report mm/kasan/report.c:442 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
 strcmp+0x9b/0xb0 lib/string.c:346
 replace_vma_anon_name mm/madvise.c:141 [inline]
 madvise_update_vma+0x4e6/0x7f0 mm/madvise.c:212
 madvise_vma_behavior+0x116/0x1910 mm/madvise.c:1043
 madvise_walk_vmas+0x1d5/0x2d0 mm/madvise.c:1207
 do_madvise mm/madvise.c:1385 [inline]
 do_madvise+0x249/0x3c0 mm/madvise.c:1343
 __do_sys_madvise mm/madvise.c:1398 [inline]
 __se_sys_madvise mm/madvise.c:1396 [inline]
 __x64_sys_madvise+0xa6/0x110 mm/madvise.c:1396
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f28f5af2ff9
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 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:00007ffd839620d8 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f28f5af2ff9
RDX: 000000000000000b RSI: 0000000000001000 RDI: 0000000020ffc000
RBP: 00007f28f5ab6fe0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020000000 R11: 0000000000000246 R12: 00007f28f5ab7070
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 3588:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:436 [inline]
 ____kasan_kmalloc mm/kasan/common.c:515 [inline]
 ____kasan_kmalloc mm/kasan/common.c:474 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:524
 kmalloc include/linux/slab.h:586 [inline]
 anon_vma_name_alloc mm/madvise.c:75 [inline]
 replace_vma_anon_name mm/madvise.c:146 [inline]
 madvise_update_vma+0x546/0x7f0 mm/madvise.c:212
 madvise_vma_anon_name+0x7c/0xc0 mm/madvise.c:1236
 madvise_walk_vmas+0x1d5/0x2d0 mm/madvise.c:1207
 madvise_set_anon_name+0xac/0xe0 mm/madvise.c:1269
 prctl_set_vma kernel/sys.c:2305 [inline]
 __do_sys_prctl+0xeb5/0x12d0 kernel/sys.c:2594
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Freed by task 3588:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free+0x130/0x160 mm/kasan/common.c:328
 kasan_slab_free include/linux/kasan.h:236 [inline]
 slab_free_hook mm/slub.c:1728 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1754
 slab_free mm/slub.c:3509 [inline]
 kfree+0xcb/0x280 mm/slub.c:4562
 vma_anon_name_free mm/madvise.c:88 [inline]
 kref_put include/linux/kref.h:65 [inline]
 free_vma_anon_name mm/madvise.c:125 [inline]
 free_vma_anon_name+0xeb/0x110 mm/madvise.c:116
 vm_area_free+0x11/0x30 kernel/fork.c:376
 __vma_adjust+0x836/0x24a0 mm/mmap.c:962
 vma_merge+0x860/0xeb0 mm/mmap.c:1217
 madvise_update_vma+0x1b6/0x7f0 mm/madvise.c:180
 madvise_vma_behavior+0x116/0x1910 mm/madvise.c:1043
 madvise_walk_vmas+0x1d5/0x2d0 mm/madvise.c:1207
 do_madvise mm/madvise.c:1385 [inline]
 do_madvise+0x249/0x3c0 mm/madvise.c:1343
 __do_sys_madvise mm/madvise.c:1398 [inline]
 __se_sys_madvise mm/madvise.c:1396 [inline]
 __x64_sys_madvise+0xa6/0x110 mm/madvise.c:1396
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

The buggy address belongs to the object at ffff88807f0711c0
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 4 bytes inside of
 32-byte region [ffff88807f0711c0, ffff88807f0711e0)
The buggy address belongs to the page:
page:ffffea0001fc1c40 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7f071
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000001 ffff888010c41500
raw: 0000000000000000 0000000080400040 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 0x12c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY), pid 2962, ts 21704624424, free_ts 19381656493
 prep_new_page mm/page_alloc.c:2434 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4165
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5389
 alloc_pages+0x1aa/0x310 mm/mempolicy.c:2271
 alloc_slab_page mm/slub.c:1799 [inline]
 allocate_slab mm/slub.c:1944 [inline]
 new_slab+0x28a/0x3b0 mm/slub.c:2004
 ___slab_alloc+0x87c/0xe90 mm/slub.c:3018
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3105
 slab_alloc_node mm/slub.c:3196 [inline]
 slab_alloc mm/slub.c:3238 [inline]
 __kmalloc+0x2fb/0x340 mm/slub.c:4420
 kmalloc include/linux/slab.h:586 [inline]
 kzalloc include/linux/slab.h:715 [inline]
 tomoyo_encode2.part.0+0xe9/0x3a0 security/tomoyo/realpath.c:45
 tomoyo_encode2 security/tomoyo/realpath.c:31 [inline]
 tomoyo_encode+0x28/0x50 security/tomoyo/realpath.c:80
 tomoyo_realpath_from_path+0x186/0x620 security/tomoyo/realpath.c:288
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_check_open_permission+0x272/0x380 security/tomoyo/file.c:771
 tomoyo_file_open security/tomoyo/tomoyo.c:311 [inline]
 tomoyo_file_open+0xa3/0xd0 security/tomoyo/tomoyo.c:306
 security_file_open+0x45/0xb0 security/security.c:1638
 do_dentry_open+0x358/0x1240 fs/open.c:811
 do_open fs/namei.c:3476 [inline]
 path_openat+0x1c9e/0x2940 fs/namei.c:3609
 do_filp_open+0x1aa/0x400 fs/namei.c:3636
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1352 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1404
 free_unref_page_prepare mm/page_alloc.c:3325 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3404
 __vunmap+0x798/0xc50 mm/vmalloc.c:2635
 free_work+0x58/0x70 mm/vmalloc.c:97
 process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
 worker_thread+0x657/0x1110 kernel/workqueue.c:2454
 kthread+0x2e9/0x3a0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Memory state around the buggy address:
 ffff88807f071080: fa fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88807f071100: fa fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
>ffff88807f071180: fb fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
                                           ^
 ffff88807f071200: fb fb fb fb fc fc fc fc 00 00 06 fc fc fc fc fc
 ffff88807f071280: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
==================================================================

Crashes (38):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce 2022/02/07 22:31 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/07 22:10 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/07 21:49 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/07 21:29 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/07 21:08 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-selinux-root 2022/02/07 20:41 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/07 20:39 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/07 20:39 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-qemu-upstream 2022/02/07 20:37 upstream dfd42facf1e4 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-linux-next-kasan-gce-root 2022/02/07 20:42 linux-next ef6b35306dd8 a7dab638 .config log report syz C KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-selinux-root 2022/02/25 08:38 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-qemu-upstream 2022/02/25 08:32 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/25 08:32 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/25 08:31 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/25 08:28 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/17 07:59 upstream 359303076163 2bea8a27 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/14 07:10 upstream 42964a18f81c 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-selinux-root 2022/02/12 20:31 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-selinux-root 2022/02/12 20:30 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/12 20:28 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/12 20:28 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/12 20:28 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/12 20:27 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/12 20:25 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/12 20:19 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce 2022/02/07 20:38 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-qemu-upstream 2022/02/07 20:31 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-selinux-root 2022/02/07 20:30 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-root 2022/02/07 20:29 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-smack-root 2022/02/07 20:28 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-386 2022/02/25 08:34 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-qemu-upstream-386 2022/02/25 08:33 upstream 73878e5eb1bd 7c337266 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-386 2022/02/12 20:31 upstream 83e396641110 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-kasan-gce-386 2022/02/07 20:40 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-qemu-upstream-386 2022/02/07 20:32 upstream dfd42facf1e4 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-linux-next-kasan-gce-root 2022/02/12 20:31 linux-next ef6b35306dd8 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-linux-next-kasan-gce-root 2022/02/12 20:31 linux-next ef6b35306dd8 8b9ca619 .config log report info KASAN: use-after-free Read in madvise_update_vma
ci-upstream-linux-next-kasan-gce-root 2022/02/07 20:30 linux-next ef6b35306dd8 a7dab638 .config log report info KASAN: use-after-free Read in madvise_update_vma