Skip to content

Commit 97daa02

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: s390: Return last valid slot if approx index is out-of-bounds
Return the index of the last valid slot from gfn_to_memslot_approx() if its binary search loop yielded an out-of-bounds index. The index can be out-of-bounds if the specified gfn is less than the base of the lowest memslot (which is also the last valid memslot). Note, the sole caller, kvm_s390_get_cmma(), ensures used_slots is non-zero. Fixes: afdad61 ("KVM: s390: Fix storage attributes migration with memory slots") Cc: [email protected] # 4.19.x: 0774a96: KVM: Fix out of range accesses to memslots Cc: [email protected] # 4.19.x Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b6467ab commit 97daa02

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

arch/s390/kvm/kvm-s390.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,9 @@ static int gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn)
19391939
start = slot + 1;
19401940
}
19411941

1942+
if (start >= slots->used_slots)
1943+
return slots->used_slots - 1;
1944+
19421945
if (gfn >= memslots[start].base_gfn &&
19431946
gfn < memslots[start].base_gfn + memslots[start].npages) {
19441947
atomic_set(&slots->lru_slot, start);

0 commit comments

Comments
 (0)