Skip to contentSkip to conversation

efi_loader: initialise partition_signature memory

PATCH New Jonathan Gray 3 participants 3 messages Nov 22, 2017 – Dec 4, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi_loader: initialise partition_signature memory

Zero partition_signature in the efi_device_path_hard_drive_path structure when signature_type is 0 (no signature) as required by the UEFI specification.

This is required so that efi_dp_match() will work as expected when doing memcmp() comparisons. Previously uninitialised memory would cause it not match nodes when it should have when the signature type was not GUID.

Corrects a problem where the loaded image protocol would not return a device path with MEDIA_DEVICE causing the OpenBSD bootloader to fail on rpi_3 and other targets.

v2: Also handle signature_type 1 (MBR) as described in the specification

---
 lib/efi_loader/efi_device_path.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
lib/efi_loader/efi_device_path.c +19 -2
index f6e368e029..12a81d311c 100644
@@ -427,10 +427,27 @@ static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
 			hddp->partmap_type = 2;
 		else
 			hddp->partmap_type = 1;
-		hddp->signature_type = desc->sig_type;
-		if (hddp->signature_type != 0)
+
+		switch (desc->sig_type) {
+		case SIG_TYPE_NONE:
+		default:
+			hddp->signature_type = 0;
+			memset(hddp->partition_signature, 0,
+			       sizeof(hddp->partition_signature));
+			break;
+		case SIG_TYPE_MBR:
+			hddp->signature_type = 1;
+			memset(hddp->partition_signature, 0,
+			       sizeof(hddp->partition_signature));
+			memcpy(hddp->partition_signature, &desc->mbr_sig,
+			       sizeof(desc->mbr_sig));
+			break;
+		case SIG_TYPE_GUID:
+			hddp->signature_type = 2;
 			memcpy(hddp->partition_signature, &desc->guid_sig,
 			       sizeof(hddp->partition_signature));
+			break;
+		}
 
 		buf = &hddp[1];
 	}
Signature · 1 line
2.15.0
#1 lore raw

PATCH v2 1/1 efi_loader: initialise partition_signature memory

Quoted 9 lines · Jonathan Gray

Zero partition_signature in the efi_device_path_hard_drive_path structure when signature_type is 0 (no signature) as required by the UEFI specification.

This is required so that efi_dp_match() will work as expected when doing memcmp() comparisons. Previously uninitialised memory would cause it not match nodes when it should have when the signature type was not GUID.

Quoted 7 lines

Corrects a problem where the loaded image protocol would not return a device path with MEDIA_DEVICE causing the OpenBSD bootloader to fail on rpi_3 and other targets.

v2: Also handle signature_type 1 (MBR) as described in the specification

Tested with Marsboard_A10_defconfig.
Thanks,
-Artturi

Quoted 45 lines
---
 lib/efi_loader/efi_device_path.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
lib/efi_loader/efi_device_path.c +19 -2
index f6e368e029..12a81d311c 100644
@@ -427,10 +427,27 @@ static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
 			hddp->partmap_type = 2;
 		else
 			hddp->partmap_type = 1;
-		hddp->signature_type = desc->sig_type;
-		if (hddp->signature_type != 0)
+
+		switch (desc->sig_type) {
+		case SIG_TYPE_NONE:
+		default:
+			hddp->signature_type = 0;
+			memset(hddp->partition_signature, 0,
+			       sizeof(hddp->partition_signature));
+			break;
+		case SIG_TYPE_MBR:
+			hddp->signature_type = 1;
+			memset(hddp->partition_signature, 0,
+			       sizeof(hddp->partition_signature));
+			memcpy(hddp->partition_signature, &desc->mbr_sig,
+			       sizeof(desc->mbr_sig));
+			break;
+		case SIG_TYPE_GUID:
+			hddp->signature_type = 2;
 			memcpy(hddp->partition_signature, &desc->guid_sig,
 			       sizeof(hddp->partition_signature));
+			break;
+		}
 
 		buf = &hddp[1];
 	}
Signature · 6 lines
2.15.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
#2 lore raw

PATCH v2 1/1 efi_loader: initialise partition_signature memory

In reply to Jonathan Gray
Quoted 9 lines

Zero partition_signature in the efi_device_path_hard_drive_path structure when signature_type is 0 (no signature) as required by the UEFI specification.

This is required so that efi_dp_match() will work as expected when doing memcmp() comparisons. Previously uninitialised memory would cause it not match nodes when it should have when the signature type was not GUID.

Quoted 8 lines

Corrects a problem where the loaded image protocol would not return a device path with MEDIA_DEVICE causing the OpenBSD bootloader to fail on rpi_3 and other targets.

v2: Also handle signature_type 1 (MBR) as described in the specification

Thanks, applied to efi-next

Alex