Skip to content

KVM: Fix memslot use-after-free bug

Sean Christopherson kvm lkml 1 version Applied

Status from this message: Queued patches 1-3, thanks.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 14 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/7KVM: Fix out of range accesses to memslotsarch/s390/kvm/kvm-s390.c include/linux/kvm_host.h virt/kvm/kvm_main.c+9 -06 replies
2/7KVM: selftests: Fix cosmetic copy-paste error in vm_mem_region_move()tools/testing/selftests/kvm/lib/kvm_util.c+2 -20 replies
3/7KVM: selftests: Take vcpu pointer instead of id in vm_vcpu_rm()tools/testing/selftests/kvm/lib/kvm_util.c+3 -40 replies
4/7KVM: selftests: Add helpers to consolidate open coded list operationstools/testing/selftests/kvm/lib/kvm_util.c+37 -312 replies
5/7KVM: selftests: Add util to delete memory regiontools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/lib/kvm_util.c+40 -210 replies
6/7KVM: selftests: Expose the primary memslot number to teststools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/lib/kvm_util.c+4 -22 replies
7/7KVM: selftests: Add "delete" testcase to set_memory_region_testtools/testing/selftests/kvm/x86_64/set_memory_region_test.c+108 -143 replies

Reviews trailers per patch

1 of 7 patches has a Reviewed-by or Acked-by.

PatchChristian BorntraegerClaudio Imbrenda
1/7A-b R-b
2/7
3/7
4/7
5/7
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/7] KVM: Fix memslot use-after-free bug

Fix a bug introduced by dynamic memslot allocation where the LRU slot can become invalid and lead to a out-of-bounds/use-after-free scenario.

The patch is different that what Qian has already tested, but I was able to reproduce the bad behavior by enhancing the set memory region selftest, i.e. I'm relatively confident the bug is fixed.

Patches 2-6 are a variety of selftest cleanup, with the aforementioned set memory region enhancement coming in patch 7.

Note, I couldn't get the selftest to fail outright or with KASAN, but was able to hit a WARN_ON an invalid slot 100% of the time (without the fix, obviously).

Regarding s390, I played around a bit with merging gfn_to_memslot_approx() into search_memslots(). Code wise it's trivial since they're basically identical, but doing so increases the code footprint of search_memslots() on x86 by 30 bytes, so I ended up abandoning the effort.

Sean Christopherson (7):
KVM: Fix out of range accesses to memslots
KVM: selftests: Fix cosmetic copy-paste error in vm_mem_region_move()
KVM: selftests: Take vcpu pointer instead of id in vm_vcpu_rm()
KVM: selftests: Add helpers to consolidate open coded list operations
KVM: selftests: Add util to delete memory region
KVM: selftests: Expose the primary memslot number to tests
KVM: selftests: Add "delete" testcase to set_memory_region_test

 arch/s390/kvm/kvm-s390.c                      |   3 +
 include/linux/kvm_host.h                      |   3 +
 .../testing/selftests/kvm/include/kvm_util.h  |   3 +
 tools/testing/selftests/kvm/lib/kvm_util.c    | 139 ++++++++++--------
 .../kvm/x86_64/set_memory_region_test.c       | 122 +++++++++++++--
 virt/kvm/kvm_main.c                           |   3 +
 6 files changed, 201 insertions(+), 72 deletions(-)
Signature · 1 line
2.24.1