Skip to content

Commit 50b14a5

Browse files
ThijsRayopsiff
authored andcommitted
KVM: x86: use array_index_nospec with indices that come from guest
commit c87bd4dd43a624109c3cc42d843138378a7f4548 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 f49161646e03d107ce81a99c6ca5da682fe5fb69)
1 parent 92f0fc3 commit 50b14a5

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
@@ -847,6 +847,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
847847
if (min > map->max_apic_id)
848848
return 0;
849849

850+
min = array_index_nospec(min, map->max_apic_id + 1);
851+
850852
for_each_set_bit(i, ipi_bitmap,
851853
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
852854
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
@@ -9864,8 +9864,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
98649864
rcu_read_lock();
98659865
map = rcu_dereference(vcpu->kvm->arch.apic_map);
98669866

9867-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
9868-
target = map->phys_map[dest_id]->vcpu;
9867+
if (likely(map) && dest_id <= map->max_apic_id) {
9868+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
9869+
if (map->phys_map[dest_id])
9870+
target = map->phys_map[dest_id]->vcpu;
9871+
}
98699872

98709873
rcu_read_unlock();
98719874

0 commit comments

Comments
 (0)