]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi: add efi_guid_equal() helper
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Nov 2022 15:05:03 +0000 (16:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 14 Dec 2022 18:16:54 +0000 (19:16 +0100)
src/boot/efi/devicetree.c
src/boot/efi/part-discovery.c
src/boot/efi/random-seed.c
src/boot/efi/util.h
src/boot/efi/vmm.c

index 031267061354607df1d9c612f0eeb9887a57ca87..daba5582aad8f6db919045d7fae7502f1c815aad 100644 (file)
@@ -10,7 +10,7 @@
 
 static void *get_dtb_table(void) {
         for (UINTN i = 0; i < ST->NumberOfTableEntries; i++)
-                if (memcmp(&EfiDtbTableGuid, &ST->ConfigurationTable[i].VendorGuid, sizeof(EfiDtbTableGuid)) == 0)
+                if (efi_guid_equal(&ST->ConfigurationTable[i].VendorGuid, &EfiDtbTableGuid))
                         return ST->ConfigurationTable[i].VendorTable;
         return NULL;
 }
index 14479c06eaee937ec2d48755da910cf938c36784..2659a5b6b4759abe8e3070d6eaab827580517889 100644 (file)
@@ -134,7 +134,7 @@ static EFI_STATUS try_gpt(
                 EFI_PARTITION_ENTRY *entry =
                                 (EFI_PARTITION_ENTRY *) ((uint8_t *) entries + gpt.gpt_header.SizeOfPartitionEntry * i);
 
-                if (memcmp(&entry->PartitionTypeGUID, type, sizeof(entry->PartitionTypeGUID)) != 0)
+                if (!efi_guid_equal(&entry->PartitionTypeGUID, type))
                         continue;
 
                 if (entry->EndingLBA < entry->StartingLBA) /* Bogus? */
index 22ba1c5a30e93f16bd48072eab3c06e9f047c2dc..bdaed2625a64419fffe62dd885881806e50795d0 100644 (file)
@@ -142,8 +142,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir) {
         sha256_process_bytes(HASH_LABEL, sizeof(HASH_LABEL) - 1, &hash);
 
         for (size_t i = 0; i < ST->NumberOfTableEntries; ++i)
-                if (memcmp(&(const EFI_GUID)LINUX_EFI_RANDOM_SEED_TABLE_GUID,
-                           &ST->ConfigurationTable[i].VendorGuid, sizeof(EFI_GUID)) == 0) {
+                if (efi_guid_equal(&ST->ConfigurationTable[i].VendorGuid, &(const EFI_GUID) LINUX_EFI_RANDOM_SEED_TABLE_GUID)) {
                         previous_seed_table = ST->ConfigurationTable[i].VendorTable;
                         break;
                 }
index fb525ba63630341c55f29a73903a6c5e8df1c46c..bacc114114f5d1107837130b98a8822de431d84c 100644 (file)
@@ -242,3 +242,7 @@ static inline bool in_hypervisor(void) {
         return false;
 }
 #endif
+
+static inline bool efi_guid_equal(const EFI_GUID *a, const EFI_GUID *b) {
+        return memcmp(a, b, sizeof(EFI_GUID)) == 0;
+}
index 2260b217b79b318cdf09cfb3d2f7f453ee1b73fa..10d4a75ab208667c663f75628d829506d0d43a5a 100644 (file)
@@ -18,7 +18,7 @@
 /* detect direct boot */
 bool is_direct_boot(EFI_HANDLE device) {
         EFI_STATUS err;
-        VENDOR_DEVICE_PATH *dp;
+        VENDOR_DEVICE_PATH *dp; /* NB: Alignment of this structure might be quirky! */
 
         err = BS->HandleProtocol(device, &DevicePathProtocol, (void **) &dp);
         if (err != EFI_SUCCESS)
@@ -27,7 +27,7 @@ bool is_direct_boot(EFI_HANDLE device) {
         /* 'qemu -kernel systemd-bootx64.efi' */
         if (dp->Header.Type == MEDIA_DEVICE_PATH &&
             dp->Header.SubType == MEDIA_VENDOR_DP &&
-            memcmp(&dp->Guid, &(EFI_GUID)QEMU_KERNEL_LOADER_FS_MEDIA_GUID, sizeof(EFI_GUID)) == 0)
+            memcmp(&dp->Guid, &(EFI_GUID)QEMU_KERNEL_LOADER_FS_MEDIA_GUID, sizeof(EFI_GUID)) == 0) /* Don't change to efi_guid_equal() because EFI device path objects are not necessarily aligned! */
                 return true;
 
         /* loaded from firmware volume (sd-boot added to ovmf) */