bisecting cause commit starting from bef7b2a7be28638770972ab2709adf11d601c11a building syzkaller on 5ed396e666c7826bed46f06c4db1409376691fed testing commit bef7b2a7be28638770972ab2709adf11d601c11a with gcc (GCC) 8.1.0 kernel signature: 3e9dc0602621621e4fb2b240fad46664d4c8922d8e2e9c972a97ef3695e96f58 all runs: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot testing release v5.6 testing commit 7111951b8d4973bda27ff663f2cf18b663d15b48 with gcc (GCC) 8.1.0 kernel signature: 794bf460bbb315d3bfa3660cff178e069d5b9b44223a81bb64914a6c08dc3789 run #0: OK run #1: OK run #2: OK run #3: OK run #4: OK run #5: OK run #6: OK run #7: OK run #8: OK run #9: boot failed: can't ssh into the instance # git bisect start bef7b2a7be28638770972ab2709adf11d601c11a 7111951b8d4973bda27ff663f2cf18b663d15b48 Bisecting: 3821 revisions left to test after this (roughly 12 steps) [29d9f30d4ce6c7a38745a54a8cddface10013490] Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next testing commit 29d9f30d4ce6c7a38745a54a8cddface10013490 with gcc (GCC) 8.1.0 kernel signature: 57335ad9719167c10bbe1de3d3a2e69181fe7b1b69594722b913734966b2c056 all runs: OK # git bisect good 29d9f30d4ce6c7a38745a54a8cddface10013490 Bisecting: 1948 revisions left to test after this (roughly 11 steps) [50a5de895dbe5df947b3a695777db5b2c313e065] Merge tag 'for-linus-hmm' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma testing commit 50a5de895dbe5df947b3a695777db5b2c313e065 with gcc (GCC) 8.1.0 kernel signature: bf04bb72020793e82b208f13dcd9f22c3b764ace5cefa16dccb4d7ebcc9788e9 all runs: OK # git bisect good 50a5de895dbe5df947b3a695777db5b2c313e065 Bisecting: 1022 revisions left to test after this (roughly 10 steps) [bc3b3f4bfbded031a11c4284106adddbfacd05bb] Merge tag 'pinctrl-v5.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl testing commit bc3b3f4bfbded031a11c4284106adddbfacd05bb with gcc (GCC) 8.1.0 kernel signature: 1e2cdc3b86e3a19ab31461f6a57e6018f5a52002cdce23d4a2688183f83eb321 all runs: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot # git bisect bad bc3b3f4bfbded031a11c4284106adddbfacd05bb Bisecting: 406 revisions left to test after this (roughly 9 steps) [6cad420cc695867b4ca710bac21fde21a4102e4b] Merge branch 'akpm' (patches from Andrew) testing commit 6cad420cc695867b4ca710bac21fde21a4102e4b with gcc (GCC) 8.1.0 kernel signature: 2f992e4067c3d60e6d6931615d5481ff17978070b779635dbc4e63fe0f409a4c all runs: OK # git bisect good 6cad420cc695867b4ca710bac21fde21a4102e4b Bisecting: 188 revisions left to test after this (roughly 8 steps) [1c482452d5db0f52e4e8eed95bd7314eec537d78] Merge tag 'kvm-s390-next-5.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD testing commit 1c482452d5db0f52e4e8eed95bd7314eec537d78 with gcc (GCC) 8.1.0 kernel signature: c78b4f45a84f3a22fd57ced603572a2613b27a11b24711e043e8ea91036bffcf run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #2: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #3: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #4: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #5: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #6: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #7: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot # git bisect bad 1c482452d5db0f52e4e8eed95bd7314eec537d78 Bisecting: 108 revisions left to test after this (roughly 7 steps) [733deafc00df1dda5130fc14f87a1d3993913243] KVM: x86: Handle RDTSCP CPUID adjustment in VMX code testing commit 733deafc00df1dda5130fc14f87a1d3993913243 with gcc (GCC) 8.1.0 kernel signature: c444a68093b28e0b2a3eaab7643bf8df6730e5b57fddadf87fe035701337ab2a run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #2: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #3: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #4: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #5: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #6: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #7: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot # git bisect bad 733deafc00df1dda5130fc14f87a1d3993913243 Bisecting: 54 revisions left to test after this (roughly 6 steps) [0be44352071dc87a4f9bf879642b1d44876971d9] KVM: x86/mmu: Reuse the current root if possible for fast switch testing commit 0be44352071dc87a4f9bf879642b1d44876971d9 with gcc (GCC) 8.1.0 kernel signature: 4be3931d258d8c92856adb2cd72e1c7d01a5c843716146d24b6f8d91598ecb1c run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #2: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #3: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #4: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #5: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #6: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #7: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva # git bisect bad 0be44352071dc87a4f9bf879642b1d44876971d9 Bisecting: 26 revisions left to test after this (roughly 5 steps) [82307e676f9d885871f121e4921b12905a53397d] KVM: PPC: Move memslot memory allocation into prepare_memory_region() testing commit 82307e676f9d885871f121e4921b12905a53397d with gcc (GCC) 8.1.0 kernel signature: 01a7c50de955a296d85f9428f04b698fc7aff5f1e7c23f9da553c191303e973d all runs: OK # git bisect good 82307e676f9d885871f121e4921b12905a53397d Bisecting: 13 revisions left to test after this (roughly 4 steps) [0577d1abe704c315bb5cdfc71f4ca7b9b5358f59] KVM: Terminate memslot walks via used_slots testing commit 0577d1abe704c315bb5cdfc71f4ca7b9b5358f59 with gcc (GCC) 8.1.0 kernel signature: 89057d0d647b75213192954e2d22f961d283212ebcf2080850d7b8783e9c69cd run #0: OK run #1: OK run #2: OK run #3: OK run #4: OK run #5: OK run #6: OK run #7: OK run #8: OK run #9: boot failed: can't ssh into the instance # git bisect good 0577d1abe704c315bb5cdfc71f4ca7b9b5358f59 Bisecting: 6 revisions left to test after this (roughly 3 steps) [d18b2f43b9147c8005ae0844fb445d8cc6a87e31] KVM: x86: Gracefully handle __vmalloc() failure during VM allocation testing commit d18b2f43b9147c8005ae0844fb445d8cc6a87e31 with gcc (GCC) 8.1.0 kernel signature: 4ea55dfd609a3a852cdf7f4fe3d88baf43025702408507c3d3468bbdb1aaf5f1 run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #2: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #3: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #4: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #5: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #6: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #7: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot # git bisect bad d18b2f43b9147c8005ae0844fb445d8cc6a87e31 Bisecting: 3 revisions left to test after this (roughly 2 steps) [b3594ffbf932c8e8b23201cdc2c173708a4472dc] KVM: x86/mmu: Move kvm_arch_flush_remote_tlbs_memslot() to mmu.c testing commit b3594ffbf932c8e8b23201cdc2c173708a4472dc with gcc (GCC) 8.1.0 kernel signature: c0df94598c0737f9421dd5dd35b5f46c746d0636e8a001748b5484e4d10b63d4 run #0: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #1: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #2: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #3: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #4: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #5: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #6: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #7: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot # git bisect bad b3594ffbf932c8e8b23201cdc2c173708a4472dc Bisecting: 0 revisions left to test after this (roughly 1 step) [13e48aa9429d1be05ecf8b9eefb212ac58f3f704] KVM: selftests: Add test for KVM_SET_USER_MEMORY_REGION testing commit 13e48aa9429d1be05ecf8b9eefb212ac58f3f704 with gcc (GCC) 8.1.0 kernel signature: 7789998e87d6c4875335ff143b0e9bed18d7df1f493cd710b3095631a2a1a0e7 run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #2: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #3: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #4: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #5: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #6: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #7: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #8: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #9: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva # git bisect bad 13e48aa9429d1be05ecf8b9eefb212ac58f3f704 Bisecting: 0 revisions left to test after this (roughly 0 steps) [36947254e5f981aeeedab1c7dfa35fc34d330e80] KVM: Dynamically size memslot array based on number of used slots testing commit 36947254e5f981aeeedab1c7dfa35fc34d330e80 with gcc (GCC) 8.1.0 kernel signature: d89145dd0bc31c5b39405cc61a60c22e45596c5d15abf81d99cc1810bb9e2d67 run #0: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #1: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #2: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #3: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #4: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #5: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #6: crashed: KASAN: slab-out-of-bounds Read in kvm_vcpu_gfn_to_memslot run #7: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #8: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva run #9: crashed: KASAN: slab-out-of-bounds Read in gfn_to_hva # git bisect bad 36947254e5f981aeeedab1c7dfa35fc34d330e80 36947254e5f981aeeedab1c7dfa35fc34d330e80 is the first bad commit commit 36947254e5f981aeeedab1c7dfa35fc34d330e80 Author: Sean Christopherson Date: Tue Feb 18 13:07:32 2020 -0800 KVM: Dynamically size memslot array based on number of used slots Now that the memslot logic doesn't assume memslots are always non-NULL, dynamically size the array of memslots instead of unconditionally allocating memory for the maximum number of memslots. Note, because a to-be-deleted memslot must first be invalidated, the array size cannot be immediately reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry. Tested-by: Christoffer Dall Tested-by: Marc Zyngier Reviewed-by: Peter Xu Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) culprit signature: d89145dd0bc31c5b39405cc61a60c22e45596c5d15abf81d99cc1810bb9e2d67 parent signature: 89057d0d647b75213192954e2d22f961d283212ebcf2080850d7b8783e9c69cd revisions tested: 15, total time: 3h2m24.52740537s (build: 1h28m46.864092351s, test: 1h32m42.694399583s) first bad commit: 36947254e5f981aeeedab1c7dfa35fc34d330e80 KVM: Dynamically size memslot array based on number of used slots cc: ["christoffer.dall@arm.com" "maz@kernel.org" "pbonzini@redhat.com" "peterx@redhat.com" "sean.j.christopherson@intel.com"] crash: KASAN: slab-out-of-bounds Read in gfn_to_hva ================================================================== BUG: KASAN: slab-out-of-bounds in search_memslots include/linux/kvm_host.h:1029 [inline] BUG: KASAN: slab-out-of-bounds in __gfn_to_memslot include/linux/kvm_host.h:1054 [inline] BUG: KASAN: slab-out-of-bounds in gfn_to_memslot arch/x86/kvm/../../../virt/kvm/kvm_main.c:1604 [inline] BUG: KASAN: slab-out-of-bounds in gfn_to_hva+0x3f7/0x430 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1684 Read of size 8 at addr ffff8880a953c410 by task syz-executor.4/8553 CPU: 1 PID: 8553 Comm: syz-executor.4 Not tainted 5.6.0-rc1-syzkaller #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+0x128/0x182 lib/dump_stack.c:118 print_address_description.constprop.8.cold.10+0x9/0x317 mm/kasan/report.c:374 __kasan_report.cold.11+0x1c/0x34 mm/kasan/report.c:506 kasan_report+0xe/0x20 mm/kasan/common.c:641 search_memslots include/linux/kvm_host.h:1029 [inline] __gfn_to_memslot include/linux/kvm_host.h:1054 [inline] gfn_to_memslot arch/x86/kvm/../../../virt/kvm/kvm_main.c:1604 [inline] gfn_to_hva+0x3f7/0x430 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1684 kvm_arch_mmu_notifier_invalidate_range+0x17/0x40 arch/x86/kvm/x86.c:8065 kvm_mmu_notifier_invalidate_range_start+0x180/0x240 arch/x86/kvm/../../../virt/kvm/kvm_main.c:423 mn_hlist_invalidate_range_start mm/mmu_notifier.c:487 [inline] __mmu_notifier_invalidate_range_start+0x394/0x5b0 mm/mmu_notifier.c:519 mmu_notifier_invalidate_range_start include/linux/mmu_notifier.h:446 [inline] change_pmd_range mm/mprotect.c:190 [inline] change_pud_range mm/mprotect.c:240 [inline] change_p4d_range mm/mprotect.c:260 [inline] change_protection_range mm/mprotect.c:285 [inline] change_protection+0x804/0x1e00 mm/mprotect.c:306 mprotect_fixup+0x3b9/0x790 mm/mprotect.c:427 do_mprotect_pkey+0x3c2/0x700 mm/mprotect.c:553 __do_sys_mprotect mm/mprotect.c:578 [inline] __se_sys_mprotect mm/mprotect.c:575 [inline] __x64_sys_mprotect+0x6f/0xb0 mm/mprotect.c:575 do_syscall_64+0xc6/0x5e0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x45c947 Code: 00 00 00 b8 0b 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 9d b5 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 b8 0a 00 00 00 0f 05 <48> 3d 01 f0 ff ff 0f 83 7d b5 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007ffd4fae7058 EFLAGS: 00000246 ORIG_RAX: 000000000000000a RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 000000000045c947 RDX: 0000000000000000 RSI: 0000000000001000 RDI: 00007f8f3362d000 RBP: 00007ffd4fae7140 R08: 00000000007217e0 R09: 00000000007217e0 R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd4fae7230 R13: 00007f8f3364d700 R14: 00007f8f3364d9c0 R15: 000000000076bfac Allocated by task 8555: save_stack+0x19/0x80 mm/kasan/common.c:72 set_track mm/kasan/common.c:80 [inline] __kasan_kmalloc.constprop.17+0xc1/0xd0 mm/kasan/common.c:515 kvmalloc include/linux/mm.h:645 [inline] kvzalloc include/linux/mm.h:653 [inline] kvm_alloc_memslots arch/x86/kvm/../../../virt/kvm/kvm_main.c:564 [inline] kvm_create_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:699 [inline] kvm_dev_ioctl_create_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:3823 [inline] kvm_dev_ioctl+0x778/0x1120 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3875 vfs_ioctl fs/ioctl.c:47 [inline] ksys_ioctl+0xb8/0x110 fs/ioctl.c:763 __do_sys_ioctl fs/ioctl.c:772 [inline] __se_sys_ioctl fs/ioctl.c:770 [inline] __x64_sys_ioctl+0x6a/0xb0 fs/ioctl.c:770 do_syscall_64+0xc6/0x5e0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe Freed by task 7237: save_stack+0x19/0x80 mm/kasan/common.c:72 set_track mm/kasan/common.c:80 [inline] kasan_set_free_info mm/kasan/common.c:337 [inline] __kasan_slab_free+0xf7/0x140 mm/kasan/common.c:476 __cache_free mm/slab.c:3426 [inline] kfree+0x107/0x2b0 mm/slab.c:3757 sk_prot_free net/core/sock.c:1640 [inline] __sk_destruct+0x470/0x640 net/core/sock.c:1724 rcu_do_batch kernel/rcu/tree.c:2186 [inline] rcu_core+0x584/0x1290 kernel/rcu/tree.c:2410 __do_softirq+0x26e/0x9b2 kernel/softirq.c:292 The buggy address belongs to the object at ffff8880a953c000 which belongs to the cache kmalloc-2k of size 2048 The buggy address is located 1040 bytes inside of 2048-byte region [ffff8880a953c000, ffff8880a953c800) The buggy address belongs to the page: page:ffffea0002a54f00 refcount:1 mapcount:0 mapping:ffff8880aa400e00 index:0x0 flags: 0xfffe0000000200(slab) raw: 00fffe0000000200 ffffea0002671b88 ffffea0002681c48 ffff8880aa400e00 raw: 0000000000000000 ffff8880a953c000 0000000100000001 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8880a953c300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff8880a953c380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >ffff8880a953c400: 00 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc ^ ffff8880a953c480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff8880a953c500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ==================================================================