[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] x86/EFI: don't let the EDD disk counter wrap


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
  • Date: Fri, 4 Dec 2026 07:49:10 +0000
  • Accept-language: en-IN, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=electrifex.com; dmarc=pass action=none header.from=electrifex.com; dkim=pass header.d=electrifex.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C9kSNicjwN2JnLGVCKvDPnGUJU4QDurUH4dw3Axs1X4=; b=KG055pe1I9SJzym/Gz7CvGLlGxpL+UOtISu7sAduzAZRpCwrShSoleSbk5SlR4UPYQ5ap0J49UCzg45Ryzv1H5Rn5ToENPnD4jv0zArDiOuWOcFCOsHXa/t+3ql1DN+JB0cyQ99Er2EOZm0UsTJWb+G56aW9BO++9eIDMR97NlF6DtNiu5tW3k3O70qFCeyvZVcG7CJsAmIxY2KawrVR0XQ9VW+wvwXBqvpu6MmAT1wdLWj2e8TkZK9db5xGz0bp82QUChTHyntoltQus4TEJ1Yz7QKh/QiNsy1ESTZx7hXSyVk5HhtmCcxrQ1yxz45tmNcjyoWy6qi/wm7zGDYLZw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g7Zhi+ka8wTK686qRKQzg7//5a5qQSglhI8OqAGA/nciz3YUvGGEHNjCzPUZmcJ4FP0XLREhfP4X0wXmT+DtTSmf9augkKwk1zGEhHnUnXghkwLyJygCGwqB8mccIT9lpjiwn+EkJMpdeqOQ8oUACgYjZMuBsqsBg3RgSN34I1yOy29QH0w3RNcWI1jwT/BIC6fAGIGfOYSObQickM+MxZTD8Wy/0WQnbuXekYLr/IxOzEdEwXzeCtbzXL9J7C5/9ol7OsA1S/8e8VSMrXl25Lz3AfVgKk0WikmbnZwRWNXZvIUpOlupuTpfR3Xb04mD46Zn4XKTmezXbH3CZBoD+Q==
  • Authentication-results: eu.smtp.expurgate.cloud; none
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=electrifex.com;
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, "andrew.cooper3@xxxxxxxxxx" <andrew.cooper3@xxxxxxxxxx>, "roger@xxxxxxxxxxxxxx" <roger@xxxxxxxxxxxxxx>, "marmarek@xxxxxxxxxxxxxxxxxxxxxx" <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, "dpsmith@xxxxxxxxxxxxxxxxxxxx" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, "teddy.astie@xxxxxxxxxx" <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Fri, 04 Dec 2026 07:49:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdg8MZ6OMMNicX8kOapE6u5JZ6Pg==
  • Thread-topic: [PATCH v2] x86/EFI: don't let the EDD disk counter wrap

efi_arch_edd() increments the u8 boot_edd_info_nr once per candidate
disk, without bound.  Disks past EDD_INFO_MAX are meant to be skipped by
the "boot_edd_info_nr > EDD_INFO_MAX" checks in the device path
handling, but with 256 or more disks the counter wraps to zero.  For the
256th disk "info" and "params" then point at boot_edd_info[255], about
20KiB past the end of the array, while the checks pass, so its details
are written there.  With xen.efi that is currently the alternatives
table, and Xen panics with "Unable to apply alternatives".  Later disks
overwrite the first entries.  "edd=" can't avoid this, as it is ignored
when booting via EFI.

Count in a local variable instead, and store the result, capped at
EDD_INFO_MAX, into boot_edd_info_nr at the end.

