• Ard Biesheuvel's avatar
    efi/x86: Handle by-ref arguments covering multiple pages in mixed mode · 8319e9d5
    Ard Biesheuvel authored
    The mixed mode runtime wrappers are fragile when it comes to how the
    memory referred to by its pointer arguments are laid out in memory, due
    to the fact that it translates these addresses to physical addresses that
    the runtime services can dereference when running in 1:1 mode. Since
    vmalloc'ed pages (including the vmap'ed stack) are not contiguous in the
    physical address space, this scheme only works if the referenced memory
    objects do not cross page boundaries.
    
    Currently, the mixed mode runtime service wrappers require that all by-ref
    arguments that live in the vmalloc space have a size that is a power of 2,
    and are aligned to that same value. While this is a sensible way to
    construct an object that is guaranteed not to cross a page boundary, it is
    overly strict when it comes to checking whether a given object violates
    this requirement, as we can simply take the physical address of the first
    and the last byte, and verify that they point into the same physical page.
    
    When this check fails, we emit a WARN(), but then simply proceed with the
    call, which could cause data corruption if the next physical page belongs
    to a mapping that is entirely unrelated.
    
    Given that with vmap'ed stacks, this condition is much more likely to
    trigger, let's relax the condition a bit, but fail the runtime service
    call if it does trigger.
    
    Fixes: f6697df3 ("x86/efi: Prevent mixed mode boot corruption with CONFIG_VMAP_STACK=y")
    Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Cc: linux-efi@vger.kernel.org
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20200221084849.26878-4-ardb@kernel.org
    8319e9d5
efi_64.c 22.8 KB