Commit c87bd4dd authored by Thijs Raymakers's avatar Thijs Raymakers Committed by Sean Christopherson
Browse files

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: default avatarThijs 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: 71506297 ("KVM: X86: Implement PV sched yield hypercall")
Fixes: bdf7ffc8 ("KVM: LAPIC: Fix pv ipis out-of-bounds access")
Fixes: 4180bf1b ("KVM: X86: Implement "send IPI" hypercall")
Link: https://lore.kernel.org/r/20250804064405.4802-1-thijs@raymakers.nl


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 8f5ae30d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -810,6 +810,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
	if (min > map->max_apic_id)
		return 0;

	min = array_index_nospec(min, map->max_apic_id + 1);

	for_each_set_bit(i, ipi_bitmap,
		min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
		if (map->phys_map[min + i]) {
+5 −2
Original line number Diff line number Diff line
@@ -9908,8 +9908,11 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
	rcu_read_lock();
	map = rcu_dereference(vcpu->kvm->arch.apic_map);

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

	rcu_read_unlock();