| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- From eb1bbc0f0023eadafe368704180f4af739aca9a9 Mon Sep 17 00:00:00 2001
- From: Andy Lutomirski <[email protected]>
- Date: Mon, 4 Dec 2017 15:07:24 +0100
- Subject: [PATCH 154/242] x86/entry/64: Return to userspace from the trampoline
- stack
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- CVE-2017-5754
- By itself, this is useless. It gives us the ability to run some final code
- before exit that cannnot run on the kernel stack. This could include a CR3
- switch a la PAGE_TABLE_ISOLATION or some kernel stack erasing, for
- example. (Or even weird things like *changing* which kernel stack gets
- used as an ASLR-strengthening mechanism.)
- The SYSRET32 path is not covered yet. It could be in the future or
- we could just ignore it and force the slow path if needed.
- Signed-off-by: Andy Lutomirski <[email protected]>
- Signed-off-by: Thomas Gleixner <[email protected]>
- Reviewed-by: Thomas Gleixner <[email protected]>
- Reviewed-by: Borislav Petkov <[email protected]>
- Cc: Boris Ostrovsky <[email protected]>
- Cc: Borislav Petkov <[email protected]>
- Cc: Borislav Petkov <[email protected]>
- Cc: Brian Gerst <[email protected]>
- Cc: Dave Hansen <[email protected]>
- Cc: Dave Hansen <[email protected]>
- Cc: David Laight <[email protected]>
- Cc: Denys Vlasenko <[email protected]>
- Cc: Eduardo Valentin <[email protected]>
- Cc: Greg KH <[email protected]>
- Cc: H. Peter Anvin <[email protected]>
- Cc: Josh Poimboeuf <[email protected]>
- Cc: Juergen Gross <[email protected]>
- Cc: Linus Torvalds <[email protected]>
- Cc: Peter Zijlstra <[email protected]>
- Cc: Rik van Riel <[email protected]>
- Cc: Will Deacon <[email protected]>
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Link: https://lkml.kernel.org/r/[email protected]
- Signed-off-by: Ingo Molnar <[email protected]>
- (cherry picked from commit 3e3b9293d392c577b62e24e4bc9982320438e749)
- Signed-off-by: Andy Whitcroft <[email protected]>
- Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
- (cherry picked from commit 40eb58584f732a2fefb5959e79e408bedeaaa43c)
- Signed-off-by: Fabian Grünbichler <[email protected]>
- ---
- arch/x86/entry/entry_64.S | 55 +++++++++++++++++++++++++++++++++++++++++++----
- 1 file changed, 51 insertions(+), 4 deletions(-)
- diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
- index f70fedc58bac..4abe5b806d2a 100644
- --- a/arch/x86/entry/entry_64.S
- +++ b/arch/x86/entry/entry_64.S
- @@ -325,8 +325,24 @@ syscall_return_via_sysret:
- popq %rsi /* skip rcx */
- popq %rdx
- popq %rsi
- +
- + /*
- + * Now all regs are restored except RSP and RDI.
- + * Save old stack pointer and switch to trampoline stack.
- + */
- + movq %rsp, %rdi
- + movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
- +
- + pushq RSP-RDI(%rdi) /* RSP */
- + pushq (%rdi) /* RDI */
- +
- + /*
- + * We are on the trampoline stack. All regs except RDI are live.
- + * We can do future final exit work right here.
- + */
- +
- popq %rdi
- - movq RSP-ORIG_RAX(%rsp), %rsp
- + popq %rsp
- USERGS_SYSRET64
- END(entry_SYSCALL_64)
-
- @@ -629,10 +645,41 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
- ud2
- 1:
- #endif
- - SWAPGS
- POP_EXTRA_REGS
- - POP_C_REGS
- - addq $8, %rsp /* skip regs->orig_ax */
- + popq %r11
- + popq %r10
- + popq %r9
- + popq %r8
- + popq %rax
- + popq %rcx
- + popq %rdx
- + popq %rsi
- +
- + /*
- + * The stack is now user RDI, orig_ax, RIP, CS, EFLAGS, RSP, SS.
- + * Save old stack pointer and switch to trampoline stack.
- + */
- + movq %rsp, %rdi
- + movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
- +
- + /* Copy the IRET frame to the trampoline stack. */
- + pushq 6*8(%rdi) /* SS */
- + pushq 5*8(%rdi) /* RSP */
- + pushq 4*8(%rdi) /* EFLAGS */
- + pushq 3*8(%rdi) /* CS */
- + pushq 2*8(%rdi) /* RIP */
- +
- + /* 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.
- + */
- +
- + /* Restore RDI. */
- + popq %rdi
- + SWAPGS
- INTERRUPT_RETURN
-
-
- --
- 2.14.2
|