Skip to content

Commit 34951f3

Browse files
ardbiesheuvelingomolnar
authored andcommitted
x86/boot: Split off PE/COFF .data section
Describe the code and data of the decompressor binary using separate .text and .data PE/COFF sections, so that we will be able to map them using restricted permissions once we increase the section and file alignment sufficiently. This avoids the need for memory mappings that are writable and executable at the same time, which is something that is best avoided for security reasons. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20230915171623.655440-17-ardb@google.com
1 parent fa57505 commit 34951f3

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
8989

9090
SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
9191

92-
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_edata\|z_.*\)$$/\#define ZO_\2 0x\1/p'
92+
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|z_.*\)$$/\#define ZO_\2 0x\1/p'
9393

9494
quiet_cmd_zoffset = ZOFFSET $@
9595
cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@

arch/x86/boot/header.S

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ optional_header:
7575
.byte 0x02 # MajorLinkerVersion
7676
.byte 0x14 # MinorLinkerVersion
7777

78-
.long setup_size + ZO__end - 0x200 # SizeOfCode
78+
.long ZO__data # SizeOfCode
7979

80-
.long 0 # SizeOfInitializedData
80+
.long ZO__end - ZO__data # SizeOfInitializedData
8181
.long 0 # SizeOfUninitializedData
8282

8383
.long setup_size + ZO_efi_pe_entry # AddressOfEntryPoint
@@ -178,9 +178,9 @@ section_table:
178178
.byte 0
179179
.byte 0
180180
.byte 0
181-
.long ZO__end
181+
.long ZO__data
182182
.long setup_size
183-
.long ZO__edata # Size of initialized data
183+
.long ZO__data # Size of initialized data
184184
# on disk
185185
.long setup_size
186186
.long 0 # PointerToRelocations
@@ -191,6 +191,17 @@ section_table:
191191
IMAGE_SCN_MEM_READ | \
192192
IMAGE_SCN_MEM_EXECUTE # Characteristics
193193

194+
.ascii ".data\0\0\0"
195+
.long ZO__end - ZO__data # VirtualSize
196+
.long setup_size + ZO__data # VirtualAddress
197+
.long ZO__edata - ZO__data # SizeOfRawData
198+
.long setup_size + ZO__data # PointerToRawData
199+
200+
.long 0, 0, 0
201+
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
202+
IMAGE_SCN_MEM_READ | \
203+
IMAGE_SCN_MEM_WRITE # Characteristics
204+
194205
.set section_count, (. - section_table) / 40
195206
#endif /* CONFIG_EFI_STUB */
196207

0 commit comments

Comments
 (0)