All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 0/2] efi_loader: LoadImage() parameter checks
@ 2019-05-06 21:22 Heinrich Schuchardt
  2019-05-06 21:22 ` [U-Boot] [PATCH v3 1/2] efi_loader: LoadImage() check parent image Heinrich Schuchardt
  2019-05-06 21:22 ` [U-Boot] [PATCH v3 2/2] efi_loader: LoadImage() check source size Heinrich Schuchardt
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2019-05-06 21:22 UTC (permalink / raw)
  To: u-boot

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)

If the size of the source buffer is 0, return EFI_LOAD_ERROR.
(UEFI SCT II 2017: 3.4.1 LoadImage() - 5.1.4.1.6)

v3
	Put each change into a separate patch

	Remove the following changes due to a conflict between UEFI
	and UEFI SCT:
	* If the file path is NULL, return EFI_INVALID_PARAMETER.
	* If the file path is invalid, return EFI_NOT_FOUND.

Heinrich Schuchardt (2):
  efi_loader: LoadImage() check parent image
  efi_loader: LoadImage() check source size

 include/efi_loader.h           |  1 +
 lib/efi_loader/efi_boottime.c  | 11 +++++++-
 lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------
 3 files changed, 37 insertions(+), 23 deletions(-)

--
2.20.1

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

* [U-Boot] [PATCH v3 1/2] efi_loader: LoadImage() check parent image
  2019-05-06 21:22 [U-Boot] [PATCH v3 0/2] efi_loader: LoadImage() parameter checks Heinrich Schuchardt
@ 2019-05-06 21:22 ` Heinrich Schuchardt
  2019-05-06 21:22 ` [U-Boot] [PATCH v3 2/2] efi_loader: LoadImage() check source size Heinrich Schuchardt
  1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2019-05-06 21:22 UTC (permalink / raw)
  To: u-boot

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>
---
v3
	put change into separate patch
---
 include/efi_loader.h           |  1 +
 lib/efi_loader/efi_boottime.c  |  7 ++++-
 lib/efi_loader/efi_root_node.c | 48 ++++++++++++++++++----------------
 3 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index d3a1d4c465..07ef14ba1c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -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,
 };
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 78a4063949..bf560c6234 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -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,
diff --git a/lib/efi_loader/efi_root_node.c b/lib/efi_loader/efi_root_node.c
index e0fcbb85a4..38514e0820 100644
--- a/lib/efi_loader/efi_root_node.c
+++ b/lib/efi_loader/efi_root_node.c
@@ -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;
 }
--
2.20.1

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

* [U-Boot] [PATCH v3 2/2] efi_loader: LoadImage() check source size
  2019-05-06 21:22 [U-Boot] [PATCH v3 0/2] efi_loader: LoadImage() parameter checks Heinrich Schuchardt
  2019-05-06 21:22 ` [U-Boot] [PATCH v3 1/2] efi_loader: LoadImage() check parent image Heinrich Schuchardt
@ 2019-05-06 21:22 ` Heinrich Schuchardt
  1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2019-05-06 21:22 UTC (permalink / raw)
  To: u-boot

If the size of the source buffer is 0, return EFI_LOAD_ERROR.
(UEFI SCT II 2017: 3.4.1 LoadImage() - 5.1.4.1.6)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3
	put change into separate patch
---
 lib/efi_loader/efi_boottime.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index bf560c6234..bc70018946 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1781,6 +1781,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 */
--
2.20.1

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

end of thread, other threads:[~2019-05-06 21:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 21:22 [U-Boot] [PATCH v3 0/2] efi_loader: LoadImage() parameter checks Heinrich Schuchardt
2019-05-06 21:22 ` [U-Boot] [PATCH v3 1/2] efi_loader: LoadImage() check parent image Heinrich Schuchardt
2019-05-06 21:22 ` [U-Boot] [PATCH v3 2/2] efi_loader: LoadImage() check source size Heinrich Schuchardt

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.