Skip to content

Commit f57a4bd

Browse files
ThijsRaygregkh
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>
1 parent c45fcd4 commit f57a4bd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

arch/x86/kvm/lapic.c

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

855+
min = array_index_nospec(min, map->max_apic_id + 1);
856+
855857
for_each_set_bit(i, ipi_bitmap,
856858
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
857859
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
@@ -10051,8 +10051,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
1005110051
rcu_read_lock();
1005210052
map = rcu_dereference(vcpu->kvm->arch.apic_map);
1005310053

10054-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
10055-
target = map->phys_map[dest_id]->vcpu;
10054+
if (likely(map) && dest_id <= map->max_apic_id) {
10055+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
10056+
if (map->phys_map[dest_id])
10057+
target = map->phys_map[dest_id]->vcpu;
10058+
}
1005610059

1005710060
rcu_read_unlock();
1005810061

0 commit comments

Comments
 (0)