diff options
author | Matt Fleming <matt.fleming@intel.com> | 2012-03-23 09:35:05 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2012-03-26 13:10:01 -0700 |
commit | e31be363df3092821bf179cf4baa076f501b8ae6 (patch) | |
tree | e35eb913df39beebd30dfcf07a916c39f4dcd4f3 /arch/x86/boot/tools | |
parent | 2e064b1e131eba262c0ba4268cb79dbc72edeece (diff) | |
download | op-kernel-dev-e31be363df3092821bf179cf4baa076f501b8ae6.zip op-kernel-dev-e31be363df3092821bf179cf4baa076f501b8ae6.tar.gz |
x86, efi: Fix .text section overlapping image header for EFI_STUB
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>
Diffstat (limited to 'arch/x86/boot/tools')
-rw-r--r-- | arch/x86/boot/tools/build.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 4e9bd6b..2aeab3d 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -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 */ |