• Ard Biesheuvel's avatar
    efi/libstub: Add support for loading the initrd from a device path · ec93fc37
    Ard Biesheuvel authored
    There are currently two ways to specify the initrd to be passed to the
    Linux kernel when booting via the EFI stub:
    - it can be passed as a initrd= command line option when doing a pure PE
      boot (as opposed to the EFI handover protocol that exists for x86)
    - otherwise, the bootloader or firmware can load the initrd into memory,
      and pass the address and size via the bootparams struct (x86) or
      device tree (ARM)
    
    In the first case, we are limited to loading from the same file system
    that the kernel was loaded from, and it is also problematic in a trusted
    boot context, given that we cannot easily protect the command line from
    tampering without either adding complicated white/blacklisting of boot
    arguments or locking down the command line altogether.
    
    In the second case, we force the bootloader to duplicate knowledge about
    the boot protocol which is already encoded in the stub, and which may be
    subject to change over time, e.g., bootparams struct definitions, memory
    allocation/alignment requirements for the placement of the initrd etc etc.
    In the ARM case, it also requires the bootloader to modify the hardware
    description provided by the firmware, as it is passed in the same file.
    On systems where the initrd is measured after loading, it creates a time
    window where the initrd contents might be manipulated in memory before
    handing over to the kernel.
    
    Address these concerns by adding support for loading the initrd into
    memory by invoking the EFI LoadFile2 protocol installed on a vendor
    GUIDed device path that specifically designates a Linux initrd.
    This addresses the above concerns, by putting the EFI stub in charge of
    placement in memory and of passing the base and size to the kernel proper
    (via whatever means it desires) while still leaving it up to the firmware
    or bootloader to obtain the file contents, potentially from other file
    systems than the one the kernel itself was loaded from. On platforms that
    implement measured boot, it permits the firmware to take the measurement
    right before the kernel actually consumes the contents.
    Acked-by: default avatarLaszlo Ersek <lersek@redhat.com>
    Tested-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
    Acked-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
    Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
    ec93fc37
x86-stub.c 19.9 KB