]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0154-x86-entry-64-Return-to-userspace-from-the-trampoline.patch
build: reformat existing patches
[pve-kernel.git] / patches / kernel / 0154-x86-entry-64-Return-to-userspace-from-the-trampoline.patch
CommitLineData
59d5af67 1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
321d628a
FG
2From: Andy Lutomirski <luto@kernel.org>
3Date: Mon, 4 Dec 2017 15:07:24 +0100
59d5af67 4Subject: [PATCH] x86/entry/64: Return to userspace from the trampoline stack
321d628a
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9CVE-2017-5754
10
11By itself, this is useless. It gives us the ability to run some final code
12before exit that cannnot run on the kernel stack. This could include a CR3
13switch a la PAGE_TABLE_ISOLATION or some kernel stack erasing, for
14example. (Or even weird things like *changing* which kernel stack gets
15used as an ASLR-strengthening mechanism.)
16
17The SYSRET32 path is not covered yet. It could be in the future or
18we could just ignore it and force the slow path if needed.
19
20Signed-off-by: Andy Lutomirski <luto@kernel.org>
21Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
22Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
23Reviewed-by: Borislav Petkov <bp@suse.de>
24Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
25Cc: Borislav Petkov <bp@alien8.de>
26Cc: Borislav Petkov <bpetkov@suse.de>
27Cc: Brian Gerst <brgerst@gmail.com>
28Cc: Dave Hansen <dave.hansen@intel.com>
29Cc: Dave Hansen <dave.hansen@linux.intel.com>
30Cc: David Laight <David.Laight@aculab.com>
31Cc: Denys Vlasenko <dvlasenk@redhat.com>
32Cc: Eduardo Valentin <eduval@amazon.com>
33Cc: Greg KH <gregkh@linuxfoundation.org>
34Cc: H. Peter Anvin <hpa@zytor.com>
35Cc: Josh Poimboeuf <jpoimboe@redhat.com>
36Cc: Juergen Gross <jgross@suse.com>
37Cc: Linus Torvalds <torvalds@linux-foundation.org>
38Cc: Peter Zijlstra <peterz@infradead.org>
39Cc: Rik van Riel <riel@redhat.com>
40Cc: Will Deacon <will.deacon@arm.com>
41Cc: aliguori@amazon.com
42Cc: daniel.gruss@iaik.tugraz.at
43Cc: hughd@google.com
44Cc: keescook@google.com
45Link: https://lkml.kernel.org/r/20171204150606.306546484@linutronix.de
46Signed-off-by: Ingo Molnar <mingo@kernel.org>
47(cherry picked from commit 3e3b9293d392c577b62e24e4bc9982320438e749)
48Signed-off-by: Andy Whitcroft <apw@canonical.com>
49Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
50(cherry picked from commit 40eb58584f732a2fefb5959e79e408bedeaaa43c)
51Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
52---
53 arch/x86/entry/entry_64.S | 55 +++++++++++++++++++++++++++++++++++++++++++----
54 1 file changed, 51 insertions(+), 4 deletions(-)
55
56diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
57index f70fedc58bac..4abe5b806d2a 100644
58--- a/arch/x86/entry/entry_64.S
59+++ b/arch/x86/entry/entry_64.S
60@@ -325,8 +325,24 @@ syscall_return_via_sysret:
61 popq %rsi /* skip rcx */
62 popq %rdx
63 popq %rsi
64+
65+ /*
66+ * Now all regs are restored except RSP and RDI.
67+ * Save old stack pointer and switch to trampoline stack.
68+ */
69+ movq %rsp, %rdi
70+ movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
71+
72+ pushq RSP-RDI(%rdi) /* RSP */
73+ pushq (%rdi) /* RDI */
74+
75+ /*
76+ * We are on the trampoline stack. All regs except RDI are live.
77+ * We can do future final exit work right here.
78+ */
79+
80 popq %rdi
81- movq RSP-ORIG_RAX(%rsp), %rsp
82+ popq %rsp
83 USERGS_SYSRET64
84 END(entry_SYSCALL_64)
85
86@@ -629,10 +645,41 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
87 ud2
88 1:
89 #endif
90- SWAPGS
91 POP_EXTRA_REGS
92- POP_C_REGS
93- addq $8, %rsp /* skip regs->orig_ax */
94+ popq %r11
95+ popq %r10
96+ popq %r9
97+ popq %r8
98+ popq %rax
99+ popq %rcx
100+ popq %rdx
101+ popq %rsi
102+
103+ /*
104+ * The stack is now user RDI, orig_ax, RIP, CS, EFLAGS, RSP, SS.
105+ * Save old stack pointer and switch to trampoline stack.
106+ */
107+ movq %rsp, %rdi
108+ movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
109+
110+ /* Copy the IRET frame to the trampoline stack. */
111+ pushq 6*8(%rdi) /* SS */
112+ pushq 5*8(%rdi) /* RSP */
113+ pushq 4*8(%rdi) /* EFLAGS */
114+ pushq 3*8(%rdi) /* CS */
115+ pushq 2*8(%rdi) /* RIP */
116+
117+ /* Push user RDI on the trampoline stack. */
118+ pushq (%rdi)
119+
120+ /*
121+ * We are on the trampoline stack. All regs except RDI are live.
122+ * We can do future final exit work right here.
123+ */
124+
125+ /* Restore RDI. */
126+ popq %rdi
127+ SWAPGS
128 INTERRUPT_RETURN
129
130
131--
1322.14.2
133