Skip to contentSkip to conversation

efi_loader: LoadImage() parameter checks

PATCH Superseded Heinrich Schuchardt 2 participants 6 messages May 6, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

If the file path is NULL, return EFI_INVALID_PARAMETER. If the file path is invalid, return EFI_NOT_FOUND.
If the size of the source buffer is 0, return EFI_LOAD_ERROR. If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

The change is required to reach UEFI SCT conformance.

---
v2
efi_load_image_from_path() must initalize *buffer even in case of an error

---
 include/efi_loader.h           |  1 +
 lib/efi_loader/efi_boottime.c  | 17 ++++++++----
 lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------
 3 files changed, 39 insertions(+), 27 deletions(-)
include/efi_loader.h +1 -0
index d3a1d4c465..07ef14ba1c 100644
@@ -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,
 };
lib/efi_loader/efi_boottime.c +12 -5
index 78a4063949..f75e6c0169 100644
@@ -1680,10 +1680,13 @@ efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
 	*buffer = NULL;
 	*size = 0;
 
+	if (!file_path)
+		return EFI_INVALID_PARAMETER;
+
 	/* Open file */
 	f = efi_file_from_path(file_path);
 	if (!f)
-		return EFI_DEVICE_ERROR;
+		return EFI_NOT_FOUND;
 
 	/* Get file size */
 	bs = 0;
@@ -1760,13 +1763,13 @@ 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;
 	}
-
-	if (!source_buffer && !file_path) {
-		ret = EFI_NOT_FOUND;
+	/* The parent image handle must refer to a loaded image */
+	if (!parent_image->type) {
+		ret = EFI_INVALID_PARAMETER;
 		goto error;
 	}
 
@@ -1776,6 +1779,10 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
 		if (ret != EFI_SUCCESS)
 			goto error;
 	} else {
+		if (!source_size) {
+			ret = EFI_LOAD_ERROR;
+			goto error;
+		}
 		dest_buffer = source_buffer;
 	}
 	/* split file_path which contains both the device and file parts */
lib/efi_loader/efi_root_node.c +26 -22

60 lines not on this page · raw message

--
2.20.1

#1 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

Quoted 2 lines · Heinrich Schuchardt

If the file path is NULL, return EFI_INVALID_PARAMETER. If the file path is invalid, return EFI_NOT_FOUND.

These 2 are a documented inEFI_LOAD_FILE_PROTOCOL.LoadFile(). It might be a good idea to indicate that for later reference.

Quoted 1 line

If the size of the source buffer is 0, return EFI_LOAD_ERROR.

The spec says this should be EFI_INVALID_PARAMETER, no? Is this a spec or an SCT bug?

Quoted 2 lines

If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

I agree that this is a good change, but where is the spec reference? I couldn't find anything.

Quoted 4 lines

The change is required to reach UEFI SCT conformance.

IMHO this really should be a patch set with multiple individual changes, each changing one piece of spec conformance at a time.

That way if we happen to break anything along the way, bisecting would point us to exactly the right point where things fell apart.

Quoted 15 lines

---
v2
efi_load_image_from_path() must initalize *buffer even in case of an error

---
  include/efi_loader.h           |  1 +
  lib/efi_loader/efi_boottime.c  | 17 ++++++++----
  lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------
  3 files changed, 39 insertions(+), 27 deletions(-)
include/efi_loader.h +0 -0
index d3a1d4c465..07ef14ba1c 100644

