]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_loader: LoadImage() check parent image
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 5 May 2019 14:55:06 +0000 (16:55 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 7 May 2019 19:10:04 +0000 (21:10 +0200)
If the parent image handle does not refer to a loaded image return
EFI_INVALID_PARAMETER.
(UEFI SCT II 2017: 3.4.1 LoadImage() - 5.1.4.1.1)

Mark our root node as a loaded image to avoid an error when using it as
parent image.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/efi_loader.h
lib/efi_loader/efi_boottime.c
lib/efi_loader/efi_root_node.c

index d3a1d4c46531c838184e9ba9cf73d692b98f94bb..07ef14ba1cd4319f7ec2ee79a80a852aac7484ed 100644 (file)
@@ -187,6 +187,7 @@ struct efi_handler {
  */
 enum efi_object_type {
        EFI_OBJECT_TYPE_UNDEFINED = 0,
+       EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,
        EFI_OBJECT_TYPE_LOADED_IMAGE,
        EFI_OBJECT_TYPE_STARTED_IMAGE,
 };
index 6d86dafc1655c87d8e2615dd1c5d36e17c9755ab..ef9e3781899c371e2c2220afcc40b40deb444d87 100644 (file)
@@ -1760,7 +1760,7 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
        EFI_ENTRY("%d, %p, %pD, %p, %zd, %p", boot_policy, parent_image,
                  file_path, source_buffer, source_size, image_handle);
 
-       if (!image_handle || !parent_image) {
+       if (!image_handle || !efi_search_obj(parent_image)) {
                ret = EFI_INVALID_PARAMETER;
                goto error;
        }
@@ -1769,6 +1769,11 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
                ret = EFI_NOT_FOUND;
                goto error;
        }
+       /* The parent image handle must refer to a loaded image */
+       if (!parent_image->type) {
+               ret = EFI_INVALID_PARAMETER;
+               goto error;
+       }
 
        if (!source_buffer) {
                ret = efi_load_image_from_path(file_path, &dest_buffer,
index e0fcbb85a4d2324dca08723a746e890512f7eda9..38514e082098e9b13d0c46d747cddf37138c0936 100644 (file)
@@ -28,6 +28,7 @@ struct efi_root_dp {
  */
 efi_status_t efi_root_node_register(void)
 {
+       efi_status_t ret;
        struct efi_root_dp *dp;
 
        /* Create device path protocol */
@@ -47,28 +48,31 @@ efi_status_t efi_root_node_register(void)
        dp->end.length = sizeof(struct efi_device_path);
 
        /* Create root node and install protocols */
-       return EFI_CALL(efi_install_multiple_protocol_interfaces(&efi_root,
-                      /* Device path protocol */
-                      &efi_guid_device_path, dp,
-                      /* Device path to text protocol */
-                      &efi_guid_device_path_to_text_protocol,
-                      (void *)&efi_device_path_to_text,
-                      /* Device path utilities protocol */
-                      &efi_guid_device_path_utilities_protocol,
-                      (void *)&efi_device_path_utilities,
-                      /* Unicode collation protocol */
-                      &efi_guid_unicode_collation_protocol,
-                      (void *)&efi_unicode_collation_protocol,
+       ret = EFI_CALL(efi_install_multiple_protocol_interfaces
+                       (&efi_root,
+                        /* Device path protocol */
+                        &efi_guid_device_path, dp,
+                        /* Device path to text protocol */
+                        &efi_guid_device_path_to_text_protocol,
+                        (void *)&efi_device_path_to_text,
+                        /* Device path utilities protocol */
+                        &efi_guid_device_path_utilities_protocol,
+                        (void *)&efi_device_path_utilities,
+                        /* Unicode collation protocol */
+                        &efi_guid_unicode_collation_protocol,
+                        (void *)&efi_unicode_collation_protocol,
 #if CONFIG_IS_ENABLED(EFI_LOADER_HII)
-                      /* HII string protocol */
-                      &efi_guid_hii_string_protocol,
-                      (void *)&efi_hii_string,
-                      /* HII database protocol */
-                      &efi_guid_hii_database_protocol,
-                      (void *)&efi_hii_database,
-                      /* HII configuration routing protocol */
-                      &efi_guid_hii_config_routing_protocol,
-                      (void *)&efi_hii_config_routing,
+                        /* HII string protocol */
+                        &efi_guid_hii_string_protocol,
+                        (void *)&efi_hii_string,
+                        /* HII database protocol */
+                        &efi_guid_hii_database_protocol,
+                        (void *)&efi_hii_database,
+                        /* HII configuration routing protocol */
+                        &efi_guid_hii_config_routing_protocol,
+                        (void *)&efi_hii_config_routing,
 #endif
-                      NULL));
+                        NULL));
+       efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE;
+       return ret;
 }