All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: speck@linutronix.de
Cc: Andi Kleen <ak@linux.intel.com>
Subject: [MODERATED] [PATCH v2 2/8] MDSv2 1
Date: Mon, 10 Dec 2018 09:53:34 -0800	[thread overview]
Message-ID: <d464217bf6889e56c7db9318bf2b94704fa2d1a9.1544464266.git.ak@linux.intel.com> (raw)
In-Reply-To: <cover.1544464266.git.ak@linux.intel.com>
In-Reply-To: <cover.1544464266.git.ak@linux.intel.com>

For MDS the CPU might leak previously touched data
in CPU internal structures. Make sure to clear these structures
every time we exit the kernel. This prevents any leakage
between user processes or between kernel and user.

The flushing is provided by new microcode as a new side
effect of the otherwise unused VERW instruction. We
add VERW to all the kernel exit paths.

We don't need to do this for guests because the L1TF cache
flush will implicitely do the same flushing, and is
automatically selected on MDS affected systems.

This mitigation doesn't address Hyper Threading.

So far this is for 64bit only, 32bit is not covered yet.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/entry/calling.h             | 2 ++
 arch/x86/entry/entry_64.S            | 8 ++++++++
 arch/x86/entry/entry_64_compat.S     | 1 +
 arch/x86/include/asm/nospec-branch.h | 8 ++++++++
 4 files changed, 19 insertions(+)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 25e5a6bda8c3..4b07f97e3874 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -1,4 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/stringify.h>
+#include <asm/segment.h>
 #include <linux/jump_label.h>
 #include <asm/unwind_hints.h>
 #include <asm/cpufeatures.h>
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ce25d84023c0..0bb7bb3dc728 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -248,6 +248,9 @@ GLOBAL(entry_SYSCALL_64_after_hwframe)
 	 * perf profiles. Nothing jumps here.
 	 */
 syscall_return_via_sysret:
+
+	EXIT_MDS
+
 	/* rcx and r11 are already restored (see code above) */
 	UNWIND_HINT_EMPTY
 	POP_REGS pop_rdi=0 skip_r11rcx=1
@@ -604,6 +607,8 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
 	ud2
 1:
 #endif
+	EXIT_MDS
+
 	POP_REGS pop_rdi=0
 
 	/*
@@ -623,6 +628,7 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
 	/* Push user RDI on the trampoline stack. */
 	pushq	(%rdi)
 
+
 	/*
 	 * We are on the trampoline stack.  All regs except RDI are live.
 	 * We can do future final exit work right here.
@@ -1616,6 +1622,8 @@ end_repeat_nmi:
 	movq	$-1, %rsi
 	call	do_nmi
 
+	EXIT_MDS
+
 	/* Always restore stashed CR3 value (see paranoid_entry) */
 	RESTORE_CR3 scratch_reg=%r15 save_reg=%r14
 
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 8eaf8952c408..8b5a11c6a32e 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -276,6 +276,7 @@ sysret32_from_system_call:
 	popq	%rdx			/* Skip pt_regs->cx */
 	popq	%rdx			/* pt_regs->dx */
 	popq	%rsi			/* pt_regs->si */
+	EXIT_MDS
 	popq	%rdi			/* pt_regs->di */
 
         /*
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 032b6009baab..f780f29e351f 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -150,6 +150,14 @@
 #endif
 .endm
 
+.macro EXIT_MDS
+	/* Clear CPU buffers that could leak. Instruction must be in memory form. */
+	ALTERNATIVE_2 "", __stringify(push $__USER_DS ; verw (% _ASM_SP ) ; add $8, % _ASM_SP ),\
+		X86_FEATURE_MB_CLEAR, \
+		"call do_clear_cpu", \
+		X86_BUG_MDS_CLEAR_CPU
+.endm
+
 #else /* __ASSEMBLY__ */
 
 #define ANNOTATE_NOSPEC_ALTERNATIVE				\