include/efi_loader.h struct efi_handler { · line 190

Quoted 4 lines
include/efi_loader.h +1 -0
@@ -187,6 +187,7 @@ struct efi_handler {
   */
  enum efi_object_type {
  	EFI_OBJECT_TYPE_UNDEFINED = 0,
+	EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,

This looks like an unrelated change?

Quoted 106 lines
include/efi_loader.h +0 -0
  	EFI_OBJECT_TYPE_LOADED_IMAGE,
  	EFI_OBJECT_TYPE_STARTED_IMAGE,
  };
lib/efi_loader/efi_boottime.c +12 -5
index 78a4063949..f75e6c0169 100644
@@ -1680,10 +1680,13 @@ efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
  	*buffer = NULL;
  	*size = 0;
 
+	if (!file_path)
+		return EFI_INVALID_PARAMETER;
+
  	/* Open file */
  	f = efi_file_from_path(file_path);
  	if (!f)
-		return EFI_DEVICE_ERROR;
+		return EFI_NOT_FOUND;
 
  	/* Get file size */
  	bs = 0;
@@ -1760,13 +1763,13 @@ 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;
  	}
-
-	if (!source_buffer && !file_path) {
-		ret = EFI_NOT_FOUND;
+	/* The parent image handle must refer to a loaded image */
+	if (!parent_image->type) {
+		ret = EFI_INVALID_PARAMETER;
  		goto error;
  	}
 
@@ -1776,6 +1779,10 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
  		if (ret != EFI_SUCCESS)
  			goto error;
  	} else {
+		if (!source_size) {
+			ret = EFI_LOAD_ERROR;
+			goto error;
+		}
  		dest_buffer = source_buffer;
  	}
  	/* split file_path which contains both the device and file parts */
lib/efi_loader/efi_root_node.c +18 -21
index e0fcbb85a4..38514e0820 100644
@@ -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 */

lib/efi_loader/efi_root_node.c efi_status_t efi_root_node_register(void) · line 77

Quoted 10 lines
lib/efi_loader/efi_root_node.c +8 -1
+			 &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;

I guess this is part of the unrelated change?

Alex

Quoted 4 lines
lib/efi_loader/efi_root_node.c +0 -1
  }
--

2.20.1

#2 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

Quoted 9 lines · Alexander
Quoted 2 lines · Heinrich Schuchardt

If the file path is NULL, return EFI_INVALID_PARAMETER. If the file path is invalid, return EFI_NOT_FOUND.

These 2 are a documented inEFI_LOAD_FILE_PROTOCOL.LoadFile(). It might be a good idea to indicate that for later reference.

See the last sentence of the commit message.

Quoted 6 lines
Quoted 2 lines

If the size of the source buffer is 0, return EFI_LOAD_ERROR.

The spec says this should be EFI_INVALID_PARAMETER, no? Is this a spec or an SCT bug?

According to the UEFI 2.7A spec:
EFI_LOAD_IMAGE should be returned if the image is corrupt.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.6

Quoted 9 lines
Quoted 4 lines

If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

I agree that this is a good change, but where is the spec reference? I couldn't find anything.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.1

Quoted 25 lines
Quoted 5 lines

The change is required to reach UEFI SCT conformance.

IMHO this really should be a patch set with multiple individual changes, each changing one piece of spec conformance at a time.

That way if we happen to break anything along the way, bisecting would point us to exactly the right point where things fell apart.

Quoted 10 lines

---
v2
    efi_load_image_from_path() must initalize *buffer even in case of an error
---
  include/efi_loader.h           |  1 + lib/efi_loader/efi_boottime.c  | 17 ++++++++---- lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------

  3 files changed, 39 insertions(+), 27 deletions(-)
Quoted 12 lines

