Skip to content

Commit c87bd4d

Browse files
ThijsRaysean-jc
authored andcommitted
KVM: x86: use array_index_nospec with indices that come from guest
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>
1 parent 8f5ae30 commit c87bd4d

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
@@ -810,6 +810,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
810810
if (min > map->max_apic_id)
811811
return 0;
812812

813+
min = array_index_nospec(min, map->max_apic_id + 1);
814+
813815
for_each_set_bit(i, ipi_bitmap,
814816
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
815817
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
@@ -9908,8 +9908,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
99089908
rcu_read_lock();
99099909
map = rcu_dereference(vcpu->kvm->arch.apic_map);
99109910

9911-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
9912-
target = map->phys_map[dest_id]->vcpu;
9911+
if (likely(map) && dest_id <= map->max_apic_id) {
9912+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
9913+
if (map->phys_map[dest_id])
9914+
target = map->phys_map[dest_id]->vcpu;
9915+
}
99139916

99149917
rcu_read_unlock();
99159918

0 commit comments

Comments
 (0)