An error occurred fetching the project authors.
  1. 20 Sep, 2022 1 commit
    • Ard Biesheuvel's avatar
      efi/libstub: implement generic EFI zboot · a0509109
      Ard Biesheuvel authored
      Implement a minimal EFI app that decompresses the real kernel image and
      launches it using the firmware's LoadImage and StartImage boot services.
      This removes the need for any arch-specific hacks.
      
      Note that on systems that have UEFI secure boot policies enabled,
      LoadImage/StartImage require images to be signed, or their hashes known
      a priori, in order to be permitted to boot.
      
      There are various possible strategies to work around this requirement,
      but they all rely either on overriding internal PI/DXE protocols (which
      are not part of the EFI spec) or omitting the firmware provided
      LoadImage() and StartImage() boot services, which is also undesirable,
      given that they encapsulate platform specific policies related to secure
      boot and measured boot, but also related to memory permissions (whether
      or not and which types of heap allocations have both write and execute
      permissions.)
      
      The only generic and truly portable way around this is to simply sign
      both the inner and the outer image with the same key/cert pair, so this
      is what is implemented here.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      a0509109
  2. 19 Sep, 2022 1 commit
  3. 17 Sep, 2022 1 commit
    • Ard Biesheuvel's avatar
      efi/libstub: use EFI provided memcpy/memset routines · c82ceb44
      Ard Biesheuvel authored
      The stub is used in different execution environments, but on arm64,
      RISC-V and LoongArch, we still use the core kernel's implementation of
      memcpy and memset, as they are just a branch instruction away, and can
      generally be reused even from code such as the EFI stub that runs in a
      completely different address space.
      
      KAsan complicates this slightly, resulting in the need for some hacks to
      expose the uninstrumented, __ prefixed versions as the normal ones, as
      the latter are instrumented to include the KAsan checks, which only work
      in the core kernel.
      
      Unfortunately, #define'ing memcpy to __memcpy when building C code does
      not guarantee that no explicit memcpy() calls will be emitted. And with
      the upcoming zboot support, which consists of a separate binary which
      therefore needs its own implementation of memcpy/memset anyway, it's
      better to provide one explicitly instead of linking to the existing one.
      
      Given that EFI exposes implementations of memmove() and memset() via the
      boot services table, let's wire those up in the appropriate way, and
      drop the references to the core kernel ones.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      c82ceb44
  4. 06 Sep, 2022 1 commit
    • Huacai Chen's avatar
      efi/loongarch: Add efistub booting support · ead384d9
      Huacai Chen authored
      This patch adds efistub booting support, which is the standard UEFI boot
      protocol for LoongArch to use.
      
      We use generic efistub, which means we can pass boot information (i.e.,
      system table, memory map, kernel command line, initrd) via a light FDT
      and drop a lot of non-standard code.
      
      We use a flat mapping to map the efi runtime in the kernel's address
      space. In efi, VA = PA; in kernel, VA = PA + PAGE_OFFSET. As a result,
      flat mapping is not identity mapping, SetVirtualAddressMap() is still
      needed for the efi runtime.
      Tested-by: default avatarXi Ruoyao <xry111@xry111.site>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      [ardb: change fpic to fpie as suggested by Xi Ruoyao]
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      ead384d9
  5. 26 Mar, 2021 1 commit
  6. 14 Jan, 2021 1 commit
  7. 02 Oct, 2020 1 commit
  8. 07 Sep, 2020 1 commit
  9. 01 Sep, 2020 1 commit
  10. 14 Aug, 2020 1 commit
  11. 09 Jul, 2020 1 commit
  12. 07 Jul, 2020 2 commits
  13. 15 Jun, 2020 1 commit
  14. 19 May, 2020 2 commits
  15. 15 May, 2020 1 commit
  16. 05 May, 2020 1 commit
    • Ard Biesheuvel's avatar
      efi/libstub/x86: Work around LLVM ELF quirk build regression · f77767ed
      Ard Biesheuvel authored
      When building the x86 EFI stub with Clang, the libstub Makefile rules
      that manipulate the ELF object files may throw an error like:
      
          STUBCPY drivers/firmware/efi/libstub/efi-stub-helper.stub.o
        strip: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
        objcopy: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
      
      This is the result of a LLVM feature [0] where symbol references are
      stored in a LLVM specific .llvm_addrsig section in a non-transparent way,
      causing generic ELF tools such as strip or objcopy to choke on them.
      
      So force the compiler not to emit these sections, by passing the
      appropriate command line option.
      
      [0] https://sourceware.org/bugzilla/show_bug.cgi?id=23817
      
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Collingbourne <pcc@google.com>
      Cc: Sami Tolvanen <samitolvanen@google.com>
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Suggested-by: default avatarFangrui Song <maskray@google.com>
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      f77767ed
  17. 24 Apr, 2020 4 commits
  18. 23 Apr, 2020 1 commit
  19. 25 Feb, 2020 1 commit
  20. 23 Feb, 2020 6 commits
    • Ard Biesheuvel's avatar
      efi/libstub: Clean up command line parsing routine · 91d150c0
      Ard Biesheuvel authored
      We currently parse the command non-destructively, to avoid having to
      allocate memory for a copy before passing it to the standard parsing
      routines that are used by the core kernel, and which modify the input
      to delineate the parsed tokens with NUL characters.
      
      Instead, we call strstr() and strncmp() to go over the input multiple
      times, and match prefixes rather than tokens, which implies that we
      would match, e.g., 'nokaslrfoo' in the stub and disable KASLR, while
      the kernel would disregard the option and run with KASLR enabled.
      
      In order to avoid having to reason about whether and how this behavior
      may be abused, let's clean up the parsing routines, and rebuild them
      on top of the existing helpers.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      91d150c0
    • Ard Biesheuvel's avatar
      efi/libstub: Move file I/O support code into separate file · 5193a33d
      Ard Biesheuvel authored
      Split off the file I/O support code into a separate source file so
      it ends up in a separate object file in the static library, allowing
      the linker to omit it if the routines are not used.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      5193a33d
    • Ard Biesheuvel's avatar
      efi/libstub: Move efi_random_alloc() into separate source file · 0ed02bda
      Ard Biesheuvel authored
      efi_random_alloc() is only used on arm64, but as it shares a source
      file with efi_random_get_seed(), the latter will pull in the former
      on other architectures as well.
      
      Let's take advantage of the fact that libstub is a static library,
      and so the linker will only incorporate objects that are needed to
      satisfy dependencies in other objects. This means we can move the
      random alloc code to a separate source file that gets built
      unconditionally, but only used when needed.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      0ed02bda
    • Ard Biesheuvel's avatar
      efi/libstub/x86: Incorporate eboot.c into libstub · c2d0b470
      Ard Biesheuvel authored
      Most of the EFI stub source files of all architectures reside under
      drivers/firmware/efi/libstub, where they share a Makefile with special
      CFLAGS and an include file with declarations that are only relevant
      for stub code.
      
      Currently, we carry a lot of stub specific stuff in linux/efi.h only
      because eboot.c in arch/x86 needs them as well. So let's move eboot.c
      into libstub/, and move the contents of eboot.h that we still care
      about into efistub.h
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      c2d0b470
    • Ard Biesheuvel's avatar
      efi/libstub: Move memory map handling and allocation routines to mem.c · f57db62c
      Ard Biesheuvel authored
      Create a new source file mem.c to keep the routines involved in memory
      allocation and deallocation and manipulation of the EFI memory map.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      f57db62c
    • Ard Biesheuvel's avatar
      efi/libstub: Use hidden visibility for all source files · 6f05106e
      Ard Biesheuvel authored
      Instead of setting the visibility pragma for a small set of symbol
      declarations that could result in absolute references that we cannot
      support in the stub, declare hidden visibility for all code in the
      EFI stub, which is more robust and future proof.
      
      To ensure that the #pragma is taken into account before any other
      includes are processed, put it in a header file of its own and
      include it via the compiler command line using the -include option.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      6f05106e
  21. 22 Feb, 2020 1 commit
    • Ard Biesheuvel's avatar
      efi/libstub/arm64: Use 1:1 mapping of RT services if property table exists · b92165d2
      Ard Biesheuvel authored
      The UEFI spec defines (and deprecates) a misguided and shortlived
      memory protection feature that is based on splitting memory regions
      covering PE/COFF executables into separate code and data regions,
      without annotating them as belonging to the same executable image.
      When the OS assigns the virtual addresses of these regions, it may
      move them around arbitrarily, without taking into account that the
      PE/COFF code sections may contain relative references into the data
      sections, which means the relative placement of these segments has
      to be preserved or the executable image will be corrupted.
      
      The original workaround on arm64 was to ensure that adjacent regions
      of the same type were mapped adjacently in the virtual mapping, but
      this requires sorting of the memory map, which we would prefer to
      avoid.
      
      Considering that the native physical mapping of the PE/COFF images
      does not suffer from this issue, let's preserve it at runtime, and
      install it as the virtual mapping as well.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      b92165d2
  22. 10 Jan, 2020 1 commit
    • Matthew Garrett's avatar
      efi: Allow disabling PCI busmastering on bridges during boot · 4444f854
      Matthew Garrett authored
      Add an option to disable the busmaster bit in the control register on
      all PCI bridges before calling ExitBootServices() and passing control
      to the runtime kernel. System firmware may configure the IOMMU to prevent
      malicious PCI devices from being able to attack the OS via DMA. However,
      since firmware can't guarantee that the OS is IOMMU-aware, it will tear
      down IOMMU configuration when ExitBootServices() is called. This leaves
      a window between where a hostile device could still cause damage before
      Linux configures the IOMMU again.
      
      If CONFIG_EFI_DISABLE_PCI_DMA is enabled or "efi=disable_early_pci_dma"
      is passed on the command line, the EFI stub will clear the busmaster bit
      on all PCI bridges before ExitBootServices() is called. This will
      prevent any malicious PCI devices from being able to perform DMA until
      the kernel reenables busmastering after configuring the IOMMU.
      
      This option may cause failures with some poorly behaved hardware and
      should not be enabled without testing. The kernel commandline options
      "efi=disable_early_pci_dma" or "efi=no_disable_early_pci_dma" may be
      used to override the default. Note that PCI devices downstream from PCI
      bridges are disconnected from their drivers first, using the UEFI
      driver model API, so that DMA can be disabled safely at the bridge
      level.
      
      [ardb: disconnect PCI I/O handles first, as suggested by Arvind]
      Co-developed-by: default avatarMatthew Garrett <mjg59@google.com>
      Signed-off-by: default avatarMatthew Garrett <mjg59@google.com>
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Arvind Sankar <nivedita@alum.mit.edu>
      Cc: Matthew Garrett <matthewgarrett@google.com>
      Cc: linux-efi@vger.kernel.org
      Link: https://lkml.kernel.org/r/20200103113953.9571-18-ardb@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      4444f854
  23. 16 Nov, 2019 1 commit
  24. 07 Nov, 2019 1 commit
  25. 31 Oct, 2019 1 commit
    • Ard Biesheuvel's avatar
      efi: libstub/arm: Account for firmware reserved memory at the base of RAM · 41cd96fa
      Ard Biesheuvel authored
      The EFI stubloader for ARM starts out by allocating a 32 MB window
      at the base of RAM, in order to ensure that the decompressor (which
      blindly copies the uncompressed kernel into that window) does not
      overwrite other allocations that are made while running in the context
      of the EFI firmware.
      
      In some cases, (e.g., U-Boot running on the Raspberry Pi 2), this is
      causing boot failures because this initial allocation conflicts with
      a page of reserved memory at the base of RAM that contains the SMP spin
      tables and other pieces of firmware data and which was put there by
      the bootloader under the assumption that the TEXT_OFFSET window right
      below the kernel is only used partially during early boot, and will be
      left alone once the memory reservations are processed and taken into
      account.
      
      So let's permit reserved memory regions to exist in the region starting
      at the base of RAM, and ending at TEXT_OFFSET - 5 * PAGE_SIZE, which is
      the window below the kernel that is not touched by the early boot code.
      Tested-by: default avatarGuillaume Gardet <Guillaume.Gardet@arm.com>
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: default avatarChester Lin <clin@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: https://lkml.kernel.org/r/20191029173755.27149-5-ardb@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      41cd96fa
  26. 09 Apr, 2019 1 commit
  27. 29 Mar, 2019 2 commits
  28. 04 Feb, 2019 1 commit
    • Ingo Molnar's avatar
      efi/fdt: Apply more cleanups · ac9aff8e
      Ingo Molnar authored
      Apply a number of cleanups:
      
       - Introduce fdt_setprop_*var() helper macros to simplify and shorten repetitive
         sequences - this also makes it less likely that the wrong variable size is
         passed in. This change makes a lot of the property-setting calls single-line
         and easier to read.
      
       - Harmonize comment style: capitalization, punctuation, whitespaces, etc.
      
       - Fix some whitespace noise in the libstub Makefile which I happened to notice.
      
       - Use the standard tabular initialization style:
      
          -       map.map =       &runtime_map;
          -       map.map_size =  &map_size;
          -       map.desc_size = &desc_size;
          -       map.desc_ver =  &desc_ver;
          -       map.key_ptr =   &mmap_key;
          -       map.buff_size = &buff_size;
      
          +       map.map         = &runtime_map;
          +       map.map_size    = &map_size;
          +       map.desc_size   = &desc_size;
          +       map.desc_ver    = &desc_ver;
          +       map.key_ptr     = &mmap_key;
          +       map.buff_size   = &buff_size;
      
       - Use tabular structure definition for better readability.
      
       - Make all pr*() lines single-line, even if they marginally exceed 80 cols - this
         makes them visually less intrusive.
      
       - Unbreak line breaks into single lines when the length exceeds 80 cols only
         marginally, for better readability.
      
       - Move assignment closer to the actual usage site.
      
       - Plus some other smaller cleanups, spelling fixes, etc.
      
      No change in functionality intended.
      
      [ ardb: move changes to upstream libfdt into local header. ]
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
      Cc: Jeffrey Hugo <jhugo@codeaurora.org>
      Cc: Lee Jones <lee.jones@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20190202094119.13230-6-ard.biesheuvel@linaro.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      ac9aff8e
  29. 30 Nov, 2018 1 commit
    • Nathan Chancellor's avatar
      efi/libstub: Disable some warnings for x86{,_64} · 3db5e0ba
      Nathan Chancellor authored
      When building the kernel with Clang, some disabled warnings appear
      because this Makefile overrides KBUILD_CFLAGS for x86{,_64}. Add them to
      this list so that the build is clean again.
      
      -Wpointer-sign was disabled for the whole kernel before the beginning of Git history.
      
      -Waddress-of-packed-member was disabled for the whole kernel and for
      the early boot code in these commits:
      
        bfb38988 ("kbuild: clang: Disable 'address-of-packed-member' warning")
        20c6c189 ("x86/boot: Disable the address-of-packed-member compiler warning").
      
      -Wgnu was disabled for the whole kernel and for the early boot code in
      these commits:
      
        61163efa ("kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang")
        6c3b56b1 ("x86/boot: Disable Clang warnings about GNU extensions").
      
       [ mingo: Made the changelog more readable. ]
      Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arend van Spriel <arend.vanspriel@broadcom.com>
      Cc: Bhupesh Sharma <bhsharma@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Eric Snowberg <eric.snowberg@oracle.com>
      Cc: Hans de Goede <hdegoede@redhat.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Jon Hunter <jonathanh@nvidia.com>
      Cc: Julien Thierry <julien.thierry@arm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: YiFei Zhu <zhuyifei1999@gmail.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20181129171230.18699-8-ard.biesheuvel@linaro.org
      Link: https://github.com/ClangBuiltLinux/linux/issues/112Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      3db5e0ba