Skip to contentSkip to conversation

efi_loader: multi part device paths to text

PATCH New Heinrich Schuchardt 2 participants 7 messages Feb 18, 2021 – Feb 19, 2021

lore
Share & tools
lore
#0 lore raw

cover efi_loader: multi part device paths to text

Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts.

Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does.

Provide a unit test for multi part device paths.

Heinrich Schuchardt (2):
efi_loader: multi part device paths to text
efi_selftest: multi part device path to text

 lib/efi_loader/efi_device_path_to_text.c   | 17 ++++--
 lib/efi_selftest/efi_selftest_devicepath.c | 65 ++++++++++++++++++++++
 2 files changed, 77 insertions(+), 5 deletions(-)

--
2.30.0

#1 lore raw

PATCH 1/2 efi_loader: multi part device paths to text

Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts.

Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does.

---
 lib/efi_loader/efi_device_path_to_text.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +12 -5
index 1aaa9f94fa..81b8ac23ba 100644
@@ -369,11 +369,18 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(
 
 	if (!device_path)
 		goto out;
-	while (device_path &&
-	       str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
-		*str++ = '/';
-		str = efi_convert_single_device_node_to_text(str, device_path);
-		device_path = efi_dp_next(device_path);
+	while (device_path && str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
+		if (device_path->type == DEVICE_PATH_TYPE_END) {
+			if (device_path->sub_type !=
+			    DEVICE_PATH_SUB_TYPE_INSTANCE_END)
+				break;
+			*str++ = ',';
+		} else {
+			*str++ = '/';
+			str = efi_convert_single_device_node_to_text(
+							str, device_path);
+		}
+		*(u8 **)&device_path += device_path->length;
 	}
 
 	text = efi_str_to_u16(buffer);

--
2.30.0

#2 lore raw

PATCH 1/2 efi_loader: multi part device paths to text

Hi Heinrich

Quoted 19 lines · Heinrich Schuchardt

Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts.

Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does.

---
 lib/efi_loader/efi_device_path_to_text.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +0 -0
index 1aaa9f94fa..81b8ac23ba 100644
@@ -369,11 +369,18 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(
 
 	if (!device_path)

lib/efi_loader/efi_device_path_to_text.c static uint16_t EFIAPI *efi_convert_device_path_to_text( · line 375

Quoted 10 lines
lib/efi_loader/efi_device_path_to_text.c +4 -5
 		goto out;
-	while (device_path &&
-	       str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
-		*str++ = '/';
-		str = efi_convert_single_device_node_to_text(str, device_path);
-		device_path = efi_dp_next(device_path);
+	while (device_path && str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
+		if (device_path->type == DEVICE_PATH_TYPE_END) {
+			if (device_path->sub_type !=
+			    DEVICE_PATH_SUB_TYPE_INSTANCE_END)

maybe it's better to check explicitly for '== DEVICE_PATH_SUB_TYPE_END'?

Quoted 12 lines
lib/efi_loader/efi_device_path_to_text.c +8 -1
+				break;
+			*str++ = ',';
+		} else {
+			*str++ = '/';
+			str = efi_convert_single_device_node_to_text(
+							str, device_path);
+		}
+		*(u8 **)&device_path += device_path->length;
 	}
 
 	text = efi_str_to_u16(buffer);
--
Quoted 2 lines

2.30.0

Cheers
/Ilias

#3 lore raw

PATCH 1/2 efi_loader: multi part device paths to text

Quoted 21 lines · Ilias Apalodimas

Hi Heinrich

Quoted 18 lines · Heinrich Schuchardt

Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts.

Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does.

---
 lib/efi_loader/efi_device_path_to_text.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +0 -0
index 1aaa9f94fa..81b8ac23ba 100644
@@ -369,11 +369,18 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(
 
Quoted 13 lines

lib/efi_loader/efi_device_path_to_text.c static uint16_t EFIAPI *efi_convert_device_path_to_text( · line 375

Quoted 11 lines
lib/efi_loader/efi_device_path_to_text.c +4 -5
 	if (!device_path)
 		goto out;
-	while (device_path &&
-	       str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
-		*str++ = '/';
-		str = efi_convert_single_device_node_to_text(str, device_path);
-		device_path = efi_dp_next(device_path);
+	while (device_path && str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
+		if (device_path->type == DEVICE_PATH_TYPE_END) {
+			if (device_path->sub_type !=
+			    DEVICE_PATH_SUB_TYPE_INSTANCE_END)

maybe it's better to check explicitly for '== DEVICE_PATH_SUB_TYPE_END'?

Thank you for reviewing.

I want to leave the loop when an unexpected value occurs.

Best regards

Heinrich

Quoted 19 lines
Quoted 13 lines
lib/efi_loader/efi_device_path_to_text.c +8 -1
+				break;
+			*str++ = ',';
+		} else {
+			*str++ = '/';
+			str = efi_convert_single_device_node_to_text(
+							str, device_path);
+		}
+		*(u8 **)&device_path += device_path->length;
 	}
 
 	text = efi_str_to_u16(buffer);
--
Quoted 2 lines

2.30.0

Cheers
/Ilias

#4 lore raw

PATCH 1/2 efi_loader: multi part device paths to text

Quoted 36 lines · Heinrich Schuchardt
Quoted 21 lines · Ilias Apalodimas

Hi Heinrich

Quoted 18 lines · Heinrich Schuchardt

Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts.

Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does.

---
 lib/efi_loader/efi_device_path_to_text.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +0 -0
index 1aaa9f94fa..81b8ac23ba 100644
@@ -369,11 +369,18 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(
 
Quoted 13 lines

lib/efi_loader/efi_device_path_to_text.c static uint16_t EFIAPI *efi_convert_device_path_to_text( · line 375

Quoted 11 lines
lib/efi_loader/efi_device_path_to_text.c +4 -5
 	if (!device_path)
 		goto out;
-	while (device_path &&
-	       str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
-		*str++ = '/';
-		str = efi_convert_single_device_node_to_text(str, device_path);
-		device_path = efi_dp_next(device_path);
+	while (device_path && str + MAX_NODE_LEN < buffer + MAX_PATH_LEN) {
+		if (device_path->type == DEVICE_PATH_TYPE_END) {
+			if (device_path->sub_type !=
+			    DEVICE_PATH_SUB_TYPE_INSTANCE_END)

maybe it's better to check explicitly for '== DEVICE_PATH_SUB_TYPE_END'?

Quoted 3 lines

Thank you for reviewing.

I want to leave the loop when an unexpected value occurs.

Fair enough

Quoted 25 lines

Best regards

Heinrich

Quoted 19 lines
Quoted 13 lines
lib/efi_loader/efi_device_path_to_text.c +8 -1
+				break;
+			*str++ = ',';
+		} else {
+			*str++ = '/';
+			str = efi_convert_single_device_node_to_text(
+							str, device_path);
+		}
+		*(u8 **)&device_path += device_path->length;
 	}
 
 	text = efi_str_to_u16(buffer);
--
Quoted 2 lines

2.30.0

Cheers
/Ilias

#5 lore raw

PATCH 2/2 efi_selftest: multi part device path to text

In reply to Heinrich Schuchardt

Test EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() for a multi part device path.

---
 lib/efi_selftest/efi_selftest_devicepath.c | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
lib/efi_selftest/efi_selftest_devicepath.c +65 -0
index 4ce3fad895..d87b9f7dcd 100644
@@ -45,6 +45,55 @@ static u8 *dp1;
 static u8 *dp2;
 static u8 *dp3;
 
+static struct {
+	struct efi_device_path_sd_mmc_path sd1;
+	struct efi_device_path sep1;
+	struct efi_device_path_sd_mmc_path sd2;
+	struct efi_device_path sep2;
+	struct efi_device_path_sd_mmc_path sd3;
+	struct efi_device_path end;
+} multi_part_dp = {
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		0,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_INSTANCE_END,
+		sizeof(struct efi_device_path),
+	},
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		1,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_INSTANCE_END,
+		sizeof(struct efi_device_path),
+	},
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		2,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_END,
+		sizeof(struct efi_device_path),
+	},
+};
+
 struct efi_device_path_to_text_protocol *device_path_to_text;
 
 /*
@@ -340,6 +389,22 @@ static int execute(void)
 		return EFI_ST_FAILURE;
 	}
 
+	string = device_path_to_text->convert_device_path_to_text(
+			(struct efi_device_path *)&multi_part_dp, true, false);
+	if (efi_st_strcmp_16_8(
+		string,
+		"/SD(0),/SD(1),/SD(2)")
+	    ) {
+		efi_st_printf("multi_part_dp: %ps\n", string);
+		efi_st_error("Incorrect text from ConvertDevicePathToText\n");
+		return EFI_ST_FAILURE;
+	}
+	ret = boottime->free_pool(string);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("FreePool failed\n");
+		return EFI_ST_FAILURE;
+	}
+
 	/* Test ConvertDeviceNodeToText */
 	string = device_path_to_text->convert_device_node_to_text(
 			(struct efi_device_path *)&dp_node, true, false);

--
2.30.0

#6 lore raw

PATCH 2/2 efi_selftest: multi part device path to text

Quoted 92 lines · Heinrich Schuchardt

Test EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() for a multi part device path.

---
 lib/efi_selftest/efi_selftest_devicepath.c | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
lib/efi_selftest/efi_selftest_devicepath.c +65 -1
index 4ce3fad895..d87b9f7dcd 100644
@@ -45,6 +45,55 @@ static u8 *dp1;
 static u8 *dp2;
 static u8 *dp3;
 
+static struct {
+	struct efi_device_path_sd_mmc_path sd1;
+	struct efi_device_path sep1;
+	struct efi_device_path_sd_mmc_path sd2;
+	struct efi_device_path sep2;
+	struct efi_device_path_sd_mmc_path sd3;
+	struct efi_device_path end;
+} multi_part_dp = {
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		0,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_INSTANCE_END,
+		sizeof(struct efi_device_path),
+	},
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		1,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_INSTANCE_END,
+		sizeof(struct efi_device_path),
+	},
+	{
+		{
+			DEVICE_PATH_TYPE_MESSAGING_DEVICE,
+			DEVICE_PATH_SUB_TYPE_MSG_SD,
+			sizeof(struct efi_device_path_sd_mmc_path),
+		},
+		2,
+	},
+	{
+		DEVICE_PATH_TYPE_END,
+		DEVICE_PATH_SUB_TYPE_END,
+		sizeof(struct efi_device_path),
+	},
+};
+
 struct efi_device_path_to_text_protocol *device_path_to_text;
 
 /*
@@ -340,6 +389,22 @@ static int execute(void)
 		return EFI_ST_FAILURE;
 	}
 
+	string = device_path_to_text->convert_device_path_to_text(
+			(struct efi_device_path *)&multi_part_dp, true, false);
+	if (efi_st_strcmp_16_8(
+		string,
+		"/SD(0),/SD(1),/SD(2)")
+	    ) {
+		efi_st_printf("multi_part_dp: %ps\n", string);
+		efi_st_error("Incorrect text from ConvertDevicePathToText\n");
+		return EFI_ST_FAILURE;
+	}
+	ret = boottime->free_pool(string);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("FreePool failed\n");
+		return EFI_ST_FAILURE;
+	}
+
 	/* Test ConvertDeviceNodeToText */
 	string = device_path_to_text->convert_device_node_to_text(
 			(struct efi_device_path *)&dp_node, true, false);
--
Quoted 2 lines

2.30.0