x86/KASLR: Fix detection 32/64 bit bootloaders for 5-level paging
commita24261d70e00e4ce03cf45bbf18398f52a7b9229
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Wed, 28 Jun 2017 12:17:30 +0000 (28 15:17 +0300)
committerIngo Molnar <mingo@kernel.org>
Fri, 30 Jun 2017 06:56:53 +0000 (30 08:56 +0200)
tree952085e6380dfcb43b3b1987909c84d0154d8cd7
parentbb43dbc5e09d52c6085dfee65f4f923b3fbcd1d4
x86/KASLR: Fix detection 32/64 bit bootloaders for 5-level paging

KASLR uses hack to detect whether we booted via startup_32() or
startup_64(): it checks what is loaded into cr3 and compares it to
_pgtables. _pgtables is the array of page tables where early code
allocates page table from.

KASLR expects cr3 to point to _pgtables if we booted via startup_32(), but
that's not true if we booted with 5-level paging enabled. In this case top
level page table is allocated separately and only the first p4d page table
is allocated from the array.

Let's modify the check to cover both 4- and 5-level paging cases.

The patch also renames 'level4p' to 'top_level_pgt' as it now can hold
page table for 4th or 5th level, depending on configuration.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arch@vger.kernel.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20170628121730.43079-1-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/boot/compressed/pagetable.c