Skip to content

Commit

Permalink
x86/boot/compressed/64: Save and restore trampoline memory
Browse files Browse the repository at this point in the history
The memory area we found for trampoline shouldn't contain anything
useful. But let's preserve the data anyway. Just to be on safe side.

paging_prepare() would save the data into a buffer.

cleanup_trampoline() would restore it back once we are done with the
trampoline.

Tested-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20180226180451.86788-4-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Kirill A. Shutemov authored and Ingo Molnar committed Mar 12, 2018
1 parent 3548e13 commit fb52683
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions arch/x86/boot/compressed/head_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ ENTRY(startup_64)
lretq
lvl5:

/*
* cleanup_trampoline() would restore trampoline memory.
*
* RSI holds real mode data and needs to be preserved across
* this function call.
*/
pushq %rsi
call cleanup_trampoline
popq %rsi

/* Zero EFLAGS */
pushq $0
popfq
Expand Down
13 changes: 13 additions & 0 deletions arch/x86/boot/compressed/pgtable_64.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <asm/processor.h>
#include "pgtable.h"
#include "../string.h"

/*
* __force_order is used by special_insns.h asm code to force instruction
Expand All @@ -18,6 +19,9 @@ struct paging_config {
unsigned long l5_required;
};

/* Buffer to preserve trampoline memory */
static char trampoline_save[TRAMPOLINE_32BIT_SIZE];

/*
* Trampoline address will be printed by extract_kernel() for debugging
* purposes.
Expand Down Expand Up @@ -69,5 +73,14 @@ struct paging_config paging_prepare(void)

trampoline_32bit = (unsigned long *)paging_config.trampoline_start;

/* Preserve trampoline memory */
memcpy(trampoline_save, trampoline_32bit, TRAMPOLINE_32BIT_SIZE);

return paging_config;
}

void cleanup_trampoline(void)
{
/* Restore trampoline memory */
memcpy(trampoline_32bit, trampoline_save, TRAMPOLINE_32BIT_SIZE);
}

0 comments on commit fb52683

Please sign in to comment.