Skip to content

Commit 69cc3e8

Browse files
yang-weijiangsean-jc
authored andcommitted
KVM: x86: Add XSS support for CET_KERNEL and CET_USER
Add CET_KERNEL and CET_USER to KVM's set of supported XSS bits when IBT *or* SHSTK is supported. Like CR4.CET, XFEATURE support for IBT and SHSTK are bundle together under the CET umbrella, and thus prone to virtualization holes if KVM or the guest supports only one of IBT or SHSTK, but hardware supports both. However, again like CR4.CET, such virtualization holes are benign from the host's perspective so long as KVM takes care to always honor the "or" logic. Require CET_KERNEL and CET_USER to come as a pair, and refuse to support IBT or SHSTK if one (or both) features is missing, as the (host) kernel expects them to come as a pair, i.e. may get confused and corrupt state if only one of CET_KERNEL or CET_USER is supported. Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> Signed-off-by: Mathias Krause <minipli@grsecurity.net> Tested-by: Mathias Krause <minipli@grsecurity.net> Tested-by: John Allen <john.allen@amd.com> Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Chao Gao <chao.gao@intel.com> [sean: split to separate patch, write changelog, add XFEATURE_MASK_CET_ALL] Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-26-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 19e6e08 commit 69cc3e8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs;
220220
| XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \
221221
| XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE)
222222

223+
#define XFEATURE_MASK_CET_ALL (XFEATURE_MASK_CET_USER | XFEATURE_MASK_CET_KERNEL)
223224
/*
224225
* Note, KVM supports exposing PT to the guest, but does not support context
225226
* switching PT via XSTATE (KVM's PT virtualization relies on perf; swapping
226227
* PT via guest XSTATE would clobber perf state), i.e. KVM doesn't support
227228
* IA32_XSS[bit 8] (guests can/must use RDMSR/WRMSR to save/restore PT MSRs).
228229
*/
229-
#define KVM_SUPPORTED_XSS 0
230+
#define KVM_SUPPORTED_XSS (XFEATURE_MASK_CET_ALL)
230231

231232
bool __read_mostly allow_smaller_maxphyaddr = 0;
232233
EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr);
@@ -10104,6 +10105,16 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
1010410105
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
1010510106
kvm_caps.supported_xss = 0;
1010610107

10108+
if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) &&
10109+
!kvm_cpu_cap_has(X86_FEATURE_IBT))
10110+
kvm_caps.supported_xss &= ~XFEATURE_MASK_CET_ALL;
10111+
10112+
if ((kvm_caps.supported_xss & XFEATURE_MASK_CET_ALL) != XFEATURE_MASK_CET_ALL) {
10113+
kvm_cpu_cap_clear(X86_FEATURE_SHSTK);
10114+
kvm_cpu_cap_clear(X86_FEATURE_IBT);
10115+
kvm_caps.supported_xss &= ~XFEATURE_MASK_CET_ALL;
10116+
}
10117+
1010710118
if (kvm_caps.has_tsc_control) {
1010810119
/*
1010910120
* Make sure the user can only configure tsc_khz values that
@@ -12772,10 +12783,11 @@ static void kvm_xstate_reset(struct kvm_vcpu *vcpu, bool init_event)
1277212783
/*
1277312784
* On INIT, only select XSTATE components are zeroed, most components
1277412785
* are unchanged. Currently, the only components that are zeroed and
12775-
* supported by KVM are MPX related.
12786+
* supported by KVM are MPX and CET related.
1277612787
*/
1277712788
xfeatures_mask = (kvm_caps.supported_xcr0 | kvm_caps.supported_xss) &
12778-
(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR);
12789+
(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR |
12790+
XFEATURE_MASK_CET_ALL);
1277912791
if (!xfeatures_mask)
1278012792
return;
1278112793

0 commit comments

Comments
 (0)