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

[PATCH] x86/EFI: fix padding of EDD strings


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
  • Date: Thu, 5 Nov 2026 09:10:28 +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=/M02mJb3jaXljVyHD2w6LUuX1f0Ld0KFuP+FtWfSHlY=; b=mEBAI8ErlIxQVs6lMRppsnKUaH6FyYuTtmddGpb28opVjExxsyaqKpLkRJOYTOMYL7fR6ndysw3ZD+2kPhFYenc1ZxcD6e4Nzib9G2xmSp8Im9Kt6XqCbkDo0mnDDfPz7UXwzBI3VR8IJQpl/GurO3LZyMMJpQs7dpzC+MYER2DcsJvfS63pZ/sLma9feMxvZ7rZE/E/aWVixqc13gVlLCltA25u5t2rqCtW5FxA6nNIBpMW5qmPNm2MwhCA5g4tCKF51hB5YtAAHsbeEP/8Hih4sTxrS9GqSSwtsDhACxg2tvnuXfnQTwcgLEOqb9lOW6xC6eopcaGTFd/94f0KiA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dCxYD14E4sPVoW0axkYIL+lYqHzgt3O3rjKnG8QX7lhb1y56YGIBiX5UhSdrx23ORLmZNp1uoMTjmUnCsvf7YqffRiTTlD9p141wrJI+avM51Yq15/1D21BOhLcQP8uEvEj0B88d/ysI5H/ui/zHLpQqLmgKE0qgXd8wph6BvDVvCBB5ul5AlIfVL+4Izt8SepT7Fxmvn3BKZu3CldMOPrSr84yKaUoiCAZuzFfPQhJqbFw31yv3g3B+0prkbHO1VQWx+ZHlZOszpAe6JNme0WIgx0GPlRanQQGr83npo/AYrS8bfZavR/GtBcTK6PK2WhbH6udCw51z2HIWDOVDoQ==
  • 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 Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Thu, 05 Nov 2026 09:23:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdbQRh3bU+0D+v9UGVw8dMUNUEuQ==
  • Thread-topic: [PATCH] x86/EFI: fix padding of EDD strings

edd_put_string() decrements n in its copy loop condition even when the
loop terminates because the end of the source string was reached.  The
padding loop then writes one space too few, leaving the final byte of
the field untouched (zero, as boot_edd_info[] lives in .bss).  On an EFI
boot this yields e.g. a host bus type of "PCI\0" and an interface type
of "ATAPI  \0", whereas BIOSes space-pad these fields (SeaBIOS reports
"PCI " and "ATA     ").

Furthermore, if the string exactly filled the field, n would wrap to
SIZE_MAX after the copy loop and the padding loop would write past the
end of the field.  No caller currently passes such a string.

Only decrement n when a character was actually copied.  While touching
the function, also correct its indentation.

Fixes: 51f03ec421fb ("x86-64/EFI: construct EDD data from device path protocol 
information")
Assisted-by: Claude
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
---
Tested in QEMU (i440fx, OVMF, 2 IDE + 2 virtio-scsi disks) with a debug
build and a Linux 7.1 PV Dom0, booting xen.efi directly and via GRUB2
multiboot2.  /sys/firmware/edd/int13_dev8?/raw_data showed
host_bus_type "50 43 49 00" and interface types ending in 00 before
the patch, and "50 43 49 20" with fully space-padded interface types
after it, on all five disks.

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

diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index d738b839ee..dab61c2d4b 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -30,13 +30,13 @@ static module_t __initdata mb_modules[5];
 
 static void __init edd_put_string(u8 *dst, size_t n, const char *src)
 {
-    while ( n-- && *src )
-       *dst++ = *src++;
+    for ( ; n && *src; --n )
+        *dst++ = *src++;
     if ( *src )
-       PrintErrMesg(L"Internal error populating EDD info",
-                    EFI_BUFFER_TOO_SMALL);
+        PrintErrMesg(L"Internal error populating EDD info",
+                     EFI_BUFFER_TOO_SMALL);
     while ( n-- )
-       *dst++ = ' ';
+        *dst++ = ' ';
 }
 #define edd_put_string(d, s) edd_put_string(d, ARRAY_SIZE(d), s)
 

base-commit: bec8e3c1fb91b96f337c08c6daf1bb2563b320c0



 


Rackspace

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