* [PATCH] KVM: VMX: Resume guest immediately when injecting #GP on ECREATE
@ 2022-09-30 23:31 Sean Christopherson
2022-10-03 1:01 ` Huang, Kai
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2022-09-30 23:31 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Kai Huang
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: stable@vger.kernel.org
Cc: Kai Huang <kai.huang@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
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(-)
diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c
index 8f95c7c01433..b12da2a6dec9 100644
--- a/arch/x86/kvm/vmx/sgx.c
+++ b/arch/x86/kvm/vmx/sgx.c
@@ -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
--
2.38.0.rc1.362.ged0d419d3c-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: VMX: Resume guest immediately when injecting #GP on ECREATE
2022-09-30 23:31 [PATCH] KVM: VMX: Resume guest immediately when injecting #GP on ECREATE Sean Christopherson
@ 2022-10-03 1:01 ` Huang, Kai
0 siblings, 0 replies; 2+ messages in thread
From: Huang, Kai @ 2022-10-03 1:01 UTC (permalink / raw)
To: pbonzini, Christopherson,, Sean; +Cc: kvm, linux-kernel
On Fri, 2022-09-30 at 23:31 +0000, Sean Christopherson wrote:
> 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: stable@vger.kernel.org
> Cc: Kai Huang <kai.huang@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>
> 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(-)
>
> diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c
> index 8f95c7c01433..b12da2a6dec9 100644
> --- a/arch/x86/kvm/vmx/sgx.c
> +++ b/arch/x86/kvm/vmx/sgx.c
> @@ -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
> --
> 2.38.0.rc1.362.ged0d419d3c-goog
>
Thanks Sean.
Reviewed-by: Kai Huang <kai.huang@intel.com>
--
Thanks,
-Kai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-03 1:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 23:31 [PATCH] KVM: VMX: Resume guest immediately when injecting #GP on ECREATE Sean Christopherson
2022-10-03 1:01 ` Huang, Kai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®