MDS basics
Subsystems (7)
v4 cover MDS basics
Hi!
Another day, another update.
Changes since V3:
- Add the #DF mitigation and document why I can't be bothered to sprinkle the buffer clear into #MC
- Add a comment about the segment selector choice. It makes sense on it's own but it won't prevent anyone from thinking that we're crazy.
- Addressed the review feedback vs. documentation
- Resurrected the admin documentation patch, tidied it up and filled the gaps.
Delta patch without the admin documentation parts below.
Git tree WIP.mds branch is updated as well.
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
There is one point left which I did not look into yet and I'm happy to delegate that to the virtualization wizards:
XEON PHI is not affected by L1TF, so it won't get the L1TF mitigations. But it is affected by MSBDS, so it needs separate mitigation, i.e. clearing CPU buffers on VMENTER.
Thanks,
Thomas
8<-------------------
Documentation/ABI/testing/sysfs-devices-system-cpu | 1 Documentation/admin-guide/hw-vuln/index.rst | 13 + Documentation/admin-guide/hw-vuln/l1tf.rst | 1 Documentation/admin-guide/hw-vuln/mds.rst | 258 +++++++++++++++++++++ Documentation/admin-guide/index.rst | 6 Documentation/admin-guide/kernel-parameters.txt | 27 ++ Documentation/index.rst | 1 Documentation/x86/conf.py | 10 Documentation/x86/index.rst | 8 Documentation/x86/mds.rst | 205 ++++++++++++++++ arch/x86/entry/common.c | 10 arch/x86/include/asm/cpufeatures.h | 2 arch/x86/include/asm/irqflags.h | 4 arch/x86/include/asm/msr-index.h | 39 +-- arch/x86/include/asm/mwait.h | 7 arch/x86/include/asm/nospec-branch.h | 39 +++ arch/x86/include/asm/processor.h | 7 arch/x86/kernel/cpu/bugs.c | 105 ++++++++ arch/x86/kernel/cpu/common.c | 13 + arch/x86/kernel/nmi.c | 6 arch/x86/kernel/traps.c | 9 arch/x86/kvm/cpuid.c | 3 drivers/base/cpu.c | 8 include/linux/cpu.h | 2 24 files changed, 762 insertions(+), 22 deletions(-)
Documentation/x86/mds.rst +43 -5
@@ -1,7 +1,12 @@ Microarchitecural Data Sampling (MDS) mitigation ================================================ -Microarchitectural Data Sampling (MDS) is a class of side channel attacks +.. _mds: + +Overview +-------- + +Microarchitectural Data Sampling (MDS) is a family of side channel attacks on internal buffers in Intel CPUs. The variants are: - Microarchitectural Store Buffer Data Sampling (MSBDS) (CVE-2018-12126)
@@ -33,6 +38,7 @@ faulting or assisting loads under certain conditions, which again can be exploited eventually. Load ports are shared between Hyper-Threads so cross thread leakage is possible. + Exposure assumptions --------------------
@@ -48,7 +54,7 @@ needed for exploiting MDS requires: - to control the pointer through which the disclosure gadget exposes the data -The existance of such a construct cannot be excluded with 100% certainty, +The existence of such a construct cannot be excluded with 100% certainty, but the complexity involved makes it extremly unlikely. There is one exception, which is untrusted BPF. The functionality of
@@ -91,13 +97,37 @@ the invocation can be enforced or conditional. As a special quirk to address virtualization scenarios where the host has the microcode updated, but the hypervisor does not (yet) expose the MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the -hope that it might work. The state is reflected accordingly. +hope that it might actually clear the buffers. The state is reflected +accordingly. According to current knowledge additional mitigations inside the kernel itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests. + +Kernel internal mitigation modes +-------------------------------- + + ======= =========================================================== + off Mitigation is disabled. Either the CPU is not affected or + mds=off is supplied on the kernel command line + + full Mitigation is eanbled. CPU is affected and MD_CLEAR is + advertised in CPUID. + + vmwerv Mitigation is enabled. CPU is affected and MD_CLEAR is not + advertised in CPUID. That is mainly for virtualization + scenarios where the host has the updated microcode but the + hypervisor does not expose MD_CLEAR in CPUID. It's a best + effort approach without guarantee. + ======= =========================================================== + +If the CPU is affected and mds=off is not supplied on the kernel +command line then the kernel selects the appropriate mitigation mode +depending on the availability of the MD_CLEAR CPUID bit. + + Mitigation points -----------------
@@ -128,8 +158,16 @@ Mitigation points coverage. There is one non maskable exception which returns through paranoid exit - and is not mitigated: #DF. If user space is able to trigger a double - fault the possible MDS leakage is the least problem to worry about. + and is to some extent controllable from user space through + modify_ldt(2): #DF. So mitigation is required in the double fault + handler as well. + + Another corner case is a #MC which hits between the buffer clear and the + actual return to user. As this still is in kernel space it takes the + paranoid exit path which does not clear the CPU buffers. So the #MC + handler repopulates the buffers to some extent. Machine checks are not + reliably controllable and the window is extremly small so mitigation + would just tick a checkbox that this theoretical corner case is covered. 2. C-State transition
arch/x86/include/asm/nospec-branch.h +2 -0
@@ -338,6 +338,8 @@ static inline void mds_clear_cpu_buffers(void)* Has to be the memory-operand variant because only that * guarantees the CPU buffer flush functionality according to * documentation. The register-operand variant does not. +* Works with any segment selector, but a valid writable +* data segment is the fastest variant. * * "cc" clobber is required because VERW modifies ZF. */
arch/x86/kernel/cpu/bugs.c +1 -0
@@ -68,6 +68,7 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always_ibpb);DEFINE_STATIC_KEY_FALSE (mds_user_clear);/* Control MDS CPU buffer clear before idling (halt, mwait) */ DEFINE_STATIC_KEY_FALSE (mds_idle_clear); +EXPORT_SYMBOL_GPL (mds_idle_clear);void __init check_bugs (void ) {
arch/x86/kernel/traps.c +9 -0
@@ -366,6 +366,15 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) regs->ip = (unsigned long )general_protection; regs->sp = (unsigned long )&gpregs->orig_ax; +/* +* This situation can be triggered by userspace via +* modify_ldt(2) and the return does not take the regular +* user space exit, so a CPU buffer clear is required when +* MDS mitigation is enabled. +*/ +if (static_branch_unlikely (&mds_user_clear)) +mds_clear_cpu_buffers (); + return; }#endif
PATCH v4 1/11 x86/msr-index: Cleanup bit defines
From: Thomas Gleixner <[email protected]>
Greg pointed out that speculation related bit defines are using (1 << N) format instead of BIT(N). Aside of that (1 << N) is wrong as it should use 1UL at least.
Clean it up.
--- arch/x86/include/asm/msr-index.h | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
arch/x86/include/asm/msr-index.h +18 -16
@@ -2,6 +2,8 @@#ifndef _ASM_X86_MSR_INDEX_H#define _ASM_X86_MSR_INDEX_H +#include <linux/bits.h> +/* * CPU model specific register (MSR) numbers. *
@@ -40,14 +42,14 @@/* Intel MSRs. Some also available on other CPUs */ #define MSR_IA32_SPEC_CTRL 0x00000048/* Speculation Control */ -#define SPEC_CTRL_IBRS (1 << 0)/* Indirect Branch Restricted Speculation */ +#define SPEC_CTRL_IBRS BIT(0)/* Indirect Branch Restricted Speculation */ #define SPEC_CTRL_STIBP_SHIFT 1/* Single Thread Indirect Branch Predictor (STIBP) bit */ -#define SPEC_CTRL_STIBP (1 << SPEC_CTRL_STIBP_SHIFT)/* STIBP mask */ +#define SPEC_CTRL_STIBP BIT(SPEC_CTRL_STIBP_SHIFT)/* STIBP mask */ #define SPEC_CTRL_SSBD_SHIFT 2/* Speculative Store Bypass Disable bit */ -#define SPEC_CTRL_SSBD (1 << SPEC_CTRL_SSBD_SHIFT)/* Speculative Store Bypass Disable */ +#define SPEC_CTRL_SSBD BIT(SPEC_CTRL_SSBD_SHIFT)/* Speculative Store Bypass Disable */ #define MSR_IA32_PRED_CMD 0x00000049/* Prediction Command */ -#define PRED_CMD_IBPB (1 << 0)/* Indirect Branch Prediction Barrier */ +#define PRED_CMD_IBPB BIT(0)/* Indirect Branch Prediction Barrier */ #define MSR_PPIN_CTL 0x0000004e#define MSR_PPIN 0x0000004f
@@ -69,20 +71,20 @@#define MSR_MTRRcap 0x000000fe#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a -#define ARCH_CAP_RDCL_NO (1 << 0)/* Not susceptible to Meltdown */ -#define ARCH_CAP_IBRS_ALL (1 << 1)/* Enhanced IBRS support */ -#define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH (1 << 3)/* Skip L1D flush on vmentry */ -#define ARCH_CAP_SSB_NO (1 << 4)/* -* Not susceptible to Speculative Store Bypass -* attack, so no Speculative Store Bypass -* control required. -*/ +#define ARCH_CAP_RDCL_NO BIT(0)/* Not susceptible to Meltdown */ +#define ARCH_CAP_IBRS_ALL BIT(1)/* Enhanced IBRS support */ +#define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH BIT(3)/* Skip L1D flush on vmentry */ +#define ARCH_CAP_SSB_NO BIT(4)/* +* Not susceptible to Speculative Store Bypass +* attack, so no Speculative Store Bypass +* control required. +*/ #define MSR_IA32_FLUSH_CMD 0x0000010b -#define L1D_FLUSH (1 << 0)/* -* Writeback and invalidate the -* L1 data cache. -*/ +#define L1D_FLUSH BIT(0)/* +* Writeback and invalidate the +* L1 data cache. +*/ #define MSR_IA32_BBL_CR_CTL 0x00000119#define MSR_IA32_BBL_CR_CTL3 0x0000011e
PATCH v4 2/11 x86/speculation/mds: Add basic bug infrastructure for MDS
In reply to Thomas GleixnerFrom: Andi Kleen <[email protected]>
Microarchitectural Data Sampling (MDS), is a class of side channel attacks on internal buffers in Intel CPUs. The variants are:
- Microarchitectural Store Buffer Data Sampling (MSBDS) (CVE-2018-12126)
- Microarchitectural Fill Buffer Data Sampling (MFBDS) (CVE-2018-12130)
- Microarchitectural Load Port Data Sampling (MLPDS) (CVE-2018-12127)
MSBDS leaks Store Buffer Entries which can be speculatively forwarded to a dependent load (store-to-load forwarding) as an optimization. The forward can also happen to a faulting or assisting load operation for a different memory address, which can be exploited under certain conditions. Store buffers are partitioned between Hyper-Threads so cross thread forwarding is not possible. But if a thread enters or exits a sleep state the store buffer is repartitioned which can expose data from one thread to the other.
MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage L1 miss situations and to hold data which is returned or sent in response to a memory or I/O operation. Fill buffers can forward data to a load operation and also write data to the cache. When the fill buffer is deallocated it can retain the stale data of the preceding operations which can then be forwarded to a faulting or assisting load operation, which can be exploited under certain conditions. Fill buffers are shared between Hyper-Threads so cross thread leakage is possible.
MLDPS leaks Load Port Data. Load ports are used to perform load operations from memory or I/O. The received data is then forwarded to the register file or a subsequent operation. In some implementations the Load Port can contain stale data from a previous operation which can be forwarded to faulting or assisting loads under certain conditions, which again can be exploited eventually. Load ports are shared between Hyper-Threads so cross thread leakage is possible.
All variants have the same mitigation for single CPU thread case (SMT off), so the kernel can treat them as one MDS issue.
Add the basic infrastructure to detect if the current CPU is affected by MDS.
[ tglx: Rewrote changelog ]
---
V3: Addressed Borislav's review comments
--- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/msr-index.h | 5 +++++ arch/x86/kernel/cpu/common.c | 13 +++++++++++++ 3 files changed, 20 insertions(+)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -344,6 +344,7 @@/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */ #define X86_FEATURE_AVX512_4VNNIW (18*32+ 2)/* AVX-512 Neural Network Instructions */ #define X86_FEATURE_AVX512_4FMAPS (18*32+ 3)/* AVX-512 Multiply Accumulation Single precision */ +#define X86_FEATURE_MD_CLEAR (18*32+10)/* VERW clears CPU buffers */ #define X86_FEATURE_PCONFIG (18*32+18)/* Intel PCONFIG */ #define X86_FEATURE_SPEC_CTRL (18*32+26)/* "" Speculation Control (IBRS + IBPB) */ #define X86_FEATURE_INTEL_STIBP (18*32+27)/* "" Single Thread Indirect Branch Predictors */
@@ -381,5 +382,6 @@#define X86_BUG_SPECTRE_V2 X86_BUG(16)/* CPU is affected by Spectre variant 2 attack with indirect branches */ #define X86_BUG_SPEC_STORE_BYPASS X86_BUG(17)/* CPU is affected by speculative store bypass attack */ #define X86_BUG_L1TF X86_BUG(18)/* CPU is affected by L1 Terminal Fault */ +#define X86_BUG_MDS X86_BUG(19)/* CPU is affected by Microarchitectural data sampling */ #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/include/asm/msr-index.h +5 -0
@@ -79,6 +79,11 @@* attack, so no Speculative Store Bypass * control required. */ +#define ARCH_CAP_MDS_NO BIT(5)/* +* Not susceptible to +* Microarchitectural Data +* Sampling (MDS) vulnerabilities. +*/ #define MSR_IA32_FLUSH_CMD 0x0000010b#define L1D_FLUSH BIT(0)/*
arch/x86/kernel/cpu/common.c +13 -0
@@ -998,6 +998,14 @@ static const __initconst struct x86_cpu_ {} }; +static const __initconst struct x86_cpu_id cpu_no_mds[] = { +/* in addition to cpu_no_speculation */ + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_GOLDMONT }, + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_GOLDMONT_X }, + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_GOLDMONT_PLUS }, + {} +}; +static void __init cpu_set_bug_bits (struct cpuinfo_x86 *c) {u64 ia32_cap =0 ;
@@ -1019,6 +1027,11 @@ static void __init cpu_set_bug_bits(struif (ia32_cap &ARCH_CAP_IBRS_ALL )setup_force_cpu_cap (X86_FEATURE_IBRS_ENHANCED ); +if ((boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL && + !x86_match_cpu (cpu_no_mds)) && + !(ia32_cap &ARCH_CAP_MDS_NO )) +setup_force_cpu_bug (X86_BUG_MDS ); +if (x86_match_cpu (cpu_no_meltdown))return ;
[MODERATED] Re: [patch V4 02/11] x86/speculation/mds: Add basic bug infrastructure for MDS
Don't take this as a NAK on this patch, I just didn't react to it on earlier versions, and I wanted to just bring it up..
arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_ · line 1003
Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/common.c +3
-0+static const __initconst struct x86_cpu_id cpu_no_mds[] = { +/* in addition to cpu_no_speculation */ + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_GOLDMONT },
...
That comment was what made me go look: we already have *four* of these tables in this file, and this is now the fifth.
And that may be ok. Maybe we do want separate tables for separate quirks, even if there are patterns there.
But I at least wanted to bring it up: maybe it would be more legible to have one table of CPU quirks, and have that table say "this CPU has / doesn't have this quirk".
Looking at the existing tables, there's often commonalities. And the 'struct x86_cpu_id' does have that "driver_data" field that is meant to be able to describe particular issues, and could contain flags for "has bug X" or "doesn't have bug Y" quirks
I dunno. I guess it depends on which way people prefer to thing about things. Do you want to have a "I wan to see which CPU's have bug X", or do you want to have a "I want to see what bugs CPU X has".
Right now it's been driven by "quirk X" having a list of CPU's associated with that quirk. And maybe that's the right thing to do.
But looking at those tables, I do wonder if maybe we should have instead a list of CPU's, and then associate the quirks with the CPU.
Anyway, that was my aside. I don't think this patch series needs to worry about it,
Linus
Re: [patch V4 02/11] x86/speculation/mds: Add basic bug infrastructure for MDS
Quoted 27 lines · speck for Linus Torvalds
arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_ · line 1003
Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/common.c +3
-0+static const __initconst struct x86_cpu_id cpu_no_mds[] = { +/* in addition to cpu_no_speculation */ + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_GOLDMONT },...
That comment was what made me go look: we already have *four* of these tables in this file, and this is now the fifth.
And that may be ok. Maybe we do want separate tables for separate quirks, even if there are patterns there.
But I at least wanted to bring it up: maybe it would be more legible to have one table of CPU quirks, and have that table say "this CPU has / doesn't have this quirk".
Looking at the existing tables, there's often commonalities. And the 'struct
x86_cpu_id' does have that "driver_data" field that is meant to be able to describe particular issues, and could contain flags for "has bug X" or "doesn't have bug Y" quirksI dunno. I guess it depends on which way people prefer to thing about things. Do you want to have a "I wan to see which CPU's have bug X", or do you want to have a "I want to see what bugs CPU X has".
Quoted 5 lines
Right now it's been driven by "quirk X" having a list of CPU's associated with that quirk. And maybe that's the right thing to do.
But looking at those tables, I do wonder if maybe we should have instead a list of CPU's, and then associate the quirks with the CPU.
Good point. Never thought about it. Should be trivial enough to do.
Thanks,
tglx
Re: [patch V4 02/11] x86/speculation/mds: Add basic bug infrastructure for MDS
Quoted 5 lines · speck for Thomas Gleixner
Quoted 2 lines · speck for Linus Torvalds
But looking at those tables, I do wonder if maybe we should have instead a list of CPU's, and then associate the quirks with the CPU.
Good point. Never thought about it. Should be trivial enough to do.
And doing so immediately shows that the current tables are inconsistent. AIRMONT is not affected by SSB, but AIRMONT_MID is according to the cpu_no_spec_store_bypass table. I noticed that when consolidating all the bits into a single table....
Thanks,
tglx
PATCH v4 3/11 x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests
In reply to Thomas GleixnerFrom: Andi Kleen <[email protected]>
Subject: [patch V4 03/11] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests
X86_FEATURE_MD_CLEAR is a new CPUID bit which is set when microcode provides the mechanism to invoke a flush of various exploitable CPU buffers by invoking the VERW instruction.
Hand it through to guests so they can adjust their mitigations.
This also requires corresponding qemu changes, which are available separately.
[ tglx: Massaged changelog ]
--- arch/x86/kvm/cpuid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +2 -1
@@ -409,7 +409,8 @@ static inline int __do_cpuid_ent(struct/* cpuid 7.0.edx*/ const u32 kvm_cpuid_7_0_edx_x86_features =F (AVX512_4VNNIW ) |F (AVX512_4FMAPS ) |F (SPEC_CTRL ) | -F (SPEC_CTRL_SSBD ) |F (ARCH_CAPABILITIES ) |F (INTEL_STIBP ); +F (SPEC_CTRL_SSBD ) |F (ARCH_CAPABILITIES ) |F (INTEL_STIBP ) | +F (MD_CLEAR );/* all calls to cpuid_count() should be made on the same cpu */ get_cpu ();
PATCH v4 4/11 x86/speculation/mds: Add mds_clear_cpu_buffer()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The Microarchitectural Data Sampling (MDS) vulernabilities are mitigated by clearing the affected CPU buffers. The mechanism for clearing the buffers uses the unused and obsolete VERW instruction in combination with a microcode update which triggers a CPU buffer clear when VERW is executed.
Provide a inline function with the assembly magic. The argument of the VERW instruction must be a memory operand as documented:
"MD_CLEAR enumerates that the memory-operand variant of VERW (for
example, VERW m16) has been extended to also overwrite buffers affected by MDS. This buffer overwriting functionality is not guaranteed for the register operand variant of VERW."
Documentation also recommends to use a writable data segment selector:
"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."
Add x86 specific documentation about MDS and the internal workings of the mitigation.
---
V3 --> V4: Document the segment selecor choice as well.
V2 --> V3: Add VERW documentation and fix typos/grammar..., dropped 'i(0)'
Add more details fo the documentation file
V1 --> V2: Add "cc" clobber and documentation
--- Documentation/index.rst | 1 Documentation/x86/conf.py | 10 +++ Documentation/x86/index.rst | 8 ++ Documentation/x86/mds.rst | 100 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/nospec-branch.h | 25 ++++++++ 5 files changed, 144 insertions(+)
Documentation/index.rst +1 -0
@@ -101,6 +101,7 @@ implementation. :maxdepth: 2 sh/index + x86/index Filesystem Documentation ------------------------
Documentation/x86/conf.py new file +10 -0
@@ -0,0 +1,10 @@ +# -*- coding: utf-8; mode: python -*- + +project = "X86 architecture specific documentation" + +tags.add("subproject") + +latex_documents = [ + ('index', 'x86.tex', project, + 'The kernel development community', 'manual'), +]
Documentation/x86/index.rst new file +8 -0
@@ -0,0 +1,8 @@ +========================== +x86 architecture specifics +========================== + +.. toctree:: + :maxdepth: 1 + + mds
Documentation/x86/mds.rst new file +100 -0
100 lines not on this page · raw message
arch/x86/include/asm/nospec-branch.h +25 -0
@@ -318,6 +318,31 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_cond_ibpb);DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +#include <asm/segment.h> + +/** +* mds_clear_cpu_buffers - Mitigation for MDS vulnerability +* +* This uses the otherwise unused and obsolete VERW instruction in +* combination with microcode which triggers a CPU buffer flush when the +* instruction is executed. +*/ +static inline void mds_clear_cpu_buffers (void ) +{ +static const u16 ds = __KERNEL_DS; + +/* +* Has to be the memory-operand variant because only that +* guarantees the CPU buffer flush functionality according to +* documentation. The register-operand variant does not. +* Works with any segment selector, but a valid writable +* data segment is the fastest variant. +* +* "cc" clobber is required because VERW modifies ZF. +*/ + asmvolatile ("verw %[ds]" : : [ds]"m" (ds) :"cc" ); +} +#endif /* __ASSEMBLY__ */ /*
[MODERATED] Re: [patch V4 04/11] x86/speculation/mds: Add mds_clear_cpu_buffer()
Quoted 23 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
The Microarchitectural Data Sampling (MDS) vulernabilities are mitigated by clearing the affected CPU buffers. The mechanism for clearing the buffers uses the unused and obsolete VERW instruction in combination with a microcode update which triggers a CPU buffer clear when VERW is executed.
Provide a inline function with the assembly magic. The argument of the VERW instruction must be a memory operand as documented:
"
MD_CLEARenumerates that the memory-operand variant of VERW (for
example, VERW m16) has been extended to also overwrite buffers affected by MDS. This buffer overwriting functionality is not guaranteed for the register operand variant of VERW."Documentation also recommends to use a writable data segment selector:
"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."
Quoted 6 lines
Add x86 specific documentation about MDS and the internal workings of the mitigation.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Borislav Petkov <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>
[MODERATED] Re: [patch V4 04/11] x86/speculation/mds: Add mds_clear_cpu_buffer()
In reply to Thomas GleixnerDocumentation/x86/mds.rst line 33
Quoted 10 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst new file +10
-0+MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage +L1 miss situations and to hold data which is returned or sent in response +to a memory or I/O operation. Fill buffers can forward data to a load +operation and also write data to the cache. When the fill buffer is +deallocated it can retain the stale data of the preceding operations which +can then be forwarded to a faulting or assisting load operation, which can +be exploited under certain conditions. Fill buffers are shared between +Hyper-Threads so cross thread leakage is possible. + +MLDPS leaks Load Port Data. Load ports are used to perform load operations
MLPDS
Quoted 15 lines
Documentation/x86/mds.rst new file +15
-0+from memory or I/O. The received data is then forwarded to the register +file or a subsequent operation. In some implementations the Load Port can +contain stale data from a previous operation which can be forwarded to +faulting or assisting loads under certain conditions, which again can be +exploited eventually. Load ports are shared between Hyper-Threads so cross +thread leakage is possible. + + +Exposure assumptions +-------------------- + +It is assumed that attack code resides in user space or in a guest with one +exception. The rationale behind this assumption is that the code construct +needed for exploiting MDS requires: +
Documentation/x86/mds.rst line 58
Quoted 10 lines
Documentation/x86/mds.rst new file +10
-0+ - to control the load to trigger a fault or assist + + - to have a disclosure gadget which exposes the speculatively accessed + data for consumption through a side channel. + + - to control the pointer through which the disclosure gadget exposes the + data + +The existence of such a construct cannot be excluded with 100% certainty, +but the complexity involved makes it extremly unlikely.
The existence of such a construct *in the kernel* cannot be excluded...
Quoted 26 lines
Documentation/x86/mds.rst new file +26
-0+There is one exception, which is untrusted BPF. The functionality of +untrusted BPF is limited, but it needs to be thoroughly investigated +whether it can be used to create such a construct. + + +Mitigation strategy +------------------- + +All variants have the same mitigation strategy at least for the single CPU +thread case (SMT off): Force the CPU to clear the affected buffers. + +This is achieved by using the otherwise unused and obsolete VERW +instruction in combination with a microcode update. The microcode clears +the affected CPU buffers when the VERW instruction is executed. + +For virtualization there are two ways to achieve CPU buffer +clearing. Either the modified VERW instruction or via the L1D Flush +command. The latter is issued when L1TF mitigation is enabled so the extra +VERW can be avoided. If the CPU is not affected by L1TF then VERW needs to +be issued. + +If the VERW instruction with the supplied segment selector argument is +executed on a CPU without the microcode update there is no side effect +other than a small number of pointlessly wasted CPU cycles. + +This does not protect against cross Hyper-Thread attacks except for MSBDS
Documentation/x86/mds.rst line 95
Quoted 10 lines
Documentation/x86/mds.rst new file +10
-0+which is only exploitable cross Hyper-thread when one of the Hyper-Threads +enters a C-state. + +The kernel provides a function to invoke the buffer clearing: + + mds_clear_cpu_buffers() + +The mitigation is invoked on kernel/userspace, hypervisor/guest and C-state +(idle) transitions. Depending on the mitigation mode and the system state +the invocation can be enforced or conditional.
The conditional bit isn't true (yet?).
What does "enforced" mean in this context? s/enforced/unconditional ? Maybe the last sentence can be removed entirely.
Signature · 1 line
Josh
[MODERATED] Encrypted Message
From: Jon Masters <[email protected]>
To: speck for Josh Poimboeuf <[email protected]>
Subject: Re: [patch V4 04/11] x86/speculation/mds: Add mds_clear_cpu_buffer()
Quoted 9 lines · speck for Josh Poimboeuf
Documentation/x86/mds.rst line 31
Quoted 8 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst new file +8
-0+MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage +L1 miss situations and to hold data which is returned or sent in response +to a memory or I/O operation. Fill buffers can forward data to a load +operation and also write data to the cache. When the fill buffer is +deallocated it can retain the stale data of the preceding operations which +can then be forwarded to a faulting or assisting load operation, which can +be exploited under certain conditions. Fill buffers are shared between +Hyper-Threads so cross thread leakage is possible.
The fill buffers sit opposite the L1D$ and participate in coherency directly. They supply data directly to the load store units. Here's the internal summary I wrote (feel free to use any of it that is useful):
"Intel processors utilize fill buffers to perform loads of data when a miss occurs in the Level 1 data cache. The fill buffer allows the processor to implement a non-blocking cache, continuing with other operations while the necessary cache data “line” is loaded from a higher level cache or from memory. It also allows the result of the fill to be forwarded directly to the EU (Execution Unit) requiring the load, without waiting for it to be written into the L1 Data Cache.
A load operation is not decoupled in the same way that a store is, but it does involve an AGU (Address Generation Unit) operation. If the AGU generates a fault (#PF, etc.) or an assist (A/D bits) then the classical Intel design would block the load and later reissue it. In contemporary designs, it instead allows subsequent speculation operations to temporarily see a forwarded data value from the fill buffer slot prior to the load actually taking place. Thus it is possible to read data that was recently accessed by another thread, if the fill buffer entry is not reused.
It is this attack that allows cross-thread SMT leakage and breaks HT without recourse other than to disable it or to implement core scheduling in the Linux kernel.
Variants of this include loads that cross cache or page boundaries due to further optimizations in Intel’s implementation. For example, Intel incorporate logic to guess at address generation prior to determining whether it crosses such a boundary (covered in US5335333A) and will forward this to the TLB/load logic prior to resolving the full address. They will retry the load by re-issuing uops in the case of a cross cacheline/page boundary but in that case will leak state as well."
Jon.
Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
[MODERATED] Encrypted Message
From: Jon Masters <[email protected]>
To: speck for Jon Masters <[email protected]>
Subject: Re: [patch V4 04/11] x86/speculation/mds: Add mds_clear_cpu_buffer()
Quoted 38 lines · speck for Jon Masters
Quoted 9 lines · speck for Josh Poimboeuf
Documentation/x86/mds.rst line 31
Quoted 8 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst new file +8
-0+MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage +L1 miss situations and to hold data which is returned or sent in response +to a memory or I/O operation. Fill buffers can forward data to a load +operation and also write data to the cache. When the fill buffer is +deallocated it can retain the stale data of the preceding operations which +can then be forwarded to a faulting or assisting load operation, which can +be exploited under certain conditions. Fill buffers are shared between +Hyper-Threads so cross thread leakage is possible.The fill buffers sit opposite the L1D$ and participate in coherency directly. They supply data directly to the load store units. Here's the internal summary I wrote (feel free to use any of it that is useful):
"Intel processors utilize fill buffers to perform loads of data when a miss occurs in the Level 1 data cache. The fill buffer allows the processor to implement a non-blocking cache, continuing with other operations while the necessary cache data “line” is loaded from a higher level cache or from memory. It also allows the result of the fill to be forwarded directly to the EU (Execution Unit) requiring the load, without waiting for it to be written into the L1 Data Cache.
A load operation is not decoupled in the same way that a store is, but it does involve an AGU (Address Generation Unit) operation. If the AGU generates a fault (#PF, etc.) or an assist (A/D bits) then the classical Intel design would block the load and later reissue it. In contemporary designs, it instead allows subsequent speculation operations to temporarily see a forwarded data value from the fill buffer slot prior to the load actually taking place. Thus it is possible to read data that was recently accessed by another thread, if the fill buffer entry is not reused.
It is this attack that allows cross-thread SMT leakage and breaks HT without recourse other than to disable it or to implement core scheduling in the Linux kernel.
Quoted 7 lines
Variants of this include loads that cross cache or page boundaries due to further optimizations in Intel’s implementation. For example, Intel incorporate logic to guess at address generation prior to determining whether it crosses such a boundary (covered in US5335333A) and will forward this to the TLB/load logic prior to resolving the full address. They will retry the load by re-issuing uops in the case of a cross cacheline/page boundary but in that case will leak state as well."
Btw, I've various reproducers here that I'm happy to share if useful with the right folks. Thomas and Linus should already have my IFU one for later testing of that, I've also e.g. an FBBF. Currently it just spews whatever it sees from the other threads, but in the next few days I'll have it cleaned up to send/receive specific messages - then can just wrap it with a bow so it can print yes/no vulnerable.
Ping if you have a need for a repro (keybase/email) and I'll go through our process for sharing as appropriate.
Jon.
Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
[MODERATED] Re: [patch V4 04/11] x86/speculation/mds: Add mds_clear_cpu_buffer()
In reply to Thomas GleixnerTwo single-letter heckles...
Quoted 1 line · speck for Thomas Gleixner
Subject: patch V4 04/11] x86/speculation/mds: Add
mds_clear_cpu_buffer()
^
bufferS()Quoted 81 lines
From: Thomas Gleixner <[email protected]>
The Microarchitectural Data Sampling (MDS) vulernabilities are mitigated by clearing the affected CPU buffers. The mechanism for clearing the buffers uses the unused and obsolete VERW instruction in combination with a microcode update which triggers a CPU buffer clear when VERW is executed.
Provide a inline function with the assembly magic. The argument of the VERW instruction must be a memory operand as documented:
"
MD_CLEARenumerates that the memory-operand variant of VERW (for
example, VERW m16) has been extended to also overwrite buffers affected by MDS. This buffer overwriting functionality is not guaranteed for the register operand variant of VERW."Documentation also recommends to use a writable data segment selector:
"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."Add x86 specific documentation about MDS and the internal workings of the mitigation.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Borislav Petkov <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>---
V3 --> V4: Document the segment selecor choice as well.V2 --> V3: Add VERW documentation and fix typos/grammar..., dropped 'i(0)'
Add more details fo the documentation fileV1 --> V2: Add "cc" clobber and documentation
--- Documentation/index.rst | 1 Documentation/x86/conf.py | 10 +++ Documentation/x86/index.rst | 8 ++ Documentation/x86/mds.rst | 100 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/nospec-branch.h | 25 ++++++++ 5 files changed, 144 insertions(+)Documentation/index.rst +1
-0@@ -101,6 +101,7 @@ implementation. :maxdepth: 2 sh/index + x86/index Filesystem Documentation ------------------------Documentation/x86/conf.py new file +10
-0@@ -0,0 +1,10 @@ +# -*- coding: utf-8; mode: python -*- + +project = "X86 architecture specific documentation" + +tags.add("subproject") + +latex_documents = [ + ('index', 'x86.tex', project, + 'The kernel development community', 'manual'), +]Documentation/x86/index.rst new file +8
-0@@ -0,0 +1,8 @@ +========================== +x86 architecture specifics +========================== + +.. toctree:: + :maxdepth: 1 + + mds
Documentation/x86/mds.rst line 1
Quoted 1 line
Documentation/x86/mds.rst new file +1
-0@@ -0,0 +1,100 @@ +Microarchitecural Data Sampling (MDS) mitigation
^
MicroarchitecTural
Quoted 135 lines
Documentation/x86/mds.rst new file +99
-0+================================================ + +.. _mds: + +Overview +-------- + +Microarchitectural Data Sampling (MDS) is a family of side channel attacks +on internal buffers in Intel CPUs. The variants are: + + - Microarchitectural Store Buffer Data Sampling (MSBDS) (CVE-2018-12126) + - Microarchitectural Fill Buffer Data Sampling (MFBDS) (CVE-2018-12130) + - Microarchitectural Load Port Data Sampling (MLPDS) (CVE-2018-12127) + +MSBDS leaks Store Buffer Entries which can be speculatively forwarded to a +dependent load (store-to-load forwarding) as an optimization. The forward +can also happen to a faulting or assisting load operation for a different +memory address, which can be exploited under certain conditions. Store +buffers are partitioned between Hyper-Threads so cross thread forwarding is +not possible. But if a thread enters or exits a sleep state the store +buffer is repartitioned which can expose data from one thread to the other. + +MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage +L1 miss situations and to hold data which is returned or sent in response +to a memory or I/O operation. Fill buffers can forward data to a load +operation and also write data to the cache. When the fill buffer is +deallocated it can retain the stale data of the preceding operations which +can then be forwarded to a faulting or assisting load operation, which can +be exploited under certain conditions. Fill buffers are shared between +Hyper-Threads so cross thread leakage is possible. + +MLDPS leaks Load Port Data. Load ports are used to perform load operations +from memory or I/O. The received data is then forwarded to the register +file or a subsequent operation. In some implementations the Load Port can +contain stale data from a previous operation which can be forwarded to +faulting or assisting loads under certain conditions, which again can be +exploited eventually. Load ports are shared between Hyper-Threads so cross +thread leakage is possible. + + +Exposure assumptions +-------------------- + +It is assumed that attack code resides in user space or in a guest with one +exception. The rationale behind this assumption is that the code construct +needed for exploiting MDS requires: + + - to control the load to trigger a fault or assist + + - to have a disclosure gadget which exposes the speculatively accessed + data for consumption through a side channel. + + - to control the pointer through which the disclosure gadget exposes the + data + +The existence of such a construct cannot be excluded with 100% certainty, +but the complexity involved makes it extremly unlikely. + +There is one exception, which is untrusted BPF. The functionality of +untrusted BPF is limited, but it needs to be thoroughly investigated +whether it can be used to create such a construct. + + +Mitigation strategy +------------------- + +All variants have the same mitigation strategy at least for the single CPU +thread case (SMT off): Force the CPU to clear the affected buffers. + +This is achieved by using the otherwise unused and obsolete VERW +instruction in combination with a microcode update. The microcode clears +the affected CPU buffers when the VERW instruction is executed. + +For virtualization there are two ways to achieve CPU buffer +clearing. Either the modified VERW instruction or via the L1D Flush +command. The latter is issued when L1TF mitigation is enabled so the extra +VERW can be avoided. If the CPU is not affected by L1TF then VERW needs to +be issued. + +If the VERW instruction with the supplied segment selector argument is +executed on a CPU without the microcode update there is no side effect +other than a small number of pointlessly wasted CPU cycles. + +This does not protect against cross Hyper-Thread attacks except for MSBDS +which is only exploitable cross Hyper-thread when one of the Hyper-Threads +enters a C-state. + +The kernel provides a function to invoke the buffer clearing: + + mds_clear_cpu_buffers() + +The mitigation is invoked on kernel/userspace, hypervisor/guest and C-state +(idle) transitions. Depending on the mitigation mode and the system state +the invocation can be enforced or conditional. + +According to current knowledge additional mitigations inside the kernel +itself are not required because the necessary gadgets to expose the leaked +data cannot be controlled in a way which allows exploitation from malicious +user space or VM guests.arch/x86/include/asm/nospec-branch.h +25
-0@@ -318,6 +318,31 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_cond_ibpb);DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +#include <asm/segment.h> + +/** +* mds_clear_cpu_buffers - Mitigation for MDS vulnerability +* +* This uses the otherwise unused and obsolete VERW instruction in +* combination with microcode which triggers a CPU buffer flush when the +* instruction is executed. +*/ +static inline void mds_clear_cpu_buffers (void ) +{ +static const u16 ds = __KERNEL_DS; + +/* +* Has to be the memory-operand variant because only that +* guarantees the CPU buffer flush functionality according to +* documentation. The register-operand variant does not. +* Works with any segment selector, but a valid writable +* data segment is the fastest variant. +* +* "cc" clobber is required because VERW modifies ZF. +*/ + asmvolatile ("verw %[ds]" : : [ds]"m" (ds) :"cc" ); +} +#endif /* __ASSEMBLY__ */ /*
PATCH v4 5/11 x86/speculation/mds: Clear CPU buffers on exit to user
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on exit to user space and add the call into prepare_exit_to_usermode() and do_nmi() right before actually returning.
Add documentation which kernel to user space transition this covers and explain why some corner cases are not mitigated.
---
V3 --> V4: Add #DS mitigation and document that the #MC corner case
is really not interesting.
V3: Add NMI conditional on user regs and update documentation accordingly.
Use the static branch scheme suggested by Peter. Fix typos ...
--- Documentation/x86/mds.rst | 41 +++++++++++++++++++++++++++++++++++ arch/x86/entry/common.c | 10 ++++++++ arch/x86/include/asm/nospec-branch.h | 2 + arch/x86/kernel/cpu/bugs.c | 4 ++- arch/x86/kernel/nmi.c | 6 +++++ arch/x86/kernel/traps.c | 9 +++++++ 6 files changed, 71 insertions(+), 1 deletion(-)
Documentation/x86/mds.rst +41 -0
@@ -94,3 +94,44 @@ According to current knowledge additiona itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests. + +Mitigation points +----------------- + +1. Return to user space +^^^^^^^^^^^^^^^^^^^^^^^ + When transitioning from kernel to user space the CPU buffers are flushed + on affected CPUs: + + - always when the mitigation mode is full. The migitation is enabled + through the static key mds_user_clear. + + This covers transitions from kernel to user space through a return to + user space from a syscall and from an interrupt or a regular exception. + + There are other kernel to user space transitions which are not covered + by this: NMIs and all non maskable exceptions which go through the + paranoid exit, which means that they are not invoking the regular + prepare_exit_to_usermode() which handles the CPU buffer clearing. + + Access to sensible data like keys, credentials in the NMI context is + mostly theoretical: The CPU can do prefetching or execute a + misspeculated code path and thereby fetching data which might end up + leaking through a buffer. + + But for mounting other attacks the kernel stack address of the task is + already valuable information. So in full mitigation mode, the NMI is + mitigated on the return from do_nmi() to provide almost complete + coverage. + + There is one non maskable exception which returns through paranoid exit + and is to some extent controllable from user space through + modify_ldt(2): #DF. So mitigation is required in the double fault + handler as well. + + Another corner case is a #MC which hits between the buffer clear and the + actual return to user. As this still is in kernel space it takes the + paranoid exit path which does not clear the CPU buffers. So the #MC + handler repopulates the buffers to some extent. Machine checks are not + reliably controllable and the window is extremly small so mitigation + would just tick a checkbox that this theoretical corner case is covered.
arch/x86/entry/common.c +10 -0
@@ -31,6 +31,7 @@#include <asm/vdso.h> #include <linux/uaccess.h> #include <asm/cpufeature.h> +#include <asm/nospec-branch.h> #define CREATE_TRACE_POINTS #include <trace/events/syscalls.h>
@@ -180,6 +181,13 @@ static void exit_to_usermode_loop(struct } } +static inline void mds_user_clear_cpu_buffers (void ) +{ +if (!static_branch_likely (&mds_user_clear)) +return ; +mds_clear_cpu_buffers (); +} +/* Called with IRQs disabled. */ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) {
@@ -212,6 +220,8 @@ static void exit_to_usermode_loop(struct#endif user_enter_irqoff (); + +mds_user_clear_cpu_buffers (); }#define SYSCALL_EXIT_WORK_FLAGS \
arch/x86/include/asm/nospec-branch.h +2 -0
@@ -318,6 +318,8 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_cond_ibpb);DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +DECLARE_STATIC_KEY_FALSE (mds_user_clear); +#include <asm/segment.h> /**
arch/x86/kernel/cpu/bugs.c +3 -1
@@ -63,10 +63,12 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_i/* Control unconditional IBPB in switch_mm() */ DEFINE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +/* Control MDS CPU buffer clear before returning to user space */ +DEFINE_STATIC_KEY_FALSE (mds_user_clear); +void __init check_bugs (void ) {identify_boot_cpu (); -/* * identify_boot_cpu() initialized SMT support information, let the * core code know.
arch/x86/kernel/nmi.c +6 -0
@@ -34,6 +34,7 @@#include <asm/x86_init.h> #include <asm/reboot.h> #include <asm/cache.h> +#include <asm/nospec-branch.h> #define CREATE_TRACE_POINTS #include <trace/events/nmi.h>
@@ -533,6 +534,11 @@ do_nmi(struct pt_regs *regs, long error_write_cr2 (this_cpu_read (nmi_cr2));if (this_cpu_dec_return (nmi_state)) goto nmi_restart; + +if (!static_branch_likely (&mds_user_clear)) +return ; +if (user_mode (regs)) +mds_clear_cpu_buffers (); }NOKPROBE_SYMBOL (do_nmi);
arch/x86/kernel/traps.c +9 -0
@@ -366,6 +366,15 @@ dotraplinkage void do_double_fault(struc regs->ip = (unsigned long )general_protection; regs->sp = (unsigned long )&gpregs->orig_ax; +/* +* This situation can be triggered by userspace via +* modify_ldt(2) and the return does not take the regular +* user space exit, so a CPU buffer clear is required when +* MDS mitigation is enabled. +*/ +if (static_branch_unlikely (&mds_user_clear)) +mds_clear_cpu_buffers (); + return; }#endif
[MODERATED] Re: [patch V4 05/11] x86/speculation/mds: Clear CPU buffers on exit to user
Quoted 10 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on exit to user space and add the call into
prepare_exit_to_usermode()anddo_nmi()right before actually returning.Add documentation which kernel to user space transition this covers and explain why some corner cases are not mitigated.
Signed-off-by Thomas Gleixner <[email protected]>
[MODERATED] Re: [patch V4 05/11] x86/speculation/mds: Clear CPU buffers on exit to user
In reply to Thomas GleixnerQuoted 31 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on exit to user space and add the call into
prepare_exit_to_usermode()anddo_nmi()right before actually returning.Add documentation which kernel to user space transition this covers and explain why some corner cases are not mitigated.
Signed-off-by Thomas Gleixner <[email protected]>---
V3 --> V4: Add #DS mitigation and document that the #MC corner case
is really not interesting.V3: Add NMI conditional on user regs and update documentation accordingly.
Use the static branch scheme suggested by Peter. Fix typos ...--- Documentation/x86/mds.rst | 41 +++++++++++++++++++++++++++++++++++ arch/x86/entry/common.c | 10 ++++++++ arch/x86/include/asm/nospec-branch.h | 2 + arch/x86/kernel/cpu/bugs.c | 4 ++- arch/x86/kernel/nmi.c | 6 +++++ arch/x86/kernel/traps.c | 9 +++++++ 6 files changed, 71 insertions(+), 1 deletion(-)Documentation/x86/mds.rst +0
-0@@ -94,3 +94,44 @@ According to current knowledge additiona itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests.
Documentation/x86/mds.rst According to current knowledge additiona · line 106
Quoted 10 lines
Documentation/x86/mds.rst +10
-0+ +Mitigation points +----------------- + +1. Return to user space +^^^^^^^^^^^^^^^^^^^^^^^ + When transitioning from kernel to user space the CPU buffers are flushed + on affected CPUs: + + - always when the mitigation mode is full. The migitation is enabled
Currently the mitigation is always full.
Documentation/x86/mds.rst According to current knowledge additiona · line 114
Quoted 8 lines
Documentation/x86/mds.rst +8
-0+ through the static key mds_user_clear. + + This covers transitions from kernel to user space through a return to + user space from a syscall and from an interrupt or a regular exception. + + There are other kernel to user space transitions which are not covered + by this: NMIs and all non maskable exceptions which go through the + paranoid exit, which means that they are not invoking the regular
Actually, NMI *is* mitigated.
What is a non maskable exception?
The statement about all paranoid exits being covered isn't correct, because #DF is mitigated.
Documentation/x86/mds.rst According to current knowledge additiona · line 120
Quoted 6 lines
Documentation/x86/mds.rst +6
-0+ prepare_exit_to_usermode() which handles the CPU buffer clearing. + + Access to sensible data like keys, credentials in the NMI context is + mostly theoretical: The CPU can do prefetching or execute a + misspeculated code path and thereby fetching data which might end up + leaking through a buffer.
This paragraph can be removed, since NMI is mitigated.
Documentation/x86/mds.rst According to current knowledge additiona · line 125
Quoted 5 lines
Documentation/x86/mds.rst +5
-0+ + But for mounting other attacks the kernel stack address of the task is + already valuable information. So in full mitigation mode, the NMI is + mitigated on the return from do_nmi() to provide almost complete + coverage.
This one is correct.
Documentation/x86/mds.rst According to current knowledge additiona · line 127
Quoted 2 lines
Documentation/x86/mds.rst +2
-0+ + There is one non maskable exception which returns through paranoid exit
Again the phrase "non maskable exception". Maybe I'm missing something but I have no idea what that means.
Documentation/x86/mds.rst According to current knowledge additiona · line 137
Quoted 10 lines
Documentation/x86/mds.rst +10
-0+ and is to some extent controllable from user space through + modify_ldt(2): #DF. So mitigation is required in the double fault + handler as well. + + Another corner case is a #MC which hits between the buffer clear and the + actual return to user. As this still is in kernel space it takes the + paranoid exit path which does not clear the CPU buffers. So the #MC + handler repopulates the buffers to some extent. Machine checks are not + reliably controllable and the window is extremly small so mitigation + would just tick a checkbox that this theoretical corner case is covered.
There is no mention of #DB anywhere, shouldn't it also be mitigated?
Quoted 71 lines
arch/x86/entry/common.c +10
-0@@ -31,6 +31,7 @@#include <asm/vdso.h> #include <linux/uaccess.h> #include <asm/cpufeature.h> +#include <asm/nospec-branch.h> #define CREATE_TRACE_POINTS #include <trace/events/syscalls.h> @@ -180,6 +181,13 @@ static void exit_to_usermode_loop(struct } } +static inline void mds_user_clear_cpu_buffers (void ) +{ +if (!static_branch_likely (&mds_user_clear)) +return ; +mds_clear_cpu_buffers (); +} +/* Called with IRQs disabled. */ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) {@@ -212,6 +220,8 @@ static void exit_to_usermode_loop(struct#endif user_enter_irqoff (); + +mds_user_clear_cpu_buffers (); }#define SYSCALL_EXIT_WORK_FLAGS \arch/x86/include/asm/nospec-branch.h +2
-0@@ -318,6 +318,8 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_cond_ibpb);DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +DECLARE_STATIC_KEY_FALSE (mds_user_clear); +#include <asm/segment.h> /** arch/x86/kernel/cpu/bugs.c +3
-1@@ -63,10 +63,12 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_i/* Control unconditional IBPB in switch_mm() */ DEFINE_STATIC_KEY_FALSE (switch_mm_always_ibpb); +/* Control MDS CPU buffer clear before returning to user space */ +DEFINE_STATIC_KEY_FALSE (mds_user_clear); +void __init check_bugs (void ) {identify_boot_cpu (); -/* * identify_boot_cpu() initialized SMT support information, let the * core code know. arch/x86/kernel/nmi.c +1
-0@@ -34,6 +34,7 @@#include <asm/x86_init.h> #include <asm/reboot.h> #include <asm/cache.h> +#include <asm/nospec-branch.h> #define CREATE_TRACE_POINTS #include <trace/events/nmi.h>
arch/x86/kernel/nmi.c do_nmi(struct pt_regs *regs, long error_ · line 541
Quoted 8 lines
arch/x86/kernel/nmi.c +5
-0@@ -533,6 +534,11 @@ do_nmi(struct pt_regs *regs, long error_write_cr2 (this_cpu_read (nmi_cr2));if (this_cpu_dec_return (nmi_state)) goto nmi_restart; + +if (!static_branch_likely (&mds_user_clear)) +return ; +if (user_mode (regs)) +mds_clear_cpu_buffers ();
This could be simplied:
if (user_mode(regs)) mds_user_clear_cpu_buffers();
Quoted 7 lines
arch/x86/kernel/nmi.c +0
-0}NOKPROBE_SYMBOL (do_nmi);arch/x86/kernel/traps.c +0
-0@@ -366,6 +366,15 @@ dotraplinkage void do_double_fault(struc regs->ip = (unsigned long )general_protection;
arch/x86/kernel/traps.c dotraplinkage void do_double_fault(struc · line 376
Quoted 10 lines
arch/x86/kernel/traps.c +8
-0regs->sp = (unsigned long )&gpregs->orig_ax; +/* +* This situation can be triggered by userspace via +* modify_ldt(2) and the return does not take the regular +* user space exit, so a CPU buffer clear is required when +* MDS mitigation is enabled. +*/ +if (static_branch_unlikely (&mds_user_clear)) +mds_clear_cpu_buffers ();
Shouldn't it be likely? Anyway this can just usemds_user_clear_cpu_buffers().
Signature · 1 line
Josh
Re: [patch V4 05/11] x86/speculation/mds: Clear CPU buffers on exit to user
Quoted 10 lines · speck for Josh Poimboeuf
Documentation/x86/mds.rst According to current knowledge additiona · line 106
Quoted 6 lines · speck for Thomas Gleixner
+1. Return to user space
+^^^^^^^^^^^^^^^^^^^^^^^Documentation/x86/mds.rst +4
-0+ When transitioning from kernel to user space the CPU buffers are flushed + on affected CPUs: + + - always when the mitigation mode is full. The migitation is enabledCurrently the mitigation is always full.
Quoted 10 lines
Documentation/x86/mds.rst According to current knowledge additiona · line 114
Quoted 8 lines
Documentation/x86/mds.rst +8
-0+ through the static key mds_user_clear. + + This covers transitions from kernel to user space through a return to + user space from a syscall and from an interrupt or a regular exception. + + There are other kernel to user space transitions which are not covered + by this: NMIs and all non maskable exceptions which go through the + paranoid exit, which means that they are not invoking the regularActually, NMI *is* mitigated.
But not by the above. That's a separate mitigation point due to the mess which the x86 exception handling is.
Quoted 1 line
What is a non maskable exception?
All exceptions which are delivered despite interrupts being disabled, NMI, MCE, DF, ....
Quoted 37 lines
The statement about all paranoid exits being covered isn't correct, because #DF is mitigated.
Documentation/x86/mds.rst According to current knowledge additiona · line 120
Quoted 6 lines
Documentation/x86/mds.rst +6
-0+ prepare_exit_to_usermode() which handles the CPU buffer clearing. + + Access to sensible data like keys, credentials in the NMI context is + mostly theoretical: The CPU can do prefetching or execute a + misspeculated code path and thereby fetching data which might end up + leaking through a buffer.This paragraph can be removed, since NMI is mitigated.
Documentation/x86/mds.rst According to current knowledge additiona · line 125
Quoted 5 lines
Documentation/x86/mds.rst +5
-0+ + But for mounting other attacks the kernel stack address of the task is + already valuable information. So in full mitigation mode, the NMI is + mitigated on the return from do_nmi() to provide almost complete + coverage.This one is correct.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + There is one non maskable exception which returns through paranoid exitAgain the phrase "non maskable exception". Maybe I'm missing something but I have no idea what that means.
Documentation/x86/mds.rst According to current knowledge additiona · line 137
Quoted 10 lines
Documentation/x86/mds.rst +10
-0+ and is to some extent controllable from user space through + modify_ldt(2): #DF. So mitigation is required in the double fault + handler as well. + + Another corner case is a #MC which hits between the buffer clear and the + actual return to user. As this still is in kernel space it takes the + paranoid exit path which does not clear the CPU buffers. So the #MC + handler repopulates the buffers to some extent. Machine checks are not + reliably controllable and the window is extremly small so mitigation + would just tick a checkbox that this theoretical corner case is covered.
Quoted 1 line
There is no mention of #DB anywhere, shouldn't it also be mitigated?
If #DB comes from a user space int1 then it will go through the regular return to user path which is mitigated. If it happens in the kernel, it's not relevant.
The thing about NMI and the #DF special case is that even if they come from user space they are not returning through the regular path and therefore need explicit mitigation.
I'll reword the whole thing so it's less confusing.
Thanks,
tglx
PATCH v4 6/11 x86/speculation/mds: Conditionally clear CPU buffers on idle entry
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on idle entry. This is independent of other MDS mitigations because the idle entry invocation to mitigate the potential leakage due to store buffer repartitioning is only necessary on SMT systems.
Add the actual invocations to the different halt/mwait variants which covers all usage sites. mwaitx is not patched as it's not available on Intel CPUs.
The buffer clear is only invoked before entering the C-State to prevent that stale data from the idling CPU is spilled to the Hyper-Thread sibling after the Store buffer got repartitioned and all entries are available to the non idle sibling.
When coming out of idle the store buffer is partitioned again so each sibling has half of it available. Now CPU which returned from idle could be speculatively exposed to contents of the sibling, but the buffers are flushed either on exit to user space or on VMENTER.
When later on conditional buffer clearing is implemented on top of this, then there is no action required either because before returning to user space the context switch will set the condition flag which causes a flush on the return to user path.
This intentionaly does not handle the case in the acpi/processor_idle driver which uses the legacy IO port interface for C-State transitions for two reasons:
- The acpi/processor_idle driver was replaced by the intel_idle driver almost a decade ago. Anything Nehalem upwards supports it and defaults to that new driver.
- The legacy IO port interface is likely to be used on older and therefore unaffected CPUs or on systems which do not receive microcode updates anymore, so there is no point in adding that.
---
V4: Export mds_idle_clear
V3: Adjust document wording
--- Documentation/x86/mds.rst | 35 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/irqflags.h | 4 ++++ arch/x86/include/asm/mwait.h | 7 +++++++ arch/x86/include/asm/nospec-branch.h | 12 ++++++++++++ arch/x86/kernel/cpu/bugs.c | 3 +++ 5 files changed, 61 insertions(+)
Documentation/x86/mds.rst +35 -0
@@ -135,3 +135,38 @@ Mitigation points handler repopulates the buffers to some extent. Machine checks are not reliably controllable and the window is extremly small so mitigation would just tick a checkbox that this theoretical corner case is covered. + + +2. C-State transition +^^^^^^^^^^^^^^^^^^^^^ + + When a CPU goes idle and enters a C-State the CPU buffers need to be + cleared on affected CPUs when SMT is active. This addresses the + repartitioning of the store buffer when one of the Hyper-Threads enters + a C-State. + + When SMT is inactive, i.e. either the CPU does not support it or all + sibling threads are offline CPU buffer clearing is not required. + + The invocation is controlled by the static key mds_idle_clear which is + switched depending on the chosen mitigation mode and the SMT state of + the system. + + The buffer clear is only invoked before entering the C-State to prevent + that stale data from the idling CPU can be spilled to the Hyper-Thread + sibling after the store buffer got repartitioned and all entries are + available to the non idle sibling. + + When coming out of idle the store buffer is partitioned again so each + sibling has half of it available. The back from idle CPU could be then + speculatively exposed to contents of the sibling. The buffers are + flushed either on exit to user space or on VMENTER so malicious code + in user space or the guest cannot speculatively access them. + + The mitigation is hooked into all variants of halt()/mwait(), but does + not cover the legacy ACPI IO-Port mechanism because the ACPI idle driver + has been superseded by the intel_idle driver around 2010 and is + preferred on all affected CPUs which are expected to gain the MD_CLEAR + functionality in microcode. Aside of that the IO-Port mechanism is a + legacy interface which is only used on older systems which are either + not affected or do not receive microcode updates anymore.
arch/x86/include/asm/irqflags.h +4 -0
@@ -6,6 +6,8 @@#ifndef __ASSEMBLY__ +#include <asm/nospec-branch.h> +/* Provide __cpuidle; we can't safely include <linux/cpu.h> */ #define __cpuidle __attribute__((__section__(".cpuidle.text")))
@@ -54,11 +56,13 @@ static inline void native_irq_enable(voi static inline __cpuidle void native_safe_halt(void) { +mds_idle_clear_cpu_buffers (); asmvolatile ("sti; hlt" : : :"memory" ); } static inline __cpuidle void native_halt(void) { +mds_idle_clear_cpu_buffers (); asmvolatile ("hlt" : : :"memory" ); }
arch/x86/include/asm/mwait.h +7 -0
@@ -6,6 +6,7 @@#include <linux/sched/idle.h> #include <asm/cpufeature.h> +#include <asm/nospec-branch.h> #define MWAIT_SUBSTATE_MASK 0xf#define MWAIT_CSTATE_MASK 0xf
@@ -40,6 +41,8 @@ static inline void __monitorx(const voidstatic inline void __mwait (unsigned long eax,unsigned long ecx) { +mds_idle_clear_cpu_buffers (); +/* "mwait %eax, %ecx;" */ asmvolatile (".byte 0x0f, 0x01, 0xc9;" ::"a" (eax),"c" (ecx));
@@ -74,6 +77,8 @@ static inline void __mwait(unsigned longstatic inline void __mwaitx (unsigned long eax,unsigned long ebx,unsigned long ecx) { +/* No MDS buffer clear as this is AMD/HYGON only */ +/* "mwaitx %eax, %ebx, %ecx;" */ asmvolatile (".byte 0x0f, 0x01, 0xfb;" ::"a" (eax),"b" (ebx),"c" (ecx));
@@ -81,6 +86,8 @@ static inline void __mwaitx(unsigned lonstatic inline void __sti_mwait (unsigned long eax,unsigned long ecx) { +mds_idle_clear_cpu_buffers (); +trace_hardirqs_on ();/* "mwait %eax, %ecx;" */ asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
arch/x86/include/asm/nospec-branch.h +12 -0
@@ -319,6 +319,7 @@ DECLARE_STATIC_KEY_FALSE(switch_mm_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb);DECLARE_STATIC_KEY_FALSE (mds_user_clear); +DECLARE_STATIC_KEY_FALSE (mds_idle_clear);#include <asm/segment.h>
@@ -345,6 +346,17 @@ static inline void mds_clear_cpu_buffers asm volatile("verw %[ds]" : : [ds] "m" (ds) : "cc"); } +/** +* mds_idle_clear_cpu_buffers - Mitigation for MDS vulnerability +* +* Clear CPU buffers if the corresponding static key is enabled +*/ +static inline void mds_idle_clear_cpu_buffers (void ) +{ +if (static_branch_likely (&mds_idle_clear)) +mds_clear_cpu_buffers (); +} +#endif /* __ASSEMBLY__ */ /*
arch/x86/kernel/cpu/bugs.c +3 -0
@@ -65,6 +65,9 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always/* Control MDS CPU buffer clear before returning to user space */ DEFINE_STATIC_KEY_FALSE (mds_user_clear); +/* Control MDS CPU buffer clear before idling (halt, mwait) */ +DEFINE_STATIC_KEY_FALSE (mds_idle_clear); +EXPORT_SYMBOL_GPL (mds_idle_clear);void __init check_bugs (void ) {
[MODERATED] Re: [patch V4 06/11] x86/speculation/mds: Conditionally clear CPU buffers on idle entry
Quoted 34 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on idle entry. This is independent of other MDS mitigations because the idle entry invocation to mitigate the potential leakage due to store buffer repartitioning is only necessary on SMT systems.
Add the actual invocations to the different halt/mwait variants which covers all usage sites. mwaitx is not patched as it's not available on Intel CPUs.
The buffer clear is only invoked before entering the C-State to prevent that stale data from the idling CPU is spilled to the Hyper-Thread sibling after the Store buffer got repartitioned and all entries are available to the non idle sibling.
When coming out of idle the store buffer is partitioned again so each sibling has half of it available. Now CPU which returned from idle could be speculatively exposed to contents of the sibling, but the buffers are flushed either on exit to user space or on VMENTER.
When later on conditional buffer clearing is implemented on top of this, then there is no action required either because before returning to user space the context switch will set the condition flag which causes a flush on the return to user path.
This intentionaly does not handle the case in the acpi/processor_idle driver which uses the legacy IO port interface for C-State transitions for two reasons:
- The acpi/processor_idle driver was replaced by the
intel_idledriver almost a decade ago. Anything Nehalem upwards supports it and defaults to that new driver.
Quoted 6 lines
- The legacy IO port interface is likely to be used on older and therefore unaffected CPUs or on systems which do not receive microcode updates anymore, so there is no point in adding that.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Borislav Petkov <[email protected]>
Comparing this to the Intel paper, I find this way more readable and understandable. Things they "hint" at are actually spelled out here, nice work.
[MODERATED] Re: [patch V4 06/11] x86/speculation/mds: Conditionally clear CPU buffers on idle entry
In reply to Thomas GleixnerQuoted 21 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Add a static key which controls the invocation of the CPU buffer clear mechanism on idle entry. This is independent of other MDS mitigations because the idle entry invocation to mitigate the potential leakage due to store buffer repartitioning is only necessary on SMT systems.
Add the actual invocations to the different halt/mwait variants which covers all usage sites. mwaitx is not patched as it's not available on Intel CPUs.
The buffer clear is only invoked before entering the C-State to prevent that stale data from the idling CPU is spilled to the Hyper-Thread sibling after the Store buffer got repartitioned and all entries are available to the non idle sibling.
When coming out of idle the store buffer is partitioned again so each sibling has half of it available. Now CPU which returned from idle could be speculatively exposed to contents of the sibling, but the buffers are flushed either on exit to user space or on VMENTER.
Quoted 6 lines
When later on conditional buffer clearing is implemented on top of this, then there is no action required either because before returning to user space the context switch will set the condition flag which causes a flush on the return to user path.
This intentionaly does not handle the case in the acpi/processor_idle
intentionally
Quoted 39 lines
driver which uses the legacy IO port interface for C-State transitions for two reasons:
- The acpi/processor_idle driver was replaced by the
intel_idledriver almost a decade ago. Anything Nehalem upwards supports it and defaults to that new driver.- The legacy IO port interface is likely to be used on older and therefore unaffected CPUs or on systems which do not receive microcode updates anymore, so there is no point in adding that.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Borislav Petkov <[email protected]>---
V4: Exportmds_idle_clear
V3: Adjust document wording--- Documentation/x86/mds.rst | 35 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/irqflags.h | 4 ++++ arch/x86/include/asm/mwait.h | 7 +++++++ arch/x86/include/asm/nospec-branch.h | 12 ++++++++++++ arch/x86/kernel/cpu/bugs.c | 3 +++ 5 files changed, 61 insertions(+)Documentation/x86/mds.rst +9
-0@@ -135,3 +135,38 @@ Mitigation points handler repopulates the buffers to some extent. Machine checks are not reliably controllable and the window is extremly small so mitigation would just tick a checkbox that this theoretical corner case is covered. + + +2. C-State transition +^^^^^^^^^^^^^^^^^^^^^ + + When a CPU goes idle and enters a C-State the CPU buffers need to be + cleared on affected CPUs when SMT is active. This addresses the + repartitioning of the store buffer when one of the Hyper-Threads enters + a C-State.
Documentation/x86/mds.rst Mitigation points · line 156
Quoted 10 lines
Documentation/x86/mds.rst +10
-0+ + When SMT is inactive, i.e. either the CPU does not support it or all + sibling threads are offline CPU buffer clearing is not required. + + The invocation is controlled by the static key mds_idle_clear which is + switched depending on the chosen mitigation mode and the SMT state of + the system. + + The buffer clear is only invoked before entering the C-State to prevent + that stale data from the idling CPU can be spilled to the Hyper-Thread
s/can be spilled/from spilling/
Quoted 92 lines
Documentation/x86/mds.rst +16
-0+ sibling after the store buffer got repartitioned and all entries are + available to the non idle sibling. + + When coming out of idle the store buffer is partitioned again so each + sibling has half of it available. The back from idle CPU could be then + speculatively exposed to contents of the sibling. The buffers are + flushed either on exit to user space or on VMENTER so malicious code + in user space or the guest cannot speculatively access them. + + The mitigation is hooked into all variants of halt()/mwait(), but does + not cover the legacy ACPI IO-Port mechanism because the ACPI idle driver + has been superseded by the intel_idle driver around 2010 and is + preferred on all affected CPUs which are expected to gain the MD_CLEAR + functionality in microcode. Aside of that the IO-Port mechanism is a + legacy interface which is only used on older systems which are either + not affected or do not receive microcode updates anymore.arch/x86/include/asm/irqflags.h +4
-0@@ -6,6 +6,8 @@#ifndef __ASSEMBLY__ +#include <asm/nospec-branch.h> +/* Provide __cpuidle; we can't safely include <linux/cpu.h> */ #define __cpuidle __attribute__((__section__(".cpuidle.text")))@@ -54,11 +56,13 @@ static inline void native_irq_enable(voi static inline __cpuidle void native_safe_halt(void) { +mds_idle_clear_cpu_buffers (); asmvolatile ("sti; hlt" : : :"memory" ); } static inline __cpuidle void native_halt(void) { +mds_idle_clear_cpu_buffers (); asmvolatile ("hlt" : : :"memory" ); }arch/x86/include/asm/mwait.h +7
-0@@ -6,6 +6,7 @@#include <linux/sched/idle.h> #include <asm/cpufeature.h> +#include <asm/nospec-branch.h> #define MWAIT_SUBSTATE_MASK 0xf#define MWAIT_CSTATE_MASK 0xf@@ -40,6 +41,8 @@ static inline void __monitorx(const voidstatic inline void __mwait (unsigned long eax,unsigned long ecx) { +mds_idle_clear_cpu_buffers (); +/* "mwait %eax, %ecx;" */ asmvolatile (".byte 0x0f, 0x01, 0xc9;" ::"a" (eax),"c" (ecx));@@ -74,6 +77,8 @@ static inline void __mwait(unsigned longstatic inline void __mwaitx (unsigned long eax,unsigned long ebx,unsigned long ecx) { +/* No MDS buffer clear as this is AMD/HYGON only */ +/* "mwaitx %eax, %ebx, %ecx;" */ asmvolatile (".byte 0x0f, 0x01, 0xfb;" ::"a" (eax),"b" (ebx),"c" (ecx));@@ -81,6 +86,8 @@ static inline void __mwaitx(unsigned lonstatic inline void __sti_mwait (unsigned long eax,unsigned long ecx) { +mds_idle_clear_cpu_buffers (); +trace_hardirqs_on ();/* "mwait %eax, %ecx;" */ asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"arch/x86/include/asm/nospec-branch.h +1
-0@@ -319,6 +319,7 @@ DECLARE_STATIC_KEY_FALSE(switch_mm_cond_DECLARE_STATIC_KEY_FALSE (switch_mm_always_ibpb);DECLARE_STATIC_KEY_FALSE (mds_user_clear); +DECLARE_STATIC_KEY_FALSE (mds_idle_clear);#include <asm/segment.h> @@ -345,6 +346,17 @@ static inline void mds_clear_cpu_buffers asmvolatile ("verw %[ds]" : : [ds]"m" (ds) :"cc" ); }
arch/x86/include/asm/nospec-branch.h static inline void mds_clear_cpu_buffers · line 358
Quoted 10 lines
arch/x86/include/asm/nospec-branch.h +10
-0+/** +* mds_idle_clear_cpu_buffers - Mitigation for MDS vulnerability +* +* Clear CPU buffers if the corresponding static key is enabled +*/ +static inline void mds_idle_clear_cpu_buffers (void ) +{ +if (static_branch_likely (&mds_idle_clear)) +mds_clear_cpu_buffers (); +}
This two-line construct is more readable than the mds_user_clear_cpu_buffers() three-line version from the previous patch, I'd suggest doing the same thing there.
Signature · 1 line
Josh
Re: [patch V4 06/11] x86/speculation/mds: Conditionally clear CPU buffers on idle entry
Quoted 15 lines · speck for Josh Poimboeuf
arch/x86/include/asm/nospec-branch.h static inline void mds_clear_cpu_buffers · line 358
Quoted 10 lines · speck for Thomas Gleixner
arch/x86/include/asm/nospec-branch.h +10
-0+/** +* mds_idle_clear_cpu_buffers - Mitigation for MDS vulnerability +* +* Clear CPU buffers if the corresponding static key is enabled +*/ +static inline void mds_idle_clear_cpu_buffers (void ) +{ +if (static_branch_likely (&mds_idle_clear)) +mds_clear_cpu_buffers (); +}This two-line construct is more readable than the
mds_user_clear_cpu_buffers()three-line version from the previous patch, I'd suggest doing the same thing there.
Will do.
Thanks,
tglx
PATCH v4 7/11 x86/speculation/mds: Add mitigation control for MDS
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Now that the mitigations are in place, add a command line parameter to control the mitigation, a mitigation selector function and a SMT update mechanism.
This is the minimal straight forward initial implementation which just provides an always on/off mode. The command line parameter is:
mds=[full|off|auto]
This is consistent with the existing mitigations for other speculative hardware vulnerabilities.
The idle invocation is dynamically updated according to the SMT state of the system similar to the dynamic update of the STIBP mitigation.
--- Documentation/admin-guide/kernel-parameters.txt | 27 ++++++++ arch/x86/include/asm/processor.h | 6 + arch/x86/kernel/cpu/bugs.c | 76 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +27 -0
@@ -2356,6 +2356,33 @@ Format: <first>,<last> Specifies range of consoles to be captured by the MDA. + mds= [X86,INTEL] + Control mitigation for the Micro-architectural Data + Sampling (MDS) vulnerability. + + Certain CPUs are vulnerable to an exploit against CPU + internal buffers which can forward information to a + disclosure gadget under certain conditions. + + In vulnerable processors, the speculatively + forwarded data can be used in a cache side channel + attack, to access data to which the attacker does + not have direct access. + + This parameter controls the MDS mitigation. The the + options are: + + full - Unconditionally enable MDS mitigation + off - Unconditionally disable MDS mitigation + auto - Kernel detects whether the CPU model is + vulnerable to MDS and picks the most + appropriate mitigation. If the CPU is not + vulnerable, "off" is selected. If the CPU + is vulnerable "full" is selected. + + Not specifying this option is equivalent to + mds=auto. + mem=nn[KMG] [KNL,BOOT] Force usage of a specific amount of memory Amount of memory to be used when the kernel is not able to see the whole system memory or for test.
arch/x86/include/asm/processor.h +6 -0
@@ -992,4 +992,10 @@ enum l1tf_mitigations {extern enum l1tf_mitigations l1tf_mitigation; +enum mds_mitigations { +MDS_MITIGATION_OFF , +MDS_MITIGATION_AUTO , +MDS_MITIGATION_FULL , +}; +#endif /* _ASM_X86_PROCESSOR_H */
arch/x86/kernel/cpu/bugs.c +76 -0
106 lines not on this page · raw message
[MODERATED] Re: [patch V4 07/11] x86/speculation/mds: Add mitigation control for MDS
Quoted 10 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Now that the mitigations are in place, add a command line parameter to control the mitigation, a mitigation selector function and a SMT update mechanism.
This is the minimal straight forward initial implementation which just provides an always on/off mode. The command line parameter is:
mds=[full|off|auto]
do we need full and auto?
Quoted 100 lines
This is consistent with the existing mitigations for other speculative hardware vulnerabilities.
The idle invocation is dynamically updated according to the SMT state of the system similar to the dynamic update of the STIBP mitigation.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Reviewed-by Borislav Petkov <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 27 ++++++++ arch/x86/include/asm/processor.h | 6 + arch/x86/kernel/cpu/bugs.c | 76 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+)Documentation/admin-guide/kernel-parameters.txt +27
-0@@ -2356,6 +2356,33 @@ Format: <first>,<last> Specifies range of consoles to be captured by the MDA. + mds= [X86,INTEL] + Control mitigation for the Micro-architectural Data + Sampling (MDS) vulnerability. + + Certain CPUs are vulnerable to an exploit against CPU + internal buffers which can forward information to a + disclosure gadget under certain conditions. + + In vulnerable processors, the speculatively + forwarded data can be used in a cache side channel + attack, to access data to which the attacker does + not have direct access. + + This parameter controls the MDS mitigation. The the + options are: + + full - Unconditionally enable MDS mitigation + off - Unconditionally disable MDS mitigation + auto - Kernel detects whether the CPU model is + vulnerable to MDS and picks the most + appropriate mitigation. If the CPU is not + vulnerable, "off" is selected. If the CPU + is vulnerable "full" is selected. + + Not specifying this option is equivalent to + mds=auto. + mem=nn[KMG] [KNL,BOOT] Force usage of a specific amount of memory Amount of memory to be used when the kernel is not able to see the whole system memory or for test.arch/x86/include/asm/processor.h +6
-0@@ -992,4 +992,10 @@ enum l1tf_mitigations {extern enum l1tf_mitigations l1tf_mitigation; +enum mds_mitigations { +MDS_MITIGATION_OFF , +MDS_MITIGATION_AUTO , +MDS_MITIGATION_FULL , +}; +#endif /* _ASM_X86_PROCESSOR_H */ arch/x86/kernel/cpu/bugs.c +15
-0@@ -37,6 +37,7 @@static void __init spectre_v2_select_mitigation (void );static void __init ssb_select_mitigation (void );static void __init l1tf_select_mitigation (void ); +static void __init mds_select_mitigation (void );/* The base value of the SPEC_CTRL MSR that always has to be preserved. */ u64 x86_spec_ctrl_base;@@ -106,6 +107,8 @@ void __init check_bugs(void)l1tf_select_mitigation (); +mds_select_mitigation (); +#ifdef CONFIG_X86_32 /* * Check whether we are able to run this kernel safely on SMP. @@ -212,6 +215,59 @@ static void x86_amd_ssb_disable(void) }#undef pr_fmt +#define pr_fmt (fmt) "MDS: " fmt + +/* Default mitigation for L1TF-affected CPUs */ +static enum mds_mitigations mds_mitigation__ro_after_init =MDS_MITIGATION_AUTO ; + +static const char *const mds_strings[] = { + [MDS_MITIGATION_OFF ] ="Vulnerable" , + [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" +}; + +static void mds_select_mitigation (void ) +{
arch/x86/kernel/cpu/bugs.c static void x86_amd_ssb_disable(void) · line 239
Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +10
-0+if (!boot_cpu_has_bug (X86_BUG_MDS )) { + mds_mitigation =MDS_MITIGATION_OFF ; +return ; + } + +switch (mds_mitigation) { +case MDS_MITIGATION_OFF : +break ; +case MDS_MITIGATION_AUTO : +case MDS_MITIGATION_FULL :
here AUTO and FULL behave identically.
Quoted 52 lines
arch/x86/kernel/cpu/bugs.c +40
-0+if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) { + mds_mitigation =MDS_MITIGATION_FULL ; +static_branch_enable (&mds_user_clear); + }else { + mds_mitigation =MDS_MITIGATION_OFF ; + } +break ; + } +pr_info ("%s\n" , mds_strings[mds_mitigation]); +} + +static int __init mds_cmdline (char *str) +{ +if (!boot_cpu_has_bug (X86_BUG_MDS )) +return 0 ; + +if (!str) +return -EINVAL ; + +if (!strcmp (str,"off" )) + mds_mitigation =MDS_MITIGATION_OFF ; +else if (!strcmp (str,"auto" )) + mds_mitigation =MDS_MITIGATION_AUTO ; +else if (!strcmp (str,"full" )) + mds_mitigation =MDS_MITIGATION_FULL ; + +return 0 ; +} +early_param ("mds" , mds_cmdline); + +#undef pr_fmt#define pr_fmt (fmt) "Spectre V2 : " fmt static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =@@ -615,6 +671,15 @@ static void update_indir_branch_cond(voistatic_branch_disable (&switch_to_cond_stibp); } +/* Update the static key controlling the MDS CPU buffer clear in idle */ +static void update_mds_branch_idle (void ) +{ +if (sched_smt_active ()) +static_branch_enable (&mds_idle_clear); +else +static_branch_disable (&mds_idle_clear); +} +void arch_smt_update (void ) {/* Enhanced IBRS implies STIBP. No update required. */ @@ -636,6 +701,17 @@ void arch_smt_update(void)break ;
arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 711
Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +8
-0} +switch (mds_mitigation) { +case MDS_MITIGATION_OFF : +break ; +case MDS_MITIGATION_FULL : +update_mds_branch_idle (); +break ; +/* Keep GCC happy */ +case MDS_MITIGATION_AUTO :
shouldn't there be a check to see if the platform needs to set mds_idle_clear and call update_mds_branch_idle conditionally?
I'm not sure what the value of having both auto and full is.
--mark
[MODERATED] Re: [patch V4 07/11] x86/speculation/mds: Add mitigation control for MDS
In reply to Thomas GleixnerQuoted 36 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Now that the mitigations are in place, add a command line parameter to control the mitigation, a mitigation selector function and a SMT update mechanism.
This is the minimal straight forward initial implementation which just provides an always on/off mode. The command line parameter is:
mds=[full|off|auto]
This is consistent with the existing mitigations for other speculative hardware vulnerabilities.
The idle invocation is dynamically updated according to the SMT state of the system similar to the dynamic update of the STIBP mitigation.
Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Reviewed-by Borislav Petkov <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 27 ++++++++ arch/x86/include/asm/processor.h | 6 + arch/x86/kernel/cpu/bugs.c | 76 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+)Documentation/admin-guide/kernel-parameters.txt +4
-0@@ -2356,6 +2356,33 @@ Format: <first>,<last> Specifies range of consoles to be captured by the MDA. + mds= [X86,INTEL] + Control mitigation for the Micro-architectural Data + Sampling (MDS) vulnerability. +
Documentation/admin-guide/kernel-parameters.txt line 2372
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10
-0+ Certain CPUs are vulnerable to an exploit against CPU + internal buffers which can forward information to a + disclosure gadget under certain conditions. + + In vulnerable processors, the speculatively + forwarded data can be used in a cache side channel + attack, to access data to which the attacker does + not have direct access. + + This parameter controls the MDS mitigation. The the
Quoted 93 lines
Documentation/admin-guide/kernel-parameters.txt +13
-0+ options are: + + full - Unconditionally enable MDS mitigation + off - Unconditionally disable MDS mitigation + auto - Kernel detects whether the CPU model is + vulnerable to MDS and picks the most + appropriate mitigation. If the CPU is not + vulnerable, "off" is selected. If the CPU + is vulnerable "full" is selected. + + Not specifying this option is equivalent to + mds=auto. + mem=nn[KMG] [KNL,BOOT] Force usage of a specific amount of memory Amount of memory to be used when the kernel is not able to see the whole system memory or for test.arch/x86/include/asm/processor.h +6
-0@@ -992,4 +992,10 @@ enum l1tf_mitigations {extern enum l1tf_mitigations l1tf_mitigation; +enum mds_mitigations { +MDS_MITIGATION_OFF , +MDS_MITIGATION_AUTO , +MDS_MITIGATION_FULL , +}; +#endif /* _ASM_X86_PROCESSOR_H */ arch/x86/kernel/cpu/bugs.c +44
-0@@ -37,6 +37,7 @@static void __init spectre_v2_select_mitigation (void );static void __init ssb_select_mitigation (void );static void __init l1tf_select_mitigation (void ); +static void __init mds_select_mitigation (void );/* The base value of the SPEC_CTRL MSR that always has to be preserved. */ u64 x86_spec_ctrl_base;@@ -106,6 +107,8 @@ void __init check_bugs(void)l1tf_select_mitigation (); +mds_select_mitigation (); +#ifdef CONFIG_X86_32 /* * Check whether we are able to run this kernel safely on SMP. @@ -212,6 +215,59 @@ static void x86_amd_ssb_disable(void) }#undef pr_fmt +#define pr_fmt (fmt) "MDS: " fmt + +/* Default mitigation for L1TF-affected CPUs */ +static enum mds_mitigations mds_mitigation__ro_after_init =MDS_MITIGATION_AUTO ; + +static const char *const mds_strings[] = { + [MDS_MITIGATION_OFF ] ="Vulnerable" , + [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" +}; + +static void mds_select_mitigation (void ) +{ +if (!boot_cpu_has_bug (X86_BUG_MDS )) { + mds_mitigation =MDS_MITIGATION_OFF ; +return ; + } + +switch (mds_mitigation) { +case MDS_MITIGATION_OFF : +break ; +case MDS_MITIGATION_AUTO : +case MDS_MITIGATION_FULL : +if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) { + mds_mitigation =MDS_MITIGATION_FULL ; +static_branch_enable (&mds_user_clear); + }else { + mds_mitigation =MDS_MITIGATION_OFF ; + } +break ; + } +pr_info ("%s\n" , mds_strings[mds_mitigation]); +} + +static int __init mds_cmdline (char *str) +{ +if (!boot_cpu_has_bug (X86_BUG_MDS )) +return 0 ; + +if (!str) +return -EINVAL ; +
arch/x86/kernel/cpu/bugs.c static void x86_amd_ssb_disable(void) · line 268
Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +10
-0+if (!strcmp (str,"off" )) + mds_mitigation =MDS_MITIGATION_OFF ; +else if (!strcmp (str,"auto" )) + mds_mitigation =MDS_MITIGATION_AUTO ; +else if (!strcmp (str,"full" )) + mds_mitigation =MDS_MITIGATION_FULL ; + +return 0 ; +} +early_param ("mds" , mds_cmdline);
I agree with Mark that mds=auto isn't needed.
Shall we also have a mds=full,nosmt?
Quoted 26 lines
arch/x86/kernel/cpu/bugs.c +12
-0+ +#undef pr_fmt#define pr_fmt (fmt) "Spectre V2 : " fmt static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =@@ -615,6 +671,15 @@ static void update_indir_branch_cond(voistatic_branch_disable (&switch_to_cond_stibp); } +/* Update the static key controlling the MDS CPU buffer clear in idle */ +static void update_mds_branch_idle (void ) +{ +if (sched_smt_active ()) +static_branch_enable (&mds_idle_clear); +else +static_branch_disable (&mds_idle_clear); +} +void arch_smt_update (void ) {/* Enhanced IBRS implies STIBP. No update required. */ @@ -636,6 +701,17 @@ void arch_smt_update(void)break ; } +switch (mds_mitigation) {
arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 714
Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +10
-0+case MDS_MITIGATION_OFF : +break ; +case MDS_MITIGATION_FULL : +update_mds_branch_idle (); +break ; +/* Keep GCC happy */ +case MDS_MITIGATION_AUTO : +break ; + } +
Per the docs, this is a bug because full and auto should be identical.
Signature · 1 line
Josh
Re: [patch V4 07/11] x86/speculation/mds: Add mitigation control for MDS
Quoted 5 lines · speck for Josh Poimboeuf
Review
Quoted 2 lines · speck for Thomas Gleixner
(quoted diff) +2
-0+ + This parameter controls the MDS mitigation. The the
Hehe.
Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/bugs.c +4
-0+if (!strcmp (str,"off" )) + mds_mitigation =MDS_MITIGATION_OFF ; +else if (!strcmp (str,"auto" )) + mds_mitigation =MDS_MITIGATION_AUTO ;
Quoted 8 lines
arch/x86/kernel/cpu/bugs.c static void x86_amd_ssb_disable(void) · line 268
Quoted 6 lines
arch/x86/kernel/cpu/bugs.c +6
-0+else if (!strcmp (str,"full" )) + mds_mitigation =MDS_MITIGATION_FULL ; + +return 0 ; +} +early_param ("mds" , mds_cmdline);I agree with Mark that mds=auto isn't needed.
Yes, if we just have full/off auto is pointless. I'll drop it.
Quoted 1 line
Shall we also have a mds=full,nosmt?
Good question.
Quoted 5 lines
Quoted 5 lines
arch/x86/kernel/cpu/bugs.c +5
-0+switch (mds_mitigation) { +case MDS_MITIGATION_OFF : +break ; +case MDS_MITIGATION_FULL : +update_mds_branch_idle ();
Quoted 8 lines
arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 714
Quoted 6 lines
arch/x86/kernel/cpu/bugs.c +6
-0+break ; +/* Keep GCC happy */ +case MDS_MITIGATION_AUTO : +break ; + } +Per the docs, this is a bug because full and auto should be identical.
Per docs, yes, but not per code because auto is replaced and that case is just there so GCC does not yell about the missed enum in the switch case. I prefer that over default, because when extending the enum, gcc will yell and you won't forget.
Thanks,
tglx
PATCH v4 8/11 x86/speculation/mds: Add sysfs reporting for MDS
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Add the sysfs reporting file for MDS. It exposes the vulnerability and mitigation state similar to the existing files for the other speculative hardware vulnerabilities.
---
V3: Copy & Paste done right :(
--- Documentation/ABI/testing/sysfs-devices-system-cpu | 1 + arch/x86/kernel/cpu/bugs.c | 20 ++++++++++++++++++++ drivers/base/cpu.c | 8 ++++++++ include/linux/cpu.h | 2 ++ 4 files changed, 31 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +1 -0
@@ -484,6 +484,7 @@ What: /sys/devices/system/cpu/vulnerabi /sys/devices/system/cpu/vulnerabilities/spectre_v2 /sys/devices/system/cpu/vulnerabilities/spec_store_bypass /sys/devices/system/cpu/vulnerabilities/l1tf + /sys/devices/system/cpu/vulnerabilities/mds Date: January 2018 Contact: Linux kernel mailing list <[email protected]> Description: Information about CPU vulnerabilities
arch/x86/kernel/cpu/bugs.c +20 -0
@@ -1176,6 +1176,17 @@ static ssize_t l1tf_show_state(char *buf }#endif +static ssize_t mds_show_state (char *buf) +{ +if (!hypervisor_is_type (X86_HYPER_NATIVE )) { +return sprintf (buf,"%s; SMT Host state unknown\n" , + mds_strings[mds_mitigation]); + } + +return sprintf (buf,"%s; SMT %s\n" , mds_strings[mds_mitigation], +sched_smt_active () ?"vulnerable" :"disabled" ); +} +static char *stibp_state (void ) {if (spectre_v2_enabled ==SPECTRE_V2_IBRS_ENHANCED )
@@ -1242,6 +1253,10 @@ static ssize_t cpu_show_common(struct deif (boot_cpu_has (X86_FEATURE_L1TF_PTEINV ))return l1tf_show_state (buf);break ; + +case X86_BUG_MDS : +return mds_show_state (buf); +default :break ; }
@@ -1273,4 +1288,9 @@ ssize_t cpu_show_l1tf(struct device *dev {return cpu_show_common (dev, attr, buf,X86_BUG_L1TF ); } + +ssize_t cpu_show_mds (struct device *dev,struct device_attribute *attr,char *buf) +{ +return cpu_show_common (dev, attr, buf,X86_BUG_MDS ); +}#endif
drivers/base/cpu.c +8 -0
@@ -546,11 +546,18 @@ ssize_t __weak cpu_show_l1tf(struct devireturn sprintf (buf,"Not affected\n" ); } +ssize_t __weak cpu_show_mds (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"Not affected\n" ); +} + static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL); static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL); +static DEVICE_ATTR(mds, 0444, cpu_show_mds, NULL);static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr,
@@ -558,6 +565,7 @@ static struct attribute *cpu_root_vulner &dev_attr_spectre_v2.attr, &dev_attr_spec_store_bypass.attr, &dev_attr_l1tf.attr, + &dev_attr_mds.attr, NULL };
include/linux/cpu.h +2 -0
@@ -57,6 +57,8 @@ extern ssize_t cpu_show_spec_store_bypas struct device_attribute *attr, char *buf);extern ssize_t cpu_show_l1tf (struct device *dev,struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_mds (struct device *dev, +struct device_attribute *attr,char *buf); extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata,
PATCH v4 9/11 x86/speculation/mds: Add mitigation mode VMWERV
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the X86_FEATURE_MD_CLEAR CPUID bit to guests.
Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if X86_FEATURE_MD_CLEAR is not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.
That said: Virtual Machines Will Eventually Receive Vaccine
---
V2 -> V3: Rename mode.
--- Documentation/x86/mds.rst | 29 +++++++++++++++++++++++++++++ arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/bugs.c | 14 ++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-)
Documentation/x86/mds.rst +29 -0
@@ -90,11 +90,40 @@ The mitigation is invoked on kernel/user (idle) transitions. Depending on the mitigation mode and the system state the invocation can be enforced or conditional. +As a special quirk to address virtualization scenarios where the host has +the microcode updated, but the hypervisor does not (yet) expose the +MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the +hope that it might actually clear the buffers. The state is reflected +accordingly. + According to current knowledge additional mitigations inside the kernel itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests. + +Kernel internal mitigation modes +-------------------------------- + + ======= =========================================================== + off Mitigation is disabled. Either the CPU is not affected or + mds=off is supplied on the kernel command line + + full Mitigation is eanbled. CPU is affected and MD_CLEAR is + advertised in CPUID. + + vmwerv Mitigation is enabled. CPU is affected and MD_CLEAR is not + advertised in CPUID. That is mainly for virtualization + scenarios where the host has the updated microcode but the + hypervisor does not expose MD_CLEAR in CPUID. It's a best + effort approach without guarantee. + ======= =========================================================== + +If the CPU is affected and mds=off is not supplied on the kernel +command line then the kernel selects the appropriate mitigation mode +depending on the availability of the MD_CLEAR CPUID bit. + + Mitigation points -----------------
arch/x86/include/asm/processor.h +1 -0
@@ -996,6 +996,7 @@ enum mds_mitigations {MDS_MITIGATION_OFF ,MDS_MITIGATION_AUTO ,MDS_MITIGATION_FULL , + MDS_MITIGATION_VMWERV, };#endif /* _ASM_X86_PROCESSOR_H */
arch/x86/kernel/cpu/bugs.c +8 -6
@@ -222,7 +222,8 @@ static enum mds_mitigations mds_mitigatistatic const char *const mds_strings[] = { [MDS_MITIGATION_OFF ] ="Vulnerable" , - [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" + [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" , + [MDS_MITIGATION_VMWERV ] ="Vulnerable: Clear CPU buffers attempted, no microcode" , };static void mds_select_mitigation (void )
@@ -237,12 +238,12 @@ static void mds_select_mitigation(void)break ;case MDS_MITIGATION_AUTO :case MDS_MITIGATION_FULL : -if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) { +case MDS_MITIGATION_VMWERV : +if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) mds_mitigation =MDS_MITIGATION_FULL ; -static_branch_enable (&mds_user_clear); - }else { - mds_mitigation =MDS_MITIGATION_OFF ; - } +else + mds_mitigation =MDS_MITIGATION_VMWERV ; +static_branch_enable (&mds_user_clear);break ; }pr_info ("%s\n" , mds_strings[mds_mitigation]);
@@ -705,6 +706,7 @@ void arch_smt_update(void)case MDS_MITIGATION_OFF :break ;case MDS_MITIGATION_FULL : +case MDS_MITIGATION_VMWERV :update_mds_branch_idle ();break ;/* Keep GCC happy */
[MODERATED] Re: [patch V4 09/11] x86/speculation/mds: Add mitigation mode VMWERV
Quoted 13 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the
X86_FEATURE_MD_CLEARCPUID bit to guests.Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if
X86_FEATURE_MD_CLEARis not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.
Quoted 3 lines
That said: Virtual Machines Will Eventually Receive Vaccine
Signed-off-by Thomas Gleixner <[email protected]>
Thanks for the documentation update here, looks good.
[MODERATED] Re: [patch V4 09/11] x86/speculation/mds: Add mitigation mode VMWERV
In reply to Thomas GleixnerQuoted 43 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the
X86_FEATURE_MD_CLEARCPUID bit to guests.Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if
X86_FEATURE_MD_CLEARis not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.That said: Virtual Machines Will Eventually Receive Vaccine
Signed-off-by Thomas Gleixner <[email protected]>---
V2 -> V3: Rename mode.--- Documentation/x86/mds.rst | 29 +++++++++++++++++++++++++++++ arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/bugs.c | 14 ++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-)Documentation/x86/mds.rst +8
-0@@ -90,11 +90,40 @@ The mitigation is invoked on kernel/user (idle) transitions. Depending on the mitigation mode and the system state the invocation can be enforced or conditional. +As a special quirk to address virtualization scenarios where the host has +the microcode updated, but the hypervisor does not (yet) expose the +MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the +hope that it might actually clear the buffers. The state is reflected +accordingly. + According to current knowledge additional mitigations inside the kernel itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests. + +Kernel internal mitigation modes
Documentation/x86/mds.rst The mitigation is invoked on kernel/user · line 115
Quoted 10 lines
Documentation/x86/mds.rst +10
-0+-------------------------------- + + ======= =========================================================== + off Mitigation is disabled. Either the CPU is not affected or + mds=off is supplied on the kernel command line + + full Mitigation is eanbled. CPU is affected and MD_CLEAR is + advertised in CPUID. + + vmwerv Mitigation is enabled. CPU is affected and MD_CLEAR is not
vmverw <-- type oh?
Quoted 17 lines
Documentation/x86/mds.rst +11
-0+ advertised in CPUID. That is mainly for virtualization + scenarios where the host has the updated microcode but the + hypervisor does not expose MD_CLEAR in CPUID. It's a best + effort approach without guarantee. + ======= =========================================================== + +If the CPU is affected and mds=off is not supplied on the kernel +command line then the kernel selects the appropriate mitigation mode +depending on the availability of the MD_CLEAR CPUID bit. + + Mitigation points -----------------
arch/x86/include/asm/processor.h enum mds_mitigations { · line 999
Quoted 4 lines
arch/x86/include/asm/processor.h +1
-0@@ -996,6 +996,7 @@ enum mds_mitigations {MDS_MITIGATION_OFF ,MDS_MITIGATION_AUTO ,MDS_MITIGATION_FULL , + MDS_MITIGATION_VMWERV,
MDS_MITIGATION_VMVERW
arch/x86/kernel/cpu/bugs.c static enum mds_mitigations mds_mitigati · line 226
Quoted 12 lines
arch/x86/include/asm/processor.h +0
-0};#endif /* _ASM_X86_PROCESSOR_H */ arch/x86/kernel/cpu/bugs.c +2
-1@@ -222,7 +222,8 @@ static enum mds_mitigations mds_mitigatistatic const char *const mds_strings[] = { [MDS_MITIGATION_OFF ] ="Vulnerable" , - [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" + [MDS_MITIGATION_FULL ] ="Mitigation: Clear CPU buffers" , + [MDS_MITIGATION_VMWERV ] ="Vulnerable: Clear CPU buffers attempted, no microcode" ,
should be [MDS_MITIGATION_VMVERW]?
arch/x86/kernel/cpu/bugs.c static void mds_select_mitigation(void) · line 241
Quoted 9 lines
arch/x86/kernel/cpu/bugs.c +1
-1};static void mds_select_mitigation (void )@@ -237,12 +238,12 @@ static void mds_select_mitigation(void)break ;case MDS_MITIGATION_AUTO :case MDS_MITIGATION_FULL : -if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) { +case MDS_MITIGATION_VMWERV :
0,$s/VMWERV/VMVERW/g
--mark
Quoted 22 lines
arch/x86/kernel/cpu/bugs.c +5
-4+if (boot_cpu_has (X86_FEATURE_MD_CLEAR )) mds_mitigation =MDS_MITIGATION_FULL ; -static_branch_enable (&mds_user_clear); - }else { - mds_mitigation =MDS_MITIGATION_OFF ; - } +else + mds_mitigation =MDS_MITIGATION_VMWERV ; +static_branch_enable (&mds_user_clear);break ; }pr_info ("%s\n" , mds_strings[mds_mitigation]);@@ -705,6 +706,7 @@ void arch_smt_update(void)case MDS_MITIGATION_OFF :break ;case MDS_MITIGATION_FULL : +case MDS_MITIGATION_VMWERV :update_mds_branch_idle ();break ;/* Keep GCC happy */
[MODERATED] Re: [patch V4 09/11] x86/speculation/mds: Add mitigation mode VMWERV
Quoted 42 lines · speck for mark gross
Quoted 41 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the
X86_FEATURE_MD_CLEARCPUID bit to guests.Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if
X86_FEATURE_MD_CLEARis not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.That said: Virtual Machines Will Eventually Receive Vaccine
Signed-off-by Thomas Gleixner <[email protected]>---
V2 -> V3: Rename mode.--- Documentation/x86/mds.rst | 29 +++++++++++++++++++++++++++++ arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/bugs.c | 14 ++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-)Documentation/x86/mds.rst +6
-0@@ -90,11 +90,40 @@ The mitigation is invoked on kernel/user (idle) transitions. Depending on the mitigation mode and the system state the invocation can be enforced or conditional. +As a special quirk to address virtualization scenarios where the host has +the microcode updated, but the hypervisor does not (yet) expose the +MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the +hope that it might actually clear the buffers. The state is reflected +accordingly. + According to current knowledge additional mitigations inside the kernel itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests.
Quoted 13 lines
Documentation/x86/mds.rst The mitigation is invoked on kernel/user · line 115
Quoted 12 lines
Documentation/x86/mds.rst +12
-0+ +Kernel internal mitigation modes +-------------------------------- + + ======= =========================================================== + off Mitigation is disabled. Either the CPU is not affected or + mds=off is supplied on the kernel command line + + full Mitigation is eanbled. CPU is affected and MD_CLEAR is + advertised in CPUID. + + vmwerv Mitigation is enabled. CPU is affected and MD_CLEAR is notvmverw <-- type oh?
I recommend re-reading the commit message :)
The position of the W isn't an accident.
~Andrew
[MODERATED] Re: [patch V4 09/11] x86/speculation/mds: Add mitigation mode VMWERV
Quoted 57 lines · speck for Andrew Cooper
Quoted 42 lines · speck for mark gross
Quoted 41 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the
X86_FEATURE_MD_CLEARCPUID bit to guests.Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if
X86_FEATURE_MD_CLEARis not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.That said: Virtual Machines Will Eventually Receive Vaccine
Signed-off-by Thomas Gleixner <[email protected]>---
V2 -> V3: Rename mode.--- Documentation/x86/mds.rst | 29 +++++++++++++++++++++++++++++ arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/bugs.c | 14 ++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-)Documentation/x86/mds.rst +6
-0@@ -90,11 +90,40 @@ The mitigation is invoked on kernel/user (idle) transitions. Depending on the mitigation mode and the system state the invocation can be enforced or conditional. +As a special quirk to address virtualization scenarios where the host has +the microcode updated, but the hypervisor does not (yet) expose the +MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the +hope that it might actually clear the buffers. The state is reflected +accordingly. + According to current knowledge additional mitigations inside the kernel itself are not required because the necessary gadgets to expose the leaked data cannot be controlled in a way which allows exploitation from malicious user space or VM guests.Quoted 13 lines
Documentation/x86/mds.rst The mitigation is invoked on kernel/user · line 115
Quoted 12 lines
Documentation/x86/mds.rst +12
-0+ +Kernel internal mitigation modes +-------------------------------- + + ======= =========================================================== + off Mitigation is disabled. Either the CPU is not affected or + mds=off is supplied on the kernel command line + + full Mitigation is eanbled. CPU is affected and MD_CLEAR is + advertised in CPUID. + + vmwerv Mitigation is enabled. CPU is affected and MD_CLEAR is notvmverw <-- type oh?
Quoted 3 lines
I recommend re-reading the commit message :)
The position of the W isn't an accident.
Virtual Machines Will Eventually Receive Vaccine (VMWERV)
I get it now.
meh,
--mark
Re: [patch V4 09/11] x86/speculation/mds: Add mitigation mode VMWERV
In reply to mark grossQuoted 14 lines · speck for mark gross
Quoted 13 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the
X86_FEATURE_MD_CLEARCPUID bit to guests.Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if
X86_FEATURE_MD_CLEARis not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.
Quoted 4 lines
Quoted 3 lines
That said: Virtual Machines Will Eventually Receive Vaccine
+ vmwerv Mitigation is enabled. CPU is affected and
MD_CLEARis notvmverw <-- type oh?
Actually it's intentional. I was looking for something which is a subtle hint for why this thing exists in the first place and is a proper acronym. See above.
I probably could come up with something for what vmverw states, but the subtle hint is then even more subtle. Not that I care much.
Thanks,
tglx
PATCH v4 10/11 Documentation: Move L1TF to separate directory
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Move L!TF to a separate directory so the MDS stuff can be added at the side. Otherwise the all hardware vulnerabilites have their own top level entry. Should have done that right away.
--- Documentation/admin-guide/hw-vuln/index.rst | 12 Documentation/admin-guide/hw-vuln/l1tf.rst | 614 ++++++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 6 Documentation/admin-guide/l1tf.rst | 614 ---------------------------- 4 files changed, 628 insertions(+), 618 deletions(-)
Documentation/admin-guide/hw-vuln/index.rst new file +12 -0
@@ -0,0 +1,12 @@ +======================== +Hardware vulnerabilities +======================== + +This section describes CPU vulnerabilities and provides an overview of the +possible mitigations along with guidance for selecting mitigations if they +are configurable at compile, boot or run time. + +.. toctree:: + :maxdepth: 1 + + l1tf
Documentation/admin-guide/hw-vuln/l1tf.rst new file +614 -0
614 lines not on this page · raw message
Documentation/admin-guide/index.rst +2 -4
@@ -17,14 +17,12 @@ etc. kernel-parameters devices -This section describes CPU vulnerabilities and provides an overview of the -possible mitigations along with guidance for selecting mitigations if they -are configurable at compile, boot or run time. +This section describes CPU vulnerabilities and their mitigations. .. toctree:: :maxdepth: 1 - l1tf + hw-vuln/index Here is a set of documents aimed at users who are trying to track down problems and bugs in particular.
Documentation/admin-guide/l1tf.rst deleted +0 -614
614 lines not on this page · raw message
[MODERATED] Re: [patch V4 10/11] Documentation: Move L1TF to separate directory
Quoted 6 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Move L!TF to a separate directory so the MDS stuff can be added at the side. Otherwise the all hardware vulnerabilites have their own top level entry. Should have done that right away.
Quoted 7 lines
Signed-off-by Thomas Gleixner <[email protected]>--- Documentation/admin-guide/hw-vuln/index.rst | 12 Documentation/admin-guide/hw-vuln/l1tf.rst | 614 ++++++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 6 Documentation/admin-guide/l1tf.rst | 614 ---------------------------- 4 files changed, 628 insertions(+), 618 deletions(-)
-M on git format-patch will show this just as a move, not a delete/add diffstat, if that really matters.
Anyway, looks good to me:
PATCH v4 11/11 Documentation: Add MDS vulnerability documentation
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Add the initial MDS vulnerability documentation.
---
V1 --> V4: Added the missing pieces
--- Documentation/admin-guide/hw-vuln/index.rst | 1 Documentation/admin-guide/hw-vuln/l1tf.rst | 1 Documentation/admin-guide/hw-vuln/mds.rst | 258 ++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+)
Documentation/admin-guide/hw-vuln/index.rst +1 -0
@@ -10,3 +10,4 @@ are configurable at compile, boot or run :maxdepth: 1 l1tf + mds
Documentation/admin-guide/hw-vuln/l1tf.rst +1 -0
@@ -445,6 +445,7 @@ The default is 'cond'. If 'l1tf=full,for line, then 'always' is enforced and the kvm-intel.vmentry_l1d_flush module parameter is ignored and writes to the sysfs file are rejected. +.. _mitigation_selection: Mitigation selection guide --------------------------
Documentation/admin-guide/hw-vuln/mds.rst new file +258 -0
258 lines not on this page · raw message
[MODERATED] Re: [patch V4 11/11] Documentation: Add MDS vulnerability documentation
Quoted 76 lines · speck for Thomas Gleixner
From: Thomas Gleixner <[email protected]>
Add the initial MDS vulnerability documentation.
Signed-off-by Thomas Gleixner <[email protected]>---
V1 --> V4: Added the missing pieces--- Documentation/admin-guide/hw-vuln/index.rst | 1 Documentation/admin-guide/hw-vuln/l1tf.rst | 1 Documentation/admin-guide/hw-vuln/mds.rst | 258 ++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+)Documentation/admin-guide/hw-vuln/index.rst +1
-0@@ -10,3 +10,4 @@ are configurable at compile, boot or run :maxdepth: 1 l1tf + mdsDocumentation/admin-guide/hw-vuln/l1tf.rst +1
-0@@ -445,6 +445,7 @@ The default is 'cond'. If 'l1tf=full,for line, then 'always' is enforced and the kvm-intel.vmentry_l1d_flush module parameter is ignored and writes to the sysfs file are rejected. +.. _mitigation_selection: Mitigation selection guide --------------------------Documentation/admin-guide/hw-vuln/mds.rst new file +43
-0@@ -0,0 +1,258 @@ +MDS - Microarchitectural Data Sampling +====================================== + +Microarchitectural Data Sampling is a hardware vulnerability which allows +unprivileged speculative access to data which is available in various CPU +internal buffers. + +Affected processors +------------------- + +This vulnerability affects a wide range of Intel processors. The +vulnerability is not present on: + + - Processors from AMD, Centaur and other non Intel vendors + + - Older processor models, where the CPU family is < 6 + + - Some Atoms (Bonnell, Saltwell, Goldmont, GoldmontPlus) + + - Intel processors which have the ARCH_CAP_MDS_NO bit set in the + IA32_ARCH_CAPABILITIES MSR. + +Whether a processor is affected or not can be read out from the MDS +vulnerability file in sysfs. See :ref:`mds_sys_info`. + +Related CVEs +------------ + +The following CVE entries are related to the MDS vulnerability: + + ============== ===== ============================================== + CVE-2018-12126 MSBDS Microarchitectural Store Buffer Data Sampling + CVE-2018-12130 MFBDS Microarchitectural Fill Buffer Data Sampling + CVE-2018-12127 MLPDS Microarchitectural Load Port Data Sampling + ============== ===== ============================================== + +Problem +------- + +When performing store, load, L1 refill operations, processors write data +into temporary microarchitectural structures (buffers). The data in the +buffer can be forwarded to load operations as an optimization. +
Documentation/admin-guide/hw-vuln/mds.rst line 53
Quoted 10 lines
Documentation/admin-guide/hw-vuln/mds.rst new file +10
-0+Under certain conditions, usually a fault/assist caused by a load +operation, data unrelated to the load memory address can be speculatively +forwarded from the buffers. Because the load operation causes a fault or +assist and its result will be discarded, the forwarded data will not cause +incorrect program execution or state changes. But a malicious operation +may be able to forward this speculative data to a disclosure gadget which +allows in turn to infer the value via a cache side channel attack. + +Because the buffers are potentially shared between Hyper-Threads cross +Hyper-Thread attacks may be possible.
Shouldn't this be "are possible."?
As "proof" of this, some of the Linux distros, and a few other operating systems, told Intel last week that they were going to be disabling hyperthreading on their systems. Some distros/OSs were only going to do that on a "new install", but others can't really tell the difference between an upgrade and new install, so were going to do it by default.
Theo was right, for all the wrong reasons :)
Anyway, good documentation, even if you don't want to change that sentance, it looks fine to me:
Re: [patch V4 11/11] Documentation: Add MDS vulnerability documentation
Quoted 5 lines · speck for Greg KH
Documentation/admin-guide/hw-vuln/mds.rst line 53
Quoted 2 lines · speck for Thomas Gleixner
Documentation/admin-guide/hw-vuln/mds.rst new file +2
-0+Because the buffers are potentially shared between Hyper-Threads cross +Hyper-Thread attacks may be possible.Shouldn't this be "are possible."?
Yes, of course.
Thanks,
tglx
[MODERATED] Re: [patch V4 11/11] Documentation: Add MDS vulnerability documentation
In reply to Thomas GleixnerDocumentation/admin-guide/hw-vuln/mds.rst line 69
Quoted 4 lines · speck for Thomas Gleixner
Documentation/admin-guide/hw-vuln/mds.rst new file +4
-0+Contrary to other speculation based vulnerabilities the MDS vulnerability +does not allow the attacker to control the memory target address. As a +consequence the attacks are purely sampling based, but as demonstrated with +the TLBleed attack samples can be postprocessed successfully.
I saw this "sampling-based" terminology in Andi's docs too. Personally, I find it a bit confusing. I think it's trying to make a distinction between attacks that pull data out of memory and attacks that pull data out of CPU-internal state that came from somewhere else. Maybe something like:
Other attacks such as Spectre and Meltdown tend to target data at a specific memory address. The MDS vulnerability itself can not be targeted at memory and can only leak memory contents that have been loaded into the CPU buffers by other means.
Or, is it trying to make a *timing* argument?
Re: [patch V4 11/11] Documentation: Add MDS vulnerability documentation
Quoted 12 lines · speck for Dave Hansen
Documentation/admin-guide/hw-vuln/mds.rst line 69
Quoted 4 lines · speck for Thomas Gleixner
Documentation/admin-guide/hw-vuln/mds.rst new file +4
-0+Contrary to other speculation based vulnerabilities the MDS vulnerability +does not allow the attacker to control the memory target address. As a +consequence the attacks are purely sampling based, but as demonstrated with +the TLBleed attack samples can be postprocessed successfully.I saw this "sampling-based" terminology in Andi's docs too. Personally, I find it a bit confusing. I think it's trying to make a distinction between attacks that pull data out of memory and attacks that pull data out of CPU-internal state that came from somewhere else. Maybe something like:
Quoted 6 lines
Other attacks such as Spectre and Meltdown tend to target data at a specific memory address. The MDS vulnerability itself can not be targeted at memory and can only leak memory contents that have been loaded into the CPU buffers by other means.
Or, is it trying to make a *timing* argument?
No, the point is that the other attacks target data at a memory address so it's more targetted in some ways, at least once the attack found something which looks interesting it can be targetted pretty good.
The MDS attacks just collect the buffer leakage and then try to make sense out of the leaked data they retrieved. I think sampling describes that pretty good. Let me think about it.
Thanks,
tglx
Quoted 24 lines · speck for Thomas Gleixner
Hi!
Another day, another update.
Changes since V3:
- Add the #DF mitigation and document why I can't be bothered to sprinkle the buffer clear into #MC
- Add a comment about the segment selector choice. It makes sense on it's own but it won't prevent anyone from thinking that we're crazy.
- Addressed the review feedback vs. documentation
- Resurrected the admin documentation patch, tidied it up and filled the gaps.
Delta patch without the admin documentation parts below.
Git tree WIP.mds branch is updated as well.
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
Quoted 6 lines
There is one point left which I did not look into yet and I'm happy to delegate that to the virtualization wizards:
XEON PHI is not affected by L1TF, so it won't get the L1TF mitigations. But it is affected by MSBDS, so it needs separate mitigation, i.e. clearing CPU buffers on VMENTER.
I haven’t got to this in Xen yet, but you're right - it is a pain to deal with.
For L1TF, the write to MSR_FLUSH_CMD has to be in an MSR load list if you want to avoid all kinds of nasty race conditions with late-hitting NMIs/etc in the path-to-vmentry.
For PHI, it would be ideal to use the same mechanism, but obviously we cant. That said - I've just asked Intel what the feasibility of getting MSR_FLUSH_CMD[1] being VERW is. I very much expect the answer is "we're months too late for a question like that", but I don't lose anything by asking.
In Xen, I've managed to get the VERW flushing down to a single instruction living in an alternative, and this is actually quite easy to sprinkle around the exit asm. Also, because it is encoded with (%rsp), it can be used after POPing all the GPRs on the exit path.
The closer it moves to the VMLAUNCH/VMRESUME instructions, the narrower the window for race conditions (which is fairly large for L1TF as you must interact with MSRs before POPing the GPRs).
An NMI happening on the instruction boundary between VERW and VMRESUME probably falls into the category of sufficiently rare to be unconcerned about[1].
~Andrew
[1] He says, fully appreciating the irony that he has spent the past 6 weeks chasing a TLB flushing bug which turned out to be an NMI hitting a single INVPCID instruction.
Peter Zijlstra
maintainerQuoted 3 lines · speck for Andrew Cooper
[1] He says, fully appreciating the irony that he has spent the past 6 weeks chasing a TLB flushing bug which turned out to be an NMI hitting a single INVPCID instruction.
That sounds like so much fun... :-)
Quoted 17 lines · speck for Thomas Gleixner
Hi!
Another day, another update.
Changes since V3:
- Add the #DF mitigation and document why I can't be bothered to sprinkle the buffer clear into #MC
- Add a comment about the segment selector choice. It makes sense on it's own but it won't prevent anyone from thinking that we're crazy.
- Addressed the review feedback vs. documentation
- Resurrected the admin documentation patch, tidied it up and filled the gaps.
Quoted 7 lines
Delta patch without the admin documentation parts below.
Git tree WIP.mds branch is updated as well.
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
My public SSH key:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3EHqCyZrI5iLrSt8ujk/MAz4V/W85IsYQ/n8dKSyCpQCrL4BDSArFLmT8PoDazKjKX8R2tS0IhvI2inAOq1ERXKbU9gj81x9EHekVfNl9jnmqrTHLmKZNwdHgkPxOastkPTMD71SS1ONqcN1Fm9t8XRsByd7Lsr22GznOjLgMl4lrj1OgOGbwXXkYGgsJNpye8au7iNWmHFvMAcjEsgVtrY+kKRDz5pPneI6XmktwWfudFKwiCyH7NOX/D4whkWp/tanHbFSjO1jmtB92ADYdU4mXMI7CxVSS8NH2petxH3IkaD+8H6AnuZnZ+jnbOD8YYhTrfnQNmNpbtbGBIcvXw== [email protected]
BTW what is the git remote for this git repo?
--mark
Quoted 1 line · speck for mark gross
On Fri, Feb 22, 2019 at 11:24:18PM +0100, speck for Thomas Gleixner wrote:
Added your key.
Quoted 1 line
BTW what is the git remote for this git repo?
cvs.ou.linutronix.de:linux/speck/linux
Thanks,
tglx
Quoted 4 lines · speck for Thomas Gleixner
Git tree WIP.mds branch is updated as well.
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
I don't think that I have access to the git repo.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDhlN1WX8KQuBV1gEka85iElgeIRnBEQjJoTghHuUrOusBpG0f3nf468fWm2gXKgItRiZp9LI7y9tkbaUV3wSlxjt7NTzixr22eYJKLiZCWQYAZZVlSSBzIreiV+nRgjkK8rojJKnjPcxMNg1JBgjSyY0R7AoPkIU9oChLVTDj6nun3yqT/ZdMJiPCtB9mxJP7krGlBWag5bQV7Cus5nJtcXqc9rGVfJ07Ur5z6ymb0DLnphRnjM8AOYjyDRdMgXo6RTN9e0VAgLPTgXBc0ejxINF6E41sUc30TMuiQ10wZbnjFzFws/PSerTEbheqMUB/tF/LFgx1J4cGbGFn86H4hp0Wn+FvmTd4jSOabmDxbBVpjtoYlzdkblsJGph9z091qY0PUj41Va3hyYfb8SbrShpf6JE9l+l5m3nXz4Dts93qEfdWo7moJLUQZ8aAL9pANspwfH7GZzFoy7h0iXtuW1DWDOluGLDbDvLtH6Ns2AK+GEgkE9DBB7pny2wOZlV1q5xSmJml+EESK8SJSjncPmkroKbhGW4G3BwVktpCfzA3nn7H75J5RLXNDulwXJWaaQhmh4jVGNI8fL/mnQFZwd9KjhcvKubDVLKCGY4rh2efFloNBZA9k1rzRDZoFYtmsB3Gni/rJ3Ctc9krcbg4n1Q2EPW/d6Ar7qEX2bASgkw== tyhicks@sec - Canonical
Thanks!
Tyler
Quoted 4 lines · speck for Tyler Hicks
Quoted 1 line · speck for Thomas Gleixner
Git tree WIP.mds branch is updated as well.
I don't think that I have access to the git repo.
Added your key.
cvs.ou.linutronix.de:linux/speck/linux
Thanks,
tglx
Quoted 9 lines · speck for Thomas Gleixner
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
Hello Thomas,
Attached is my public access key. Thanks.
-kanth
Quoted 5 lines · speck for Kanth Ghatraju
Quoted 4 lines · speck for Thomas Gleixner
If anyone of the people new to this need access to the git repo, please send me a public SSH key so I can add to the gitolite config.
Attached is my public access key. Thanks.
Added your key.
cvs.ou.linutronix.de:linux/speck/linux
Thanks,
tglx