Skip to content
  • Baoquan He's avatar
    x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address · c05cd797
    Baoquan He authored
    
    
    Currently KASLR will parse all e820 entries of RAM type and add all
    candidate positions into the slots array. After that we choose one slot
    randomly as the new position which the kernel will be decompressed into
    and run at.
    
    On systems with EFI enabled, e820 memory regions are coming from EFI
    memory regions by combining adjacent regions.
    
    These EFI memory regions have various attributes, and the "mirrored"
    attribute is one of them. The physical memory region whose descriptors
    in EFI memory map has EFI_MEMORY_MORE_RELIABLE attribute (bit: 16) are
    mirrored. The address range mirroring feature of the kernel arranges such
    mirrored regions into normal zones and other regions into movable zones.
    
    With the mirroring feature enabled, the code and data of the kernel can only
    be located in the more reliable mirrored regions. However, the current KASLR
    code doesn't check EFI memory entries, and could choose a new kernel position
    in non-mirrored regions. This will break the intended functionality of the
    address range mirroring feature.
    
    To fix this, if EFI is detected, iterate EFI memory map and pick the mirrored
    region to process for adding candidate of randomization slot. If EFI is disabled
    or no mirrored region found, still process the e820 memory map.
    
    Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: ard.biesheuvel@linaro.org
    Cc: fanc.fnst@cn.fujitsu.com
    Cc: izumi.taku@jp.fujitsu.com
    Cc: keescook@chromium.org
    Cc: linux-efi@vger.kernel.org
    Cc: matt@codeblueprint.co.uk
    Cc: n-horiguchi@ah.jp.nec.com
    Cc: thgarnie@google.com
    Link: http://lkml.kernel.org/r/1502722464-20614-3-git-send-email-bhe@redhat.com
    
    
    [ Rewrote most of the text. ]
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    c05cd797