Fixes: 51f03ec421fb ("x86-64/EFI: construct EDD data from device path protocol 
information")
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
---
Changes in v2:
- Use a local counter, as suggested by Jan.  Output is now unchanged
  for up to 255 disks, including the MBR signature device numbers.

Reproduced in QEMU/OVMF with 256 and 260 whole disks (NVMe namespaces):
xen.efi panics; via GRUB/multiboot2 Xen boots, but Dom0 gets wrong EDD
entries.  With this patch both boot with the first 6 disks, and with 5,
15 and 255 disks Dom0's EDD data is unchanged.

 xen/arch/x86/efi/efi-boot.h | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 8bca03a66b..a38dccc910 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -360,7 +360,7 @@ static void __init efi_arch_edd(void)
     static EFI_GUID __initdata bio_guid = BLOCK_IO_PROTOCOL;
     static EFI_GUID __initdata devp_guid = DEVICE_PATH_PROTOCOL;
     EFI_HANDLE *handles = NULL;
-    unsigned int i;
+    unsigned int i, nr = 0;
     UINTN size;
     EFI_STATUS status;
 
@@ -380,7 +380,7 @@ static void __init efi_arch_edd(void)
     {
         EFI_BLOCK_IO *bio;
         EFI_DEV_PATH_PTR devp;
-        struct edd_info *info = boot_edd_info + boot_edd_info_nr;
+        struct edd_info *info = boot_edd_info + nr;
         struct edd_device_params *params = &info->edd_device_params;
         enum { root, acpi, pci, ctrlr } state = root;
 
@@ -389,16 +389,16 @@ static void __init efi_arch_edd(void)
              bio->Media->RemovableMedia ||
              bio->Media->LogicalPartition )
             continue;
-        if ( boot_edd_info_nr < EDD_INFO_MAX )
+        if ( nr < EDD_INFO_MAX )
         {
-            info->device = 0x80 + boot_edd_info_nr; /* fake */
+            info->device = 0x80 + nr; /* fake */
             info->version = 0x11;
             params->length = offsetof(struct edd_device_params, dpte_ptr);
             params->number_of_sectors = bio->Media->LastBlock + 1;
             params->bytes_per_sector = bio->Media->BlockSize;
             params->dpte_ptr = ~0;
         }
-        ++boot_edd_info_nr;
+        ++nr;
         status = efi_bs->HandleProtocol(handles[i], &devp_guid,
                                         (void **)&devp);
         if ( EFI_ERROR(status) )
@@ -411,7 +411,7 @@ static void __init efi_arch_edd(void)
                 const u8 *p;
 
             case ACPI_DEVICE_PATH:
-                if ( state != root || boot_edd_info_nr > EDD_INFO_MAX )
+                if ( state != root || nr > EDD_INFO_MAX )
                     break;
                 switch ( DevicePathSubType(devp.DevPath) )
                 {
@@ -430,7 +430,7 @@ static void __init efi_arch_edd(void)
             case HARDWARE_DEVICE_PATH:
                 if ( state != acpi ||
                      DevicePathSubType(devp.DevPath) != HW_PCI_DP ||
-                     boot_edd_info_nr > EDD_INFO_MAX )
+                     nr > EDD_INFO_MAX )
                     break;
                 state = pci;
                 edd_put_string(params->host_bus_type, "PCI");
@@ -438,7 +438,7 @@ static void __init efi_arch_edd(void)
                 params->interface_path.pci.function = devp.Pci->Function;
                 break;
             case MESSAGING_DEVICE_PATH:
-                if ( state != pci || boot_edd_info_nr > EDD_INFO_MAX )
+                if ( state != pci || nr > EDD_INFO_MAX )
                     break;
                 state = ctrlr;
                 switch ( DevicePathSubType(devp.DevPath) )
@@ -492,7 +492,7 @@ static void __init efi_arch_edd(void)
                     struct mbr_signature *sig = boot_mbr_signature +
                                                 boot_mbr_signature_nr;
 
-                    sig->device = 0x80 + boot_edd_info_nr; /* fake */
+                    sig->device = 0x80 + nr; /* fake */
                     memcpy(&sig->signature, devp.HardDrive->Signature,
                            sizeof(sig->signature));
                     ++boot_mbr_signature_nr;
@@ -503,8 +503,7 @@ static void __init efi_arch_edd(void)
     }
     if ( handles )
         efi_bs->FreePool(handles);
-    if ( boot_edd_info_nr > EDD_INFO_MAX )
-        boot_edd_info_nr = EDD_INFO_MAX;
+    boot_edd_info_nr = min_t(unsigned int, nr, EDD_INFO_MAX);
 }
 
 static void __init efi_arch_console_init(UINTN cols, UINTN rows)

base-commit: 77ff75d3244faa2bc083c0ba8686830f8de30d9e
-- 
2.53.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.