syzbot


KASAN: use-after-free Write in io_submit_one

Status: fixed on 2022/03/08 16:11
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+3587cbbc6e1868796292@syzkaller.appspotmail.com
Fix commit: 75feae73a280 block: fix single bio async DIO error handling
First crash: 1136d, last: 1096d
Cause bisection: introduced by (bisect log) :
commit 54a88eb838d37af930c9f19e1930a4fba6789cb5
Author: Pavel Begunkov <asml.silence@gmail.com>
Date: Sat Oct 23 16:21:32 2021 +0000

  block: add single bio async direct IO helper

Crash: KASAN: use-after-free Write in io_submit_one (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] KASAN: use-after-free Write in io_submit_one 1 (4) 2021/12/08 18:14

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
BUG: KASAN: use-after-free in atomic_fetch_sub_release include/linux/atomic/atomic-instrumented.h:167 [inline]
BUG: KASAN: use-after-free in __refcount_sub_and_test include/linux/refcount.h:272 [inline]
BUG: KASAN: use-after-free in __refcount_dec_and_test include/linux/refcount.h:315 [inline]
BUG: KASAN: use-after-free in refcount_dec_and_test include/linux/refcount.h:333 [inline]
BUG: KASAN: use-after-free in iocb_put fs/aio.c:1162 [inline]
BUG: KASAN: use-after-free in io_submit_one+0x6fb/0x1c70 fs/aio.c:2000
Write of size 4 at addr ffff8880186720c8 by task syz-executor789/3602

CPU: 0 PID: 3602 Comm: syz-executor789 Not tainted 5.16.0-rc4-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/0x320 mm/kasan/report.c:247
 __kasan_report mm/kasan/report.c:433 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:450
 check_region_inline mm/kasan/generic.c:183 [inline]
 kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
 instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
 atomic_fetch_sub_release include/linux/atomic/atomic-instrumented.h:167 [inline]
 __refcount_sub_and_test include/linux/refcount.h:272 [inline]
 __refcount_dec_and_test include/linux/refcount.h:315 [inline]
 refcount_dec_and_test include/linux/refcount.h:333 [inline]
 iocb_put fs/aio.c:1162 [inline]
 io_submit_one+0x6fb/0x1c70 fs/aio.c:2000
 __do_sys_io_submit fs/aio.c:2056 [inline]
 __se_sys_io_submit fs/aio.c:2026 [inline]
 __x64_sys_io_submit+0x18c/0x330 fs/aio.c:2026
 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:0x7f1ef62dde89
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 b1 14 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 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fffd6590348 EFLAGS: 00000246 ORIG_RAX: 00000000000000d1
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f1ef62dde89
RDX: 0000000020000800 RSI: 0000000000000002 RDI: 00007f1ef6295000
RBP: 0000000000000000 R08: 00007fffd65904e8 R09: 00007fffd65904e8
R10: 00007fffd65904e8 R11: 0000000000000246 R12: 00007f1ef62a1710
R13: 431bde82d7b634db R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 3602:
 kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:434 [inline]
 __kasan_slab_alloc+0x90/0xc0 mm/kasan/common.c:467
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:519 [inline]
 slab_alloc_node mm/slub.c:3234 [inline]
 slab_alloc mm/slub.c:3242 [inline]
 kmem_cache_alloc+0x202/0x3a0 mm/slub.c:3247
 aio_get_req fs/aio.c:1029 [inline]
 io_submit_one+0xfd/0x1c70 fs/aio.c:1993
 __do_sys_io_submit fs/aio.c:2056 [inline]
 __se_sys_io_submit fs/aio.c:2026 [inline]
 __x64_sys_io_submit+0x18c/0x330 fs/aio.c:2026
 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 3602:
 kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:46
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free mm/kasan/common.c:328 [inline]
 __kasan_slab_free+0xff/0x130 mm/kasan/common.c:374
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:1723 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1749
 slab_free mm/slub.c:3513 [inline]
 kmem_cache_free+0xbd/0x5d0 mm/slub.c:3530
 iocb_destroy fs/aio.c:1081 [inline]
 iocb_put fs/aio.c:1164 [inline]
 iocb_put fs/aio.c:1160 [inline]
 aio_complete_rw+0x474/0x8c0 fs/aio.c:1441
 aio_rw_done fs/aio.c:1511 [inline]
 aio_read+0x30d/0x460 fs/aio.c:1538
 __io_submit_one fs/aio.c:1948 [inline]
 io_submit_one+0xfbe/0x1c70 fs/aio.c:1997
 __do_sys_io_submit fs/aio.c:2056 [inline]
 __se_sys_io_submit fs/aio.c:2026 [inline]
 __x64_sys_io_submit+0x18c/0x330 fs/aio.c:2026
 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 ffff888018672000
 which belongs to the cache aio_kiocb of size 216
