Skip to content

Commit 72777fc

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 <[email protected]> Cc: [email protected] Cc: Sean Christopherson <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> 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/[email protected] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0f63fba commit 72777fc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

arch/x86/kvm/lapic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
589589

590590
if (min > map->max_apic_id)
591591
goto out;
592+
593+
min = array_index_nospec(min, map->max_apic_id + 1);
594+
592595
/* Bits above cluster_size are masked in the caller. */
593596
for_each_set_bit(i, &ipi_bitmap_low,
594597
min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {

arch/x86/kvm/x86.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7506,8 +7506,11 @@ static void kvm_sched_yield(struct kvm *kvm, unsigned long dest_id)
75067506
rcu_read_lock();
75077507
map = rcu_dereference(kvm->arch.apic_map);
75087508

7509-
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
7510-
target = map->phys_map[dest_id]->vcpu;
7509+
if (likely(map) && dest_id <= map->max_apic_id) {
7510+
dest_id = array_index_nospec(dest_id, map->max_apic_id + 1);
7511+
if (map->phys_map[dest_id])
7512+
target = map->phys_map[dest_id]->vcpu;
7513+
}
75117514

75127515
rcu_read_unlock();
75137516

0 commit comments

Comments
 (0)