Skip to content

Commit 3ebb5d2

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nSVM: more strict SMM checks when returning to nested guest
* check that guest is 64 bit guest, otherwise the SVM related fields in the smm state area are not defined * If the SMM area indicates that SMM interrupted a running guest, check that EFER.SVME which is also saved in this area is set, otherwise the guest might have tampered with SMM save area, and so indicate emulation failure which should triple fault the guest. * Check that that guest CPUID supports SVM (due to the same issue as above) Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20200827162720.278690-4-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 772b81b commit 3ebb5d2

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,21 +3899,28 @@ static int svm_pre_enter_smm(struct kvm_vcpu *vcpu, char *smstate)
38993899
static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
39003900
{
39013901
struct vcpu_svm *svm = to_svm(vcpu);
3902-
struct vmcb *nested_vmcb;
39033902
struct kvm_host_map map;
3904-
u64 guest;
3905-
u64 vmcb;
39063903
int ret = 0;
39073904

3908-
guest = GET_SMSTATE(u64, smstate, 0x7ed8);
3909-
vmcb = GET_SMSTATE(u64, smstate, 0x7ee0);
3905+
if (guest_cpuid_has(vcpu, X86_FEATURE_LM)) {
3906+
u64 saved_efer = GET_SMSTATE(u64, smstate, 0x7ed0);
3907+
u64 guest = GET_SMSTATE(u64, smstate, 0x7ed8);
3908+
u64 vmcb = GET_SMSTATE(u64, smstate, 0x7ee0);
39103909

3911-
if (guest) {
3912-
if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb), &map) == -EINVAL)
3913-
return 1;
3914-
nested_vmcb = map.hva;
3915-
ret = enter_svm_guest_mode(svm, vmcb, nested_vmcb);
3916-
kvm_vcpu_unmap(&svm->vcpu, &map, true);
3910+
if (guest) {
3911+
if (!guest_cpuid_has(vcpu, X86_FEATURE_SVM))
3912+
return 1;
3913+
3914+
if (!(saved_efer & EFER_SVME))
3915+
return 1;
3916+
3917+
if (kvm_vcpu_map(&svm->vcpu,
3918+
gpa_to_gfn(vmcb), &map) == -EINVAL)
3919+
return 1;
3920+
3921+
ret = enter_svm_guest_mode(svm, vmcb, map.hva);
3922+
kvm_vcpu_unmap(&svm->vcpu, &map, true);
3923+
}
39173924
}
39183925

39193926
return ret;

0 commit comments

Comments
 (0)