The buggy address is located 200 bytes inside of
 216-byte region [ffff888018672000, ffff8880186720d8)
The buggy address belongs to the page:
page:ffffea0000619c80 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x18672
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000122 ffff88814663b8c0
raw: 0000000000000000 00000000800c000c 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 3602, ts 67267165484, free_ts 16951029362
 prep_new_page mm/page_alloc.c:2418 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4149
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5369
 alloc_pages+0x1a7/0x300 mm/mempolicy.c:2191
 alloc_slab_page mm/slub.c:1793 [inline]
 allocate_slab mm/slub.c:1930 [inline]
 new_slab+0x32d/0x4a0 mm/slub.c:1993
 ___slab_alloc+0x918/0xfe0 mm/slub.c:3022
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3109
 slab_alloc_node mm/slub.c:3200 [inline]
 slab_alloc mm/slub.c:3242 [inline]
 kmem_cache_alloc+0x35c/0x3a0 mm/slub.c:3247
 aio_get_req fs/aio.c:1029 [inline]
 io_submit_one+0xfd/0x1c70 fs/aio.c:1993
 __do_sys_io_submit fs/aio.c:2056 [inline]
 __se_sys_io_submit fs/aio.c:2026 [inline]
 __x64_sys_io_submit+0x18c/0x330 fs/aio.c:2026
 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
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1338 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1389
 free_unref_page_prepare mm/page_alloc.c:3309 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3388
 kasan_depopulate_vmalloc_pte+0x5c/0x70 mm/kasan/shadow.c:380
 apply_to_pte_range mm/memory.c:2518 [inline]
 apply_to_pmd_range mm/memory.c:2562 [inline]
 apply_to_pud_range mm/memory.c:2598 [inline]
 apply_to_p4d_range mm/memory.c:2634 [inline]
 __apply_to_page_range+0x694/0x1080 mm/memory.c:2668
 kasan_release_vmalloc+0xa7/0xc0 mm/kasan/shadow.c:490
 __purge_vmap_area_lazy+0x8f9/0x1c50 mm/vmalloc.c:1708
 _vm_unmap_aliases.part.0+0x3f0/0x500 mm/vmalloc.c:2111
 _vm_unmap_aliases mm/vmalloc.c:2085 [inline]
 vm_unmap_aliases+0x45/0x50 mm/vmalloc.c:2134
 change_page_attr_set_clr+0x241/0x500 arch/x86/mm/pat/set_memory.c:1743
 change_page_attr_set arch/x86/mm/pat/set_memory.c:1793 [inline]
 set_memory_nx+0xb2/0x110 arch/x86/mm/pat/set_memory.c:1941
 free_init_pages+0x73/0xc0 arch/x86/mm/init.c:894
 kernel_init+0x2e/0x1d0 init/main.c:1508
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Memory state around the buggy address:
 ffff888018671f80: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888018672000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888018672080: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
                                              ^
 ffff888018672100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888018672180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================

Crashes (11):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/12/11 15:24 upstream 6f513529296f 49ca1f59 .config console log report syz C ci-upstream-kasan-gce KASAN: use-after-free Write in io_submit_one
2021/12/07 18:48 linux-next 04fe99a8d936 0230ba3e .config console log report syz C ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Write in io_submit_one
2021/11/24 08:49 upstream 5d9f4cf36721 545ab074 .config console log report info ci-qemu-upstream KASAN: use-after-free Write in io_submit_one
2021/11/05 08:51 upstream d4439a1189f9 4c1be0be .config console log report info ci-upstream-kasan-gce KASAN: use-after-free Write in io_submit_one
2021/11/03 04:44 upstream cc0356d6a02e 17f3edd2 .config console log report info ci-upstream-kasan-gce-root KASAN: use-after-free Write in io_submit_one
2021/11/02 00:10 upstream e66435936756 098b5d53 .config console log report info ci-upstream-kasan-gce KASAN: use-after-free Write in io_submit_one
2021/11/02 02:24 upstream e66435936756 098b5d53 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Write in io_submit_one
2021/11/02 02:01 upstream e66435936756 098b5d53 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Write in io_submit_one
2021/11/01 23:19 upstream e66435936756 098b5d53 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Write in io_submit_one
2021/11/01 22:59 upstream e66435936756 098b5d53 .config console log report info ci-qemu-upstream-386 KASAN: use-after-free Write in io_submit_one
2021/12/07 15:47 linux-next 04fe99a8d936 0230ba3e .config console log report info ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Write in io_submit_one
* Struck through repros no longer work on HEAD.