syzbot


KASAN: invalid-free in io_commit_cqring

Status: fixed on 2021/11/04 08:35
Reported-by: syzbot+59d8a1f4e60c20c066cf@syzkaller.appspotmail.com
Fix commit: 3f2c12ec8a3f io_uring: don't take uring_lock during iowq cancel
First crash: 1126d, last: 1115d
Cause bisection: failed (error log, bisect log)
  
Discussions (3)
Title Replies (including bot) Last reply
[PATCH 5.10 00/77] 5.10.77-rc1 review 99 (99) 2021/11/12 22:56
[PATCH v5.10.y 1/1] io_uring: don't take uring_lock during iowq cancel 2 (2) 2021/10/27 16:11
[PATCH 5.10 1/1] io_uring: fix double free in the deferred/cancelled path 9 (9) 2021/10/27 14:42

Sample crash report:
==================================================================
BUG: KASAN: double-free or invalid-free in slab_free mm/slub.c:3204 [inline]
BUG: KASAN: double-free or invalid-free in kfree+0xd5/0x320 mm/slub.c:4192

CPU: 0 PID: 455 Comm: syz-executor934 Not tainted 5.10.76-syzkaller-01178-g4944ec82ebb9 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
 print_address_description+0x8d/0x3d0 mm/kasan/report.c:233
 kasan_report_invalid_free+0x58/0x130 mm/kasan/report.c:358
 ____kasan_slab_free+0x14b/0x170 mm/kasan/common.c:362
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:1596 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1622
 slab_free mm/slub.c:3204 [inline]
 kfree+0xd5/0x320 mm/slub.c:4192
 __io_queue_deferred fs/io_uring.c:1541 [inline]
 io_commit_cqring+0x76a/0xa00 fs/io_uring.c:1587
 io_iopoll_complete fs/io_uring.c:2378 [inline]
 io_do_iopoll+0x1e18/0x23f0 fs/io_uring.c:2431
 io_iopoll_try_reap_events+0x116/0x290 fs/io_uring.c:2470
 io_ring_ctx_wait_and_kill+0x295/0x670 fs/io_uring.c:8575
 io_uring_release+0x5b/0x70 fs/io_uring.c:8602
 __fput+0x348/0x7d0 fs/file_table.c:281
 ____fput+0x15/0x20 fs/file_table.c:314
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 exit_task_work include/linux/task_work.h:30 [inline]
 do_exit+0x70e/0x23a0 kernel/exit.c:813
 do_group_exit+0x16a/0x2d0 kernel/exit.c:910
 __do_sys_exit_group+0x17/0x20 kernel/exit.c:921
 __se_sys_exit_group+0x14/0x20 kernel/exit.c:919
 __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:919
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f992802de29
Code: Unable to access opcode bytes at RIP 0x7f992802ddff.
RSP: 002b:00007ffc72469aa8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 00007f99280a2350 RCX: 00007f992802de29
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
RBP: 0000000000000000 R08: ffffffffffffffc0 R09: 000000000000005e
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f99280a2350
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001

Allocated by task 455:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:428 [inline]
 ____kasan_kmalloc+0xdc/0x110 mm/kasan/common.c:507
 __kasan_kmalloc+0x9/0x10 mm/kasan/common.c:516
 kasan_kmalloc include/linux/kasan.h:269 [inline]
 kmem_cache_alloc_trace+0x210/0x3a0 mm/slub.c:2975
 kmalloc include/linux/slab.h:552 [inline]
 io_req_defer+0x40e/0x11b0 fs/io_uring.c:5921
 io_queue_sqe+0x2a/0x1180 fs/io_uring.c:6397
 io_submit_sqe+0x385/0xfd0 fs/io_uring.c:6487
 io_submit_sqes+0x1050/0x2da0 fs/io_uring.c:6715
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052
 __x64_sys_io_uring_enter+0xe5/0x100 fs/io_uring.c:9052
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 456:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4c/0x80 mm/kasan/common.c:46
 kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:357
 ____kasan_slab_free+0x133/0x170 mm/kasan/common.c:360
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:1596 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1622
 slab_free mm/slub.c:3204 [inline]
 kfree+0xd5/0x320 mm/slub.c:4192
 __io_queue_deferred fs/io_uring.c:1541 [inline]
 io_commit_cqring+0x76a/0xa00 fs/io_uring.c:1587
 __io_req_task_cancel+0x64/0x720 fs/io_uring.c:2065
 io_req_task_cancel+0x51/0x130 fs/io_uring.c:2078
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

