Skip to contentSkip to conversation

efi/libstub/x86: deal with exit() boot service returning

PATCH In review Ard Biesheuvel 2 participants 2 messages Mar 3, 2020 EFI

lore
Share & tools
lore

Ard Biesheuvel

author maintainer
#0 lore raw

PATCH 1/1 efi/libstub/x86: deal with exit() boot service returning

Even though it is uncommon, there are cases where the Exit() EFI boot service might return, e.g., when we were booted via the EFI handover protocol from OVMF and the kernel image was specified on the command line, in which case Exit() attempts to terminate the boot manager, which is not an EFI application itself. So let's drop into a deadloop instead.

Cc Nathan Chancellor <[email protected]>

---
As a side effect, this also fixes [0], which is as yet undiagnosed.

[0] https://github.com/ClangBuiltLinux/linux/issues/917

 drivers/firmware/efi/libstub/x86-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/x86-stub.c +1 -1
index 7f3e97c2aad3..5c7480c4d379 100644
@@ -344,7 +344,7 @@ static void setup_graphics(struct boot_params *boot_params)
 static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status)
 {
 	efi_bs_call(exit, handle, status, 0, NULL);
-	unreachable();
+	for(;;);
 }
 
 void startup_32(struct boot_params *boot_params);
Signature · 1 line
2.17.1
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ard Biesheuvel

Even though it is uncommon, there are cases where the Exit() EFI boot service might return, e.g., when we were booted via the EFI handover protocol from OVMF and the kernel image was specified on the command line, in which case Exit() attempts to terminate the boot manager, which is not an EFI application itself. So let's drop into a deadloop instead.

Quoted 6 lines
Cc Nathan Chancellor <[email protected]>

---
As a side effect, this also fixes [0], which is as yet undiagnosed.

[0] https://github.com/ClangBuiltLinux/linux/issues/917

And for that:

drivers/firmware/efi/libstub/x86-stub.c static void setup_graphics(struct boot_params *boot_params) · line 347

Quoted 13 lines
 drivers/firmware/efi/libstub/x86-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/x86-stub.c +1 -1
index 7f3e97c2aad3..5c7480c4d379 100644
@@ -344,7 +344,7 @@ static void setup_graphics(struct boot_params *boot_params)
 static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status)
 {
 	efi_bs_call(exit, handle, status, 0, NULL);
-	unreachable();
+	for(;;);

I thought this would have tripped up clang's -Wempty-body but it doesn't so that is good.

Quoted 6 lines
drivers/firmware/efi/libstub/x86-stub.c +0 -0
 }
 
 void startup_32(struct boot_params *boot_params);
Signature · 1 line
2.17.1