summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2023-07-24 13:17:36 +0300
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2023-07-28 12:36:37 +0300
commit54edc37a22ecd7d640e449f098575ef2ff22f315 (patch)
tree968752653e7efd57ef5f58b6546cf94a21028782 /cmd
parent8505c0bb5c075a5d9f5849ec9e79617aa07555b2 (diff)
downloadu-boot-54edc37a22ecd7d640e449f098575ef2ff22f315.tar.xz
efi_loader: make efi_delete_handle() follow the EFI spec
The EFI doesn't allow removal of handles, unless all hosted protocols are cleanly removed. Our efi_delete_handle() is a bit intrusive. Although it does try to delete protocols before removing a handle, it doesn't care if that fails. Instead it only returns an error if the handle is invalid. On top of that none of the callers of that function check the return code. So let's rewrite this in a way that fits the EFI spec better. Instead of forcing the handle removal, gracefully uninstall all the handle protocols. According to the EFI spec when the last protocol is removed the handle will be deleted. Also switch all the callers and check the return code. Some callers can't do anything useful apart from reporting an error. The disk related functions on the other hand, can prevent a medium that is being used by EFI from removal. The only function that doesn't check the result is efi_delete_image(). But that function needs a bigger rework anyway, so we can clean it up in the future Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootefi.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 5c0afec154..f73d6eb0e2 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -607,20 +607,6 @@ failure:
}
/**
- * bootefi_run_finish() - finish up after running an EFI test
- *
- * @loaded_image_info: Pointer to a struct which holds the loaded image info
- * @image_obj: Pointer to a struct which holds the loaded image object
- */
-static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj,
- struct efi_loaded_image *loaded_image_info)
-{
- efi_restore_gd();
- free(loaded_image_info->load_options);
- efi_delete_handle(&image_obj->header);
-}
-
-/**
* do_efi_selftest() - execute EFI selftest
*
* Return: status code
@@ -638,7 +624,12 @@ static int do_efi_selftest(void)
/* Execute the test */
ret = EFI_CALL(efi_selftest(&image_obj->header, &systab));
- bootefi_run_finish(image_obj, loaded_image_info);
+ efi_restore_gd();
+ free(loaded_image_info->load_options);
+ if (ret != EFI_SUCCESS)
+ efi_delete_handle(&image_obj->header);
+ else
+ ret = efi_delete_handle(&image_obj->header);
return ret != EFI_SUCCESS;
}