include/efi_loader.h struct efi_handler { · line 190

Quoted 9 lines
include/efi_loader.h +1 -0
index d3a1d4c465..07ef14ba1c 100644
@@ -187,6 +187,7 @@ struct efi_handler {
    */
   enum efi_object_type {
       EFI_OBJECT_TYPE_UNDEFINED = 0,
+    EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,

This looks like an unrelated change?

No. We use efi_root as parent_image. We test if parent_image is an image in LoadImage. So efi_root must be marked as image.

Quoted 118 lines
Quoted 118 lines
include/efi_loader.h +0 -0
       EFI_OBJECT_TYPE_LOADED_IMAGE,
       EFI_OBJECT_TYPE_STARTED_IMAGE,
   };
lib/efi_loader/efi_boottime.c +4 -1
index 78a4063949..f75e6c0169 100644
@@ -1680,10 +1680,13 @@ efi_status_t efi_load_image_from_path(struct
 efi_device_path *file_path,
       *buffer = NULL;
       *size = 0;
 
+    if (!file_path)
+        return EFI_INVALID_PARAMETER;
+
       /* Open file */
       f = efi_file_from_path(file_path);
       if (!f)
-        return EFI_DEVICE_ERROR;
+        return EFI_NOT_FOUND;
 
       /* Get file size */

      bs = 0;

lib/efi_loader/efi_boottime.c +8 -4
@@ -1760,13 +1763,13 @@ 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;
       }
-
-    if (!source_buffer && !file_path) {
-        ret = EFI_NOT_FOUND;
+    /* The parent image handle must refer to a loaded image */
+    if (!parent_image->type) {
+        ret = EFI_INVALID_PARAMETER;
           goto error;
       }
@@ -1776,6 +1779,10 @@ efi_status_t EFIAPI efi_load_image(bool
 boot_policy,
           if (ret != EFI_SUCCESS)
               goto error;
       } else {
+        if (!source_size) {
+            ret = EFI_LOAD_ERROR;
+            goto error;
+        }
           dest_buffer = source_buffer;
       }

      /* split file_path which contains both the device and file parts */

lib/efi_loader/efi_root_node.c +23 -21
index e0fcbb85a4..38514e0820 100644
@@ -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,
Quoted 8 lines

lib/efi_loader/efi_root_node.c efi_status_t efi_root_node_register(void) · line 77

Quoted 5 lines
lib/efi_loader/efi_root_node.c +3 -1
   #endif
-               NULL));
+             NULL));
+    efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE;
+    return ret;

I guess this is part of the unrelated change?

No. We use efi_root as parent_image. We test if parent_image is an image in LoadImage. So efi_root must be marked as image.

Best regards

Heinrich

Quoted 12 lines

Alex

Quoted 4 lines
lib/efi_loader/efi_root_node.c +0 -0
   }
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

Quoted 9 lines · Heinrich Schuchardt
Quoted 7 lines · Alexander
Quoted 2 lines · Heinrich Schuchardt

If the file path is NULL, return EFI_INVALID_PARAMETER. If the file path is invalid, return EFI_NOT_FOUND.

These 2 are a documented inEFI_LOAD_FILE_PROTOCOL.LoadFile(). It might be a good idea to indicate that for later reference.

See the last sentence of the commit message.

I don't understand? The return values are not defined as part of generic LoadImage(), but as part of EFI_LOAD_FILE_PROTOCOL.LoadFile() which is pretty counterintuitive IMHO.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

If the size of the source buffer is 0, return EFI_LOAD_ERROR.

The spec says this should be EFI_INVALID_PARAMETER, no? Is this a spec or an SCT bug?

According to the UEFI 2.7A spec:
EFI_LOAD_IMAGE should be returned if the image is corrupt.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.6

Hm, but LoadFile() explicitly says:

  EFI_INVALID_PARAMETER | FilePath is not a valid device path, or
BufferSize is NULL.

Or are we beyond that point here?

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

I agree that this is a good change, but where is the spec reference? I couldn't find anything.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.1

Could you please add that reference to the commit message?

Quoted 34 lines
Quoted 23 lines
Quoted 4 lines

The change is required to reach UEFI SCT conformance.

IMHO this really should be a patch set with multiple individual changes, each changing one piece of spec conformance at a time.

That way if we happen to break anything along the way, bisecting would point us to exactly the right point where things fell apart.

Quoted 10 lines

---
v2
    efi_load_image_from_path() must initalize *buffer even in case of an error

---
   include/efi_loader.h           |  1 +
   lib/efi_loader/efi_boottime.c  | 17 ++++++++----
   lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------
   3 files changed, 39 insertions(+), 27 deletions(-)
Quoted 11 lines

