]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Treat writable sections as data sections
authorMichael Brown <mcb30@ipxe.org>
Wed, 22 Nov 2023 23:14:38 +0000 (23:14 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 23 Nov 2023 13:20:21 +0000 (13:20 +0000)
Hybrid bzImage and UEFI binaries (such as wimboot) may include 16-bit
executable code that is opaque data from the perspective of a UEFI PE
binary, as described in wimboot commit fe456ca ("[efi] Use separate
.text and .data PE sections").

The ELF section will be marked as containing both executable code and
writable data.  Choose to treat such a section as a data section
rather than a code section, since that matches the expected semantics
for ELF files that we expect to process.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/util/elf2efi.c

index 5b3e785f53bb7b63a7973fe39da5034aa77c4c46..4ed016c0f25c99e3c91628b47b6c79faa1c20149 100644 (file)
@@ -591,17 +591,7 @@ static struct pe_section * process_section ( struct elf_file *elf,
 
        /* Fill in section characteristics and update RVA limits */
        if ( ( shdr->sh_type == SHT_PROGBITS ) &&
-            ( shdr->sh_flags & SHF_EXECINSTR ) ) {
-               /* .text-type section */
-               new->hdr.Characteristics =
-                       ( EFI_IMAGE_SCN_CNT_CODE |
-                         EFI_IMAGE_SCN_MEM_NOT_PAGED |
-                         EFI_IMAGE_SCN_MEM_EXECUTE |
-                         EFI_IMAGE_SCN_MEM_READ );
-               applicable_start = &code_start;
-               applicable_end = &code_end;
-       } else if ( ( shdr->sh_type == SHT_PROGBITS ) &&
-                   ( shdr->sh_flags & SHF_WRITE ) ) {
+            ( shdr->sh_flags & SHF_WRITE ) ) {
                /* .data-type section */
                new->hdr.Characteristics =
                        ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
@@ -610,6 +600,16 @@ static struct pe_section * process_section ( struct elf_file *elf,
                          EFI_IMAGE_SCN_MEM_WRITE );
                applicable_start = &data_start;
                applicable_end = &data_mid;
+       } else if ( ( shdr->sh_type == SHT_PROGBITS ) &&
+                   ( shdr->sh_flags & SHF_EXECINSTR ) ) {
+               /* .text-type section */
+               new->hdr.Characteristics =
+                       ( EFI_IMAGE_SCN_CNT_CODE |
+                         EFI_IMAGE_SCN_MEM_NOT_PAGED |
+                         EFI_IMAGE_SCN_MEM_EXECUTE |
+                         EFI_IMAGE_SCN_MEM_READ );
+               applicable_start = &code_start;
+               applicable_end = &code_end;
        } else if ( shdr->sh_type == SHT_PROGBITS ) {
                /* .rodata-type section */
                new->hdr.Characteristics =