summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_block.c
diff options
context:
space:
mode:
authorMichael Brown2020-12-17 21:37:27 +0100
committerMichael Brown2020-12-17 22:32:49 +0100
commit6769a7c3c669cbb0455c7d83a3257c4582cf683d (patch)
treed2fe6e941df207b447fb823923e1d35bf08af10c /src/interface/efi/efi_block.c
parent[efi] Nullify interfaces unconditionally on error and shutdown paths (diff)
downloadipxe-6769a7c3c669cbb0455c7d83a3257c4582cf683d.tar.gz
ipxe-6769a7c3c669cbb0455c7d83a3257c4582cf683d.tar.xz
ipxe-6769a7c3c669cbb0455c7d83a3257c4582cf683d.zip
[efi] Skip interface uninstallation during shutdown
iPXE seems to be almost alone in the UEFI world in attempting to shut down cleanly, free resources, and leave hardware in a well-defined reset state before handing over to the booted operating system. The UEFI driver model does allow for graceful shutdown via uninstallation of protocol interfaces. However, virtually no other UEFI drivers do this, and the external code paths that react to uninstallation are consequently poorly tested. This leads to a proliferation of bugs found in UEFI implementations in the wild, as described in commits such as 1295b4a ("[efi] Allow initialisation via SNP interface even while claimed") or b6e2ea0 ("[efi] Veto the HP XhciDxe Driver"). Try to avoid triggering such bugs by unconditionally skipping the protocol interface uninstallation during UEFI boot services shutdown, leaving the interfaces present but nullified and deliberately leaking the containing memory. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface/efi/efi_block.c')
-rw-r--r--src/interface/efi/efi_block.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c
index eeae8fca5..74cf7c0c0 100644
--- a/src/interface/efi/efi_block.c
+++ b/src/interface/efi/efi_block.c
@@ -358,7 +358,7 @@ static void efi_block_unhook ( unsigned int drive ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct san_device *sandev;
struct efi_block_data *block;
- int leak = 0;
+ int leak = efi_shutdown_in_progress;
EFI_STATUS efirc;
/* Find SAN device */
@@ -370,11 +370,12 @@ static void efi_block_unhook ( unsigned int drive ) {
block = sandev->priv;
/* Uninstall protocols */
- if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
block->handle,
&efi_block_io_protocol_guid, &block->block_io,
&efi_device_path_protocol_guid, block->path,
- NULL ) ) != 0 ) {
+ NULL ) ) != 0 ) ) {
DBGC ( sandev, "EFIBLK %#02x could not uninstall protocols: "
"%s\n", sandev->drive, strerror ( -EEFI ( efirc ) ) );
leak = 1;
@@ -395,7 +396,7 @@ static void efi_block_unhook ( unsigned int drive ) {
sandev_put ( sandev );
/* Report leakage, if applicable */
- if ( leak ) {
+ if ( leak && ( ! efi_shutdown_in_progress ) ) {
DBGC ( sandev, "EFIBLK %#02x nullified and leaked\n",
sandev->drive );
}