Skip to contentSkip to conversation

efi_loader: Fix potential deref-after-null

PATCH In review Maks Mishin 2 participants 2 messages Feb 2, 2025 – Feb 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: Fix potential deref-after-null

After having been compared to a NULL value at efi_disk.c:426, pointer 'part_info' is dereferenced at efi_disk.c:534.

---
 lib/efi_loader/efi_disk.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
lib/efi_loader/efi_disk.c +9 -7
index 1f3de0a233..83e8eb6fe4 100644
@@ -531,13 +531,15 @@ static efi_status_t efi_disk_add_dev(
 
 	/* Store first EFI system partition */
 	if (part && efi_system_partition.uclass_id == UCLASS_INVALID) {
-		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
-			efi_system_partition.uclass_id = desc->uclass_id;
-			efi_system_partition.devnum = desc->devnum;
-			efi_system_partition.part = part;
-			EFI_PRINT("EFI system partition: %s %x:%x\n",
-				  blk_get_uclass_name(desc->uclass_id),
-				  desc->devnum, part);
+		if (part_info) {
+			if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
+				efi_system_partition.uclass_id = desc->uclass_id;
+				efi_system_partition.devnum = desc->devnum;
+				efi_system_partition.part = part;
+				EFI_PRINT("EFI system partition: %s %x:%x\n",
+					blk_get_uclass_name(desc->uclass_id),
+					desc->devnum, part);
+			}
 		}
 	}
 	return EFI_SUCCESS;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Maks Mishin

After having been compared to a NULL value at efi_disk.c:426, pointer 'part_info' is dereferenced at efi_disk.c:534.

---
  lib/efi_loader/efi_disk.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
lib/efi_loader/efi_disk.c +0 -0
index 1f3de0a233..83e8eb6fe4 100644
@@ -531,13 +531,15 @@ static efi_status_t efi_disk_add_dev(
 
  	/* Store first EFI system partition */

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 535

Quoted 10 lines
lib/efi_loader/efi_disk.c +2 -7
  	if (part && efi_system_partition.uclass_id == UCLASS_INVALID) {
-		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
-			efi_system_partition.uclass_id = desc->uclass_id;
-			efi_system_partition.devnum = desc->devnum;
-			efi_system_partition.part = part;
-			EFI_PRINT("EFI system partition: %s %x:%x\n",
-				  blk_get_uclass_name(desc->uclass_id),
-				  desc->devnum, part);
+		if (part_info) {
+			if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {

Hello Maks,

Thank you for spotting this and providing a patch.

U-Boot has scripts/get_maintainer.pl to find whom patches should be addressed to.

We could use a single if statement with &&. But that is just a matter of taste.

Quoted 10 lines
lib/efi_loader/efi_disk.c +7 -0
+				efi_system_partition.uclass_id = desc->uclass_id;
+				efi_system_partition.devnum = desc->devnum;
+				efi_system_partition.part = part;
+				EFI_PRINT("EFI system partition: %s %x:%x\n",
+					blk_get_uclass_name(desc->uclass_id),
+					desc->devnum, part);
+			}
  		}
  	}
  	return EFI_SUCCESS;