syzbot


KASAN: slab-use-after-free Read in thread_group_cputime

Status: upstream: reported on 2025/01/10 13:51
Subsystems: io-uring
[Documentation on labels]
Reported-by: syzbot+3d92cfcfa84070b0a470@syzkaller.appspotmail.com
Fix commit: 4b7cfa8b6c28 io_uring/sqpoll: zero sqd->thread on tctx errors
Patched on: [ci-qemu-gce-upstream-auto ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-snapshot-upstream-root ci-upstream-bpf-kasan-gce ci-upstream-gce-arm64 ci-upstream-gce-leak ci-upstream-kasan-badwrites-root 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-386-root ci-upstream-kmsan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-fs ci2-upstream-kcsan-gce ci2-upstream-usb], missing on: [ci-qemu-native-arm64-kvm ci-qemu2-arm32 ci-qemu2-riscv64 ci-upstream-bpf-next-kasan-gce ci-upstream-linux-next-kasan-gce-root]
First crash: 19d, last: 2d10h
Discussions (2)
Title Replies (including bot) Last reply
[PATCH 1/1] io_uring: sqpoll: zero sqd->thread on tctx errors 2 (2) 2025/01/10 14:34
[syzbot] [kernel?] KASAN: slab-use-after-free Read in thread_group_cputime 5 (6) 2025/01/10 14:32

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
Read of size 8 at addr ffff88807bef0910 by task syz.5.351/9717

CPU: 0 UID: 0 PID: 9717 Comm: syz.5.351 Not tainted 6.13.0-rc7-syzkaller-00189-g595523945be0 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:378 [inline]
 print_report+0x169/0x550 mm/kasan/report.c:489
 kasan_report+0x143/0x180 mm/kasan/report.c:602
 thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
 thread_group_cputime_adjusted+0xa6/0x340 kernel/sched/cputime.c:639
 getrusage+0x1000/0x1340 kernel/sys.c:1863
 io_uring_show_fdinfo+0xdfe/0x1770 io_uring/fdinfo.c:197
 seq_show+0x608/0x770 fs/proc/fd.c:68
 seq_read_iter+0x43f/0xd70 fs/seq_file.c:230
 seq_read+0x3a9/0x4f0 fs/seq_file.c:162
 vfs_read+0x1fc/0xb70 fs/read_write.c:563
 ksys_pread64 fs/read_write.c:756 [inline]
 __do_sys_pread64 fs/read_write.c:764 [inline]
 __se_sys_pread64 fs/read_write.c:761 [inline]
 __x64_sys_pread64+0x1ac/0x240 fs/read_write.c:761
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f33b2585d29
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f33b3344038 EFLAGS: 00000246 ORIG_RAX: 0000000000000011
RAX: ffffffffffffffda RBX: 00007f33b2776080 RCX: 00007f33b2585d29
RDX: 00000000000000ed RSI: 0000000020000080 RDI: 0000000000000004
RBP: 00007f33b2601b08 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f33b2776080 R15: 00007ffe73f87f18
 </TASK>

Allocated by task 9717:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 unpoison_slab_object mm/kasan/common.c:319 [inline]
 __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:345
 kasan_slab_alloc include/linux/kasan.h:250 [inline]
 slab_post_alloc_hook mm/slub.c:4119 [inline]
 slab_alloc_node mm/slub.c:4168 [inline]
 kmem_cache_alloc_node_noprof+0x1d9/0x380 mm/slub.c:4220
 alloc_task_struct_node kernel/fork.c:180 [inline]
 dup_task_struct+0x57/0x8c0 kernel/fork.c:1108
 copy_process+0x5d1/0x3d50 kernel/fork.c:2224
 create_io_thread+0x166/0x1d0 kernel/fork.c:2754
 io_sq_offload_create+0xa35/0x11b0 io_uring/sqpoll.c:481
 io_uring_create+0x68b/0xc00 io_uring/io_uring.c:3725
 io_uring_setup io_uring/io_uring.c:3807 [inline]
 __do_sys_io_uring_setup io_uring/io_uring.c:3834 [inline]
 __se_sys_io_uring_setup+0x2ba/0x330 io_uring/io_uring.c:3828
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 24:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:582
 poison_slab_object mm/kasan/common.c:247 [inline]
 __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264
 kasan_slab_free include/linux/kasan.h:233 [inline]
 slab_free_hook mm/slub.c:2353 [inline]
 slab_free mm/slub.c:4613 [inline]
 kmem_cache_free+0x195/0x410 mm/slub.c:4715
 put_task_struct include/linux/sched/task.h:144 [inline]
 delayed_put_task_struct+0x125/0x300 kernel/exit.c:227
 rcu_do_batch kernel/rcu/tree.c:2567 [inline]
 rcu_core+0xaaa/0x17a0 kernel/rcu/tree.c:2823
 handle_softirqs+0x2d4/0x9b0 kernel/softirq.c:561
 run_ksoftirqd+0xca/0x130 kernel/softirq.c:950
 smpboot_thread_fn+0x544/0xa30 kernel/smpboot.c:164
 kthread+0x2f0/0x390 kernel/kthread.c:389
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

