Xen Security Advisory 452 v1 (CVE-2023-28746) - x86: Register File Data Sampling
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Xen Security Advisory CVE-2023-28746 / XSA-452
x86: Register File Data Sampling
ISSUE DESCRIPTION
=================
Intel have disclosed RFDS, Register File Data Sampling, affecting some Atom cores.
This came from internal validation work. There is no information provided about how an attacker might go about inferring data from the register files.
For more details, see:
https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/register-file-data-sampling.html
IMPACT
======
An attacker might be able to infer the contents of data held previously in floating point, vector and/or integer register files on the same logical processor, including data from a more privileged context.
Note: None of the vulnerable processors support HyperThreading, so there
is no instantaneous exposure of data from other threads.
VULNERABLE SYSTEMS
==================
Systems running all versions of Xen are affected.
RFDS is only known to affect certain Atom processors from Intel. Other Intel CPUs, and CPUs from other hardware vendors are not known to be affected.
RFDS affects Atom processors between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid client systems which have a mix of Gracemont and other types of cores.
MITIGATION
==========
There is no mitigation.
RESOLUTION
==========
Intel are producing microcode update to address the issue for in-support CPUs. This is done by extending the VERW instruction with more scrubbing side effects. Consult your dom0 OS vendor and/or hardware vendor for updated microcode.
In addition to the microcode, changes are required in Xen to reposition the VERW scrubbing and to activate it when necessary, as well as to inform guest kernels of when the extra side effect is present and/or when the system is believed to be not vulnerable. The appropriate set of patches does this.
Note that patches for released versions are generally prepared to apply to the stable branches, and may not apply cleanly to the most recent release tarball. Downstreams are encouraged to update to the tip of the stable branch before applying these patches.
xsa452/xsa452-?.patch xen-unstable xsa452/xsa452-4.18-?.patch Xen 4.18.x xsa452/xsa452-4.17-?.patch Xen 4.17.x xsa452/xsa452-4.16-?.patch Xen 4.16.x xsa452/xsa452-4.15-?.patch Xen 4.15.x
$ sha256sum xsa452*/* 9365456e85fc04947206075cdfe4a805c3d628d7c1f5b8020785d8fd84c93aa9 xsa452/xsa452-1.patch 89ce3001975352a1321dc1577d9d14273e6b383080900881603339e5a860e1fd xsa452/xsa452-2.patch 775a2d57b7aa8e2522cce61b1ddebd267e36218ecdcc0f678db7ed0ed1f54c21 xsa452/xsa452-3.patch 0e56da437f3ea30b97f79fa1d247561815625e152c963dd504f11082863eaa32 xsa452/xsa452-4.15-1.patch 184f2fe90b614e3e5c7056669ea6c829242058f5c00407a3db1e34bcd4fb4aed xsa452/xsa452-4.15-2.patch 237e9aa65122ef4a18f57e44f6841a80e967deac90e251ce629cba6ea2f66030 xsa452/xsa452-4.15-3.patch 59d5ec14b784b6c4f9ce2bb6258cb91ee6233fc01761f27c655f4582bdeb6830 xsa452/xsa452-4.15-4.patch 946a8d80f7c11a03a26a045eb2ba4e03be7e739f04df72e5e1f67279e374136e xsa452/xsa452-4.15-5.patch 6eba7f56a67a101c39e2345b53530a4036b2fad50f4b745e39f8da1d0bffcbd5 xsa452/xsa452-4.15-6.patch 326571a214f358787bc4af8c71d96ae6455a9da80da4d43358af282eebb51e4d xsa452/xsa452-4.15-7.patch 5aca7cf8ca97dd735769fc4c154dab576461da7ec1838ad152e90ceebb5af60d xsa452/xsa452-4.16-1.patch c7167c270a28cb639a9b94b898e656123767c21d0951fe48404bbbcf7d2be151 xsa452/xsa452-4.16-2.patch 55d61becc38663c6756baceb919645bc2cb4794b517cd067f9b452822fe11ecf xsa452/xsa452-4.16-3.patch 6e7a93935d1a4df2dea5d9a6542127feb5d662b33cc766587a713746e4992841 xsa452/xsa452-4.16-4.patch ee4bbf1988a05cc00c51512d5f258d310f3d5f21d23094d4a7b9ca3cf55ffcde xsa452/xsa452-4.16-5.patch f44dc3d957eca731834d13c1b7bf31cadfee5c4d354dbdb1e6aa317063c26420 xsa452/xsa452-4.16-6.patch 520188698c87ebfd42457b8f22d62e20e715d1bf28bfe43f93fbac4479485b15 xsa452/xsa452-4.16-7.patch 5ee4fffcb0418d34ec03605cf507d7c24d82355716fde250d3fd01308c40b29f xsa452/xsa452-4.17-1.patch a4081d6329c9ba7dd95b2f693ef6cfa61ef3a6148b0e4279f2cc8648be98b1ca xsa452/xsa452-4.17-2.patch bd6364569bb1d2841df6e9dad2d0c0d859b5cab5046141ba6c54a53ab7cbef76 xsa452/xsa452-4.17-3.patch 9c7aedd1a4f1e3dab344dd4ac0438de3ab25079f6aaa8d2f1b384b8f6f2df770 xsa452/xsa452-4.17-4.patch 7886b2da37de7c8bb0ed1bd9e8f001dbc46aa8802152c315fa1141f76e09dc77 xsa452/xsa452-4.17-5.patch 01dd485e5b2130b85905187ef6351d2fb6514cefb0096db3f710bff4345b8c29 xsa452/xsa452-4.17-6.patch f64109a3e0a2237cc4fabc94f680c96a82e71d037e9d263ee7782fef0895fa32 xsa452/xsa452-4.17-7.patch 2fa4d889fc193e4ddd46e570e8c37d59e89fd667db52afb912d692d2775b25d6 xsa452/xsa452-4.18-1.patch a4081d6329c9ba7dd95b2f693ef6cfa61ef3a6148b0e4279f2cc8648be98b1ca xsa452/xsa452-4.18-2.patch d4f61f50c9c6c17888ae6a371a2bde95cfad92d4e72c5e3ca54638fb4cc6fcfa xsa452/xsa452-4.18-3.patch 7922255f39744c75fa2e84c3971a27432b1f1f177ddb40647bdc753eacea412c xsa452/xsa452-4.18-4.patch b262adff116cb00c371b45cffffb111c4ca359490a27a69ad7482a1ae92ac173 xsa452/xsa452-4.18-5.patch 0c0830b81f60b5a5b4d6bd339410ab6f512276491d30881587361b9c9fb7d0ff xsa452/xsa452-4.18-6.patch 4ab5a0106c4ffdf713ebd3059eccd07ae8589e0d8348413685ecf0ff7d7b2a05 xsa452/xsa452-4.18-7.patch 51c1561026f32415cf69a362cca33a14aa361f34ddce3785667d99d25e922488 xsa452/xsa452-4.patch 518da7d12c295851a1ae3a03cc28b290bc0e9dee4c4446d20d341c88c9908961 xsa452/xsa452-5.patch $ -----BEGIN PGP SIGNATURE-----
iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAmXwhmMMHHBncEB4ZW4u b3JnAAoJEIP+FMlX6CvZfzUIALkcXm6t44EmYio/o6hUaxtx/V13QAANeTVss/V/ jRblCgWLw5hb39IToDmoDaX46fIxNDjAzT6GqOB/rnLHj9vNv15zVEsiAxgKPQXs YQyYZQxKB/4kb24JG/KhPLBc1iQOXWmK9BmNdgHgOlC1fqXzYHInZsm69BZhs6Dk nScFOeCaT/zvLybhehRioHFpNKkiFXSxZnIuj7IB9zkVrbS0YzZX9+H56Rs/VAuF wTqoCdqSZ0F5KnWsXsnWCYfz3Sd/mTiT5qvFROPCqbfNClEnU7NzCd4Mz2/QVjJJ LXhN/CrllJKWcpAcFW6Bx250uDC3/oSBfHNL/D+AsC/abcM=
=N4gH
-----END PGP SIGNATURE-----
From: Andrew Cooper <[email protected]>
Subject: x86/vmx: Perform VERW flushing later in the VMExit path
Broken out of the following patch because this change is subtle enough on its own. See it for the rational of why we're moving VERW.
As for how, extend the trick already used to hold one condition in flags (RESUME vs LAUNCH) through the POPing of GPRs.
Move the MOV CR earlier. Intel specify flags to be undefined across it.
Encode the two conditions we want using SF and PF. See the code comment for exactly how.
Leave a comment to explain the lack of any content around SPEC_CTRL_EXIT_TO_VMX, but leave the block in place. Sods law says if we delete it, we'll need to reintroduce it.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/hvm/vmx/entry.S +32 -4
@@ -87,17 +87,39 @@ UNLIKELY_END(realmode) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* SPEC_CTRL_EXIT_TO_VMX Req: %rsp=regs/cpuinfo Clob: */ - DO_SPEC_CTRL_COND_VERW + /* + * All speculation safety work happens to be elsewhere. VERW is after + * popping the GPRs, while restoring the guest MSR_SPEC_CTRL is left + * to the MSR load list. + */ mov VCPU_hvm_guest_cr2(%rbx),%rax + mov %rax, %cr2 + + /* + * We need to perform two conditional actions (VERW, and Resume vs + * Launch) after popping GPRs. With some cunning, we can encode both + * of these in eflags together. + * + * Parity is only calculated over the bottom byte of the answer, while + * Sign is simply the top bit. + * + * Therefore, the final OR instruction ends up producing: + * SF = VCPU_vmx_launched + * PF = !SCF_verw + */ + BUILD_BUG_ON(SCF_verw & ~0xff) + movzbl VCPU_vmx_launched(%rbx), %ecx + shl $31, %ecx + movzbl CPUINFO_spec_ctrl_flags(%rsp), %eax + and $SCF_verw, %eax + or %eax, %ecx pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp - mov %rax,%cr2 - cmpb $0,VCPU_vmx_launched(%rbx) pop %rbx pop %r11 pop %r10
@@ -108,7 +130,13 @@ UNLIKELY_END(realmode) pop %rdx pop %rsi pop %rdi - je .Lvmx_launch + + jpe .L_skip_verw + /* VERW clobbers ZF, but preserves all others, including SF. */ + verw STK_REL(CPUINFO_verw_sel, CPUINFO_error_code)(%rsp) +.L_skip_verw: + + jns .Lvmx_launch /*.Lvmx_resume:*/ VMRESUME
xen/arch/x86/include/asm/spec_ctrl_asm.h +7 -0
@@ -152,6 +152,13 @@#endif .endm +/* +* Helper to improve the readibility of stack dispacements with %rsp in +* unusual positions. Both @field and @top_of_stack should be constants from +* the same object. @top_of_stack should be where %rsp is currently pointing. + */ +#define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) + .macro DO_SPEC_CTRL_COND_VERW/* * Requires %rsp=cpuinfo
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -135,6 +135,7 @@ void __dummy__(void)#endif OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); + OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); OFFSET(CPUINFO_processor_id, struct cpu_info, processor_id); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu);
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Perform VERW flushing later in exit paths
On parts vulnerable to RFDS, VERW's side effects are extended to scrub all non-architectural entries in various Physical Register Files. To remove all of Xen's values, the VERW must be after popping the GPRs.
Rework SPEC_CTRL_COND_VERW to default to an CPUINFO_error_code %rsp position, but with overrides for other contexts. Identify that it clobbers eflags; this is particularly relevant for the SYSRET path.
For the IST exit return to Xen, have the main SPEC_CTRL_EXIT_TO_XEN put a shadow copy of spec_ctrl_flags, as GPRs can't be used at the point we want to issue the VERW.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/include/asm/spec_ctrl_asm.h +24 -12
@@ -159,16 +159,23 @@*/ #define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) -.macro DO_SPEC_CTRL_COND_VERW +.macro SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_error_code), \ + sel=STK_REL (CPUINFO_verw_sel, CPUINFO_error_code)/* -* Requires %rsp=cpuinfo +* Requires \scf and \sel as %rsp-relative expressions +* Clobbers eflags +* +* VERW needs to run after guest GPRs have been restored, where only %rsp is +* good to use. Default to expecting %rsp pointing at CPUINFO_error_code. +* Contexts where this is not true must provide an alternative \scf and \sel. * * Issue a VERW for its flushing side effect, if indicated. This is a Spectre * v1 gadget, but the IRET/VMEntry is serialising. */ - testb $SCF_verw, CPUINFO_spec_ctrl_flags(%rsp) + testb $SCF_verw, \scf(%rsp) jz .L\@_verw_skip - verw CPUINFO_verw_sel(%rsp) + verw \sel(%rsp) .L\@_verw_skip: .endm
@@ -286,8 +293,6 @@*/ ALTERNATIVE "", DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR_PV - DO_SPEC_CTRL_COND_VERW -ALTERNATIVE "" ,DO_SPEC_CTRL_DIV ,X86_FEATURE_SC_DIV .endm
@@ -367,7 +372,7 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise):*/ .macro SPEC_CTRL_EXIT_TO_XEN/* -* Requires %r12=ist_exit, %r14=stack_end +* Requires %r12=ist_exit, %r14=stack_end, %rsp=regs * Clobbers %rax, %rbx, %rcx, %rdx */ movzbl STACK_CPUINFO_FIELD(spec_ctrl_flags)(%r14), %ebx
@@ -395,11 +400,18 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise): test %r12, %r12 jz .L\@_skip_ist_exit - /* Logically DO_SPEC_CTRL_COND_VERW but without the %rsp=cpuinfo dependency */ - testb $SCF_verw, %bl - jz .L\@_skip_verw - verw STACK_CPUINFO_FIELD(verw_sel)(%r14) -.L\@_skip_verw: +/* +* Stash SCF and verw_sel above eflags in the case of an IST_exit. The +* VERW logic needs to run after guest GPRs have been restored; i.e. where +* we cannot use %r12 or %r14 for the purposes they have here. +* +* When the CPU pushed this exception frame, it zero-extended eflags. +* Therefore it is safe for the VERW logic to look at the stashed SCF +* outside of the ist_exit condition. Also, this stashing won't influence +* any other restore_all_guest() paths. +*/ + or $(__HYPERVISOR_DS32 << 16), %ebx + mov %ebx, UREGS_eflags + 4(%rsp) /* EFRAME_shadow_scf/sel */ ALTERNATIVE "", DO_SPEC_CTRL_DIV, X86_FEATURE_SC_DIV
xen/arch/x86/x86_64/asm-offsets.c +11 -2
@@ -55,14 +55,22 @@ void __dummy__(void)* EFRAME_* is for the entry/exit logic where %rsp is pointing at * UREGS_error_code and GPRs are still/already guest values. */ -#define OFFSET_EF (sym, mem) \ +#define OFFSET_EF (sym, mem, ...) \ DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ - offsetof(struct cpu_user_regs, error_code)) + offsetof(struct cpu_user_regs, error_code) __VA_ARGS__)OFFSET_EF (EFRAME_entry_vector, entry_vector);OFFSET_EF (EFRAME_rip, rip);OFFSET_EF (EFRAME_cs, cs);OFFSET_EF (EFRAME_eflags, eflags); + +/* +* These aren't real fields. They're spare space, used by the IST +* exit-to-xen path. +*/ +OFFSET_EF (EFRAME_shadow_scf, eflags,+4 ); +OFFSET_EF (EFRAME_shadow_sel, eflags,+6 ); +OFFSET_EF (EFRAME_rsp, rsp);BLANK ();
@@ -136,6 +144,7 @@ void __dummy__(void) OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); + OFFSET(CPUINFO_rip, struct cpu_info, guest_cpu_user_regs.rip); OFFSET(CPUINFO_processor_id, struct cpu_info, processor_id); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu);
xen/arch/x86/x86_64/compat/entry.S +6 -0
@@ -159,6 +159,12 @@ FUNC(compat_restore_all_guest) SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ RESTORE_ALL adj=8, compat=1 + + /* Account for ev/ec having already been popped off the stack. */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_rip), \ + sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception) END(compat_restore_all_guest)
xen/arch/x86/x86_64/entry.S +20 -1
@@ -212,6 +212,9 @@ FUNC_LOCAL(restore_all_guest) #endif mov EFRAME_rip(%rsp), %rcx + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + cmpw $FLAT_USER_CS32, EFRAME_cs(%rsp) mov EFRAME_rsp(%rsp), %rsp je 1f
@@ -224,6 +227,9 @@ LABEL_LOCAL(.Lrestore_rcx_iret_exit_to_guest) iret_exit_to_guest: andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), EFRAME_eflags(%rsp) orl $X86_EFLAGS_IF, EFRAME_eflags(%rsp) + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + addq $8,%rsp .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception)
@@ -688,9 +694,22 @@ UNLIKELY_START(ne, exit_cr3) UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end, Clob: abcd */ + SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ RESTORE_ALL adj=8 + + /* + * When the CPU pushed this exception frame, it zero-extended eflags. + * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of + * spec_ctrl_flags and ver_sel above eflags, as we can't use any GPRs, + * and we're at a random place on the stack, not in a CPUFINFO block. + * + * Account for ev/ec having already been popped off the stack. + */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ + sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + iretq END(restore_all_xen)
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Rename VERW related options
VERW is going to be used for a 3rd purpose, and the existing nomenclature didn't survive the Stale MMIO issues terribly well.
Rename the command line option from md-clear= to verw=. This is more consistent with other options which tend to be named based on what they're doing, not which feature enumeration they use behind the scenes. Retain md-clear= as a deprecated alias.
Rename opt_md_clear_{pv,hvm} and opt_fb_clear_mmio to opt_verw_{pv,hvm,mmio}, which has a side effect of making spec_ctrl_init_domain() rather clearer to follow.
No functional change.
This is part of XSA-452 / CVE-2023-28746.
docs/misc/xen-command-line.pandoc +8 -7
@@ -2363,7 +2363,7 @@ By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm}=<bool>, -> {msr-sc,rsb,md-clear,ibpb-entry}=<bool>|{pv,hvm}=<bool>, +> {msr-sc,rsb,verw,ibpb-entry}=<bool>|{pv,hvm}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd,psfd, > eager-fpu,l1d-flush,branch-harden,srb-lock, > unpriv-mmio,gds-mit,div-scrub}=<bool> ]`
@@ -2388,7 +2388,7 @@ in place for guests to use. Use of a positive boolean value for either of these options is invalid. -The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `md-clear=` and `ibpb-entry=` options +The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `verw=` and `ibpb-entry=` options offer fine grained control over the primitives by Xen. These impact Xen's ability to protect itself, and/or Xen's ability to virtualise support for guests to use.
@@ -2405,11 +2405,12 @@ guests to use. guests and if disabled, guests will be unable to use IBRS/STIBP/SSBD/etc. * `rsb=` offers control over whether to overwrite the Return Stack Buffer / Return Address Stack on entry to Xen and on idle. -* `md-clear=` offers control over whether to use VERW to flush - microarchitectural buffers on idle and exit from Xen. *Note: For - compatibility with development versions of this fix, `mds=` is also accepted - on Xen 4.12 and earlier as an alias. Consult vendor documentation in - preference to here.* +* `verw=` offers control over whether to use VERW for its scrubbing side + effects at appropriate privilege transitions. The exact side effects are + microarchitecture and microcode specific. *Note: `md-clear=` is accepted as + a deprecated alias. For compatibility with development versions of XSA-297, + `mds=` is also accepted on Xen 4.12 and earlier as an alias. Consult vendor + documentation in preference to here.* * `ibpb-entry=` offers control over whether IBPB (Indirect Branch Prediction Barrier) is used on entry to Xen. This is used by default on hardware vulnerable to Branch Type Confusion, and hardware vulnerable to Speculative
xen/arch/x86/spec_ctrl.c +32 -30
161 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/entry: Introduce EFRAME_* constants
restore_all_guest() does a lot of manipulation of the stack after popping the GPRs, and uses raw %rsp displacements to do so. Also, almost all entrypaths use raw %rsp displacements prior to pushing GPRs.
Provide better mnemonics, to aid readability and reduce the chance of errors when editing.
No functional change. The resulting binary is identical.
xen/arch/x86/x86_64/asm-offsets.c +17 -0
@@ -51,6 +51,23 @@ void __dummy__(void) OFFSET(UREGS_kernel_sizeof, struct cpu_user_regs, es);BLANK (); +/* +* EFRAME_* is for the entry/exit logic where %rsp is pointing at +* UREGS_error_code and GPRs are still/already guest values. +*/ +#define OFFSET_EF (sym, mem) \ + DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ + offsetof(struct cpu_user_regs, error_code)) + +OFFSET_EF (EFRAME_entry_vector, entry_vector); +OFFSET_EF (EFRAME_rip, rip); +OFFSET_EF (EFRAME_cs, cs); +OFFSET_EF (EFRAME_eflags, eflags); +OFFSET_EF (EFRAME_rsp, rsp); +BLANK (); + +#undef OFFSET_EF + OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info);
xen/arch/x86/x86_64/compat/entry.S +2 -2
@@ -17,7 +17,7 @@ ENTRY(entry_int82) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movl $HYPERCALL_VECTOR, 4(%rsp) + movl $HYPERCALL_VECTOR, EFRAME_entry_vector(%rsp) SAVE_ALL compat=1 /* DPL1 gate, restricted to 32bit PV guests only. */ SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=regs/cpuinfo, %rdx=0, Clob: acd */
@@ -214,7 +214,7 @@ ENTRY(cstar_enter) pushq $FLAT_USER_CS32 pushq %rcx pushq $0 - movl $TRAP_syscall, 4(%rsp) + movl $TRAP_syscall, EFRAME_entry_vector(%rsp) SAVE_ALL SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=regs/cpuinfo, %rdx=0, Clob: acd */
xen/arch/x86/x86_64/entry.S +34 -34
222 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/cpu-policy: Allow for levelling of VERW side effects
MD_CLEAR and FB_CLEAR need OR-ing across a migrate pool. Allow this, by having them unconditinally set in max, with the host values reflected in default. Annotate the bits as having special properies.
xen/arch/x86/cpu-policy.c +24 -0
@@ -434,6 +434,16 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)__set_bit (X86_FEATURE_RSBA , fs);__set_bit (X86_FEATURE_RRSBA , fs); +/* +* These bits indicate that the VERW instruction may have gained +* scrubbing side effects. With pooling, they mean "you might migrate +* somewhere where scrubbing is necessary", and may need exposing on +* unaffected hardware. This is fine, because the VERW instruction +* has been around since the 286. +*/ +__set_bit (X86_FEATURE_MD_CLEAR , fs); +__set_bit (X86_FEATURE_FB_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
@@ -468,6 +478,20 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs) cpu_has_rdrand && !is_forced_cpu_cap(X86_FEATURE_RDRAND) )__clear_bit (X86_FEATURE_RDRAND , fs); +/* +* These bits indicate that the VERW instruction may have gained +* scrubbing side effects. The max policy has them set for migration +* reasons, so reset the default policy back to the host values in +* case we're unaffected. +*/ +__clear_bit (X86_FEATURE_MD_CLEAR , fs); +if ( cpu_has_md_clear ) +__set_bit (X86_FEATURE_MD_CLEAR , fs); + +__clear_bit (X86_FEATURE_FB_CLEAR , fs); +if ( cpu_has_fb_clear ) +__set_bit (X86_FEATURE_FB_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
xen/include/asm-x86/cpufeature.h +1 -0
@@ -137,6 +137,7 @@#define cpu_has_avx512_4fmaps boot_cpu_has(X86_FEATURE_AVX512_4FMAPS)#define cpu_has_avx512_vp2intersect boot_cpu_has(X86_FEATURE_AVX512_VP2INTERSECT)#define cpu_has_srbds_ctrl boot_cpu_has(X86_FEATURE_SRBDS_CTRL) +#define cpu_has_md_clear boot_cpu_has(X86_FEATURE_MD_CLEAR)#define cpu_has_rtm_always_abort boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)#define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE)
xen/include/public/arch-x86/cpufeatureset.h +2 -2
@@ -273,7 +273,7 @@ XEN_CPUFEATURE(AVX512_4VNNIW, 9*32+ 2) /*A AVX512 Neural Network Instructions * XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A AVX512 Multiply Accumulation Single Precision */ XEN_CPUFEATURE(AVX512_VP2INTERSECT, 9*32+8) /*a VP2INTERSECT{D,Q} insns */ XEN_CPUFEATURE(SRBDS_CTRL, 9*32+ 9) /* MSR_MCU_OPT_CTRL and RNGDS_MITG_DIS. */ -XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*A VERW clears microarchitectural buffers */ +XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*!A VERW clears microarchitectural buffers */ XEN_CPUFEATURE(RTM_ALWAYS_ABORT, 9*32+11) /*! June 2021 TSX defeaturing in microcode. */ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */XEN_CPUFEATURE (SERIALIZE ,9 *32 +14 )/*a SERIALIZE insn */
@@ -322,7 +322,7 @@ XEN_CPUFEATURE(DOITM, 16*32+12) /* Data Operand Invariant Timing XEN_CPUFEATURE(SBDR_SSDP_NO, 16*32+13) /*A No Shared Buffer Data Read or Sideband Stale Data Propagation */ XEN_CPUFEATURE(FBSDP_NO, 16*32+14) /*A No Fill Buffer Stale Data Propagation */ XEN_CPUFEATURE(PSDP_NO, 16*32+15) /*A No Primary Stale Data Propagation */ -XEN_CPUFEATURE(FB_CLEAR, 16*32+17) /*A Fill Buffers cleared by VERW */ +XEN_CPUFEATURE(FB_CLEAR, 16*32+17) /*!A Fill Buffers cleared by VERW */ XEN_CPUFEATURE(FB_CLEAR_CTRL, 16*32+18) /* MSR_OPT_CPU_CTRL.FB_CLEAR_DIS */ XEN_CPUFEATURE(RRSBA, 16*32+19) /*! Restricted RSB Alternative */XEN_CPUFEATURE (BHI_NO ,16 *32 +20 )/*A No Branch History Injection */
From: Andrew Cooper <[email protected]>
Subject: x86/vmx: Perform VERW flushing later in the VMExit path
Broken out of the following patch because this change is subtle enough on its own. See it for the rational of why we're moving VERW.
As for how, extend the trick already used to hold one condition in flags (RESUME vs LAUNCH) through the POPing of GPRs.
Move the MOV CR earlier. Intel specify flags to be undefined across it.
Encode the two conditions we want using SF and PF. See the code comment for exactly how.
Leave a comment to explain the lack of any content around SPEC_CTRL_EXIT_TO_VMX, but leave the block in place. Sods law says if we delete it, we'll need to reintroduce it.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/hvm/vmx/entry.S +32 -4
@@ -87,17 +87,39 @@ UNLIKELY_END(realmode) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* SPEC_CTRL_EXIT_TO_VMX Req: %rsp=regs/cpuinfo Clob: */ - DO_SPEC_CTRL_COND_VERW + /* + * All speculation safety work happens to be elsewhere. VERW is after + * popping the GPRs, while restoring the guest MSR_SPEC_CTRL is left + * to the MSR load list. + */ mov VCPU_hvm_guest_cr2(%rbx),%rax + mov %rax, %cr2 + + /* + * We need to perform two conditional actions (VERW, and Resume vs + * Launch) after popping GPRs. With some cunning, we can encode both + * of these in eflags together. + * + * Parity is only calculated over the bottom byte of the answer, while + * Sign is simply the top bit. + * + * Therefore, the final OR instruction ends up producing: + * SF = VCPU_vmx_launched + * PF = !SCF_verw + */ + BUILD_BUG_ON(SCF_verw & ~0xff) + movzbl VCPU_vmx_launched(%rbx), %ecx + shl $31, %ecx + movzbl CPUINFO_spec_ctrl_flags(%rsp), %eax + and $SCF_verw, %eax + or %eax, %ecx pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp - mov %rax,%cr2 - cmpb $0,VCPU_vmx_launched(%rbx) pop %rbx pop %r11 pop %r10
@@ -108,7 +130,13 @@ UNLIKELY_END(realmode) pop %rdx pop %rsi pop %rdi - je .Lvmx_launch + + jpe .L_skip_verw + /* VERW clobbers ZF, but preserves all others, including SF. */ + verw STK_REL(CPUINFO_verw_sel, CPUINFO_error_code)(%rsp) +.L_skip_verw: + + jns .Lvmx_launch /*.Lvmx_resume:*/ VMRESUME
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -133,6 +133,7 @@ void __dummy__(void)#endif OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); + OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu); OFFSET(CPUINFO_per_cpu_offset, struct cpu_info, per_cpu_offset);
xen/include/asm-x86/asm_defns.h +8 -0
@@ -81,6 +81,14 @@ register unsigned long current_stack_pointer asm("rsp");#ifdef __ASSEMBLY__ +.macro BUILD_BUG_ON condstr, cond:vararg + .if \cond + .error "Condition \"\condstr\" not satisfied" + .endif +.endm +/* preprocessor macro to make error message more user friendly */ +#define BUILD_BUG_ON (cond) BUILD_BUG_ON #cond, cond +#ifdef HAVE_AS_QUOTED_SYM #define SUBSECTION_LBL (tag) \ .ifndef .L.tag; \
xen/include/asm-x86/spec_ctrl_asm.h +7 -0
@@ -164,6 +164,13 @@#endif .endm +/* +* Helper to improve the readibility of stack dispacements with %rsp in +* unusual positions. Both @field and @top_of_stack should be constants from +* the same object. @top_of_stack should be where %rsp is currently pointing. + */ +#define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) + .macro DO_SPEC_CTRL_COND_VERW/* * Requires %rsp=cpuinfo
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Perform VERW flushing later in exit paths
On parts vulnerable to RFDS, VERW's side effects are extended to scrub all non-architectural entries in various Physical Register Files. To remove all of Xen's values, the VERW must be after popping the GPRs.
Rework SPEC_CTRL_COND_VERW to default to an CPUINFO_error_code %rsp position, but with overrides for other contexts. Identify that it clobbers eflags; this is particularly relevant for the SYSRET path.
For the IST exit return to Xen, have the main SPEC_CTRL_EXIT_TO_XEN put a shadow copy of spec_ctrl_flags, as GPRs can't be used at the point we want to issue the VERW.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/x86_64/asm-offsets.c +11 -2
@@ -55,14 +55,22 @@ void __dummy__(void)* EFRAME_* is for the entry/exit logic where %rsp is pointing at * UREGS_error_code and GPRs are still/already guest values. */ -#define OFFSET_EF (sym, mem) \ +#define OFFSET_EF (sym, mem, ...) \ DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ - offsetof(struct cpu_user_regs, error_code)) + offsetof(struct cpu_user_regs, error_code) __VA_ARGS__)OFFSET_EF (EFRAME_entry_vector, entry_vector);OFFSET_EF (EFRAME_rip, rip);OFFSET_EF (EFRAME_cs, cs);OFFSET_EF (EFRAME_eflags, eflags); + +/* +* These aren't real fields. They're spare space, used by the IST +* exit-to-xen path. +*/ +OFFSET_EF (EFRAME_shadow_scf, eflags,+4 ); +OFFSET_EF (EFRAME_shadow_sel, eflags,+6 ); +OFFSET_EF (EFRAME_rsp, rsp);BLANK ();
@@ -134,6 +142,7 @@ void __dummy__(void) OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); + OFFSET(CPUINFO_rip, struct cpu_info, guest_cpu_user_regs.rip); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu); OFFSET(CPUINFO_per_cpu_offset, struct cpu_info, per_cpu_offset);
xen/arch/x86/x86_64/compat/entry.S +6 -0
@@ -165,6 +165,12 @@ ENTRY(compat_restore_all_guest) SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ RESTORE_ALL adj=8 compat=1 + + /* Account for ev/ec having already been popped off the stack. */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_rip), \ + sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception)
xen/arch/x86/x86_64/entry.S +20 -1
@@ -214,6 +214,9 @@ restore_all_guest: #endif mov EFRAME_rip(%rsp), %rcx + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + cmpw $FLAT_USER_CS32, EFRAME_cs(%rsp) mov EFRAME_rsp(%rsp), %rsp je 1f
@@ -227,6 +230,9 @@ restore_all_guest: iret_exit_to_guest: andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), EFRAME_eflags(%rsp) orl $X86_EFLAGS_IF, EFRAME_eflags(%rsp) + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + addq $8,%rsp .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception)
@@ -613,9 +619,22 @@ UNLIKELY_START(ne, exit_cr3) UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end, Clob: abcd */ + SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ RESTORE_ALL adj=8 + + /* + * When the CPU pushed this exception frame, it zero-extended eflags. + * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of + * spec_ctrl_flags and ver_sel above eflags, as we can't use any GPRs, + * and we're at a random place on the stack, not in a CPUFINFO block. + * + * Account for ev/ec having already been popped off the stack. + */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ + sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + iretq ENTRY(common_interrupt)
xen/include/asm-x86/spec_ctrl_asm.h +24 -12
@@ -171,16 +171,23 @@*/ #define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) -.macro DO_SPEC_CTRL_COND_VERW +.macro SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_error_code), \ + sel=STK_REL (CPUINFO_verw_sel, CPUINFO_error_code)/* -* Requires %rsp=cpuinfo +* Requires \scf and \sel as %rsp-relative expressions +* Clobbers eflags +* +* VERW needs to run after guest GPRs have been restored, where only %rsp is +* good to use. Default to expecting %rsp pointing at CPUINFO_error_code. +* Contexts where this is not true must provide an alternative \scf and \sel. * * Issue a VERW for its flushing side effect, if indicated. This is a Spectre * v1 gadget, but the IRET/VMEntry is serialising. */ - testb $SCF_verw, CPUINFO_spec_ctrl_flags(%rsp) + testb $SCF_verw, \scf(%rsp) jz .L\@_verw_skip - verw CPUINFO_verw_sel(%rsp) + verw \sel(%rsp) .L\@_verw_skip: .endm
@@ -298,8 +305,6 @@*/ ALTERNATIVE "", DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR_PV - DO_SPEC_CTRL_COND_VERW -ALTERNATIVE "" ,DO_SPEC_CTRL_DIV ,X86_FEATURE_SC_DIV .endm
@@ -379,7 +384,7 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise):*/ .macro SPEC_CTRL_EXIT_TO_XEN/* -* Requires %r12=ist_exit, %r14=stack_end +* Requires %r12=ist_exit, %r14=stack_end, %rsp=regs * Clobbers %rax, %rbx, %rcx, %rdx */ movzbl STACK_CPUINFO_FIELD(spec_ctrl_flags)(%r14), %ebx
@@ -407,11 +412,18 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise): test %r12, %r12 jz .L\@_skip_ist_exit - /* Logically DO_SPEC_CTRL_COND_VERW but without the %rsp=cpuinfo dependency */ - testb $SCF_verw, %bl - jz .L\@_skip_verw - verw STACK_CPUINFO_FIELD(verw_sel)(%r14) -.L\@_skip_verw: +/* +* Stash SCF and verw_sel above eflags in the case of an IST_exit. The +* VERW logic needs to run after guest GPRs have been restored; i.e. where +* we cannot use %r12 or %r14 for the purposes they have here. +* +* When the CPU pushed this exception frame, it zero-extended eflags. +* Therefore it is safe for the VERW logic to look at the stashed SCF +* outside of the ist_exit condition. Also, this stashing won't influence +* any other restore_all_guest() paths. +*/ + or $(__HYPERVISOR_DS32 << 16), %ebx + mov %ebx, UREGS_eflags + 4(%rsp) /* EFRAME_shadow_scf/sel */ ALTERNATIVE "", DO_SPEC_CTRL_DIV, X86_FEATURE_SC_DIV
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Rename VERW related options
VERW is going to be used for a 3rd purpose, and the existing nomenclature didn't survive the Stale MMIO issues terribly well.
Rename the command line option from md-clear= to verw=. This is more consistent with other options which tend to be named based on what they're doing, not which feature enumeration they use behind the scenes. Retain md-clear= as a deprecated alias.
Rename opt_md_clear_{pv,hvm} and opt_fb_clear_mmio to opt_verw_{pv,hvm,mmio}, which has a side effect of making spec_ctrl_init_domain() rather clearer to follow.
No functional change.
This is part of XSA-452 / CVE-2023-28746.
docs/misc/xen-command-line.pandoc +8 -7
@@ -2186,7 +2186,7 @@ By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm}=<bool>, -> {msr-sc,rsb,md-clear,ibpb-entry}=<bool>|{pv,hvm}=<bool>, +> {msr-sc,rsb,verw,ibpb-entry}=<bool>|{pv,hvm}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd,psfd, > eager-fpu,l1d-flush,branch-harden,srb-lock, > unpriv-mmio,gds-mit,div-scrub}=<bool> ]`
@@ -2211,7 +2211,7 @@ in place for guests to use. Use of a positive boolean value for either of these options is invalid. -The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `md-clear=` and `ibpb-entry=` options +The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `verw=` and `ibpb-entry=` options offer fine grained control over the primitives by Xen. These impact Xen's ability to protect itself, and/or Xen's ability to virtualise support for guests to use.
@@ -2228,11 +2228,12 @@ guests to use. guests and if disabled, guests will be unable to use IBRS/STIBP/SSBD/etc. * `rsb=` offers control over whether to overwrite the Return Stack Buffer / Return Address Stack on entry to Xen. -* `md-clear=` offers control over whether to use VERW to flush - microarchitectural buffers on idle and exit from Xen. *Note: For - compatibility with development versions of this fix, `mds=` is also accepted - on Xen 4.12 and earlier as an alias. Consult vendor documentation in - preference to here.* +* `verw=` offers control over whether to use VERW for its scrubbing side + effects at appropriate privilege transitions. The exact side effects are + microarchitecture and microcode specific. *Note: `md-clear=` is accepted as + a deprecated alias. For compatibility with development versions of XSA-297, + `mds=` is also accepted on Xen 4.12 and earlier as an alias. Consult vendor + documentation in preference to here.* * `ibpb-entry=` offers control over whether IBPB (Indirect Branch Prediction Barrier) is used on entry to Xen. This is used by default on hardware vulnerable to Branch Type Confusion, and hardware vulnerable to Speculative
xen/arch/x86/spec_ctrl.c +32 -30
159 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: VERW-handling adjustments
... before we add yet more complexity to this logic. Mostly expanded comments, but with three minor changes.
1) Introduce cpu_has_useful_md_clear to simplify later logic in this patch and future ones.
2) We only ever need SC_VERW_IDLE when SMT is active. If SMT isn't active, then there's no re-partition of pipeline resources based on thread-idleness to worry about.
3) The logic to adjust HVM VERW based on L1D_FLUSH is unmaintainable and, as it turns out, wrong. SKIP_L1DFL is just a hint bit, whereas opt_l1d_flush is the relevant decision of whether to use L1D_FLUSH based on susceptibility and user preference.
Rewrite the logic so it can be followed, and incorporate the fact that when FB_CLEAR is visible, L1D_FLUSH isn't a safe substitution.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +73 -26
130 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Mitigation Register File Data Sampling
RFDS affects Atom cores, also branded E-cores, between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid clien systems which have a mix of Gracemont and other types of cores.
Two new bits have been defined; RFDS_CLEAR to indicate VERW has more side effets, and RFDS_NO to incidate that the system is unaffected. Plenty of unaffected CPUs won't be getting RFDS_NO retrofitted in microcode, so we synthesise it. Alder Lake and Raptor Lake Xeon-E's are unaffected due to their platform configuration, and we must use the Hybrid CPUID bit to distinguish them from their non-Xeon counterparts.
Like MD_CLEAR and FB_CLEAR, RFDS_CLEAR needs OR-ing across a resource pool, so set it in the max policies and reflect the host setting in default.
This is part of XSA-452 / CVE-2023-28746.
tools/misc/xen-cpuid.c +3 -2
@@ -169,7 +169,7 @@ static const char *const str_7d0[32] = [ 8] = "avx512-vp2intersect", [ 9] = "srbds-ctrl", [10] = "md-clear", [11] = "rtm-always-abort", /* 12 */ [13] = "tsx-force-abort", - [14] = "serialize", + [14] = "serialize", [15] = "hybrid", [16] = "tsxldtrk", [18] = "pconfig", [20] = "cet-ibt",
@@ -224,7 +224,8 @@ static const char *const str_m10Al[32] = [20] = "bhi-no", [21] = "xapic-status", /* 22 */ [23] = "ovrclk-status", [24] = "pbrsb-no", [25] = "gds-ctrl", - [26] = "gds-no", + [26] = "gds-no", [27] = "rfds-no", + [28] = "rfds-clear", }; static const char *const str_m10Ah[32] =
xen/arch/x86/cpu-policy.c +5 -0
@@ -443,6 +443,7 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)*/ __set_bit (X86_FEATURE_MD_CLEAR , fs);__set_bit (X86_FEATURE_FB_CLEAR , fs); +__set_bit (X86_FEATURE_RFDS_CLEAR , fs);/* * The Gather Data Sampling microcode mitigation (August 2023) has an
@@ -492,6 +493,10 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)if ( cpu_has_fb_clear )__set_bit (X86_FEATURE_FB_CLEAR , fs); +__clear_bit (X86_FEATURE_RFDS_CLEAR , fs); +if ( cpu_has_rfds_clear ) +__set_bit (X86_FEATURE_RFDS_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
xen/arch/x86/spec_ctrl.c +94 -5
162 lines not on this page · raw message
xen/include/asm-x86/cpufeature.h +3 -0
@@ -141,6 +141,7 @@#define cpu_has_rtm_always_abort boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)#define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE) +#define cpu_has_hybrid boot_cpu_has(X86_FEATURE_HYBRID)#define cpu_has_arch_caps boot_cpu_has(X86_FEATURE_ARCH_CAPS)/* CPUID level 0x00000007:1.eax */
@@ -160,6 +161,8 @@#define cpu_has_rrsba boot_cpu_has(X86_FEATURE_RRSBA)#define cpu_has_gds_ctrl boot_cpu_has(X86_FEATURE_GDS_CTRL)#define cpu_has_gds_no boot_cpu_has(X86_FEATURE_GDS_NO) +#define cpu_has_rfds_no boot_cpu_has(X86_FEATURE_RFDS_NO) +#define cpu_has_rfds_clear boot_cpu_has(X86_FEATURE_RFDS_CLEAR)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/include/asm-x86/msr-index.h +2 -0
@@ -70,6 +70,8 @@#define ARCH_CAPS_PBRSB_NO (_AC(1, ULL) << 24)#define ARCH_CAPS_GDS_CTRL (_AC(1, ULL) << 25)#define ARCH_CAPS_GDS_NO (_AC(1, ULL) << 26) +#define ARCH_CAPS_RFDS_NO (_AC(1, ULL) << 27) +#define ARCH_CAPS_RFDS_CLEAR (_AC(1, ULL) << 28)#define MSR_FLUSH_CMD 0x0000010b#define FLUSH_CMD_L1D (_AC(1, ULL) << 0)
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -277,6 +277,7 @@ XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*!A VERW clears microarchitectural buffe XEN_CPUFEATURE(RTM_ALWAYS_ABORT, 9*32+11) /*! June 2021 TSX defeaturing in microcode. */ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */ XEN_CPUFEATURE(SERIALIZE, 9*32+14) /*a SERIALIZE insn */ +XEN_CPUFEATURE(HYBRID, 9*32+15) /* Heterogeneous platform */ XEN_CPUFEATURE(TSXLDTRK, 9*32+16) /*a TSX load tracking suspend/resume insns */ XEN_CPUFEATURE(CET_IBT, 9*32+20) /* CET - Indirect Branch Tracking */XEN_CPUFEATURE (IBRSB ,9 *32 +26 )/*A IBRS and IBPB support (used by Intel) */
@@ -331,6 +332,8 @@ XEN_CPUFEATURE(OVRCLK_STATUS, 16*32+23) /* MSR_OVERCLOCKING_STATUS */ XEN_CPUFEATURE(PBRSB_NO, 16*32+24) /*A No Post-Barrier RSB predictions */ XEN_CPUFEATURE(GDS_CTRL, 16*32+25) /* MCU_OPT_CTRL.GDS_MIT_{DIS,LOCK} */ XEN_CPUFEATURE(GDS_NO, 16*32+26) /*A No Gather Data Sampling */ +XEN_CPUFEATURE(RFDS_NO, 16*32+27) /*A No Register File Data Sampling */ +XEN_CPUFEATURE (RFDS_CLEAR ,16 *32 +28 )/*!A Register File(s) cleared by VERW */ /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */
From: Andrew Cooper <[email protected]>
Subject: x86/entry: Introduce EFRAME_* constants
restore_all_guest() does a lot of manipulation of the stack after popping the GPRs, and uses raw %rsp displacements to do so. Also, almost all entrypaths use raw %rsp displacements prior to pushing GPRs.
Provide better mnemonics, to aid readability and reduce the chance of errors when editing.
No functional change. The resulting binary is identical.
xen/arch/x86/x86_64/asm-offsets.c +17 -0
@@ -51,6 +51,23 @@ void __dummy__(void) OFFSET(UREGS_kernel_sizeof, struct cpu_user_regs, es);BLANK (); +/* +* EFRAME_* is for the entry/exit logic where %rsp is pointing at +* UREGS_error_code and GPRs are still/already guest values. +*/ +#define OFFSET_EF (sym, mem) \ + DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ + offsetof(struct cpu_user_regs, error_code)) + +OFFSET_EF (EFRAME_entry_vector, entry_vector); +OFFSET_EF (EFRAME_rip, rip); +OFFSET_EF (EFRAME_cs, cs); +OFFSET_EF (EFRAME_eflags, eflags); +OFFSET_EF (EFRAME_rsp, rsp); +BLANK (); + +#undef OFFSET_EF + OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info);
xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -15,7 +15,7 @@ ENTRY(entry_int82) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movl $HYPERCALL_VECTOR, 4(%rsp) + movl $HYPERCALL_VECTOR, EFRAME_entry_vector(%rsp) SAVE_ALL compat=1 /* DPL1 gate, restricted to 32bit PV guests only. */ SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=regs/cpuinfo, %rdx=0, Clob: acd */
xen/arch/x86/x86_64/entry.S +35 -35
230 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/cpu-policy: Allow for levelling of VERW side effects
MD_CLEAR and FB_CLEAR need OR-ing across a migrate pool. Allow this, by having them unconditinally set in max, with the host values reflected in default. Annotate the bits as having special properies.
xen/arch/x86/cpu-policy.c +24 -0
@@ -434,6 +434,16 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)__set_bit (X86_FEATURE_RSBA , fs);__set_bit (X86_FEATURE_RRSBA , fs); +/* +* These bits indicate that the VERW instruction may have gained +* scrubbing side effects. With pooling, they mean "you might migrate +* somewhere where scrubbing is necessary", and may need exposing on +* unaffected hardware. This is fine, because the VERW instruction +* has been around since the 286. +*/ +__set_bit (X86_FEATURE_MD_CLEAR , fs); +__set_bit (X86_FEATURE_FB_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
@@ -468,6 +478,20 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs) cpu_has_rdrand && !is_forced_cpu_cap(X86_FEATURE_RDRAND) )__clear_bit (X86_FEATURE_RDRAND , fs); +/* +* These bits indicate that the VERW instruction may have gained +* scrubbing side effects. The max policy has them set for migration +* reasons, so reset the default policy back to the host values in +* case we're unaffected. +*/ +__clear_bit (X86_FEATURE_MD_CLEAR , fs); +if ( cpu_has_md_clear ) +__set_bit (X86_FEATURE_MD_CLEAR , fs); + +__clear_bit (X86_FEATURE_FB_CLEAR , fs); +if ( cpu_has_fb_clear ) +__set_bit (X86_FEATURE_FB_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
xen/include/asm-x86/cpufeature.h +1 -0
@@ -134,6 +134,7 @@#define cpu_has_avx512_4fmaps boot_cpu_has(X86_FEATURE_AVX512_4FMAPS)#define cpu_has_avx512_vp2intersect boot_cpu_has(X86_FEATURE_AVX512_VP2INTERSECT)#define cpu_has_srbds_ctrl boot_cpu_has(X86_FEATURE_SRBDS_CTRL) +#define cpu_has_md_clear boot_cpu_has(X86_FEATURE_MD_CLEAR)#define cpu_has_rtm_always_abort boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)#define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE)
xen/include/public/arch-x86/cpufeatureset.h +2 -2
@@ -275,7 +275,7 @@ XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A AVX512 Multiply Accumulation Single XEN_CPUFEATURE(FSRM, 9*32+ 4) /*A Fast Short REP MOVS */ XEN_CPUFEATURE(AVX512_VP2INTERSECT, 9*32+8) /*a VP2INTERSECT{D,Q} insns */ XEN_CPUFEATURE(SRBDS_CTRL, 9*32+ 9) /* MSR_MCU_OPT_CTRL and RNGDS_MITG_DIS. */ -XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*A VERW clears microarchitectural buffers */ +XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*!A VERW clears microarchitectural buffers */ XEN_CPUFEATURE(RTM_ALWAYS_ABORT, 9*32+11) /*! June 2021 TSX defeaturing in microcode. */ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */XEN_CPUFEATURE (SERIALIZE ,9 *32 +14 )/*a SERIALIZE insn */
@@ -329,7 +329,7 @@ XEN_CPUFEATURE(DOITM, 16*32+12) /* Data Operand Invariant Timing XEN_CPUFEATURE(SBDR_SSDP_NO, 16*32+13) /*A No Shared Buffer Data Read or Sideband Stale Data Propagation */ XEN_CPUFEATURE(FBSDP_NO, 16*32+14) /*A No Fill Buffer Stale Data Propagation */ XEN_CPUFEATURE(PSDP_NO, 16*32+15) /*A No Primary Stale Data Propagation */ -XEN_CPUFEATURE(FB_CLEAR, 16*32+17) /*A Fill Buffers cleared by VERW */ +XEN_CPUFEATURE(FB_CLEAR, 16*32+17) /*!A Fill Buffers cleared by VERW */ XEN_CPUFEATURE(FB_CLEAR_CTRL, 16*32+18) /* MSR_OPT_CPU_CTRL.FB_CLEAR_DIS */ XEN_CPUFEATURE(RRSBA, 16*32+19) /*! Restricted RSB Alternative */XEN_CPUFEATURE (BHI_NO ,16 *32 +20 )/*A No Branch History Injection */
From: Andrew Cooper <[email protected]>
Subject: x86/vmx: Perform VERW flushing later in the VMExit path
Broken out of the following patch because this change is subtle enough on its own. See it for the rational of why we're moving VERW.
As for how, extend the trick already used to hold one condition in flags (RESUME vs LAUNCH) through the POPing of GPRs.
Move the MOV CR earlier. Intel specify flags to be undefined across it.
Encode the two conditions we want using SF and PF. See the code comment for exactly how.
Leave a comment to explain the lack of any content around SPEC_CTRL_EXIT_TO_VMX, but leave the block in place. Sods law says if we delete it, we'll need to reintroduce it.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/hvm/vmx/entry.S +32 -4
@@ -87,17 +87,39 @@ UNLIKELY_END(realmode) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* SPEC_CTRL_EXIT_TO_VMX Req: %rsp=regs/cpuinfo Clob: */ - DO_SPEC_CTRL_COND_VERW + /* + * All speculation safety work happens to be elsewhere. VERW is after + * popping the GPRs, while restoring the guest MSR_SPEC_CTRL is left + * to the MSR load list. + */ mov VCPU_hvm_guest_cr2(%rbx),%rax + mov %rax, %cr2 + + /* + * We need to perform two conditional actions (VERW, and Resume vs + * Launch) after popping GPRs. With some cunning, we can encode both + * of these in eflags together. + * + * Parity is only calculated over the bottom byte of the answer, while + * Sign is simply the top bit. + * + * Therefore, the final OR instruction ends up producing: + * SF = VCPU_vmx_launched + * PF = !SCF_verw + */ + BUILD_BUG_ON(SCF_verw & ~0xff) + movzbl VCPU_vmx_launched(%rbx), %ecx + shl $31, %ecx + movzbl CPUINFO_spec_ctrl_flags(%rsp), %eax + and $SCF_verw, %eax + or %eax, %ecx pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp - mov %rax,%cr2 - cmpb $0,VCPU_vmx_launched(%rbx) pop %rbx pop %r11 pop %r10
@@ -108,7 +130,13 @@ UNLIKELY_END(realmode) pop %rdx pop %rsi pop %rdi - je .Lvmx_launch + + jpe .L_skip_verw + /* VERW clobbers ZF, but preserves all others, including SF. */ + verw STK_REL(CPUINFO_verw_sel, CPUINFO_error_code)(%rsp) +.L_skip_verw: + + jns .Lvmx_launch /*.Lvmx_resume:*/ VMRESUME
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -135,6 +135,7 @@ void __dummy__(void)#endif OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); + OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu); OFFSET(CPUINFO_per_cpu_offset, struct cpu_info, per_cpu_offset);
xen/include/asm-x86/asm_defns.h +8 -0
@@ -81,6 +81,14 @@ register unsigned long current_stack_pointer asm("rsp");#ifdef __ASSEMBLY__ +.macro BUILD_BUG_ON condstr, cond:vararg + .if \cond + .error "Condition \"\condstr\" not satisfied" + .endif +.endm +/* preprocessor macro to make error message more user friendly */ +#define BUILD_BUG_ON (cond) BUILD_BUG_ON #cond, cond +#ifdef HAVE_AS_QUOTED_SYM #define SUBSECTION_LBL (tag) \ .ifndef .L.tag; \
xen/include/asm-x86/spec_ctrl_asm.h +7 -0
@@ -169,6 +169,13 @@#endif .endm +/* +* Helper to improve the readibility of stack dispacements with %rsp in +* unusual positions. Both @field and @top_of_stack should be constants from +* the same object. @top_of_stack should be where %rsp is currently pointing. + */ +#define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) + .macro DO_SPEC_CTRL_COND_VERW/* * Requires %rsp=cpuinfo
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Perform VERW flushing later in exit paths
On parts vulnerable to RFDS, VERW's side effects are extended to scrub all non-architectural entries in various Physical Register Files. To remove all of Xen's values, the VERW must be after popping the GPRs.
Rework SPEC_CTRL_COND_VERW to default to an CPUINFO_error_code %rsp position, but with overrides for other contexts. Identify that it clobbers eflags; this is particularly relevant for the SYSRET path.
For the IST exit return to Xen, have the main SPEC_CTRL_EXIT_TO_XEN put a shadow copy of spec_ctrl_flags, as GPRs can't be used at the point we want to issue the VERW.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/x86_64/asm-offsets.c +11 -2
@@ -55,14 +55,22 @@ void __dummy__(void)* EFRAME_* is for the entry/exit logic where %rsp is pointing at * UREGS_error_code and GPRs are still/already guest values. */ -#define OFFSET_EF (sym, mem) \ +#define OFFSET_EF (sym, mem, ...) \ DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ - offsetof(struct cpu_user_regs, error_code)) + offsetof(struct cpu_user_regs, error_code) __VA_ARGS__)OFFSET_EF (EFRAME_entry_vector, entry_vector);OFFSET_EF (EFRAME_rip, rip);OFFSET_EF (EFRAME_cs, cs);OFFSET_EF (EFRAME_eflags, eflags); + +/* +* These aren't real fields. They're spare space, used by the IST +* exit-to-xen path. +*/ +OFFSET_EF (EFRAME_shadow_scf, eflags,+4 ); +OFFSET_EF (EFRAME_shadow_sel, eflags,+6 ); +OFFSET_EF (EFRAME_rsp, rsp);BLANK ();
@@ -136,6 +144,7 @@ void __dummy__(void) OFFSET(CPUINFO_guest_cpu_user_regs, struct cpu_info, guest_cpu_user_regs); OFFSET(CPUINFO_error_code, struct cpu_info, guest_cpu_user_regs.error_code); + OFFSET(CPUINFO_rip, struct cpu_info, guest_cpu_user_regs.rip); OFFSET(CPUINFO_verw_sel, struct cpu_info, verw_sel); OFFSET(CPUINFO_current_vcpu, struct cpu_info, current_vcpu); OFFSET(CPUINFO_per_cpu_offset, struct cpu_info, per_cpu_offset);
xen/arch/x86/x86_64/compat/entry.S +6 -0
@@ -161,6 +161,12 @@ ENTRY(compat_restore_all_guest) SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ RESTORE_ALL adj=8 compat=1 + + /* Account for ev/ec having already been popped off the stack. */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_rip), \ + sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception)
xen/arch/x86/x86_64/entry.S +20 -1
@@ -214,6 +214,9 @@ restore_all_guest: #endif mov EFRAME_rip(%rsp), %rcx + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + cmpw $FLAT_USER_CS32, EFRAME_cs(%rsp) mov EFRAME_rsp(%rsp), %rsp je 1f
@@ -227,6 +230,9 @@ restore_all_guest: iret_exit_to_guest: andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), EFRAME_eflags(%rsp) orl $X86_EFLAGS_IF, EFRAME_eflags(%rsp) + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + addq $8,%rsp .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception)
@@ -670,9 +676,22 @@ UNLIKELY_START(ne, exit_cr3) UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end, Clob: abcd */ + SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ RESTORE_ALL adj=8 + + /* + * When the CPU pushed this exception frame, it zero-extended eflags. + * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of + * spec_ctrl_flags and ver_sel above eflags, as we can't use any GPRs, + * and we're at a random place on the stack, not in a CPUFINFO block. + * + * Account for ev/ec having already been popped off the stack. + */ + SPEC_CTRL_COND_VERW \ + scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ + sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + iretq ENTRY(common_interrupt)
xen/include/asm-x86/spec_ctrl_asm.h +24 -12
@@ -176,16 +176,23 @@*/ #define STK_REL (field, top_of_stk) ((field) - (top_of_stk)) -.macro DO_SPEC_CTRL_COND_VERW +.macro SPEC_CTRL_COND_VERW \ + scf=STK_REL(CPUINFO_spec_ctrl_flags, CPUINFO_error_code), \ + sel=STK_REL (CPUINFO_verw_sel, CPUINFO_error_code)/* -* Requires %rsp=cpuinfo +* Requires \scf and \sel as %rsp-relative expressions +* Clobbers eflags +* +* VERW needs to run after guest GPRs have been restored, where only %rsp is +* good to use. Default to expecting %rsp pointing at CPUINFO_error_code. +* Contexts where this is not true must provide an alternative \scf and \sel. * * Issue a VERW for its flushing side effect, if indicated. This is a Spectre * v1 gadget, but the IRET/VMEntry is serialising. */ - testb $SCF_verw, CPUINFO_spec_ctrl_flags(%rsp) + testb $SCF_verw, \scf(%rsp) jz .L\@_verw_skip - verw CPUINFO_verw_sel(%rsp) + verw \sel(%rsp) .L\@_verw_skip: .endm
@@ -303,8 +310,6 @@*/ ALTERNATIVE "", DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR_PV - DO_SPEC_CTRL_COND_VERW -ALTERNATIVE "" ,DO_SPEC_CTRL_DIV ,X86_FEATURE_SC_DIV .endm
@@ -384,7 +389,7 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise):*/ .macro SPEC_CTRL_EXIT_TO_XEN/* -* Requires %r12=ist_exit, %r14=stack_end +* Requires %r12=ist_exit, %r14=stack_end, %rsp=regs * Clobbers %rax, %rbx, %rcx, %rdx */ movzbl STACK_CPUINFO_FIELD(spec_ctrl_flags)(%r14), %ebx
@@ -412,11 +417,18 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise): test %r12, %r12 jz .L\@_skip_ist_exit - /* Logically DO_SPEC_CTRL_COND_VERW but without the %rsp=cpuinfo dependency */ - testb $SCF_verw, %bl - jz .L\@_skip_verw - verw STACK_CPUINFO_FIELD(verw_sel)(%r14) -.L\@_skip_verw: +/* +* Stash SCF and verw_sel above eflags in the case of an IST_exit. The +* VERW logic needs to run after guest GPRs have been restored; i.e. where +* we cannot use %r12 or %r14 for the purposes they have here. +* +* When the CPU pushed this exception frame, it zero-extended eflags. +* Therefore it is safe for the VERW logic to look at the stashed SCF +* outside of the ist_exit condition. Also, this stashing won't influence +* any other restore_all_guest() paths. +*/ + or $(__HYPERVISOR_DS32 << 16), %ebx + mov %ebx, UREGS_eflags + 4(%rsp) /* EFRAME_shadow_scf/sel */ ALTERNATIVE "", DO_SPEC_CTRL_DIV, X86_FEATURE_SC_DIV
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Rename VERW related options
VERW is going to be used for a 3rd purpose, and the existing nomenclature didn't survive the Stale MMIO issues terribly well.
Rename the command line option from md-clear= to verw=. This is more consistent with other options which tend to be named based on what they're doing, not which feature enumeration they use behind the scenes. Retain md-clear= as a deprecated alias.
Rename opt_md_clear_{pv,hvm} and opt_fb_clear_mmio to opt_verw_{pv,hvm,mmio}, which has a side effect of making spec_ctrl_init_domain() rather clearer to follow.
No functional change.
This is part of XSA-452 / CVE-2023-28746.
docs/misc/xen-command-line.pandoc +8 -7
@@ -2260,7 +2260,7 @@ By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm}=<bool>, -> {msr-sc,rsb,md-clear,ibpb-entry}=<bool>|{pv,hvm}=<bool>, +> {msr-sc,rsb,verw,ibpb-entry}=<bool>|{pv,hvm}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd,psfd, > eager-fpu,l1d-flush,branch-harden,srb-lock, > unpriv-mmio,gds-mit,div-scrub}=<bool> ]`
@@ -2285,7 +2285,7 @@ in place for guests to use. Use of a positive boolean value for either of these options is invalid. -The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `md-clear=` and `ibpb-entry=` options +The `pv=`, `hvm=`, `msr-sc=`, `rsb=`, `verw=` and `ibpb-entry=` options offer fine grained control over the primitives by Xen. These impact Xen's ability to protect itself, and/or Xen's ability to virtualise support for guests to use.
@@ -2302,11 +2302,12 @@ guests to use. guests and if disabled, guests will be unable to use IBRS/STIBP/SSBD/etc. * `rsb=` offers control over whether to overwrite the Return Stack Buffer / Return Address Stack on entry to Xen and on idle. -* `md-clear=` offers control over whether to use VERW to flush - microarchitectural buffers on idle and exit from Xen. *Note: For - compatibility with development versions of this fix, `mds=` is also accepted - on Xen 4.12 and earlier as an alias. Consult vendor documentation in - preference to here.* +* `verw=` offers control over whether to use VERW for its scrubbing side + effects at appropriate privilege transitions. The exact side effects are + microarchitecture and microcode specific. *Note: `md-clear=` is accepted as + a deprecated alias. For compatibility with development versions of XSA-297, + `mds=` is also accepted on Xen 4.12 and earlier as an alias. Consult vendor + documentation in preference to here.* * `ibpb-entry=` offers control over whether IBPB (Indirect Branch Prediction Barrier) is used on entry to Xen. This is used by default on hardware vulnerable to Branch Type Confusion, and hardware vulnerable to Speculative
xen/arch/x86/spec_ctrl.c +32 -30
159 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: VERW-handling adjustments
... before we add yet more complexity to this logic. Mostly expanded comments, but with three minor changes.
1) Introduce cpu_has_useful_md_clear to simplify later logic in this patch and future ones.
2) We only ever need SC_VERW_IDLE when SMT is active. If SMT isn't active, then there's no re-partition of pipeline resources based on thread-idleness to worry about.
3) The logic to adjust HVM VERW based on L1D_FLUSH is unmaintainable and, as it turns out, wrong. SKIP_L1DFL is just a hint bit, whereas opt_l1d_flush is the relevant decision of whether to use L1D_FLUSH based on susceptibility and user preference.
Rewrite the logic so it can be followed, and incorporate the fact that when FB_CLEAR is visible, L1D_FLUSH isn't a safe substitution.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +73 -26
130 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Mitigation Register File Data Sampling
RFDS affects Atom cores, also branded E-cores, between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid clien systems which have a mix of Gracemont and other types of cores.
Two new bits have been defined; RFDS_CLEAR to indicate VERW has more side effets, and RFDS_NO to incidate that the system is unaffected. Plenty of unaffected CPUs won't be getting RFDS_NO retrofitted in microcode, so we synthesise it. Alder Lake and Raptor Lake Xeon-E's are unaffected due to their platform configuration, and we must use the Hybrid CPUID bit to distinguish them from their non-Xeon counterparts.
Like MD_CLEAR and FB_CLEAR, RFDS_CLEAR needs OR-ing across a resource pool, so set it in the max policies and reflect the host setting in default.
This is part of XSA-452 / CVE-2023-28746.
tools/misc/xen-cpuid.c +3 -2
@@ -170,7 +170,7 @@ static const char *const str_7d0[32] = [ 8] = "avx512-vp2intersect", [ 9] = "srbds-ctrl", [10] = "md-clear", [11] = "rtm-always-abort", /* 12 */ [13] = "tsx-force-abort", - [14] = "serialize", + [14] = "serialize", [15] = "hybrid", [16] = "tsxldtrk", [18] = "pconfig", [20] = "cet-ibt",
@@ -230,7 +230,8 @@ static const char *const str_m10Al[32] = [20] = "bhi-no", [21] = "xapic-status", /* 22 */ [23] = "ovrclk-status", [24] = "pbrsb-no", [25] = "gds-ctrl", - [26] = "gds-no", + [26] = "gds-no", [27] = "rfds-no", + [28] = "rfds-clear", }; static const char *const str_m10Ah[32] =
xen/arch/x86/cpu-policy.c +5 -0
@@ -443,6 +443,7 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)*/ __set_bit (X86_FEATURE_MD_CLEAR , fs);__set_bit (X86_FEATURE_FB_CLEAR , fs); +__set_bit (X86_FEATURE_RFDS_CLEAR , fs);/* * The Gather Data Sampling microcode mitigation (August 2023) has an
@@ -492,6 +493,10 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)if ( cpu_has_fb_clear )__set_bit (X86_FEATURE_FB_CLEAR , fs); +__clear_bit (X86_FEATURE_RFDS_CLEAR , fs); +if ( cpu_has_rfds_clear ) +__set_bit (X86_FEATURE_RFDS_CLEAR , fs); +/* * The Gather Data Sampling microcode mitigation (August 2023) has an * adverse performance impact on the CLWB instruction on SKX/CLX/CPX.
xen/arch/x86/spec_ctrl.c +94 -5
162 lines not on this page · raw message
xen/include/asm-x86/cpufeature.h +3 -0
@@ -138,6 +138,7 @@#define cpu_has_rtm_always_abort boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)#define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE) +#define cpu_has_hybrid boot_cpu_has(X86_FEATURE_HYBRID)#define cpu_has_arch_caps boot_cpu_has(X86_FEATURE_ARCH_CAPS)/* CPUID level 0x00000007:1.eax */
@@ -157,6 +158,8 @@#define cpu_has_rrsba boot_cpu_has(X86_FEATURE_RRSBA)#define cpu_has_gds_ctrl boot_cpu_has(X86_FEATURE_GDS_CTRL)#define cpu_has_gds_no boot_cpu_has(X86_FEATURE_GDS_NO) +#define cpu_has_rfds_no boot_cpu_has(X86_FEATURE_RFDS_NO) +#define cpu_has_rfds_clear boot_cpu_has(X86_FEATURE_RFDS_CLEAR)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/include/asm-x86/msr-index.h +2 -0
@@ -77,6 +77,8 @@#define ARCH_CAPS_PBRSB_NO (_AC(1, ULL) << 24)#define ARCH_CAPS_GDS_CTRL (_AC(1, ULL) << 25)#define ARCH_CAPS_GDS_NO (_AC(1, ULL) << 26) +#define ARCH_CAPS_RFDS_NO (_AC(1, ULL) << 27) +#define ARCH_CAPS_RFDS_CLEAR (_AC(1, ULL) << 28)#define MSR_FLUSH_CMD 0x0000010b#define FLUSH_CMD_L1D (_AC(1, ULL) << 0)
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -279,6 +279,7 @@ XEN_CPUFEATURE(MD_CLEAR, 9*32+10) /*!A VERW clears microarchitectural buffe XEN_CPUFEATURE(RTM_ALWAYS_ABORT, 9*32+11) /*! June 2021 TSX defeaturing in microcode. */ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */ XEN_CPUFEATURE(SERIALIZE, 9*32+14) /*a SERIALIZE insn */ +XEN_CPUFEATURE(HYBRID, 9*32+15) /* Heterogeneous platform */ XEN_CPUFEATURE(TSXLDTRK, 9*32+16) /*a TSX load tracking suspend/resume insns */ XEN_CPUFEATURE(CET_IBT, 9*32+20) /* CET - Indirect Branch Tracking */XEN_CPUFEATURE (IBRSB ,9 *32 +26 )/*A IBRS and IBPB support (used by Intel) */
@@ -338,6 +339,8 @@ XEN_CPUFEATURE(OVRCLK_STATUS, 16*32+23) /* MSR_OVERCLOCKING_STATUS */ XEN_CPUFEATURE(PBRSB_NO, 16*32+24) /*A No Post-Barrier RSB predictions */ XEN_CPUFEATURE(GDS_CTRL, 16*32+25) /* MCU_OPT_CTRL.GDS_MIT_{DIS,LOCK} */ XEN_CPUFEATURE(GDS_NO, 16*32+26) /*A No Gather Data Sampling */ +XEN_CPUFEATURE(RFDS_NO, 16*32+27) /*A No Register File Data Sampling */ +XEN_CPUFEATURE (RFDS_CLEAR ,16 *32 +28 )/*!A Register File(s) cleared by VERW */ /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */
From: Andrew Cooper <[email protected]>
Subject: x86/entry: Introduce EFRAME_* constants
restore_all_guest() does a lot of manipulation of the stack after popping the GPRs, and uses raw %rsp displacements to do so. Also, almost all entrypaths use raw %rsp displacements prior to pushing GPRs.
Provide better mnemonics, to aid readability and reduce the chance of errors when editing.
No functional change. The resulting binary is identical.
xen/arch/x86/x86_64/asm-offsets.c +17 -0
@@ -51,6 +51,23 @@ void __dummy__(void) OFFSET(UREGS_kernel_sizeof, struct cpu_user_regs, es);BLANK (); +/* +* EFRAME_* is for the entry/exit logic where %rsp is pointing at +* UREGS_error_code and GPRs are still/already guest values. +*/ +#define OFFSET_EF (sym, mem) \ + DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ + offsetof(struct cpu_user_regs, error_code)) + +OFFSET_EF (EFRAME_entry_vector, entry_vector); +OFFSET_EF (EFRAME_rip, rip); +OFFSET_EF (EFRAME_cs, cs); +OFFSET_EF (EFRAME_eflags, eflags); +OFFSET_EF (EFRAME_rsp, rsp); +BLANK (); + +#undef OFFSET_EF + OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info);
xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -15,7 +15,7 @@ ENTRY(entry_int82) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movl $HYPERCALL_VECTOR, 4(%rsp) + movl $HYPERCALL_VECTOR, EFRAME_entry_vector(%rsp) SAVE_ALL compat=1 /* DPL1 gate, restricted to 32bit PV guests only. */ SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=regs/cpuinfo, %rdx=0, Clob: acd */
xen/arch/x86/x86_64/entry.S +35 -35
230 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Subject: x86: Resync intel-family.h from Linux
From v6.8-rc6
xen/arch/x86/include/asm/intel-family.h +34 -4
@@ -26,6 +26,9 @@* _G - parts with extra graphics on * _X - regular server parts * _D - micro server parts +* _N,_P - other mobile parts +* _H - premium mobile parts +* _S - other client parts * * Historical OPTDIFFs: *
@@ -37,6 +40,9 @@* their own names :-( */ +/* Wildcard match for FAM6 so X86_MATCH_INTEL_FAM6_MODEL(ANY) works */ +#define INTEL_FAM6_ANY X86_MODEL_ANY +#define INTEL_FAM6_CORE_YONAH 0x0E#define INTEL_FAM6_CORE2_MEROM 0x0F
@@ -93,8 +99,6 @@#define INTEL_FAM6_ICELAKE_L 0x7E/* Sunny Cove */ #define INTEL_FAM6_ICELAKE_NNPI 0x9D/* Sunny Cove */ -#define INTEL_FAM6_LAKEFIELD 0x8A/* Sunny Cove / Tremont */ -#define INTEL_FAM6_ROCKETLAKE 0xA7/* Cypress Cove */ #define INTEL_FAM6_TIGERLAKE_L 0x8C/* Willow Cove */
@@ -102,12 +106,31 @@#define INTEL_FAM6_SAPPHIRERAPIDS_X 0x8F/* Golden Cove */ +#define INTEL_FAM6_EMERALDRAPIDS_X 0xCF + +#define INTEL_FAM6_GRANITERAPIDS_X 0xAD +#define INTEL_FAM6_GRANITERAPIDS_D 0xAE + +/* "Hybrid" Processors (P-Core/E-Core) */ + +#define INTEL_FAM6_LAKEFIELD 0x8A/* Sunny Cove / Tremont */ +#define INTEL_FAM6_ALDERLAKE 0x97/* Golden Cove / Gracemont */ #define INTEL_FAM6_ALDERLAKE_L 0x9A/* Golden Cove / Gracemont */ -#define INTEL_FAM6_RAPTORLAKE 0xB7 +#define INTEL_FAM6_RAPTORLAKE 0xB7/* Raptor Cove / Enhanced Gracemont */ +#define INTEL_FAM6_RAPTORLAKE_P 0xBA +#define INTEL_FAM6_RAPTORLAKE_S 0xBF + +#define INTEL_FAM6_METEORLAKE 0xAC +#define INTEL_FAM6_METEORLAKE_L 0xAA + +#define INTEL_FAM6_ARROWLAKE_H 0xC5 +#define INTEL_FAM6_ARROWLAKE 0xC6 + +#define INTEL_FAM6_LUNARLAKE_M 0xBD -/* "Small Core" Processors (Atom) */ +/* "Small Core" Processors (Atom/E-Core) */ #define INTEL_FAM6_ATOM_BONNELL 0x1C/* Diamondville, Pineview */ #define INTEL_FAM6_ATOM_BONNELL_MID 0x26/* Silverthorne, Lincroft */
@@ -134,6 +157,13 @@#define INTEL_FAM6_ATOM_TREMONT 0x96/* Elkhart Lake */ #define INTEL_FAM6_ATOM_TREMONT_L 0x9C/* Jasper Lake */ +#define INTEL_FAM6_ATOM_GRACEMONT 0xBE/* Alderlake N */ + +#define INTEL_FAM6_ATOM_CRESTMONT_X 0xAF/* Sierra Forest */ +#define INTEL_FAM6_ATOM_CRESTMONT 0xB6/* Grand Ridge */ + +#define INTEL_FAM6_ATOM_DARKMONT_X 0xDD/* Clearwater Forest */ +/* Xeon Phi */ #define INTEL_FAM6_XEON_PHI_KNL 0x57/* Knights Landing */
From: Andrew Cooper <[email protected]>
Subject: x86/vmx: Perform VERW flushing later in the VMExit path
Broken out of the following patch because this change is subtle enough on its own. See it for the rational of why we're moving VERW.
As for how, extend the trick already used to hold one condition in flags (RESUME vs LAUNCH) through the POPing of GPRs.
Move the MOV CR earlier. Intel specify flags to be undefined across it.
Encode the two conditions we want using SF and PF. See the code comment for exactly how.
Leave a comment to explain the lack of any content around SPEC_CTRL_EXIT_TO_VMX, but leave the block in place. Sods law says if we delete it, we'll need to reintroduce it.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/hvm/vmx/entry.S +32 -4
@@ -87,17 +87,39 @@ UNLIKELY_END(realmode) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* SPEC_CTRL_EXIT_TO_VMX Req: %rsp=regs/cpuinfo Clob: */ - DO_SPEC_CTRL_COND_VERW + /* + * All speculation safety work happens to be elsewhere. VERW is after + * popping the GPRs, while restoring the guest MSR_SPEC_CTRL is left + * to the MSR load list. + */ mov VCPU_hvm_guest_cr2(%rbx),%rax + mov %rax, %cr2 + + /* + * We need to perform two conditional actions (VERW, and Resume vs
Lines of this file are not shown. View the raw message.
xen/arch/x86/include/asm/spec_ctrl_asm.h +7 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Perform VERW flushing later in exit paths
On parts vulnerable to RFDS, VERW's side effects are extended to scrub all non-architectural entries in various Physical Register Files. To remove all of Xen's values, the VERW must be after popping the GPRs.
Rework SPEC_CTRL_COND_VERW to default to an CPUINFO_error_code %rsp position, but with overrides for other contexts. Identify that it clobbers eflags; this is particularly relevant for the SYSRET path.
For the IST exit return to Xen, have the main SPEC_CTRL_EXIT_TO_XEN put a shadow copy of spec_ctrl_flags, as GPRs can't be used at the point we want to issue the VERW.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/include/asm/spec_ctrl_asm.h +24 -12
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Rename VERW related options
VERW is going to be used for a 3rd purpose, and the existing nomenclature didn't survive the Stale MMIO issues terribly well.
Rename the command line option from md-clear= to verw=. This is more consistent with other options which tend to be named based on what they're doing, not which feature enumeration they use behind the scenes. Retain md-clear= as a deprecated alias.
Rename opt_md_clear_{pv,hvm} and opt_fb_clear_mmio to opt_verw_{pv,hvm,mmio}, which has a side effect of making spec_ctrl_init_domain() rather clearer to follow.
No functional change.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +32 -30
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: VERW-handling adjustments
... before we add yet more complexity to this logic. Mostly expanded comments, but with three minor changes.
1) Introduce cpu_has_useful_md_clear to simplify later logic in this patch and future ones.
2) We only ever need SC_VERW_IDLE when SMT is active. If SMT isn't active, then there's no re-partition of pipeline resources based on thread-idleness to worry about.
3) The logic to adjust HVM VERW based on L1D_FLUSH is unmaintainable and, as it turns out, wrong. SKIP_L1DFL is just a hint bit, whereas opt_l1d_flush is the relevant decision of whether to use L1D_FLUSH based on susceptibility and user preference.
Rewrite the logic so it can be followed, and incorporate the fact that when FB_CLEAR is visible, L1D_FLUSH isn't a safe substitution.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +73 -26
99 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Mitigation Register File Data Sampling
RFDS affects Atom cores, also branded E-cores, between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid clien systems which have a mix of Gracemont and other types of cores.
Two new bits have been defined; RFDS_CLEAR to indicate VERW has more side effets, and RFDS_NO to incidate that the system is unaffected. Plenty of unaffected CPUs won't be getting RFDS_NO retrofitted in microcode, so we synthesise it. Alder Lake and Raptor Lake Xeon-E's are unaffected due to their platform configuration, and we must use the Hybrid CPUID bit to distinguish them from their non-Xeon counterparts.
Like MD_CLEAR and FB_CLEAR, RFDS_CLEAR needs OR-ing across a resource pool, so set it in the max policies and reflect the host setting in default.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +95 -5
100 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/entry: Introduce EFRAME_* constants
restore_all_guest() does a lot of manipulation of the stack after popping the GPRs, and uses raw %rsp displacements to do so. Also, almost all entrypaths use raw %rsp displacements prior to pushing GPRs.
Provide better mnemonics, to aid readability and reduce the chance of errors when editing.
No functional change. The resulting binary is identical.
xen/arch/x86/x86_64/entry.S +35 -35
70 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86: Resync intel-family.h from Linux
From v6.8-rc6
xen/arch/x86/include/asm/intel-family.h +34 -4
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/vmx: Perform VERW flushing later in the VMExit path
Broken out of the following patch because this change is subtle enough on its own. See it for the rational of why we're moving VERW.
As for how, extend the trick already used to hold one condition in flags (RESUME vs LAUNCH) through the POPing of GPRs.
Move the MOV CR earlier. Intel specify flags to be undefined across it.
Encode the two conditions we want using SF and PF. See the code comment for exactly how.
Leave a comment to explain the lack of any content around SPEC_CTRL_EXIT_TO_VMX, but leave the block in place. Sods law says if we delete it, we'll need to reintroduce it.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/include/asm/spec_ctrl_asm.h +7 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Perform VERW flushing later in exit paths
On parts vulnerable to RFDS, VERW's side effects are extended to scrub all non-architectural entries in various Physical Register Files. To remove all of Xen's values, the VERW must be after popping the GPRs.
Rework SPEC_CTRL_COND_VERW to default to an CPUINFO_error_code %rsp position, but with overrides for other contexts. Identify that it clobbers eflags; this is particularly relevant for the SYSRET path.
For the IST exit return to Xen, have the main SPEC_CTRL_EXIT_TO_XEN put a shadow copy of spec_ctrl_flags, as GPRs can't be used at the point we want to issue the VERW.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/include/asm/spec_ctrl_asm.h +24 -12
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Rename VERW related options
VERW is going to be used for a 3rd purpose, and the existing nomenclature didn't survive the Stale MMIO issues terribly well.
Rename the command line option from md-clear= to verw=. This is more consistent with other options which tend to be named based on what they're doing, not which feature enumeration they use behind the scenes. Retain md-clear= as a deprecated alias.
Rename opt_md_clear_{pv,hvm} and opt_fb_clear_mmio to opt_verw_{pv,hvm,mmio}, which has a side effect of making spec_ctrl_init_domain() rather clearer to follow.
No functional change.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +32 -30
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: VERW-handling adjustments
... before we add yet more complexity to this logic. Mostly expanded comments, but with three minor changes.
1) Introduce cpu_has_useful_md_clear to simplify later logic in this patch and future ones.
2) We only ever need SC_VERW_IDLE when SMT is active. If SMT isn't active, then there's no re-partition of pipeline resources based on thread-idleness to worry about.
3) The logic to adjust HVM VERW based on L1D_FLUSH is unmaintainable and, as it turns out, wrong. SKIP_L1DFL is just a hint bit, whereas opt_l1d_flush is the relevant decision of whether to use L1D_FLUSH based on susceptibility and user preference.
Rewrite the logic so it can be followed, and incorporate the fact that when FB_CLEAR is visible, L1D_FLUSH isn't a safe substitution.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +73 -26
99 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Mitigation Register File Data Sampling
RFDS affects Atom cores, also branded E-cores, between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid clien systems which have a mix of Gracemont and other types of cores.
Two new bits have been defined; RFDS_CLEAR to indicate VERW has more side effets, and RFDS_NO to incidate that the system is unaffected. Plenty of unaffected CPUs won't be getting RFDS_NO retrofitted in microcode, so we synthesise it. Alder Lake and Raptor Lake Xeon-E's are unaffected due to their platform configuration, and we must use the Hybrid CPUID bit to distinguish them from their non-Xeon counterparts.
Like MD_CLEAR and FB_CLEAR, RFDS_CLEAR needs OR-ing across a resource pool, so set it in the max policies and reflect the host setting in default.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +95 -5
100 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: VERW-handling adjustments
... before we add yet more complexity to this logic. Mostly expanded comments, but with three minor changes.
1) Introduce cpu_has_useful_md_clear to simplify later logic in this patch and future ones.
2) We only ever need SC_VERW_IDLE when SMT is active. If SMT isn't active, then there's no re-partition of pipeline resources based on thread-idleness to worry about.
3) The logic to adjust HVM VERW based on L1D_FLUSH is unmaintainable and, as it turns out, wrong. SKIP_L1DFL is just a hint bit, whereas opt_l1d_flush is the relevant decision of whether to use L1D_FLUSH based on susceptibility and user preference.
Rewrite the logic so it can be followed, and incorporate the fact that when FB_CLEAR is visible, L1D_FLUSH isn't a safe substitution.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +73 -26
99 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Subject: x86/spec-ctrl: Mitigation Register File Data Sampling
RFDS affects Atom cores, also branded E-cores, between the Goldmont and Gracemont microarchitectures. This includes Alder Lake and Raptor Lake hybrid clien systems which have a mix of Gracemont and other types of cores.
Two new bits have been defined; RFDS_CLEAR to indicate VERW has more side effets, and RFDS_NO to incidate that the system is unaffected. Plenty of unaffected CPUs won't be getting RFDS_NO retrofitted in microcode, so we synthesise it. Alder Lake and Raptor Lake Xeon-E's are unaffected due to their platform configuration, and we must use the Hybrid CPUID bit to distinguish them from their non-Xeon counterparts.
Like MD_CLEAR and FB_CLEAR, RFDS_CLEAR needs OR-ing across a resource pool, so set it in the max policies and reflect the host setting in default.
This is part of XSA-452 / CVE-2023-28746.
xen/arch/x86/spec_ctrl.c +95 -5
100 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.