1. 11 11月, 2022 1 次提交
    • A
      arm64: efi: Force the use of SetVirtualAddressMap() on Altra machines · 550b33cf
      Ard Biesheuvel 提交于
      Ampere Altra machines are reported to misbehave when the SetTime() EFI
      runtime service is called after ExitBootServices() but before calling
      SetVirtualAddressMap(). Given that the latter is horrid, pointless and
      explicitly documented as optional by the EFI spec, we no longer invoke
      it at boot if the configured size of the VA space guarantees that the
      EFI runtime memory regions can remain mapped 1:1 like they are at boot
      time.
      
      On Ampere Altra machines, this results in SetTime() calls issued by the
      rtc-efi driver triggering synchronous exceptions during boot.  We can
      now recover from those without bringing down the system entirely, due to
      commit 23715a26 ("arm64: efi: Recover from synchronous
      exceptions occurring in firmware"). However, it would be better to avoid
      the issue entirely, given that the firmware appears to remain in a funny
      state after this.
      
      So attempt to identify these machines based on the 'family' field in the
      type #1 SMBIOS record, and call SetVirtualAddressMap() unconditionally
      in that case.
      Tested-by: NAlexandru Elisei <alexandru.elisei@gmail.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      550b33cf
  2. 04 10月, 2022 1 次提交
    • A
      kmsan: disable instrumentation of unsupported common kernel code · 79dbd006
      Alexander Potapenko 提交于
      EFI stub cannot be linked with KMSAN runtime, so we disable
      instrumentation for it.
      
      Instrumenting kcov, stackdepot or lockdep leads to infinite recursion
      caused by instrumentation hooks calling instrumented code again.
      
      Link: https://lkml.kernel.org/r/20220915150417.722975-13-glider@google.comSigned-off-by: NAlexander Potapenko <glider@google.com>
      Reviewed-by: NMarco Elver <elver@google.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andrey Konovalov <andreyknvl@gmail.com>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Eric Biggers <ebiggers@google.com>
      Cc: Eric Biggers <ebiggers@kernel.org>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Ilya Leoshkevich <iii@linux.ibm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vegard Nossum <vegard.nossum@oracle.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      79dbd006
  3. 27 9月, 2022 2 次提交
    • A
      efi/loongarch: libstub: remove dependency on flattened DT · 40cd01a9
      Ard Biesheuvel 提交于
      LoongArch does not use FDT or DT natively [yet], and the only reason it
      currently uses it is so that it can reuse the existing EFI stub code.
      
      Overloading the DT with data passed between the EFI stub and the core
      kernel has been a source of problems: there is the overlap between
      information provided by EFI which DT can also provide (initrd base/size,
      command line, memory descriptions), requiring us to reason about which
      is which and what to prioritize. It has also resulted in ABI leaks,
      i.e., internal ABI being promoted to external ABI inadvertently because
      the bootloader can set the EFI stub's DT properties as well (e.g.,
      "kaslr-seed"). This has become especially problematic with boot
      environments that want to pretend that EFI boot is being done (to access
      ACPI and SMBIOS tables, for instance) but have no ability to execute the
      EFI stub, and so the environment that the EFI stub creates is emulated
      [poorly, in some cases].
      
      Another downside of treating DT like this is that the DT binary that the
      kernel receives is different from the one created by the firmware, which
      is undesirable in the context of secure and measured boot.
      
      Given that LoongArch support in Linux is brand new, we can avoid these
      pitfalls, and treat the DT strictly as a hardware description, and use a
      separate handover method between the EFI stub and the kernel. Now that
      initrd loading and passing the EFI memory map have been refactored into
      pure EFI routines that use EFI configuration tables, the only thing we
      need to pass directly is the kernel command line (even if we could pass
      this via a config table as well, it is used extremely early, so passing
      it directly is preferred in this case.)
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Acked-by: NHuacai Chen <chenhuacai@loongson.cn>
      40cd01a9
    • S
      treewide: Filter out CC_FLAGS_CFI · f143ff39
      Sami Tolvanen 提交于
      In preparation for removing CC_FLAGS_CFI from CC_FLAGS_LTO, explicitly
      filter out CC_FLAGS_CFI in all the makefiles where we currently filter
      out CC_FLAGS_LTO.
      Signed-off-by: NSami Tolvanen <samitolvanen@google.com>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Tested-by: NKees Cook <keescook@chromium.org>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Tested-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20220908215504.3686827-2-samitolvanen@google.com
      f143ff39
  4. 20 9月, 2022 1 次提交
    • A
      efi/libstub: implement generic EFI zboot · a0509109
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      a0509109
  5. 19 9月, 2022 1 次提交
  6. 17 9月, 2022 1 次提交
    • A
      efi/libstub: use EFI provided memcpy/memset routines · c82ceb44
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      c82ceb44
  7. 06 9月, 2022 1 次提交
    • H
      efi/loongarch: Add efistub booting support · ead384d9
      Huacai Chen 提交于
      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: NXi Ruoyao <xry111@xry111.site>
      Signed-off-by: NHuacai Chen <chenhuacai@loongson.cn>
      [ardb: change fpic to fpie as suggested by Xi Ruoyao]
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      ead384d9
  8. 25 8月, 2022 1 次提交
    • A
      efi: libstub: Disable struct randomization · 1a388792
      Ard Biesheuvel 提交于
      The EFI stub is a wrapper around the core kernel that makes it look like
      a EFI compatible PE/COFF application to the EFI firmware. EFI
      applications run on top of the EFI runtime, which is heavily based on
      so-called protocols, which are struct types consisting [mostly] of
      function pointer members that are instantiated and recorded in a
      protocol database.
      
      These structs look like the ideal randomization candidates to the
      randstruct plugin (as they only carry function pointers), but of course,
      these protocols are contracts between the firmware that exposes them,
      and the EFI applications (including our stubbed kernel) that invoke
      them. This means that struct randomization for EFI protocols is not a
      great idea, and given that the stub shares very little data with the
      core kernel that is represented as a randomizable struct, we're better
      off just disabling it completely here.
      
      Cc: <stable@vger.kernel.org> # v4.14+
      Reported-by: NDaniel Marth <daniel.marth@inso.tuwien.ac.at>
      Tested-by: NDaniel Marth <daniel.marth@inso.tuwien.ac.at>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Acked-by: NKees Cook <keescook@chromium.org>
      1a388792
  9. 26 3月, 2021 1 次提交
  10. 15 1月, 2021 1 次提交
  11. 03 10月, 2020 1 次提交
  12. 07 9月, 2020 1 次提交
  13. 01 9月, 2020 1 次提交
  14. 14 8月, 2020 1 次提交
  15. 09 7月, 2020 1 次提交
  16. 07 7月, 2020 2 次提交
  17. 15 6月, 2020 1 次提交
  18. 19 5月, 2020 2 次提交
  19. 15 5月, 2020 1 次提交
  20. 05 5月, 2020 1 次提交
    • A
      efi/libstub/x86: Work around LLVM ELF quirk build regression · f77767ed
      Ard Biesheuvel 提交于
      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: NArnd Bergmann <arnd@arndb.de>
      Suggested-by: NFangrui Song <maskray@google.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      f77767ed
  21. 24 4月, 2020 4 次提交
  22. 23 4月, 2020 1 次提交
  23. 25 2月, 2020 1 次提交
  24. 24 2月, 2020 6 次提交
    • A
      efi/libstub: Clean up command line parsing routine · 91d150c0
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      91d150c0
    • A
      efi/libstub: Move file I/O support code into separate file · 5193a33d
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      5193a33d
    • A
      efi/libstub: Move efi_random_alloc() into separate source file · 0ed02bda
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      0ed02bda
    • A
      efi/libstub/x86: Incorporate eboot.c into libstub · c2d0b470
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      c2d0b470
    • A
      efi/libstub: Move memory map handling and allocation routines to mem.c · f57db62c
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      f57db62c
    • A
      efi/libstub: Use hidden visibility for all source files · 6f05106e
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      6f05106e
  25. 23 2月, 2020 1 次提交
    • A
      efi/libstub/arm64: Use 1:1 mapping of RT services if property table exists · b92165d2
      Ard Biesheuvel 提交于
      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: NArd Biesheuvel <ardb@kernel.org>
      b92165d2
  26. 11 1月, 2020 1 次提交
    • M
      efi: Allow disabling PCI busmastering on bridges during boot · 4444f854
      Matthew Garrett 提交于
      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: NMatthew Garrett <mjg59@google.com>
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Signed-off-by: NArd 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: NIngo Molnar <mingo@kernel.org>
      4444f854
  27. 16 11月, 2019 1 次提交
  28. 07 11月, 2019 1 次提交
  29. 31 10月, 2019 1 次提交
    • A
      efi: libstub/arm: Account for firmware reserved memory at the base of RAM · 41cd96fa
      Ard Biesheuvel 提交于
      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: NGuillaume Gardet <Guillaume.Gardet@arm.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: NChester 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: NIngo Molnar <mingo@kernel.org>
      41cd96fa