Skip to content

Commit 1e3ddda

Browse files
committed
KVM: SVM: Harden exit_code against being used in Spectre-like attacks
Explicitly clamp the exit code used to index KVM's exit handlers to guard against Spectre-like attacks, mainly to provide consistency between VMX and SVM (VMX was given the same treatment by commit c926f2f ("KVM: x86: Protect exit_reason from being used in Spectre-v1/L1TF attacks"). For normal VMs, it's _extremely_ unlikely the exit code could be used to exploit a speculation vulnerability, as the exit code is set by hardware and unexpected/unknown exit codes should be quite well bounded (as is/was the case with VMX). But with SEV-ES+, the exit code is guest-controlled as it comes from the GHCB, not from hardware, i.e. an attack from the guest is at least somewhat plausible. Irrespective of SEV-ES+, hardening KVM is easy and inexpensive, and such an attack is theoretically possible. Link: https://patch.msgid.link/20251230211347.4099600-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a08ca66 commit 1e3ddda

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,7 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 __exit_code)
35013501
if (exit_code >= ARRAY_SIZE(svm_exit_handlers))
35023502
goto unexpected_vmexit;
35033503

3504+
exit_code = array_index_nospec(exit_code, ARRAY_SIZE(svm_exit_handlers));
35043505
if (!svm_exit_handlers[exit_code])
35053506
goto unexpected_vmexit;
35063507

0 commit comments

Comments
 (0)