x86/boot/compressed/64: Fix moving page table out of trampoline memory
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Wed, 16 May 2018 08:01:29 +0000 (11:01 +0300)
committerIngo Molnar <mingo@kernel.org>
Wed, 16 May 2018 10:15:13 +0000 (12:15 +0200)
commit589bb62be316401603453c7d2d3c60ad8b9c3cf3
treeab530c19d1e742bdcde35a7866ab0827e9ecee15
parent5c9b0b1c49881c680d4a56b9d9e03dfb3160fd4d
x86/boot/compressed/64: Fix moving page table out of trampoline memory

cleanup_trampoline() relocates the top-level page table out of
trampoline memory. We use 'top_pgtable' as our new top-level page table.

But if the 'top_pgtable' would be referenced from C in a usual way,
the address of the table will be calculated relative to RIP.
After kernel gets relocated, the address will be in the middle of
decompression buffer and the page table may get overwritten.
This leads to a crash.

We calculate the address of other page tables relative to the relocation
address. It makes them safe. We should do the same for 'top_pgtable'.

Calculate the address of 'top_pgtable' in assembly and pass down to
cleanup_trampoline().

Move the page table to .pgtable section where the rest of page tables
are. The section is @nobits so we save 4k in kernel image.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Hugh Dickins <hughd@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Fixes: e9d0e6330eb8 ("x86/boot/compressed/64: Prepare new top-level page table for trampoline")
Link: http://lkml.kernel.org/r/20180516080131.27913-3-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/boot/compressed/head_64.S
arch/x86/boot/compressed/pgtable_64.c