syzbot


KASAN: use-after-free Read in handle_userfault (4)

Status: auto-closed as invalid on 2022/08/15 08:51
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+2972481db16665f2cb84@syzkaller.appspotmail.com
First crash: 713d, last: 678d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] KASAN: use-after-free Read in handle_userfault (4) 0 (1) 2022/05/16 10:57
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in handle_userfault (3) fs 1 1899d 1899d 0/26 closed as invalid on 2019/02/12 06:42
upstream KASAN: use-after-free Read in handle_userfault (2) fs 1 1960d 1960d 0/26 closed as dup on 2019/01/07 09:45
upstream KASAN: use-after-free Read in handle_userfault fs C 151 2308d 2371d 3/26 fixed on 2018/01/10 09:03

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in handle_userfault+0x1342/0x1530 fs/userfaultfd.c:408
Read of size 8 at addr ffff88801f478190 by task syz-executor.0/20829

CPU: 0 PID: 20829 Comm: syz-executor.0 Not tainted 5.19.0-rc2-next-20220615-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+0xeb/0x495 mm/kasan/report.c:313
 print_report mm/kasan/report.c:429 [inline]
 kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
 handle_userfault+0x1342/0x1530 fs/userfaultfd.c:408
 shmem_getpage_gfp+0x1ab6/0x1f30 mm/shmem.c:1896
 shmem_fault+0x1ae/0x750 mm/shmem.c:2115
 __do_fault+0x107/0x650 mm/memory.c:4188
 do_read_fault mm/memory.c:4534 [inline]
 do_fault mm/memory.c:4663 [inline]
 handle_pte_fault mm/memory.c:4926 [inline]
 __handle_mm_fault+0x291b/0x4110 mm/memory.c:5065
 handle_mm_fault+0x1c8/0x790 mm/memory.c:5163
 do_user_addr_fault+0x489/0x1250 arch/x86/mm/fault.c:1397
 handle_page_fault arch/x86/mm/fault.c:1488 [inline]
 exc_page_fault+0x9e/0x180 arch/x86/mm/fault.c:1544
 asm_exc_page_fault+0x27/0x30 arch/x86/include/asm/idtentry.h:570
RIP: 0033:0x7f571ca27c93
Code: 00 00 00 00 00 66 90 48 89 7c 24 f0 48 89 74 24 e8 48 89 54 24 e0 48 89 4c 24 d8 48 8b 4c 24 f0 48 8b 74 24 e8 4c 8b 44 24 e0 <8b> 81 0c 01 00 00 44 8b 89 08 01 00 00 48 8b 54 24 d8 c1 e0 04 8d
RSP: 002b:00007f571dcb6158 EFLAGS: 00010216
RAX: 00007f571ca27c70 RBX: 00007f571cb9bf60 RCX: 0000000020883000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020883000
RBP: 00007f571cae305d R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020883000 R11: 0000000000000000 R12: 0000000000000000
R13: 00007fff35db2f2f R14: 00007f571dcb6300 R15: 0000000000022000
 </TASK>

Allocated by task 20829:
 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_slab_alloc+0x90/0xc0 mm/kasan/common.c:469
 kasan_slab_alloc include/linux/kasan.h:224 [inline]
 slab_post_alloc_hook mm/slab.h:750 [inline]
 slab_alloc_node mm/slub.c:3243 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3258 [inline]
 kmem_cache_alloc+0x142/0x3b0 mm/slub.c:3268
 new_userfaultfd+0xb0/0x3e0 fs/userfaultfd.c:2108
 __do_sys_userfaultfd fs/userfaultfd.c:2136 [inline]
 __se_sys_userfaultfd fs/userfaultfd.c:2134 [inline]
 __x64_sys_userfaultfd+0x32/0x40 fs/userfaultfd.c:2134
 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+0x46/0xb0

Freed by task 20828:
 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+0x166/0x1a0 mm/kasan/common.c:328
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3536 [inline]
 kmem_cache_free+0xdd/0x5a0 mm/slub.c:3553
 userfaultfd_ctx_put fs/userfaultfd.c:181 [inline]
 userfaultfd_ctx_put+0x312/0x400 fs/userfaultfd.c:169
 userfaultfd_release+0x399/0x670 fs/userfaultfd.c:913
 __fput+0x277/0x9d0 fs/file_table.c:317
 task_work_run+0xdd/0x1a0 kernel/task_work.c:177
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:169 [inline]
 exit_to_user_mode_prepare+0x23c/0x250 kernel/entry/common.c:201
 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
 syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x46/0xb0

