[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>
This commit is contained in:
Michael Brown
2020-12-17 20:37:27 +00:00
parent fb91542f2a
commit 6769a7c3c6
4 changed files with 23 additions and 18 deletions

View File

@@ -1673,7 +1673,7 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
void efi_pxe_uninstall ( EFI_HANDLE handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_pxe *pxe;
int leak = 0;
int leak = efi_shutdown_in_progress;
EFI_STATUS efirc;
/* Locate PXE base code */
@@ -1688,11 +1688,12 @@ void efi_pxe_uninstall ( EFI_HANDLE handle ) {
efi_pxe_stop ( &pxe->base );
/* Uninstall PXE base code protocol */
if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
if ( ( ! efi_shutdown_in_progress ) &&
( ( efirc = bs->UninstallMultipleProtocolInterfaces (
handle,
&efi_pxe_base_code_protocol_guid, &pxe->base,
&efi_apple_net_boot_protocol_guid, &pxe->apple,
NULL ) ) != 0 ) {
NULL ) ) != 0 ) ) {
DBGC ( pxe, "PXE %s could not uninstall: %s\n",
pxe->name, strerror ( -EEFI ( efirc ) ) );
leak = 1;
@@ -1706,6 +1707,6 @@ void efi_pxe_uninstall ( EFI_HANDLE handle ) {
ref_put ( &pxe->refcnt );
/* Report leakage, if applicable */
if ( leak )
if ( leak && ( ! efi_shutdown_in_progress ) )
DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
}