Skip to contentSkip to conversation

KVM: VMX: Resume guest immediately when injecting #GP on ECREATE

PATCH In review Sean Christopherson 2 participants 2 messages Sep 30, 2022 – Oct 3, 2022

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: VMX: Resume guest immediately when injecting #GP on ECREATE

Resume the guest immediately when injecting a #GP on ECREATE due to an invalid enclave size, i.e. don't attempt ECREATE in the host. The #GP is a terminal fault, e.g. skipping the instruction if ECREATE is successful would result in KVM injecting #GP on the instruction following ECREATE.

Fixes 70210c044b4e ("KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions")
Cc Kai Huang <[email protected]>

---

Effectively compile tested only, found by inspection when auditing use of kvm_skip_emulated_instruction().

 arch/x86/kvm/vmx/sgx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/sgx.c +3 -1
index 8f95c7c01433..b12da2a6dec9 100644
@@ -182,8 +182,10 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcpu,
 	/* Enforce CPUID restriction on max enclave size. */
 	max_size_log2 = (attributes & SGX_ATTR_MODE64BIT) ? sgx_12_0->edx >> 8 :
 							    sgx_12_0->edx;
-	if (size >= BIT_ULL(max_size_log2))
+	if (size >= BIT_ULL(max_size_log2)) {
 		kvm_inject_gp(vcpu, 0);
+		return 1;
+	}
 
 	/*
 	 * sgx_virt_ecreate() returns:

base-commit: c59fb127583869350256656b7ed848c398bef879

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Sean Christopherson

Resume the guest immediately when injecting a #GP on ECREATE due to an invalid enclave size, i.e. don't attempt ECREATE in the host. The #GP is a terminal fault, e.g. skipping the instruction if ECREATE is successful would result in KVM injecting #GP on the instruction following ECREATE.

Fixes 70210c044b4e ("KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions")
Cc Kai Huang <[email protected]>

---

Effectively compile tested only, found by inspection when auditing use of kvm_skip_emulated_instruction().

 arch/x86/kvm/vmx/sgx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/sgx.c +3 -1
index 8f95c7c01433..b12da2a6dec9 100644
@@ -182,8 +182,10 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcpu,
 	/* Enforce CPUID restriction on max enclave size. */
 	max_size_log2 = (attributes & SGX_ATTR_MODE64BIT) ? sgx_12_0->edx >> 8 :
 							    sgx_12_0->edx;
-	if (size >= BIT_ULL(max_size_log2))
+	if (size >= BIT_ULL(max_size_log2)) {
 		kvm_inject_gp(vcpu, 0);
+		return 1;
+	}
 
 	/*
 	 * sgx_virt_ecreate() returns:
Quoted 4 lines

base-commit: c59fb127583869350256656b7ed848c398bef879

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog

Thanks Sean.

Signature · 2 lines
Thanks,
-Kai