The buggy address belongs to the object at ffff88801f478000
 which belongs to the cache userfaultfd_ctx_cache of size 408
The buggy address is located 400 bytes inside of
 408-byte region [ffff88801f478000, ffff88801f478198)

The buggy address belongs to the physical page:
page:ffffea00007d1e00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1f478
head:ffffea00007d1e00 order:1 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 0000000000000000 dead000000000122 ffff888018695640
raw: 0000000000000000 0000000080100010 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 20829, tgid 20828 (syz-executor.0), ts 1496271911196, free_ts 1496145760837
 prep_new_page mm/page_alloc.c:2525 [inline]
 get_page_from_freelist+0x1efe/0x3a20 mm/page_alloc.c:4296
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5512
 alloc_pages+0x1aa/0x310 mm/mempolicy.c:2279
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x26c/0x3c0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x9c4/0xe20 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3258 [inline]
 kmem_cache_alloc+0x360/0x3b0 mm/slub.c:3268
 new_userfaultfd+0xb0/0x3e0 fs/userfaultfd.c:2108
 __do_sys_userfaultfd fs/userfaultfd.c:2136 [inline]
 __se_sys_userfaultfd fs/userfaultfd.c:2134 [inline]
 __x64_sys_userfaultfd+0x32/0x40 fs/userfaultfd.c:2134
 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+0x46/0xb0
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1443 [inline]
 free_pcp_prepare+0x549/0xd20 mm/page_alloc.c:1493
 free_unref_page_prepare mm/page_alloc.c:3373 [inline]
 free_unref_page+0x19/0x560 mm/page_alloc.c:3470
 qlink_free mm/kasan/quarantine.c:168 [inline]
 qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:294
 __kasan_slab_alloc+0xa2/0xc0 mm/kasan/common.c:446
 kasan_slab_alloc include/linux/kasan.h:224 [inline]
 slab_post_alloc_hook mm/slab.h:750 [inline]
 slab_alloc_node mm/slub.c:3243 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmalloc+0x200/0x350 mm/slub.c:4442
 kmalloc include/linux/slab.h:605 [inline]
 tomoyo_realpath_from_path+0xc3/0x620 security/tomoyo/realpath.c:254
 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:320 [inline]
 tomoyo_file_open+0x9d/0xc0 security/tomoyo/tomoyo.c:315
 security_file_open+0x45/0xb0 security/security.c:1645
 do_dentry_open+0x349/0x11f0 fs/open.c:835
 do_open fs/namei.c:3520 [inline]
 path_openat+0x1c71/0x2910 fs/namei.c:3653
 do_filp_open+0x1aa/0x400 fs/namei.c:3680
 do_sys_openat2+0x16d/0x4c0 fs/open.c:1278
 do_sys_open fs/open.c:1294 [inline]
 __do_sys_openat fs/open.c:1310 [inline]
 __se_sys_openat fs/open.c:1305 [inline]
 __x64_sys_openat+0x13f/0x1f0 fs/open.c:1305
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80

Memory state around the buggy address:
 ffff88801f478080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88801f478100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88801f478180: fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc fc
                         ^
 ffff88801f478200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88801f478280: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================

Crashes (14):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/06/16 08:50 linux-next 6012273897fe 1719ee24 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/06/13 05:57 linux-next 6d0c80680317 0d5abf15 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/06/13 05:57 linux-next 6d0c80680317 0d5abf15 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/06/11 20:53 linux-next 6d0c80680317 0d5abf15 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/06/03 18:17 linux-next 1cfd968b58a1 eee80d3c .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/06/03 15:48 linux-next 1cfd968b58a1 eee80d3c .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/19 17:41 linux-next 3f7bdc402fb0 50c53f39 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/13 13:53 linux-next 1e1b28b936ae 107f6434 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/13 11:45 linux-next 1e1b28b936ae 107f6434 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/12 17:15 linux-next 187b9ac8c348 9ad6612a .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/12 17:15 linux-next 187b9ac8c348 9ad6612a .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/12 13:32 linux-next 187b9ac8c348 9ad6612a .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/12 13:02 linux-next 187b9ac8c348 beb0b407 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
2022/05/12 10:48 linux-next 187b9ac8c348 beb0b407 .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in handle_userfault
* Struck through repros no longer work on HEAD.