1. 01 6月, 2022 2 次提交
    • A
      efi: clean up Kconfig dependencies on CONFIG_EFI · 75ed63d9
      Ard Biesheuvel 提交于
      Geert reports that the new option CONFIG_EFI_DISABLE_RUNTIME is user
      visible even when EFI support is disabled, which is unnecessary and
      clutters the Kconfig interface.
      
      So let's move this option into the existing Kconfig submenu that already
      depends on CONFIG_EFI, and while at it, give some other options the same
      treatment.
      
      Also clean up a small wart where the efi/ subdirectory is listed twice.
      Let's just list it unconditionally so that both EFI and UEFI_CPER based
      pieces will be built independently (the latter only depends on the
      former on !X86)
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      75ed63d9
    • A
      efi/x86: libstub: Make DXE calls mixed mode safe · 31f1a0ed
      Ard Biesheuvel 提交于
      The newly added DXE calls use 64-bit quantities, which means we need to
      marshall them explicitly when running in mixed mode. Currently, we get
      away without it because we just bail when GetMemorySpaceDescriptor()
      fails, which is guaranteed to happen due to the function argument mixup.
      
      Let's fix this properly, though, by defining the macros that describe
      how to marshall the arguments. While at it, drop an incorrect cast on a
      status variable.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      31f1a0ed
  2. 19 5月, 2022 1 次提交
  3. 06 5月, 2022 1 次提交
    • A
      efi: stub: prefer mirrored memory for randomized allocations · a6cfe03c
      Ard Biesheuvel 提交于
      If the system exposes memory regions with the EFI_MORE_RELIABLE
      attribute, it is implied that it is intended to be used for allocations
      that are relatively important, such as the kernel's static image.
      
      Since efi_random_alloc() is mostly (only) used for allocating space for
      the kernel image, let's update it to take this into account, and
      disregard all memory without the EFI_MORE_RELIABLE attribute if there is
      sufficient memory available that does have this attribute.
      
      Note that this change only affects booting with randomization enabled.
      In other cases, the EFI stub runs the kernel image in place unless its
      placement is unsuitable for some reason (i.e., misaligned, or its BSS
      overlaps with another allocation), and it is left to the bootloader to
      ensure that the kernel was loaded into EFI_MORE_RELIABLE memory if this
      is desired.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
      a6cfe03c
  4. 03 5月, 2022 4 次提交
  5. 14 4月, 2022 3 次提交
  6. 08 4月, 2022 3 次提交
  7. 16 3月, 2022 1 次提交
    • J
      pstore: Don't use semaphores in always-atomic-context code · 8126b1c7
      Jann Horn 提交于
      pstore_dump() is *always* invoked in atomic context (nowadays in an RCU
      read-side critical section, before that under a spinlock).
      It doesn't make sense to try to use semaphores here.
      
      This is mostly a revert of commit ea84b580 ("pstore: Convert buf_lock
      to semaphore"), except that two parts aren't restored back exactly as they
      were:
      
       - keep the lock initialization in pstore_register
       - in efi_pstore_write(), always set the "block" flag to false
       - omit "is_locked", that was unnecessary since
         commit 959217c8 ("pstore: Actually give up during locking failure")
       - fix the bailout message
      
      The actual problem that the buggy commit was trying to address may have
      been that the use of preemptible() in efi_pstore_write() was wrong - it
      only looks at preempt_count() and the state of IRQs, but __rcu_read_lock()
      doesn't touch either of those under CONFIG_PREEMPT_RCU.
      (Sidenote: CONFIG_PREEMPT_RCU means that the scheduler can preempt tasks in
      RCU read-side critical sections, but you're not allowed to actively
      block/reschedule.)
      
      Lockdep probably never caught the problem because it's very rare that you
      actually hit the contended case, so lockdep always just sees the
      down_trylock(), not the down_interruptible(), and so it can't tell that
      there's a problem.
      
      Fixes: ea84b580 ("pstore: Convert buf_lock to semaphore")
      Cc: stable@vger.kernel.org
      Acked-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: NJann Horn <jannh@google.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20220314185953.2068993-1-jannh@google.com
      8126b1c7
  8. 08 3月, 2022 1 次提交
  9. 01 3月, 2022 1 次提交
    • R
      efi: fix return value of __setup handlers · 9feaf8b3
      Randy Dunlap 提交于
      When "dump_apple_properties" is used on the kernel boot command line,
      it causes an Unknown parameter message and the string is added to init's
      argument strings:
      
        Unknown kernel command line parameters "dump_apple_properties
          BOOT_IMAGE=/boot/bzImage-517rc6 efivar_ssdt=newcpu_ssdt", will be
          passed to user space.
      
       Run /sbin/init as init process
         with arguments:
           /sbin/init
           dump_apple_properties
         with environment:
           HOME=/
           TERM=linux
           BOOT_IMAGE=/boot/bzImage-517rc6
           efivar_ssdt=newcpu_ssdt
      
      Similarly when "efivar_ssdt=somestring" is used, it is added to the
      Unknown parameter message and to init's environment strings, polluting
      them (see examples above).
      
      Change the return value of the __setup functions to 1 to indicate
      that the __setup options have been handled.
      
      Fixes: 58c5475a ("x86/efi: Retrieve and assign Apple device properties")
      Fixes: 475fb4e8 ("efi / ACPI: load SSTDs from EFI variables")
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Reported-by: NIgor Zhbanov <i.zhbanov@omprussia.ru>
      Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: linux-efi@vger.kernel.org
      Cc: Lukas Wunner <lukas@wunner.de>
      Cc: Octavian Purdila <octavian.purdila@intel.com>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Link: https://lore.kernel.org/r/20220301041851.12459-1-rdunlap@infradead.orgSigned-off-by: NArd Biesheuvel <ardb@kernel.org>
      9feaf8b3
  10. 28 2月, 2022 2 次提交
  11. 23 1月, 2022 2 次提交
    • A
      efi: runtime: avoid EFIv2 runtime services on Apple x86 machines · f5390cd0
      Ard Biesheuvel 提交于
      Aditya reports [0] that his recent MacbookPro crashes in the firmware
      when using the variable services at runtime. The culprit appears to be a
      call to QueryVariableInfo(), which we did not use to call on Apple x86
      machines in the past as they only upgraded from EFI v1.10 to EFI v2.40
      firmware fairly recently, and QueryVariableInfo() (along with
      UpdateCapsule() et al) was added in EFI v2.00.
      
      The only runtime service introduced in EFI v2.00 that we actually use in
      Linux is QueryVariableInfo(), as the capsule based ones are optional,
      generally not used at runtime (all the LVFS/fwupd firmware update
      infrastructure uses helper EFI programs that invoke capsule update at
      boot time, not runtime), and not implemented by Apple machines in the
      first place. QueryVariableInfo() is used to 'safely' set variables,
      i.e., only when there is enough space. This prevents machines with buggy
      firmwares from corrupting their NVRAMs when they run out of space.
      
      Given that Apple machines have been using EFI v1.10 services only for
      the longest time (the EFI v2.0 spec was released in 2006, and Linux
      support for the newly introduced runtime services was added in 2011, but
      the MacbookPro12,1 released in 2015 still claims to be EFI v1.10 only),
      let's avoid the EFI v2.0 ones on all Apple x86 machines.
      
      [0] https://lore.kernel.org/all/6D757C75-65B1-468B-842D-10410081A8E4@live.com/
      
      Cc: <stable@vger.kernel.org>
      Cc: Jeremy Kerr <jk@ozlabs.org>
      Cc: Matthew Garrett <mjg59@srcf.ucam.org>
      Reported-by: NAditya Garg <gargaditya08@live.com>
      Tested-by: NOrlando Chamberlain <redecorating@protonmail.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NAditya Garg <gargaditya08@live.com>
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215277
      f5390cd0
    • M
      efi/libstub: arm64: Fix image check alignment at entry · e9b7c3a4
      Mihai Carabas 提交于
      The kernel is aligned at SEGMENT_SIZE and this is the size populated in the PE
      headers:
      
      arch/arm64/kernel/efi-header.S: .long   SEGMENT_ALIGN // SectionAlignment
      
      EFI_KIMG_ALIGN is defined as: (SEGMENT_ALIGN > THREAD_ALIGN ? SEGMENT_ALIGN :
      THREAD_ALIGN)
      
      So it depends on THREAD_ALIGN. On newer builds this message started to appear
      even though the loader is taking into account the PE header (which is stating
      SEGMENT_ALIGN).
      
      Fixes: c32ac11d ("efi/libstub: arm64: Double check image alignment at entry")
      Signed-off-by: NMihai Carabas <mihai.carabas@oracle.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      e9b7c3a4
  12. 20 1月, 2022 1 次提交
    • A
      riscv: Implement sv48 support · e8a62cc2
      Alexandre Ghiti 提交于
      By adding a new 4th level of page table, give the possibility to 64bit
      kernel to address 2^48 bytes of virtual address: in practice, that offers
      128TB of virtual address space to userspace and allows up to 64TB of
      physical memory.
      
      If the underlying hardware does not support sv48, we will automatically
      fallback to a standard 3-level page table by folding the new PUD level into
      PGDIR level. In order to detect HW capabilities at runtime, we
      use SATP feature that ignores writes with an unsupported mode.
      Signed-off-by: NAlexandre Ghiti <alexandre.ghiti@canonical.com>
      Signed-off-by: NPalmer Dabbelt <palmer@rivosinc.com>
      e8a62cc2
  13. 07 1月, 2022 2 次提交
  14. 22 12月, 2021 1 次提交
    • P
      efi: apply memblock cap after memblock_add() · b398123b
      Pingfan Liu 提交于
      On arm64, during kdump kernel saves vmcore, it runs into the following bug:
      ...
      [   15.148919] usercopy: Kernel memory exposure attempt detected from SLUB object 'kmem_cache_node' (offset 0, size 4096)!
      [   15.159707] ------------[ cut here ]------------
      [   15.164311] kernel BUG at mm/usercopy.c:99!
      [   15.168482] Internal error: Oops - BUG: 0 [#1] SMP
      [   15.173261] Modules linked in: xfs libcrc32c crct10dif_ce ghash_ce sha2_ce sha256_arm64 sha1_ce sbsa_gwdt ast i2c_algo_bit drm_vram_helper drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops cec drm_ttm_helper ttm drm nvme nvme_core xgene_hwmon i2c_designware_platform i2c_designware_core dm_mirror dm_region_hash dm_log dm_mod overlay squashfs zstd_decompress loop
      [   15.206186] CPU: 0 PID: 542 Comm: cp Not tainted 5.16.0-rc4 #1
      [   15.212006] Hardware name: GIGABYTE R272-P30-JG/MP32-AR0-JG, BIOS F12 (SCP: 1.5.20210426) 05/13/2021
      [   15.221125] pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
      [   15.228073] pc : usercopy_abort+0x9c/0xa0
      [   15.232074] lr : usercopy_abort+0x9c/0xa0
      [   15.236070] sp : ffff8000121abba0
      [   15.239371] x29: ffff8000121abbb0 x28: 0000000000003000 x27: 0000000000000000
      [   15.246494] x26: 0000000080000400 x25: 0000ffff885c7000 x24: 0000000000000000
      [   15.253617] x23: 000007ff80400000 x22: ffff07ff80401000 x21: 0000000000000001
      [   15.260739] x20: 0000000000001000 x19: ffff07ff80400000 x18: ffffffffffffffff
      [   15.267861] x17: 656a626f2042554c x16: 53206d6f72662064 x15: 6574636574656420
      [   15.274983] x14: 74706d6574746120 x13: 2129363930342065 x12: 7a6973202c302074
      [   15.282105] x11: ffffc8b041d1b148 x10: 00000000ffff8000 x9 : ffffc8b04012812c
      [   15.289228] x8 : 00000000ffff7fff x7 : ffffc8b041d1b148 x6 : 0000000000000000
      [   15.296349] x5 : 0000000000000000 x4 : 0000000000007fff x3 : 0000000000000000
      [   15.303471] x2 : 0000000000000000 x1 : ffff07ff8c064800 x0 : 000000000000006b
      [   15.310593] Call trace:
      [   15.313027]  usercopy_abort+0x9c/0xa0
      [   15.316677]  __check_heap_object+0xd4/0xf0
      [   15.320762]  __check_object_size.part.0+0x160/0x1e0
      [   15.325628]  __check_object_size+0x2c/0x40
      [   15.329711]  copy_oldmem_page+0x7c/0x140
      [   15.333623]  read_from_oldmem.part.0+0xfc/0x1c0
      [   15.338142]  __read_vmcore.constprop.0+0x23c/0x350
      [   15.342920]  read_vmcore+0x28/0x34
      [   15.346309]  proc_reg_read+0xb4/0xf0
      [   15.349871]  vfs_read+0xb8/0x1f0
      [   15.353088]  ksys_read+0x74/0x100
      [   15.356390]  __arm64_sys_read+0x28/0x34
      ...
      
      This bug introduced by commit b261dba2 ("arm64: kdump: Remove custom
      linux,usable-memory-range handling"), which moves
      memblock_cap_memory_range() to fdt, but it breaches the rules that
      memblock_cap_memory_range() should come after memblock_add() etc as said
      in commit e888fa7b ("memblock: Check memory add/cap ordering").
      
      As a consequence, the virtual address set up by copy_oldmem_page() does
      not bail out from the test of virt_addr_valid() in check_heap_object(),
      and finally hits the BUG_ON().
      
      Since memblock allocator has no idea about when the memblock is fully
      populated, while efi_init() is aware, so tackling this issue by calling the
      interface early_init_dt_check_for_usable_mem_range() exposed by of/fdt.
      
      Fixes: b261dba2 ("arm64: kdump: Remove custom linux,usable-memory-range handling")
      Signed-off-by: NPingfan Liu <kernelfans@gmail.com>
      Cc: Rob Herring <robh+dt@kernel.org>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Geert Uytterhoeven <geert+renesas@glider.be>
      Cc: Frank Rowand <frowand.list@gmail.com>
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: linux-arm-kernel@lists.infradead.org
      To: devicetree@vger.kernel.org
      To: linux-efi@vger.kernel.org
      Acked-by: NArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: NRob Herring <robh@kernel.org>
      Link: https://lore.kernel.org/r/20211215021348.8766-1-kernelfans@gmail.com
      b398123b
  15. 22 11月, 2021 2 次提交
  16. 07 11月, 2021 1 次提交
  17. 05 10月, 2021 3 次提交
    • Z
      efi: Change down_interruptible() in virt_efi_reset_system() to down_trylock() · 38fa3206
      Zhang Jianhua 提交于
      While reboot the system by sysrq, the following bug will be occur.
      
      BUG: sleeping function called from invalid context at kernel/locking/semaphore.c:90
      in_atomic(): 0, irqs_disabled(): 128, non_block: 0, pid: 10052, name: rc.shutdown
      CPU: 3 PID: 10052 Comm: rc.shutdown Tainted: G        W O      5.10.0 #1
      Call trace:
       dump_backtrace+0x0/0x1c8
       show_stack+0x18/0x28
       dump_stack+0xd0/0x110
       ___might_sleep+0x14c/0x160
       __might_sleep+0x74/0x88
       down_interruptible+0x40/0x118
       virt_efi_reset_system+0x3c/0xd0
       efi_reboot+0xd4/0x11c
       machine_restart+0x60/0x9c
       emergency_restart+0x1c/0x2c
       sysrq_handle_reboot+0x1c/0x2c
       __handle_sysrq+0xd0/0x194
       write_sysrq_trigger+0xbc/0xe4
       proc_reg_write+0xd4/0xf0
       vfs_write+0xa8/0x148
       ksys_write+0x6c/0xd8
       __arm64_sys_write+0x18/0x28
       el0_svc_common.constprop.3+0xe4/0x16c
       do_el0_svc+0x1c/0x2c
       el0_svc+0x20/0x30
       el0_sync_handler+0x80/0x17c
       el0_sync+0x158/0x180
      
      The reason for this problem is that irq has been disabled in
      machine_restart() and then it calls down_interruptible() in
      virt_efi_reset_system(), which would occur sleep in irq context,
      it is dangerous! Commit 99409b93("locking/semaphore: Add
      might_sleep() to down_*() family") add might_sleep() in
      down_interruptible(), so the bug info is here. down_trylock()
      can solve this problem, cause there is no might_sleep.
      
      --------
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NZhang Jianhua <chris.zjh@huawei.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      38fa3206
    • A
      efi/cper: use stack buffer for error record decoding · b3a72ca8
      Ard Biesheuvel 提交于
      Joe reports that using a statically allocated buffer for converting CPER
      error records into human readable text is probably a bad idea. Even
      though we are not aware of any actual issues, a stack buffer is clearly
      a better choice here anyway, so let's move the buffer into the stack
      frames of the two functions that refer to it.
      
      Cc: <stable@vger.kernel.org>
      Reported-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      b3a72ca8
    • H
      efi/libstub: Simplify "Exiting bootservices" message · 68c9cdf3
      Heinrich Schuchardt 提交于
      The message
      
          "Exiting boot services and installing virtual address map...\n"
      
      is even shown if we have efi=novamap on the command line or the firmware
      does not provide EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP.
      
      To avoid confusion just print
      
          "Exiting boot services...\n"
      Signed-off-by: NHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      68c9cdf3
  18. 29 9月, 2021 2 次提交
  19. 27 8月, 2021 2 次提交
  20. 19 8月, 2021 1 次提交
  21. 03 8月, 2021 4 次提交
    • A
      efi/libstub: arm64: Double check image alignment at entry · c32ac11d
      Ard Biesheuvel 提交于
      On arm64, the stub only moves the kernel image around in memory if
      needed, which is typically only for KASLR, given that relocatable
      kernels (which is the default) can run from any 64k aligned address,
      which is also the minimum alignment communicated to EFI via the PE/COFF
      header.
      
      Unfortunately, some loaders appear to ignore this header, and load the
      kernel at some arbitrary offset in memory. We can deal with this, but
      let's check for this condition anyway, so non-compliant code can be
      spotted and fixed.
      
      Cc: <stable@vger.kernel.org> # v5.10+
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      c32ac11d
    • A
      efi/libstub: arm64: Warn when efi_random_alloc() fails · ff80ef5b
      Ard Biesheuvel 提交于
      Randomization of the physical load address of the kernel image relies on
      efi_random_alloc() returning successfully, and currently, we ignore any
      failures and just carry on, using the ordinary, non-randomized page
      allocator routine. This means we never find out if a failure occurs,
      which could harm security, so let's at least warn about this condition.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      ff80ef5b
    • A
      efi/libstub: arm64: Relax 2M alignment again for relocatable kernels · 3a262423
      Ard Biesheuvel 提交于
      Commit 82046702 ("efi/libstub/arm64: Replace 'preferred' offset with
      alignment check") simplified the way the stub moves the kernel image
      around in memory before booting it, given that a relocatable image does
      not need to be copied to a 2M aligned offset if it was loaded on a 64k
      boundary by EFI.
      
      Commit d32de913 ("efi/arm64: libstub: Deal gracefully with
      EFI_RNG_PROTOCOL failure") inadvertently defeated this logic by
      overriding the value of efi_nokaslr if EFI_RNG_PROTOCOL is not
      available, which was mistaken by the loader logic as an explicit request
      on the part of the user to disable KASLR and any associated relocation
      of an Image not loaded on a 2M boundary.
      
      So let's reinstate this functionality, by capturing the value of
      efi_nokaslr at function entry to choose the minimum alignment.
      
      Fixes: d32de913 ("efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure")
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      3a262423
    • A
      efi/libstub: arm64: Force Image reallocation if BSS was not reserved · 5b94046e
      Ard Biesheuvel 提交于
      Distro versions of GRUB replace the usual LoadImage/StartImage calls
      used to load the kernel image with some local code that fails to honor
      the allocation requirements described in the PE/COFF header, as it
      does not account for the image's BSS section at all: it fails to
      allocate space for it, and fails to zero initialize it.
      
      Since the EFI stub itself is allocated in the .init segment, which is
      in the middle of the image, its BSS section is not impacted by this,
      and the main consequence of this omission is that the BSS section may
      overlap with memory regions that are already used by the firmware.
      
      So let's warn about this condition, and force image reallocation to
      occur in this case, which works around the problem.
      
      Fixes: 82046702 ("efi/libstub/arm64: Replace 'preferred' offset with alignment check")
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      5b94046e