arm64/efi: only disable the EFI runtime service that faulted
Subsystems (4)
PATCH 1/1 arm64/efi: only disable the EFI runtime service that faulted
When the firmware faults while executing an EFI runtime service, arm64 recovers from the exception, returns EFI_ABORTED to the caller and disables all EFI runtime services for the remainder of the boot.
That is a rather big hammer. For instance, on Microsoft C2141 and C4143 machines, GetTime() faults when it is called by the rtc-efi driver:
[Firmware Bug]: Unable to handle paging request in EFI runtime service
WARNING: CPU: 9 PID: 1 at drivers/firmware/efi/runtime-wrappers.c:498 __efi_queue_work+0xe8/0x128 Hardware name: Microsoft C2141/C2141 , BIOS C2141.BS.0301.AG.01.03 08/21/2024 Call trace: __efi_queue_work+0xe8/0x128 virt_efi_get_time+0x64/0xc0 efi_rtc_probe+0x4c/0x188 platform_probe+0x70/0xd8 really_probe+0x190/0x3d8 ...
and as a result, the variable services become unavailable too, which breaks efivarfs (and with it efibootmgr, fwupd etc.), even though there is nothing wrong with them.
So, if the faulting call was made via efi_rts_wq, which is the case for all runtime services apart from ResetSystem() and the non-blocking variable services, only disable the service that faulted: clear its bit in efi.runtime_supported_mask, so that callers that check for it via efi_rt_services_supported() no longer try to use it, and fail any further calls to it with EFI_DEVICE_ERROR, which is what all runtime service calls return today once they have been disabled. Otherwise, and for the ACPI PRM handlers and the LKDTM tests, which have no bit of their own, keep disabling all runtime services.
Update the LKDTM EFI_RUNTIME_CRASH test accordingly, as the fault it provokes in GetNextVariableName() now only disables that service.
--- arch/arm64/kernel/efi.c | 2 +- drivers/firmware/efi/runtime-wrappers.c | 85 ++++++++++++++++++++++++- drivers/misc/lkdtm/bugs.c | 4 +- include/linux/efi.h | 1 + 4 files changed, 88 insertions(+), 4 deletions(-)
arch/arm64/kernel/efi.c +1 -1
@@ -227,7 +227,7 @@ bool efi_runtime_fixup_exception(struct pt_regs *regs, const char *msg)pr_err (FW_BUG "Unable to handle %s in EFI runtime service\n" , msg);add_taint (TAINT_FIRMWARE_WORKAROUND ,LOCKDEP_STILL_OK ); -clear_bit (EFI_RUNTIME_SERVICES , &efi.flags); +efi_runtime_disable_faulting_service (); regs->regs[0 ] =EFI_ABORTED ; regs->regs[30 ] = efi_rt_stack_top[-1 ];
drivers/firmware/efi/runtime-wrappers.c +83 -2
109 lines not on this page · raw message
drivers/misc/lkdtm/bugs.c +3 -1
@@ -836,7 +836,9 @@ static void __maybe_unused lkdtm_EFI_RUNTIME_CRASH(void)*/ status = efi.get_next_variable (&size,L"" , &(efi_guid_t ){}); -if (status !=EFI_ABORTED ||efi_enabled (EFI_RUNTIME_SERVICES )) +if (status !=EFI_ABORTED || + (efi_enabled (EFI_RUNTIME_SERVICES ) && +efi_rt_services_supported (EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME )))pr_err ("FAIL: EFI GetNextVariable() did not abort (%#lx)\n" , status); }
include/linux/efi.h +1 -0
@@ -1139,6 +1139,7 @@ extern unsigned long efi_call_virt_save_flags(void);void efi_runtime_assert_lock_held (void );efi_status_t efi_runtime_set_enable_flag (bool enable); +void efi_runtime_disable_faulting_service (void );enum efi_secureboot_mode { efi_secureboot_mode_unset,
Signature · 1 line
2.56.0
Ard Biesheuvel
maintainerHello Hamza,
Quoted 5 lines · Hamza Mahfooz
When the firmware faults while executing an EFI runtime service, arm64 recovers from the exception, returns
EFI_ABORTEDto the caller and disables all EFI runtime services for the remainder of the boot.That is a rather big hammer.
It does not just return EFI_ABORTED to the caller. It basically does a longjmp() out of the faulting context straight back to the caller in the kernel, skipping all execution that would have occurred on the way back out if the fault had not occurred.
Assuming that the runtime services are still in a sane state after this is not justified, so I don't think making this change is a good idea.
Do the systems in question expose the RTC via the standardized ACPI methods as well? I'd be fine with some logic that avoids rtc-efi entirely if the RTC can be driven by a native ACPI driver: that seems a worthwhile improvement in its own right, given that EFI runtime services are evil and should be avoided where possible.
Quoted 14 lines · Ard Biesheuvel
Hello Hamza,
Quoted 5 lines · Hamza Mahfooz
When the firmware faults while executing an EFI runtime service, arm64 recovers from the exception, returns
EFI_ABORTEDto the caller and disables all EFI runtime services for the remainder of the boot.That is a rather big hammer.
It does not just return
EFI_ABORTEDto the caller. It basically does alongjmp()out of the faulting context straight back to the caller in the kernel, skipping all execution that would have occurred on the way back out if the fault had not occurred.
Quoted 5 lines
Assuming that the runtime services are still in a sane state after this is not justified, so I don't think making this change is a good idea.
Do the systems in question expose the RTC via the standardized ACPI methods as well? I'd be fine with some logic that avoids rtc-efi
Ya the machines export ACPI000E devices and acpi-tad is able to register them (as /dev/rtc0). I'll send out a series that I've tested that implements that idea soon.
Quoted 3 lines
entirely if the RTC can be driven by a native ACPI driver: that seems a worthwhile improvement in its own right, given that EFI runtime services are evil and should be avoided where possible.