Skip to content

Commit 1ad55ce

Browse files
committed
x86/efistub: Use 1:1 file:memory mapping for PE/COFF .compat section
The .compat section is a dummy PE section that contains the address of the 32-bit entrypoint of the 64-bit kernel image if it is bootable from 32-bit firmware (i.e., CONFIG_EFI_MIXED=y) This section is only 8 bytes in size and is only referenced from the loader, and so it is placed at the end of the memory view of the image, to avoid the need for padding it to 4k, which is required for sections appearing in the middle of the image. Unfortunately, this violates the PE/COFF spec, and even if most EFI loaders will work correctly (including the Tianocore reference implementation), PE loaders do exist that reject such images, on the basis that both the file and memory views of the file contents should be described by the section headers in a monotonically increasing manner without leaving any gaps. So reorganize the sections to avoid this issue. This results in a slight padding overhead (< 4k) which can be avoided if desired by disabling CONFIG_EFI_MIXED (which is only needed in rare cases these days) Fixes: 3e3eabe ("x86/boot: Increase section and file alignment to 4k/512") Reported-by: Mike Beaton <mjsbeaton@gmail.com> Link: https://lkml.kernel.org/r/CAHzAAWQ6srV6LVNdmfbJhOwhBw5ZzxxZZ07aHt9oKkfYAdvuQQ%40mail.gmail.com Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent dbea519 commit 1ad55ce

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

arch/x86/boot/header.S

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ extra_header_fields:
106106
.word 0 # MinorSubsystemVersion
107107
.long 0 # Win32VersionValue
108108

109-
.long setup_size + ZO__end + pecompat_vsize
110-
# SizeOfImage
109+
.long setup_size + ZO__end # SizeOfImage
111110

112111
.long salign # SizeOfHeaders
113112
.long 0 # CheckSum
@@ -143,7 +142,7 @@ section_table:
143142
.ascii ".setup"
144143
.byte 0
145144
.byte 0
146-
.long setup_size - salign # VirtualSize
145+
.long pecompat_fstart - salign # VirtualSize
147146
.long salign # VirtualAddress
148147
.long pecompat_fstart - salign # SizeOfRawData
149148
.long salign # PointerToRawData
@@ -156,8 +155,8 @@ section_table:
156155
#ifdef CONFIG_EFI_MIXED
157156
.asciz ".compat"
158157

159-
.long 8 # VirtualSize
160-
.long setup_size + ZO__end # VirtualAddress
158+
.long pecompat_fsize # VirtualSize
159+
.long pecompat_fstart # VirtualAddress
161160
.long pecompat_fsize # SizeOfRawData
162161
.long pecompat_fstart # PointerToRawData
163162

@@ -172,17 +171,16 @@ section_table:
172171
* modes this image supports.
173172
*/
174173
.pushsection ".pecompat", "a", @progbits
175-
.balign falign
176-
.set pecompat_vsize, salign
174+
.balign salign
177175
.globl pecompat_fstart
178176
pecompat_fstart:
179177
.byte 0x1 # Version
180178
.byte 8 # Size
181179
.word IMAGE_FILE_MACHINE_I386 # PE machine type
182180
.long setup_size + ZO_efi32_pe_entry # Entrypoint
181+
.byte 0x0 # Sentinel
183182
.popsection
184183
#else
185-
.set pecompat_vsize, 0
186184
.set pecompat_fstart, setup_size
187185
#endif
188186
.ascii ".text"

arch/x86/boot/setup.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ SECTIONS
2424
.text : { *(.text .text.*) }
2525
.text32 : { *(.text32) }
2626

27+
.pecompat : { *(.pecompat) }
28+
PROVIDE(pecompat_fsize = setup_size - pecompat_fstart);
29+
2730
. = ALIGN(16);
2831
.rodata : { *(.rodata*) }
2932

@@ -36,9 +39,6 @@ SECTIONS
3639
. = ALIGN(16);
3740
.data : { *(.data*) }
3841

39-
.pecompat : { *(.pecompat) }
40-
PROVIDE(pecompat_fsize = setup_size - pecompat_fstart);
41-
4242
.signature : {
4343
setup_sig = .;
4444
LONG(0x5a5aaa55)

0 commit comments

Comments
 (0)