All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: [patch V2 03/10] MDS basics+ 3
Date: Wed, 20 Feb 2019 16:07:56 +0100	[thread overview]
Message-ID: <20190220151400.217101404@linutronix.de> (raw)
In-Reply-To: 20190220150753.665964899@linutronix.de

Subject: [patch V2 03/10] x86/speculation/mds: Add mds_clear_cpu_buffer()
From: Thomas Gleixner <tglx@linutronix.de>

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.

Add x86 specific documentation about MDS and the internal workings of the
mitigation.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
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            |   72 +++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/nospec-branch.h |   20 +++++++++
 5 files changed, 111 insertions(+)

--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -101,6 +101,7 @@ implementation.
    :maxdepth: 2
 
    sh/index
+   x86/index
 
 Filesystem Documentation
 ------------------------
--- /dev/null
+++ b/Documentation/x86/conf.py
@@ -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'),
+]
--- /dev/null
+++ b/Documentation/x86/index.rst
@@ -0,0 +1,8 @@
+==========================
+x86 architecture specifics
+==========================
+
+.. toctree::
+   :maxdepth: 1
+
+   mds
--- /dev/null
+++ b/Documentation/x86/mds.rst
@@ -0,0 +1,72 @@
+Microarchitecural Data Sampling (MDS) mitigation
+================================================
+
+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 (MLPDS) (CVE-2018-12127)
+
+MSBDS leaks Store Buffer Entries which can be speculatively forwarded to a
+dependent load (store-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 partitionened between Hyper-Threads so cross thread forwarding
+is not possible. But if a thread enters or exits a sleep state the store
+buffer is repartioned 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 preceeding 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.
+
+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 spared. 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.
+
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -318,6 +318,26 @@ 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 memory form, don't modify to use a register. VERW
+	 * modifies ZF.
+	 */
+	asm volatile("verw %[ds]" : : "i" (0), [ds] "m" (ds) : "cc");
+}
+
 #endif /* __ASSEMBLY__ */
 
 /*

  parent reply	other threads:[~2019-02-20 15:18 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 15:07 [patch V2 00/10] MDS basics+ 0 Thomas Gleixner
2019-02-20 15:07 ` [patch V2 01/10] MDS basics+ 1 Thomas Gleixner
2019-02-20 16:27   ` [MODERATED] " Borislav Petkov
2019-02-20 16:46   ` Greg KH
2019-02-20 15:07 ` [patch V2 02/10] MDS basics+ 2 Thomas Gleixner
2019-02-20 16:47   ` [MODERATED] " Borislav Petkov
2019-02-20 16:48   ` Greg KH
2019-02-20 15:07 ` Thomas Gleixner [this message]
2019-02-20 16:54   ` [MODERATED] Re: [patch V2 03/10] MDS basics+ 3 mark gross
2019-02-20 16:57     ` Thomas Gleixner
2019-02-20 18:08       ` [MODERATED] " mark gross
2019-02-20 21:40         ` Thomas Gleixner
2019-02-20 17:14   ` [MODERATED] " Borislav Petkov
2019-02-20 21:31     ` Thomas Gleixner
2019-02-21  2:12   ` [MODERATED] " Andrew Cooper
2019-02-21  9:27     ` Peter Zijlstra
2019-02-21  9:33     ` [MODERATED] " Borislav Petkov
2019-02-21 10:04     ` Thomas Gleixner
2019-02-21 10:18       ` [MODERATED] Re: " Borislav Petkov
2019-02-20 15:07 ` [patch V2 04/10] MDS basics+ 4 Thomas Gleixner
2019-02-20 16:52   ` [MODERATED] " Greg KH
2019-02-20 17:10   ` mark gross
2019-02-21 19:26     ` [MODERATED] Encrypted Message Tim Chen
2019-02-21 20:32       ` Thomas Gleixner
2019-02-21 21:07       ` [MODERATED] " Jiri Kosina
2019-02-20 18:43   ` [MODERATED] Re: [patch V2 04/10] MDS basics+ 4 Borislav Petkov
2019-02-20 19:26   ` Jiri Kosina
2019-02-20 21:42     ` Thomas Gleixner
2019-02-20 15:07 ` [patch V2 05/10] MDS basics+ 5 Thomas Gleixner
2019-02-20 20:05   ` [MODERATED] " Borislav Petkov
2019-02-21  2:24   ` Andrew Cooper
2019-02-21 10:36     ` Thomas Gleixner
2019-02-21 11:22       ` Thomas Gleixner
2019-02-21 11:51       ` [MODERATED] Attack Surface [Was [patch V2 05/10] MDS basics+ 5] Andrew Cooper
2019-02-21 18:41         ` Thomas Gleixner
2019-02-20 15:07 ` [patch V2 06/10] MDS basics+ 6 Thomas Gleixner
2019-02-21 10:18   ` [MODERATED] " Borislav Petkov
2019-02-20 15:08 ` [patch V2 07/10] MDS basics+ 7 Thomas Gleixner
2019-02-21 12:47   ` [MODERATED] " Borislav Petkov
2019-02-21 13:48     ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 08/10] MDS basics+ 8 Thomas Gleixner
2019-02-21 14:04   ` [MODERATED] " Borislav Petkov
2019-02-21 14:11     ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 09/10] MDS basics+ 9 Thomas Gleixner
2019-02-20 16:21   ` [MODERATED] " Peter Zijlstra
2019-02-20 22:32     ` Thomas Gleixner
2019-02-20 22:50       ` [MODERATED] " Jiri Kosina
2019-02-20 23:22         ` Thomas Gleixner
2019-02-21 11:04   ` [MODERATED] " Peter Zijlstra
2019-02-21 11:50     ` Peter Zijlstra
2019-02-21 14:18   ` Borislav Petkov
2019-02-21 18:00   ` Kees Cook
2019-02-21 19:46     ` Thomas Gleixner
2019-02-21 20:56       ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 10/10] MDS basics+ 10 Thomas Gleixner
2019-02-22 16:05 ` [MODERATED] Re: [patch V2 00/10] MDS basics+ 0 mark gross
2019-02-22 17:12   ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190220151400.217101404@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=speck@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.