-- 
2.17.2

  parent reply	other threads:[~2018-12-10 22:34 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10 17:53 [MODERATED] [PATCH v2 0/8] MDSv2 8 Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 1/8] MDSv2 4 Andi Kleen
2018-12-11 14:14   ` [MODERATED] " Paolo Bonzini
2018-12-12 21:22   ` Konrad Rzeszutek Wilk
2018-12-12 21:28     ` Andi Kleen
2018-12-12 21:25   ` Konrad Rzeszutek Wilk
2018-12-10 17:53 ` Andi Kleen [this message]
2018-12-10 22:49   ` [MODERATED] Re: [PATCH v2 2/8] MDSv2 1 Jiri Kosina
2018-12-11  0:03     ` Andi Kleen
2018-12-11  0:13     ` Kanth Ghatraju
2018-12-11  2:00       ` Andi Kleen
2018-12-11  5:36       ` Jiri Kosina
2018-12-11 10:03       ` Borislav Petkov
2018-12-12 21:31         ` Konrad Rzeszutek Wilk
2018-12-12 21:43           ` Andi Kleen
2018-12-12 22:17           ` Borislav Petkov
2018-12-12 22:40             ` Konrad Rzeszutek Wilk
2018-12-12 22:45               ` Borislav Petkov
2018-12-13 15:15                 ` Andrew Cooper
2018-12-13 16:52                   ` Borislav Petkov
2018-12-10 17:53 ` [MODERATED] [PATCH v2 3/8] MDSv2 5 Andi Kleen
2018-12-10 23:00   ` [MODERATED] " Linus Torvalds
2018-12-11  0:03     ` Andi Kleen
2018-12-11  0:43       ` Linus Torvalds
2018-12-11  1:33         ` Linus Torvalds
2018-12-11  2:12           ` Andi Kleen
2018-12-11  2:20           ` Linus Torvalds
2018-12-11  3:25             ` Andi Kleen
2018-12-11 17:55               ` Linus Torvalds
2018-12-11 18:10                 ` Borislav Petkov
2018-12-11 18:21                 ` Linus Torvalds
2018-12-11 18:26                   ` Borislav Petkov
2018-12-11 19:47                   ` Andi Kleen
2018-12-11 21:22                   ` Thomas Gleixner
2018-12-12 14:02               ` [MODERATED] " Paolo Bonzini
2018-12-12 17:58                 ` Andi Kleen
2018-12-12 18:47                   ` Linus Torvalds
2018-12-13 19:44                     ` Linus Torvalds
2018-12-13 20:48                       ` Andi Kleen
2018-12-13 20:56                         ` Linus Torvalds
2018-12-15  0:30                         ` Andi Kleen
2018-12-11  2:10         ` Andi Kleen
2018-12-11  0:09     ` Andrew Cooper
2018-12-10 17:53 ` [MODERATED] [PATCH v2 4/8] MDSv2 0 Andi Kleen
2018-12-12 21:45   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-12-12 22:09     ` Andi Kleen
2018-12-12 22:36       ` Konrad Rzeszutek Wilk
2018-12-10 17:53 ` [MODERATED] [PATCH v2 5/8] MDSv2 7 Andi Kleen
2018-12-11  0:33   ` [MODERATED] " Andrew Cooper
2018-12-12 18:05     ` Andrew Cooper
2018-12-12 21:41   ` Konrad Rzeszutek Wilk
2018-12-12 22:12     ` Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 6/8] MDSv2 3 Andi Kleen
2018-12-11  0:37   ` [MODERATED] " Andrew Cooper
2018-12-11  0:46     ` Luck, Tony
2018-12-11  1:02       ` Andrew Cooper
2018-12-11  1:53       ` Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 7/8] MDSv2 6 Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 8/8] MDSv2 2 Andi Kleen

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=d464217bf6889e56c7db9318bf2b94704fa2d1a9.1544464266.git.ak@linux.intel.com \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --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.