Skip to contentSkip to conversation

KASAN: use-after-free Write in preempt_notifier_register

DISCUSSION Eric Biggers 1 participant 1 message Dec 21, 2017 1 message not in the archive KVM

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 97 lines · syzbot

Hello,

syzkaller hit the following crash on
7dc9f647127d6955ffacaf51cb6a627b31dceec2
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.

Unfortunately, I don't have any reproducer for this bug yet.

binder: 7432:7451 BC_CLEAR_DEATH_NOTIFICATION invalid ref 0
==================================================================

BUG: KASAN: use-after-free in hlist_add_head include/linux/list.h:674
[inline]
BUG: KASAN: use-after-free in preempt_notifier_register+0x1e2/0x210
kernel/sched/core.c:2513
Write of size 8 at addr ffff8801bddf0d50 by task syz-executor2/7427

CPU: 1 PID: 7427 Comm: syz-executor2 Not tainted 4.15.0-rc4-next-20171220+
#77
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:17 [inline]
 dump_stack+0x194/0x257 lib/dump_stack.c:53
 print_address_description+0x73/0x250 mm/kasan/report.c:252
 kasan_report_error mm/kasan/report.c:351 [inline]
 kasan_report+0x25b/0x340 mm/kasan/report.c:409
 __asan_report_store8_noabort+0x17/0x20 mm/kasan/report.c:435
 hlist_add_head include/linux/list.h:674 [inline]
 preempt_notifier_register+0x1e2/0x210 kernel/sched/core.c:2513
 vcpu_load+0x27/0x40 arch/x86/kvm/../../../virt/kvm/kvm_main.c:157
 vmx_free_vcpu_nested arch/x86/kvm/vmx.c:9795 [inline]
 vmx_free_vcpu+0x11b/0x260 arch/x86/kvm/vmx.c:9809
 kvm_arch_vcpu_free arch/x86/kvm/x86.c:7870 [inline]
 kvm_free_vcpus arch/x86/kvm/x86.c:8317 [inline]
 kvm_arch_destroy_vm+0x4a2/0x980 arch/x86/kvm/x86.c:8416
 kvm_destroy_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:728 [inline]
 kvm_put_kvm+0x695/0xde0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:749
 kvm_vm_release+0x42/0x50 arch/x86/kvm/../../../virt/kvm/kvm_main.c:760
 __fput+0x327/0x7e0 fs/file_table.c:209
 ____fput+0x15/0x20 fs/file_table.c:243
 task_work_run+0x199/0x270 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0x9bb/0x1ad0 kernel/exit.c:869
 do_group_exit+0x149/0x400 kernel/exit.c:972
 get_signal+0x73f/0x16c0 kernel/signal.c:2337
 do_signal+0x94/0x1ee0 arch/x86/kernel/signal.c:809
 exit_to_usermode_loop+0x258/0x2f0 arch/x86/entry/common.c:161
 prepare_exit_to_usermode arch/x86/entry/common.c:195 [inline]
 syscall_return_slowpath+0x490/0x550 arch/x86/entry/common.c:264
 entry_SYSCALL_64_fastpath+0x94/0x96
RIP: 0033:0x452a09
RSP: 002b:00007f067fe32ce8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: 0000000000000000 RBX: 000000000071bec8 RCX: 0000000000452a09
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000000000071bec8
RBP: 000000000071bec8 R08: 00000000000003bb R09: 000000000071bea0
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000a2f7ff R14: 00007f067fe339c0 R15: 0000000000000000

Allocated by task 7447:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
 kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:489
 kmem_cache_alloc+0x12e/0x760 mm/slab.c:3545
 kmem_cache_zalloc include/linux/slab.h:695 [inline]
 vmx_create_vcpu+0xc4/0x2f20 arch/x86/kvm/vmx.c:9819
 kvm_arch_vcpu_create+0x12c/0x1a0 arch/x86/kvm/x86.c:7884
 kvm_vm_ioctl_create_vcpu arch/x86/kvm/../../../virt/kvm/kvm_main.c:2445
[inline]
 kvm_vm_ioctl+0x48b/0x1c60 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2943
 vfs_ioctl fs/ioctl.c:46 [inline]
 do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
 SYSC_ioctl fs/ioctl.c:701 [inline]
 SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
 entry_SYSCALL_64_fastpath+0x1f/0x96

Freed by task 7427:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
 __cache_free mm/slab.c:3489 [inline]
 kmem_cache_free+0x83/0x2a0 mm/slab.c:3747
 vmx_free_vcpu+0x1ee/0x260 arch/x86/kvm/vmx.c:9813
 kvm_arch_vcpu_free arch/x86/kvm/x86.c:7870 [inline]
 kvm_free_vcpus arch/x86/kvm/x86.c:8317 [inline]
 kvm_arch_destroy_vm+0x4a2/0x980 arch/x86/kvm/x86.c:8416
 kvm_destroy_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:728 [inline]
 kvm_put_kvm+0x695/0xde0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:749
 kvm_vm_release+0x42/0x50 arch/x86/kvm/../../../virt/kvm/kvm_main.c:760
 __fput+0x327/0x7e0 fs/file_table.c:209
 ____fput+0x15/0x20 fs/file_table.c:243
 task_work_run+0x199/0x270 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
Quoted 8 lines
 do_exit+0x9bb/0x1ad0 kernel/exit.c:869
 do_group_exit+0x149/0x400 kernel/exit.c:972
 get_signal+0x73f/0x16c0 kernel/signal.c:2337
 do_signal+0x94/0x1ee0 arch/x86/kernel/signal.c:809
 exit_to_usermode_loop+0x258/0x2f0 arch/x86/entry/common.c:161
 prepare_exit_to_usermode arch/x86/entry/common.c:195 [inline]
 syscall_return_slowpath+0x490/0x550 arch/x86/entry/common.c:264
 entry_SYSCALL_64_fastpath+0x94/0x96

Probably a duplicate of the kvm_arch_vcpu_ioctl_set_sregs() bug:

#syz dup: KASAN: use-after-free Read in __schedule