• Baoquan He's avatar
    x86/mm/KASLR: Compute the size of the vmemmap section properly · 00e5a2bb
    Baoquan He authored
    The size of the vmemmap section is hardcoded to 1 TB to support the
    maximum amount of system RAM in 4-level paging mode - 64 TB.
    
    However, 1 TB is not enough for vmemmap in 5-level paging mode. Assuming
    the size of struct page is 64 Bytes, to support 4 PB system RAM in 5-level,
    64 TB of vmemmap area is needed:
    
      4 * 1000^5 PB / 4096 bytes page size * 64 bytes per page struct / 1000^4 TB = 62.5 TB.
    
    This hardcoding may cause vmemmap to corrupt the following
    cpu_entry_area section, if KASLR puts vmemmap very close to it and the
    actual vmemmap size is bigger than 1 TB.
    
    So calculate the actual size of the vmemmap region needed and then align
    it up to 1 TB boundary.
    
    In 4-level paging mode it is always 1 TB. In 5-level it's adjusted on
    demand. The current code reserves 0.5 PB for vmemmap on 5-level. With
    this change, the space can be saved and thus used to increase entropy
    for the randomization.
    
     [ bp: Spell out how the 64 TB needed for vmemmap is computed and massage commit
       message. ]
    
    Fixes: eedb92ab ("x86/mm: Make virtual memory layout dynamic for CONFIG_X86_5LEVEL=y")
    Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Acked-by: default avatarKirill A. Shutemov <kirill@linux.intel.com>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: kirill.shutemov@linux.intel.com
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: stable <stable@vger.kernel.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: x86-ml <x86@kernel.org>
    Link: https://lkml.kernel.org/r/20190523025744.3756-1-bhe@redhat.com
    00e5a2bb
kaslr.c 6.38 KB