Skip to content

Commit 55cd57b

Browse files
committed
KVM: x86: Filter out XTILE_CFG if XTILE_DATA isn't permitted
Filter out XTILE_CFG from the supported XCR0 reported to userspace if the current process doesn't have access to XTILE_DATA. Attempting to set XTILE_CFG in XCR0 will #GP if XTILE_DATA is also not set, and so keeping XTILE_CFG as supported results in explosions if userspace feeds KVM_GET_SUPPORTED_CPUID back into KVM and the guest doesn't sanity check CPUID. Fixes: 445ecdf ("kvm: x86: Exclude unpermitted xfeatures at KVM_GET_SUPPORTED_CPUID") Reported-by: Aaron Lewis <aaronlewis@google.com> Reviewed-by: Aaron Lewis <aaronlewis@google.com> Tested-by: Aaron Lewis <aaronlewis@google.com> Link: https://lore.kernel.org/r/20230405004520.421768-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6be3ae4 commit 55cd57b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

arch/x86/kvm/x86.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define ARCH_X86_KVM_X86_H
44

55
#include <linux/kvm_host.h>
6+
#include <asm/fpu/xstate.h>
67
#include <asm/mce.h>
78
#include <asm/pvclock.h>
89
#include "kvm_cache_regs.h"
@@ -325,7 +326,22 @@ extern bool enable_pmu;
325326
*/
326327
static inline u64 kvm_get_filtered_xcr0(void)
327328
{
328-
return kvm_caps.supported_xcr0 & xstate_get_guest_group_perm();
329+
u64 permitted_xcr0 = kvm_caps.supported_xcr0;
330+
331+
BUILD_BUG_ON(XFEATURE_MASK_USER_DYNAMIC != XFEATURE_MASK_XTILE_DATA);
332+
333+
if (permitted_xcr0 & XFEATURE_MASK_USER_DYNAMIC) {
334+
permitted_xcr0 &= xstate_get_guest_group_perm();
335+
336+
/*
337+
* Treat XTILE_CFG as unsupported if the current process isn't
338+
* allowed to use XTILE_DATA, as attempting to set XTILE_CFG in
339+
* XCR0 without setting XTILE_DATA is architecturally illegal.
340+
*/
341+
if (!(permitted_xcr0 & XFEATURE_MASK_XTILE_DATA))
342+
permitted_xcr0 &= ~XFEATURE_MASK_XTILE_CFG;
343+
}
344+
return permitted_xcr0;
329345
}
330346

331347
static inline bool kvm_mpx_supported(void)

0 commit comments

Comments
 (0)