]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
x86/speculation/mds: Add basic bug infrastructure for MDS
authorAndi Kleen <ak@linux.intel.com>
Sat, 19 Jan 2019 00:50:16 +0000 (16:50 -0800)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 6 May 2019 16:58:12 +0000 (18:58 +0200)
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 ]

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CVE-2018-12126
CVE-2018-12127
CVE-2018-12130

(backported from commit 5edd28bac163689d3ab84c7545d9d0212504be86)
[tyhicks: Backport to 4.18:
 - X86_VENDOR_HYGON does not exist because commit c9661c1e80b6 is
   missing]
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/x86/include/asm/cpufeatures.h
arch/x86/include/asm/msr-index.h
arch/x86/kernel/cpu/common.c

index 62411fd1cef787788cfe29ae8d104c7b8bcf7de2..26d968bed4569551fe41cc902dfeea77582fae64 100644 (file)
 /* 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 */
 #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 */
index 769b6f72ec50620baabe69fc7a29b99bd61267de..7ca92f9b5eae7bef36b62790af33f7c9c2b1fae5 100644 (file)
                                                 * 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)  /*
index 95b3f41d00d5094a43a9221ac41f03056b0b9d5a..42b264e5ff9ffb7b52fdd5423e5143251039fe1c 100644 (file)
@@ -939,6 +939,7 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
 #define NO_MELTDOWN    BIT(1)
 #define NO_SSB         BIT(2)
 #define NO_L1TF                BIT(3)
+#define NO_MDS         BIT(4)
 
 #define VULNWL(_vendor, _family, _model, _whitelist)   \
        { X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
@@ -955,6 +956,7 @@ static const __initconst struct x86_cpu_id cpu_vuln_whitelist[] = {
        VULNWL(INTEL,   5, X86_MODEL_ANY,       NO_SPECULATION),
        VULNWL(NSC,     5, X86_MODEL_ANY,       NO_SPECULATION),
 
+       /* Intel Family 6 */
        VULNWL_INTEL(ATOM_SALTWELL,             NO_SPECULATION),
        VULNWL_INTEL(ATOM_SALTWELL_TABLET,      NO_SPECULATION),
        VULNWL_INTEL(ATOM_SALTWELL_MID,         NO_SPECULATION),
@@ -971,17 +973,19 @@ static const __initconst struct x86_cpu_id cpu_vuln_whitelist[] = {
        VULNWL_INTEL(CORE_YONAH,                NO_SSB),
 
        VULNWL_INTEL(ATOM_AIRMONT_MID,          NO_L1TF),
-       VULNWL_INTEL(ATOM_GOLDMONT,             NO_L1TF),
-       VULNWL_INTEL(ATOM_GOLDMONT_X,           NO_L1TF),
-       VULNWL_INTEL(ATOM_GOLDMONT_PLUS,        NO_L1TF),
 
-       VULNWL_AMD(0x0f,                NO_MELTDOWN | NO_SSB | NO_L1TF),
-       VULNWL_AMD(0x10,                NO_MELTDOWN | NO_SSB | NO_L1TF),
-       VULNWL_AMD(0x11,                NO_MELTDOWN | NO_SSB | NO_L1TF),
-       VULNWL_AMD(0x12,                NO_MELTDOWN | NO_SSB | NO_L1TF),
+       VULNWL_INTEL(ATOM_GOLDMONT,             NO_MDS | NO_L1TF),
+       VULNWL_INTEL(ATOM_GOLDMONT_X,           NO_MDS | NO_L1TF),
+       VULNWL_INTEL(ATOM_GOLDMONT_PLUS,        NO_MDS | NO_L1TF),
+
+       /* AMD Family 0xf - 0x12 */
+       VULNWL_AMD(0x0f,        NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+       VULNWL_AMD(0x10,        NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+       VULNWL_AMD(0x11,        NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+       VULNWL_AMD(0x12,        NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
 
        /* FAMILY_ANY must be last, otherwise 0x0f - 0x12 matches won't work */
-       VULNWL_AMD(X86_FAMILY_ANY,      NO_MELTDOWN | NO_L1TF),
+       VULNWL_AMD(X86_FAMILY_ANY,      NO_MELTDOWN | NO_L1TF | NO_MDS),
        {}
 };
 
@@ -1012,6 +1016,9 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
        if (ia32_cap & ARCH_CAP_IBRS_ALL)
                setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);
 
+       if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO))
+               setup_force_cpu_bug(X86_BUG_MDS);
+
        if (cpu_matches(NO_MELTDOWN))
                return;