syzbot


KASAN: use-after-free Read in io_rsrc_node_ref_zero

Status: upstream: reported C repro on 2022/02/21 22:17
Reported-by: syzbot+ca8bf833622a1662745b@syzkaller.appspotmail.com
Fix commit: 80912cef18f1 io_uring: disallow modification of rsrc_data during quiesce
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: 127d, last: 127d

Cause bisection: introduced by (bisect log) :
commit b36a2050040b2d839bdc044007cdd57101d7f881
Author: Dylan Yudaken <dylany@fb.com>
Date: Fri Jan 21 12:38:56 2022 +0000

  io_uring: fix bug in slow unregistering of nodes

Crash: WARNING in io_ring_exit_work (log)
Repro: C syz .config

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in io_rsrc_node_ref_zero+0x5a/0x274 fs/io_uring.c:7821
Read of size 8 at addr ffff888013de6900 by task ksoftirqd/1/19

CPU: 1 PID: 19 Comm: ksoftirqd/1 Not tainted 5.17.0-rc4-syzkaller-00241-g7f25f0412c9e #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
 io_rsrc_node_ref_zero+0x5a/0x274 fs/io_uring.c:7821
 percpu_ref_put_many.constprop.0+0x22b/0x260 include/linux/percpu-refcount.h:335
 rcu_do_batch kernel/rcu/tree.c:2527 [inline]
 rcu_core+0x7b1/0x1820 kernel/rcu/tree.c:2778
 __do_softirq+0x29b/0x9c2 kernel/softirq.c:558
 run_ksoftirqd kernel/softirq.c:921 [inline]
 run_ksoftirqd+0x2d/0x60 kernel/softirq.c:913
 smpboot_thread_fn+0x645/0x9c0 kernel/smpboot.c:164
 kthread+0x2e9/0x3a0 kernel/kthread.c:377
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
 </TASK>

Allocated by task 4252:
 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
 io_rsrc_data_alloc+0x40/0x3b8 fs/io_uring.c:7968
 io_sqe_buffers_register.cold+0x1f/0x443 fs/io_uring.c:9255
 __io_uring_register fs/io_uring.c:11039 [inline]
 __do_sys_io_uring_register+0x109b/0x15a0 fs/io_uring.c:11170
 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 4252:
 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+0x126/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+0xd0/0x390 mm/slub.c:4562
 __io_sqe_buffers_unregister+0xf6/0x18d fs/io_uring.c:8997
 io_sqe_buffers_unregister fs/io_uring.c:9012 [inline]
 __io_uring_register fs/io_uring.c:11045 [inline]
 __do_sys_io_uring_register.cold+0x28f/0x1611 fs/io_uring.c:11170
 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 ffff888013de6900
 which belongs to the cache kmalloc-192 of size 192
The buggy address is located 0 bytes inside of
 192-byte region [ffff888013de6900, ffff888013de69c0)
The buggy address belongs to the page:
page:ffffea00004f7980 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x13de6
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 0000000000000000 dead000000000001 ffff888010c41a00
raw: 0000000000000000 0000000080100010 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 1, ts 2185796206, free_ts 0
 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_page_interleave+0x1e/0x200 mm/mempolicy.c:2116
 alloc_pages+0x2b1/0x310 mm/mempolicy.c:2266
 alloc_slab_page mm/slub.c:1799 [inline]
 allocate_slab+0x27f/0x3c0 mm/slub.c:1944
 new_slab mm/slub.c:2004 [inline]
 ___slab_alloc+0xbe1/0x12b0 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]
 kmem_cache_alloc_trace+0x2f8/0x3d0 mm/slub.c:3255
 kmalloc include/linux/slab.h:581 [inline]
 kzalloc include/linux/slab.h:715 [inline]
 call_usermodehelper_setup+0x97/0x340 kernel/umh.c:365
 kobject_uevent_env+0xf28/0x1600 lib/kobject_uevent.c:614
 kernel_add_sysfs_param kernel/params.c:816 [inline]
 param_sysfs_builtin kernel/params.c:851 [inline]
 param_sysfs_init+0x367/0x43b kernel/params.c:970
 do_one_initcall+0x103/0x650 init/main.c:1300
 do_initcall_level init/main.c:1373 [inline]
 do_initcalls init/main.c:1389 [inline]
 do_basic_setup init/main.c:1408 [inline]
 kernel_init_freeable+0x6b1/0x73a init/main.c:1613
 kernel_init+0x1a/0x1d0 init/main.c:1502
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888013de6800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888013de6880: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888013de6900: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888013de6980: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
 ffff888013de6a00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (3):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce 2022/02/21 08:42 upstream 7f25f0412c9e 3cd800e4 .config log report syz C KASAN: use-after-free Read in io_rsrc_node_ref_zero
ci-upstream-kasan-gce-selinux-root 2022/02/21 08:15 upstream 7f25f0412c9e 3cd800e4 .config log report syz C KASAN: use-after-free Read in io_rsrc_node_ref_zero
ci-upstream-kasan-gce-selinux-root 2022/02/21 08:01 upstream 7f25f0412c9e 3cd800e4 .config log report info KASAN: use-after-free Read in io_rsrc_node_ref_zero