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

[xen staging-4.22] x86/EFI: fix padding of EDD strings



commit 29f64dfca2d19575af6772a350dcd8a478f2f9f6
Author:     Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
AuthorDate: Wed Nov 11 14:23:13 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Nov 11 14:23:13 2026 +0100

    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>
    Reviewed-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
    master commit: a6bc1a68b0d00d656cf42aabb4d619c95b38fa90
    master date: 2026-11-10 09:46:13 +0100
---
 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)
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.22



 


Rackspace

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