include/efi_loader.h struct efi_handler { · line 190

Quoted 9 lines
include/efi_loader.h +1 -0
index d3a1d4c465..07ef14ba1c 100644
@@ -187,6 +187,7 @@ struct efi_handler {
    */
   enum efi_object_type {
       EFI_OBJECT_TYPE_UNDEFINED = 0,
+    EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,

This looks like an unrelated change?

Quoted 2 lines

No. We use efi_root as parent_image. We test if parent_image is an image in LoadImage. So efi_root must be marked as image.

I see, that was not obvious :).

Alex

#4 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

Quoted 5 lines · Alexander
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · Alexander
Quoted 1 line · Heinrich Schuchardt

If the file path is NULL, return EFI_INVALID_PARAMETER.

There is a nice contradiction between UEFI Spec 2.7 Errata B and the UEFI SCT specfication.

The UEFI spec has:
EFI_NOT_FOUND: Both SourceBuffer and DevicePath are NULL

UEFI SCT Specification (2017): 3.4.1 LoadImage, 5.1.4.1.2 BS.LoadImage – LoadImage() returns EFI_INVALID_PARAMETER with NULL FilePath.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

If the file path is invalid, return EFI_NOT_FOUND.

UEFI Spec 2.7 Errata B:
EFI_DEVICE_ERROR - Image was not loaded because the device returned a read error.

UEFI SCT Specification (2017): 3.4.1 LoadImage, 5.1.4.1.4 BS.LoadImage – LoadImage() returns EFI_NOT_FOUND with a non-existent FilePath.

Quoted 10 lines
Quoted 5 lines
Quoted 4 lines

These 2 are a documented inEFI_LOAD_FILE_PROTOCOL.LoadFile(). It might be a good idea to indicate that for later reference.

See the last sentence of the commit message.

I don't understand? The return values are not defined as part of generic LoadImage(), but as part of EFI_LOAD_FILE_PROTOCOL.LoadFile() which is pretty counterintuitive IMHO.

The definitions in the EFI_LOAD_FILE_PROTOCOL should not prescribe the return values of LoadImage().

I guess we should stick with the UEFI spec in case of contradiction and try to convince uefi.org that there is a bug in the SCT.

Best regards

Heinrich

Quoted 82 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

If the size of the source buffer is 0, return EFI_LOAD_ERROR.

Quoted 7 lines
Quoted 2 lines

The spec says this should be EFI_INVALID_PARAMETER, no? Is this a spec or an SCT bug?

According to the UEFI 2.7A spec:
EFI_LOAD_IMAGE should be returned if the image is corrupt.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.6

Hm, but LoadFile() explicitly says:

  EFI_INVALID_PARAMETER | FilePath is not a valid device path, or BufferSize is NULL.

Or are we beyond that point here?

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

I agree that this is a good change, but where is the spec reference? I couldn't find anything.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.1

Could you please add that reference to the commit message?

Quoted 35 lines
Quoted 24 lines
Quoted 4 lines

The change is required to reach UEFI SCT conformance.

IMHO this really should be a patch set with multiple individual changes, each changing one piece of spec conformance at a time.

That way if we happen to break anything along the way, bisecting would point us to exactly the right point where things fell apart.

Quoted 11 lines

---
v2
     efi_load_image_from_path() must initalize *buffer even in case of an error
---
   include/efi_loader.h           |  1 + lib/efi_loader/efi_boottime.c  | 17 ++++++++---- lib/efi_loader/efi_root_node.c | 48
++++++++++++++++++----------------

   3 files changed, 39 insertions(+), 27 deletions(-)
Quoted 11 lines

include/efi_loader.h struct efi_handler { · line 190

Quoted 9 lines
include/efi_loader.h +1 -0
index d3a1d4c465..07ef14ba1c 100644
@@ -187,6 +187,7 @@ struct efi_handler {
     */
    enum efi_object_type {
        EFI_OBJECT_TYPE_UNDEFINED = 0,
+    EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,

This looks like an unrelated change?

Quoted 2 lines

No. We use efi_root as parent_image. We test if parent_image is an image in LoadImage. So efi_root must be marked as image.

I see, that was not obvious :).

Alex

#5 lore raw

PATCH v2 1/1 efi_loader: LoadImage() parameter checks

Quoted 29 lines · Heinrich Schuchardt
Quoted 4 lines · Alexander
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · Alexander
Quoted 1 line · Heinrich Schuchardt

If the file path is NULL, return EFI_INVALID_PARAMETER.

There is a nice contradiction between UEFI Spec 2.7 Errata B and the UEFI SCT specfication.

The UEFI spec has:
EFI_NOT_FOUND: Both SourceBuffer and DevicePath are NULL

UEFI SCT Specification (2017): 3.4.1 LoadImage, 5.1.4.1.2 BS.LoadImage – LoadImage() returns EFI_INVALID_PARAMETER with NULL FilePath.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

If the file path is invalid, return EFI_NOT_FOUND.

UEFI Spec 2.7 Errata B:
EFI_DEVICE_ERROR - Image was not loaded because the device returned a read error.

UEFI SCT Specification (2017): 3.4.1 LoadImage, 5.1.4.1.4 BS.LoadImage – LoadImage() returns EFI_NOT_FOUND with a non-existent FilePath.

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

These 2 are a documented inEFI_LOAD_FILE_PROTOCOL.LoadFile(). It might be a good idea to indicate that for later reference.

See the last sentence of the commit message.

Quoted 8 lines
Quoted 3 lines

I don't understand? The return values are not defined as part of generic LoadImage(), but as part of EFI_LOAD_FILE_PROTOCOL.LoadFile() which is pretty counterintuitive IMHO.

The definitions in the EFI_LOAD_FILE_PROTOCOL should not prescribe the return values of LoadImage().

I guess we should stick with the UEFI spec in case of contradiction and try to convince uefi.org that there is a bug in the SCT.

Vincent, do you have any further input for us here? :)

Thanks!

Alex

Quoted 75 lines

Best regards

Heinrich

Quoted 70 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

If the size of the source buffer is 0, return EFI_LOAD_ERROR.

The spec says this should be EFI_INVALID_PARAMETER, no? Is this a spec or an SCT bug?

According to the UEFI 2.7A spec:
EFI_LOAD_IMAGE should be returned if the image is corrupt.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.6

Hm, but LoadFile() explicitly says:

  EFI_INVALID_PARAMETER | FilePath is not a valid device path, or
BufferSize is NULL.

Or are we beyond that point here?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER.

I agree that this is a good change, but where is the spec reference? I couldn't find anything.

UEFI SCT II Case Specification (June 2017), 3.4.1 LoadImage, Number 5.1.4.1.1

Could you please add that reference to the commit message?

Quoted 32 lines
Quoted 22 lines
Quoted 3 lines

The change is required to reach UEFI SCT conformance.

IMHO this really should be a patch set with multiple individual changes, each changing one piece of spec conformance at a time.

That way if we happen to break anything along the way, bisecting would point us to exactly the right point where things fell apart.

Quoted 11 lines

---
v2
     efi_load_image_from_path() must initalize *buffer even in case of an error

---
    include/efi_loader.h           |  1 +
    lib/efi_loader/efi_boottime.c  | 17 ++++++++----
    lib/efi_loader/efi_root_node.c | 48
++++++++++++++++++----------------
    3 files changed, 39 insertions(+), 27 deletions(-)
Quoted 10 lines

include/efi_loader.h struct efi_handler { · line 190

Quoted 9 lines
include/efi_loader.h +1 -0
index d3a1d4c465..07ef14ba1c 100644
@@ -187,6 +187,7 @@ struct efi_handler {
     */
    enum efi_object_type {
        EFI_OBJECT_TYPE_UNDEFINED = 0,
+    EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,

This looks like an unrelated change?

Quoted 2 lines

No. We use efi_root as parent_image. We test if parent_image is an image in LoadImage. So efi_root must be marked as image.

I see, that was not obvious :).

Alex