All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] lib: efi_loader: don't delete invalid handles
@ 2022-09-07  8:20 Etienne Carriere
  2022-09-07 21:10 ` Simon Glass
  2022-09-08  6:03 ` Heinrich Schuchardt
  0 siblings, 2 replies; 8+ messages in thread
From: Etienne Carriere @ 2022-09-07  8:20 UTC (permalink / raw)
  To: u-boot
  Cc: AKASHI Takahiro, Heinrich Schuchardt, Ilias Apalodimas,
	Etienne Carriere

Changes efi_delete_handle() to not free EFI handles that are not related
to EFI objects.

This change tries to resolved an issue seen since U-Boot v2022.07
in which EFI ExitBootService  attempts to release some EFI handles twice.

The issue was seen booting a EFI shell that invokes 'connect -r' and
then boots a Linux kernel. Execution of connect command makes EFI
subsystem to bind a block device for each root block devices EFI handles.
However these EFI device handles are already bound to a driver and we
can have 2 registered devices relating to the same EFI handler. On
ExitBootService, the loop removing the devices makes these EFI handles
to be released twice which corrupts memory.

This patch prevents the memory release operation caused by the issue but
I don't think this patch is the right way to addresse the problem. Any
help will be much appreciated.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
 lib/efi_loader/efi_boottime.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 4da64b5d29..e38990ace2 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -619,9 +619,15 @@ efi_status_t efi_remove_all_protocols(const efi_handle_t handle)
  */
 void efi_delete_handle(efi_handle_t handle)
 {
+	efi_status_t ret;
+
 	if (!handle)
 		return;
-	efi_remove_all_protocols(handle);
+
+	ret = efi_remove_all_protocols(handle);
+	if (ret == EFI_INVALID_PARAMETER)
+		return;
+
 	list_del(&handle->link);
 	free(handle);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-09  8:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-07  8:20 [PATCH] [RFC] lib: efi_loader: don't delete invalid handles Etienne Carriere
2022-09-07 21:10 ` Simon Glass
2022-09-08  5:17   ` AKASHI Takahiro
2022-09-08  5:56   ` Heinrich Schuchardt
2022-09-09  6:49     ` Heinrich Schuchardt
2022-09-09  8:46       ` Etienne Carriere
2022-09-08  6:03 ` Heinrich Schuchardt
2022-09-08 10:10   ` Etienne Carriere

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.