[PATCH] x86/mkelf32: correct off-by-1 in empty PHDR checking loop

Jan Beulich posted 1 patch 2 days, 1 hour ago
[PATCH] x86/mkelf32: correct off-by-1 in empty PHDR checking loop
Posted by Jan Beulich 2 days, 1 hour ago
To read the trailing PHDR, we need to seek to its start position within
the file, not its ending one.

Fixes: 54279f87ecbc ("x86/build: make linking work again with ld incapable of generating build ID")
Reported-by: Roger Pau Monné <roger.pau@amd.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/boot/mkelf32.c
+++ b/xen/arch/x86/boot/mkelf32.c
@@ -320,7 +320,8 @@ int main(int argc, char **argv)
     while ( in64_ehdr.e_phnum > num_phdrs )
     {
         (void)lseek(infd,
-                    in64_ehdr.e_phoff + in64_ehdr.e_phnum * sizeof(in64_phdr),
+                    in64_ehdr.e_phoff + (in64_ehdr.e_phnum - 1) *
+                                        sizeof(in64_phdr),
                     SEEK_SET);
         do_read(infd, &in64_phdr, sizeof(in64_phdr));
         endianadjust_phdr64(&in64_phdr);

Re: [PATCH] x86/mkelf32: correct off-by-1 in empty PHDR checking loop
Posted by Andrew Cooper 2 days, 1 hour ago
On 24/11/2026 9:57 am, Jan Beulich wrote:
> To read the trailing PHDR, we need to seek to its start position within
> the file, not its ending one.
>
> Fixes: 54279f87ecbc ("x86/build: make linking work again with ld incapable of generating build ID")
> Reported-by: Roger Pau Monné <roger.pau@amd.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>