Skip to contentSkip to conversation

x86/mkelf32: correct VA/PA of PT_NOTE / .note

PATCH In review Jan Beulich 3 participants 3 messages Sep 21 – Sep 25

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mkelf32: correct VA/PA of PT_NOTE / .note

For the .p_paddr, .p_vaddr, and .sh_addr fields the image load base (passed in by command line argument) also needs taking into account. It is _not_ merely the delta between incoming PT_NOTE and PT_LOAD segments. (The fields aren't really used anywhere, so this is largely a cosmetic issue; static analysis tools may be affected, though.)

Fixes a353cab905af ("build_id: Provide ld-embedded build-ids")
xen/arch/x86/boot/mkelf32.c +1 -1
@@ -362,7 +362,7 @@ int main(int argc, char **argv)
         (void)lseek(infd, offset, SEEK_SET);
 
         note_sz = in64_phdr.p_memsz;
-        note_base = in64_phdr.p_vaddr - note_base;
+        note_base = in64_phdr.p_vaddr - note_base + loadbase;
 
         if ( in64_phdr.p_offset < offset ||
              in64_phdr.p_offset + in64_phdr.p_filesz > offset + dat_siz )
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jan Beulich

For the .p_paddr, .p_vaddr, and .sh_addr fields the image load base (passed in by command line argument) also needs taking into account. It is _not_ merely the delta between incoming PT_NOTE and PT_LOAD segments. (The fields aren't really used anywhere, so this is largely a cosmetic issue; static analysis tools may be affected, though.)

Fixes a353cab905af ("build_id: Provide ld-embedded build-ids")

xen/arch/x86/boot/mkelf32.c int main(int argc, char **argv) · line 368

Quoted 8 lines
xen/arch/x86/boot/mkelf32.c +1 -1
@@ -362,7 +362,7 @@ int main(int argc, char **argv)
          (void)lseek(infd, offset, SEEK_SET);
 
          note_sz = in64_phdr.p_memsz;
-        note_base = in64_phdr.p_vaddr - note_base;
+        note_base = in64_phdr.p_vaddr - note_base + loadbase;
 
          if ( in64_phdr.p_offset < offset ||
               in64_phdr.p_offset + in64_phdr.p_filesz > offset + dat_siz )

The diff before/after shows the note section and program header addresses moving by 0x200000 as expected (with no other changes):

@@ -24,7 +24,7 @@

   [ 0]                   NULL            00000000 000000 000000 00      0   0  0
   [ 1] .text             PROGBITS        00200000 000080 2df354 00 WAX  0   0 64
   [ 2] .shstrtab         STRTAB          00000000 2df474 000018 00      0   0  1
-  [ 3] .note             NOTE            002072b8 207338 000024 00      0   0  4
+  [ 3] .note             NOTE            004072b8 207338 000024 00      0   0  4

Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS),
@@ -36,7 +36,7 @@
Program Headers:

   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
   LOAD           0x000080 0x00200000 0x00200000 0x2df354 0x400000 RWE 0x40
-  NOTE           0x207338 0x002072b8 0x002072b8 0x00024 0x00024 R   0x4
+  NOTE           0x207338 0x004072b8 0x004072b8 0x00024 0x00024 R   0x4

Section to Segment mapping:
Segment Sections...

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

For the .p_paddr, .p_vaddr, and .sh_addr fields the image load base (passed in by command line argument) also needs taking into account. It is _not_ merely the delta between incoming PT_NOTE and PT_LOAD segments. (The fields aren't really used anywhere, so this is largely a cosmetic issue; static analysis tools may be affected, though.)

Fixes a353cab905af ("build_id: Provide ld-embedded build-ids")