• Kirill A. Shutemov's avatar
    x86/KASLR: Fix detection 32/64 bit bootloaders for 5-level paging · a24261d7
    Kirill A. Shutemov authored
    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: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Acked-by: default avatarKees 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    a24261d7
pagetable.c 4.36 KB