Last potentially related work creation:
 kasan_save_stack+0x3f/0x60 mm/kasan/common.c:47
 __kasan_record_aux_stack+0xac/0xc0 mm/kasan/generic.c:544
 __call_rcu_common kernel/rcu/tree.c:3086 [inline]
 call_rcu+0x167/0xa70 kernel/rcu/tree.c:3190
 context_switch kernel/sched/core.c:5372 [inline]
 __schedule+0x1803/0x4be0 kernel/sched/core.c:6756
 preempt_schedule_irq+0xfb/0x1c0 kernel/sched/core.c:7078
 irqentry_exit+0x5e/0x90 kernel/entry/common.c:354
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702

The buggy address belongs to the object at ffff88807bef0000
 which belongs to the cache task_struct of size 7424
The buggy address is located 2320 bytes inside of
 freed 7424-byte region [ffff88807bef0000, ffff88807bef1d00)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7bef0
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
memcg:ffff88807a8daa01
anon flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801bafe500 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000040004 00000001f5000000 ffff88807a8daa01
head: 00fff00000000040 ffff88801bafe500 0000000000000000 dead000000000001
head: 0000000000000000 0000000000040004 00000001f5000000 ffff88807a8daa01
head: 00fff00000000003 ffffea0001efbc01 ffffffffffffffff 0000000000000000
head: 0000000000000008 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5488, tgid 5488 (dhcpcd), ts 53583332879, free_ts 52445382086
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1558
 prep_new_page mm/page_alloc.c:1566 [inline]
 get_page_from_freelist+0x3651/0x37a0 mm/page_alloc.c:3476
 __alloc_pages_noprof+0x292/0x710 mm/page_alloc.c:4753
 alloc_pages_mpol_noprof+0x3e1/0x780 mm/mempolicy.c:2269
 alloc_slab_page+0x6a/0x110 mm/slub.c:2423
 allocate_slab+0x5a/0x2b0 mm/slub.c:2589
 new_slab mm/slub.c:2642 [inline]
 ___slab_alloc+0xc27/0x14a0 mm/slub.c:3830
 __slab_alloc+0x58/0xa0 mm/slub.c:3920
 __slab_alloc_node mm/slub.c:3995 [inline]
 slab_alloc_node mm/slub.c:4156 [inline]
 kmem_cache_alloc_node_noprof+0x269/0x380 mm/slub.c:4220
 alloc_task_struct_node kernel/fork.c:180 [inline]
 dup_task_struct+0x57/0x8c0 kernel/fork.c:1108
 copy_process+0x5d1/0x3d50 kernel/fork.c:2224
 kernel_clone+0x223/0x870 kernel/fork.c:2806
 __do_sys_clone kernel/fork.c:2949 [inline]
 __se_sys_clone kernel/fork.c:2933 [inline]
 __x64_sys_clone+0x258/0x2a0 kernel/fork.c:2933
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 0 tgid 0 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1127 [inline]
 free_unref_page+0xd2c/0x1000 mm/page_alloc.c:2659
 __folio_put+0x2b3/0x360 mm/swap.c:112
 page_to_skb+0x3dd/0x9b0 drivers/net/virtio_net.c:914
 receive_mergeable drivers/net/virtio_net.c:2434 [inline]
 receive_buf+0x3ae/0x1850 drivers/net/virtio_net.c:2572
 virtnet_receive_packets drivers/net/virtio_net.c:2887 [inline]
 virtnet_receive drivers/net/virtio_net.c:2911 [inline]
 virtnet_poll+0x27aa/0x39b0 drivers/net/virtio_net.c:3006
 __napi_poll+0xcb/0x490 net/core/dev.c:6902
 napi_poll net/core/dev.c:6971 [inline]
 net_rx_action+0x89b/0x1240 net/core/dev.c:7093
 handle_softirqs+0x2d4/0x9b0 kernel/softirq.c:561
 __do_softirq kernel/softirq.c:595 [inline]
 invoke_softirq kernel/softirq.c:435 [inline]
 __irq_exit_rcu+0xf7/0x220 kernel/softirq.c:662
 irq_exit_rcu+0x9/0x30 kernel/softirq.c:678
 common_interrupt+0xb9/0xd0 arch/x86/kernel/irq.c:278
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:693

Memory state around the buggy address:
 ffff88807bef0800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807bef0880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807bef0900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                         ^
 ffff88807bef0980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807bef0a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/01/18 13:57 upstream 595523945be0 f2cb035c .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: slab-use-after-free Read in thread_group_cputime
2025/01/01 13:49 upstream ccb98ccef0e5 d3ccff63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce KASAN: slab-use-after-free Read in thread_group_cputime
* Struck through repros no longer work on HEAD.