x86, efi: Fix .text section overlapping image header for EFI_STUB
authorMatt Fleming <matt.fleming@intel.com>
Fri, 23 Mar 2012 16:35:05 +0000 (09:35 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Mon, 26 Mar 2012 20:10:01 +0000 (13:10 -0700)
This change modifes the PE .text section to start after
the first sector of the kernel image.

The header may be modified by the UEFI secure boot signing,
so it is not appropriate for it to be included in one of the
image sections. Since the sections are part of the secure
boot hash, this modification to the .text section contents
would invalidate the secure boot signed hash.

Note: UEFI secure boot does hash the image header, but
fields that are changed by the signing process are excluded
from the hash calculation.  This exclusion process is only
handled for the image header, and not image sections.

Luckily, we can still easily boot without the first sector
by initializing a few fields in arch/x86/boot/compressed/eboot.c.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Link: http://lkml.kernel.org/r/1332520506-6472-3-git-send-email-jordan.l.justen@intel.com
[jordan.l.justen@intel.com: set .text vma & file offset]
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/boot/compressed/eboot.c
arch/x86/boot/header.S
arch/x86/boot/tools/build.c

index fec216f4fbc3854f11e6253607511c000b995134..01cbb8707a313180a7a8a93730991b03b2ad6a44 100644 (file)
@@ -904,11 +904,19 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
 
        memset(boot_params, 0x0, 0x4000);
 
-       /* Copy first two sectors to boot_params */
-       memcpy(boot_params, image->image_base, 1024);
-
        hdr = &boot_params->hdr;
 
+       /* Copy the second sector to boot_params */
+       memcpy(&hdr->jump, image->image_base + 512, 512);
+
+       /*
+        * Fill out some of the header fields ourselves because the
+        * EFI firmware loader doesn't load the first sector.
+        */
+       hdr->root_flags = 1;
+       hdr->vid_mode = 0xffff;
+       hdr->boot_flag = 0xAA55;
+
        /*
         * The EFI firmware loader could have placed the kernel image
         * anywhere in memory, but the kernel has various restrictions
index 4e9124b148c2a4c3d3f693c0fc385eadaf656698..4ceb56e9a4ce65de46907d05b61d67e445492fe1 100644 (file)
@@ -147,7 +147,7 @@ optional_header:
        # Filled in by build.c
        .long   0x0000                          # AddressOfEntryPoint
 
-       .long   0x0000                          # BaseOfCode
+       .long   0x0200                          # BaseOfCode
 #ifdef CONFIG_X86_32
        .long   0                               # data
 #endif
index 4e9bd6bcafa6d078a0226fd8fed05902d71d0920..2aeab3dc9e5f21753b3dd6b444f047d66fbfe2db 100644 (file)
@@ -202,12 +202,19 @@ int main(int argc, char ** argv)
 
        pe_header = *(unsigned int *)&buf[0x3c];
 
-       /* Size of code */
-       *(unsigned int *)&buf[pe_header + 0x1c] = file_sz;
-
        /* Size of image */
        *(unsigned int *)&buf[pe_header + 0x50] = file_sz;
 
+       /*
+        * Subtract the size of the first section (512 bytes) which
+        * includes the header and .reloc section. The remaining size
+        * is that of the .text section.
+        */
+       file_sz -= 512;
+
+       /* Size of code */
+       *(unsigned int *)&buf[pe_header + 0x1c] = file_sz;
+
 #ifdef CONFIG_X86_32
        /* Address of entry point */
        *(unsigned int *)&buf[pe_header + 0x28] = i;
@@ -215,8 +222,14 @@ int main(int argc, char ** argv)
        /* .text size */
        *(unsigned int *)&buf[pe_header + 0xb0] = file_sz;
 
+       /* .text vma */
+       *(unsigned int *)&buf[pe_header + 0xb4] = 0x200;
+
        /* .text size of initialised data */
        *(unsigned int *)&buf[pe_header + 0xb8] = file_sz;
+
+       /* .text file offset */
+       *(unsigned int *)&buf[pe_header + 0xbc] = 0x200;
 #else
        /*
         * Address of entry point. startup_32 is at the beginning and
@@ -228,8 +241,14 @@ int main(int argc, char ** argv)
        /* .text size */
        *(unsigned int *)&buf[pe_header + 0xc0] = file_sz;
 
+       /* .text vma */
+       *(unsigned int *)&buf[pe_header + 0xc4] = 0x200;
+
        /* .text size of initialised data */
        *(unsigned int *)&buf[pe_header + 0xc8] = file_sz;
+
+       /* .text file offset */
+       *(unsigned int *)&buf[pe_header + 0xcc] = 0x200;
 #endif /* CONFIG_X86_32 */
 #endif /* CONFIG_EFI_STUB */
 
This page took 0.034838 seconds and 5 git commands to generate.