Skip to content

Commit ad45413

Browse files
sean-jcbonzini
authored andcommitted
KVM: VMX: Don't rely _only_ on CPUID to enforce XCR0 restrictions for ECREATE
Explicitly check the vCPU's supported XCR0 when determining whether or not the XFRM for ECREATE is valid. Checking CPUID works because KVM updates guest CPUID.0x12.1 to restrict the leaf to a subset of the guest's allowed XCR0, but that is rather subtle and KVM should not modify guest CPUID except for modeling true runtime behavior (allowed XFRM is most definitely not "runtime" behavior). Reviewed-by: Kai Huang <kai.huang@intel.com> Tested-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230503160838.3412617-2-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent afb2acb commit ad45413

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/x86/kvm/vmx/sgx.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,19 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcpu,
170170
return 1;
171171
}
172172

173-
/* Enforce CPUID restrictions on MISCSELECT, ATTRIBUTES and XFRM. */
173+
/*
174+
* Enforce CPUID restrictions on MISCSELECT, ATTRIBUTES and XFRM. Note
175+
* that the allowed XFRM (XFeature Request Mask) isn't strictly bound
176+
* by the supported XCR0. FP+SSE *must* be set in XFRM, even if XSAVE
177+
* is unsupported, i.e. even if XCR0 itself is completely unsupported.
178+
*/
174179
if ((u32)miscselect & ~sgx_12_0->ebx ||
175180
(u32)attributes & ~sgx_12_1->eax ||
176181
(u32)(attributes >> 32) & ~sgx_12_1->ebx ||
177182
(u32)xfrm & ~sgx_12_1->ecx ||
178-
(u32)(xfrm >> 32) & ~sgx_12_1->edx) {
183+
(u32)(xfrm >> 32) & ~sgx_12_1->edx ||
184+
xfrm & ~(vcpu->arch.guest_supported_xcr0 | XFEATURE_MASK_FPSSE) ||
185+
(xfrm & XFEATURE_MASK_FPSSE) != XFEATURE_MASK_FPSSE) {
179186
kvm_inject_gp(vcpu, 0);
180187
return 1;
181188
}

0 commit comments

Comments
 (0)