Skip to content

Commit c926f2f

Browse files
marpombonzini
authored andcommitted
KVM: x86: Protect exit_reason from being used in Spectre-v1/L1TF attacks
This fixes a Spectre-v1/L1TF vulnerability in vmx_handle_exit(). While exit_reason is set by the hardware and therefore should not be attacker-influenced, an unknown exit_reason could potentially be used to perform such an attack. Fixes: 55d2375 ("KVM: nVMX: Move nested code to dedicated files") Signed-off-by: Marios Pomonis <[email protected]> Signed-off-by: Nick Finco <[email protected]> Suggested-by: Sean Christopherson <[email protected]> Reviewed-by: Andrew Honig <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 125ffc5 commit c926f2f

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,34 +5913,41 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu,
59135913
if (exit_fastpath == EXIT_FASTPATH_SKIP_EMUL_INS) {
59145914
kvm_skip_emulated_instruction(vcpu);
59155915
return 1;
5916-
} else if (exit_reason < kvm_vmx_max_exit_handlers
5917-
&& kvm_vmx_exit_handlers[exit_reason]) {
5916+
}
5917+
5918+
if (exit_reason >= kvm_vmx_max_exit_handlers)
5919+
goto unexpected_vmexit;
59185920
#ifdef CONFIG_RETPOLINE
5919-
if (exit_reason == EXIT_REASON_MSR_WRITE)
5920-
return kvm_emulate_wrmsr(vcpu);
5921-
else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER)
5922-
return handle_preemption_timer(vcpu);
5923-
else if (exit_reason == EXIT_REASON_INTERRUPT_WINDOW)
5924-
return handle_interrupt_window(vcpu);
5925-
else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
5926-
return handle_external_interrupt(vcpu);
5927-
else if (exit_reason == EXIT_REASON_HLT)
5928-
return kvm_emulate_halt(vcpu);
5929-
else if (exit_reason == EXIT_REASON_EPT_MISCONFIG)
5930-
return handle_ept_misconfig(vcpu);
5921+
if (exit_reason == EXIT_REASON_MSR_WRITE)
5922+
return kvm_emulate_wrmsr(vcpu);
5923+
else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER)
5924+
return handle_preemption_timer(vcpu);
5925+
else if (exit_reason == EXIT_REASON_INTERRUPT_WINDOW)
5926+
return handle_interrupt_window(vcpu);
5927+
else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
5928+
return handle_external_interrupt(vcpu);
5929+
else if (exit_reason == EXIT_REASON_HLT)
5930+
return kvm_emulate_halt(vcpu);
5931+
else if (exit_reason == EXIT_REASON_EPT_MISCONFIG)
5932+
return handle_ept_misconfig(vcpu);
59315933
#endif
5932-
return kvm_vmx_exit_handlers[exit_reason](vcpu);
5933-
} else {
5934-
vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
5935-
exit_reason);
5936-
dump_vmcs();
5937-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
5938-
vcpu->run->internal.suberror =
5934+
5935+
exit_reason = array_index_nospec(exit_reason,
5936+
kvm_vmx_max_exit_handlers);
5937+
if (!kvm_vmx_exit_handlers[exit_reason])
5938+
goto unexpected_vmexit;
5939+
5940+
return kvm_vmx_exit_handlers[exit_reason](vcpu);
5941+
5942+
unexpected_vmexit:
5943+
vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n", exit_reason);
5944+
dump_vmcs();
5945+
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
5946+
vcpu->run->internal.suberror =
59395947
KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
5940-
vcpu->run->internal.ndata = 1;
5941-
vcpu->run->internal.data[0] = exit_reason;
5942-
return 0;
5943-
}
5948+
vcpu->run->internal.ndata = 1;
5949+
vcpu->run->internal.data[0] = exit_reason;
5950+
return 0;
59445951
}
59455952

59465953
/*

0 commit comments

Comments
 (0)