The buggy address belongs to the object at ffff88810c636a00
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
 32-byte region [ffff88810c636a00, ffff88810c636a20)
The buggy address belongs to the page:
page:ffffea0004318d80 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10c636
flags: 0x8000000000000200(slab)
raw: 8000000000000200 dead000000000100 dead000000000122 ffff888100043980
raw: 0000000000000000 0000000000400040 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 455, ts 27656068447, free_ts 27650333165
 set_page_owner include/linux/page_owner.h:35 [inline]
 post_alloc_hook mm/page_alloc.c:2385 [inline]
 prep_new_page mm/page_alloc.c:2391 [inline]
 get_page_from_freelist+0xa74/0xa90 mm/page_alloc.c:4063
 __alloc_pages_nodemask+0x3c8/0x820 mm/page_alloc.c:5106
 alloc_slab_page mm/slub.c:1807 [inline]
 allocate_slab+0x6b/0x350 mm/slub.c:1809
 new_slab mm/slub.c:1870 [inline]
 new_slab_objects mm/slub.c:2629 [inline]
 ___slab_alloc+0x143/0x2f0 mm/slub.c:2792
 __slab_alloc mm/slub.c:2832 [inline]
 slab_alloc_node mm/slub.c:2914 [inline]
 slab_alloc mm/slub.c:2956 [inline]
 kmem_cache_alloc_trace+0x278/0x3a0 mm/slub.c:2973
 kmalloc include/linux/slab.h:552 [inline]
 io_req_defer+0x40e/0x11b0 fs/io_uring.c:5921
 io_queue_sqe+0x2a/0x1180 fs/io_uring.c:6397
 io_submit_sqe+0x385/0xfd0 fs/io_uring.c:6487
 io_submit_sqes+0x1050/0x2da0 fs/io_uring.c:6715
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052
 __x64_sys_io_uring_enter+0xe5/0x100 fs/io_uring.c:9052
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:28 [inline]
 free_pages_prepare mm/page_alloc.c:1331 [inline]
 __free_pages_ok+0xbe7/0xc20 mm/page_alloc.c:1611
 free_the_page mm/page_alloc.c:5167 [inline]
 __free_pages+0x2d6/0x4a0 mm/page_alloc.c:5173
 __free_slab+0xdf/0x1a0 mm/slub.c:1895
 free_slab mm/slub.c:1910 [inline]
 discard_slab mm/slub.c:1916 [inline]
 unfreeze_partials+0x17d/0x1b0 mm/slub.c:2410
 put_cpu_partial+0xc8/0x190 mm/slub.c:2446
 __slab_free+0x2eb/0x4e0 mm/slub.c:3096
 do_slab_free mm/slub.c:3192 [inline]
 ___cache_free+0x131/0x150 mm/slub.c:3211
 qlink_free+0x38/0x40 mm/kasan/quarantine.c:146
 qlist_free_all mm/kasan/quarantine.c:165 [inline]
 kasan_quarantine_reduce+0x178/0x1d0 mm/kasan/quarantine.c:272
 __kasan_slab_alloc+0x2f/0xe0 mm/kasan/common.c:438
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:583 [inline]
 slab_alloc_node mm/slub.c:2948 [inline]
 slab_alloc mm/slub.c:2956 [inline]
 kmem_cache_alloc_trace+0x1a5/0x3a0 mm/slub.c:2973
 kmalloc include/linux/slab.h:552 [inline]
 io_req_defer+0x40e/0x11b0 fs/io_uring.c:5921
 io_queue_sqe+0x2a/0x1180 fs/io_uring.c:6397
 io_submit_sqe+0x385/0xfd0 fs/io_uring.c:6487
 io_submit_sqes+0x1050/0x2da0 fs/io_uring.c:6715
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052

Memory state around the buggy address:
 ffff88810c636900: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
 ffff88810c636980: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
>ffff88810c636a00: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
                   ^
 ffff88810c636a80: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
 ffff88810c636b00: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/11/01 17:01 android12-5.10-lts 4944ec82ebb9 098b5d53 .config console log report syz C ci2-android-5-10 KASAN: invalid-free in io_commit_cqring
2021/10/23 23:54 android12-5.10-lts 234d53d2bb60 282f03fb .config console log report syz C ci2-android-5-10 KASAN: invalid-free in io_commit_cqring
2021/11/03 13:33 android12-5.10-lts 4944ec82ebb9 17f3edd2 .config console log report info ci2-android-5-10 KASAN: invalid-free in io_commit_cqring
* Struck through repros no longer work on HEAD.