Skip to content

Commit d4b69c3

Browse files
committed
KVM: SVM: Inject #GP if memory operand for INVPCID is non-canonical
Inject a #GP if the memory operand received by INVCPID is non-canonical. The APM clearly states that the intercept takes priority over all #GP checks except the CPL0 restriction. Of course, that begs the question of how the CPU generates a linear address in the first place. Tracing confirms that EXITINFO1 does hold a linear address, at least for 64-bit mode guests (hooray GS prefix). Unfortunately, the APM says absolutely nothing about the EXITINFO fields for INVPCID intercepts, so it's not at all clear what's supposed to happen. Add a FIXME to call out that KVM still does the wrong thing for 32-bit guests, and if the stack segment is used for the memory operand. Cc: Babu Moger <babu.moger@amd.com> Cc: Jim Mattson <jmattson@google.com> Fixes: 4407a79 ("KVM: SVM: Enable INVPCID feature on AMD") Link: https://lore.kernel.org/r/20250224174522.2363400-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent fa662c9 commit d4b69c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,6 +3272,17 @@ static int invpcid_interception(struct kvm_vcpu *vcpu)
32723272
type = svm->vmcb->control.exit_info_2;
32733273
gva = svm->vmcb->control.exit_info_1;
32743274

3275+
/*
3276+
* FIXME: Perform segment checks for 32-bit mode, and inject #SS if the
3277+
* stack segment is used. The intercept takes priority over all
3278+
* #GP checks except CPL>0, but somehow still generates a linear
3279+
* address? The APM is sorely lacking.
3280+
*/
3281+
if (is_noncanonical_address(gva, vcpu, 0)) {
3282+
kvm_queue_exception_e(vcpu, GP_VECTOR, 0);
3283+
return 1;
3284+
}
3285+
32753286
return kvm_handle_invpcid(vcpu, type, gva);
32763287
}
32773288

0 commit comments

Comments
 (0)