summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSean Christopherson <sean.j.christopherson@intel.com>2020-03-20 13:55:40 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2020-03-26 05:58:27 -0400
commit0774a964ef561b7170d8d1b1bfe6f88002b6d219 (patch)
treee79fd43bb434c3bcd34843d7caee2e65b7f4af25 /include
parentd5361678e63c8a5e72d75cee6d15b840c44306f2 (diff)
downloadlinux-stable-0774a964ef561b7170d8d1b1bfe6f88002b6d219.tar.gz
linux-stable-0774a964ef561b7170d8d1b1bfe6f88002b6d219.tar.bz2
linux-stable-0774a964ef561b7170d8d1b1bfe6f88002b6d219.zip
KVM: Fix out of range accesses to memslots
Reset the LRU slot if it becomes invalid when deleting a memslot to fix an out-of-bounds/use-after-free access when searching through memslots. Explicitly check for there being no used slots in search_memslots(), and in the caller of s390's approximation variant. Fixes: 36947254e5f9 ("KVM: Dynamically size memslot array based on number of used slots") Reported-by: Qian Cai <cai@lca.pw> Cc: Peter Xu <peterx@redhat.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Message-Id: <20200320205546.2396-2-sean.j.christopherson@intel.com> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/kvm_host.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 35bc52e187a2..b19dee4ed7d9 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1032,6 +1032,9 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn)
int slot = atomic_read(&slots->lru_slot);
struct kvm_memory_slot *memslots = slots->memslots;
+ if (unlikely(!slots->used_slots))
+ return NULL;
+
if (gfn >= memslots[slot].base_gfn &&
gfn < memslots[slot].base_gfn + memslots[slot].npages)
return &memslots[slot];