Skip to content

Commit e2e45e6

Browse files
ThijsRaydongert
authored andcommitted
KVM: x86: use array_index_nospec with indices that come from guest
commit c87bd4d upstream. min and dest_id are guest-controlled indices. Using array_index_nospec() after the bounds checks clamps these values to mitigate speculative execution side-channels. Signed-off-by: Thijs Raymakers <thijs@raymakers.nl> Cc: stable@vger.kernel.org Cc: Sean Christopherson <seanjc@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Fixes: 7150629 ("KVM: X86: Implement PV sched yield hypercall") Fixes: bdf7ffc ("KVM: LAPIC: Fix pv ipis out-of-bounds access") Fixes: 4180bf1 ("KVM: X86: Implement "send IPI" hypercall") Link: https://lore.kernel.org/r/20250804064405.4802-1-thijs@raymakers.nl Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 67a05679621b7f721bdba37a5d18665d3aceb695)
1 parent 2cc991d commit e2e45e6

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

arch/x86/kvm/lapic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
860860
if (min > map->max_apic_id)
861861
return 0;
862862

863+
min = array_index_nospec(min, map->max_apic_id + 1);
864+
863865
for_each_set_bit(i, ipi_bitmap,
864866
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
865867
if (map->phys_map[min + i]) {

arch/x86/kvm/x86.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9974,8 +9974,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
99749974
rcu_read_lock();
99759975
map = rcu_dereference(vcpu->kvm->arch.apic_map);
99769976

9977-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
9978-
target = map->phys_map[dest_id]->vcpu;
9977+
if (likely(map) && dest_id <= map->max_apic_id) {
9978+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
9979+
if (map->phys_map[dest_id])
9980+
target = map->phys_map[dest_id]->vcpu;
9981+
}
99799982

99809983
rcu_read_unlock();
99819984

0 commit comments

Comments
 (0)