]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
efistub/x86: Remap inittext read-execute when needed
authorArd Biesheuvel <ardb@kernel.org>
Thu, 28 Aug 2025 10:22:23 +0000 (12:22 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 3 Sep 2025 16:05:42 +0000 (18:05 +0200)
Recent EFI x86 systems are more strict when it comes to mapping boot
images, and require that mappings are either read-write or read-execute.

Now that the boot code is being cleaned up and refactored, most of it is
being moved into .init.text [where it arguably belongs] but that implies
that when booting on such strict EFI firmware, we need to take care to
map .init.text (and the .altinstr_aux section that follows it)
read-execute as well.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/20250828102202.1849035-44-ardb+git@google.com
arch/x86/boot/compressed/Makefile
arch/x86/boot/compressed/misc.c
arch/x86/include/asm/boot.h
arch/x86/kernel/vmlinux.lds.S
drivers/firmware/efi/libstub/x86-stub.c

index 3a38fdcdb9bd3991549a8c966c5b6787b50189bb..74657589264dfa22ff6b235fe9dc878201ce4a3d 100644 (file)
@@ -73,7 +73,7 @@ LDFLAGS_vmlinux += -T
 hostprogs      := mkpiggy
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
-sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_rodata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
+sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_rodata\|_sinittext\|__inittext_end\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
 
 quiet_cmd_voffset = VOFFSET $@
       cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
index 94b5991da001a7c926680e94c754a504b4c815d2..0f41ca0e52c0fb40cb73d9974b4599615f04b5c9 100644 (file)
@@ -332,6 +332,8 @@ static size_t parse_elf(void *output)
 }
 
 const unsigned long kernel_text_size = VO___start_rodata - VO__text;
+const unsigned long kernel_inittext_offset = VO__sinittext - VO__text;
+const unsigned long kernel_inittext_size = VO___inittext_end - VO__sinittext;
 const unsigned long kernel_total_size = VO__end - VO__text;
 
 static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4);
index 02b23aa78955fb0268757c4d7ca026d457d46c2b..f7b67cb7391562e984323a66563cf532da54fdcf 100644 (file)
@@ -82,6 +82,8 @@
 #ifndef __ASSEMBLER__
 extern unsigned int output_len;
 extern const unsigned long kernel_text_size;
+extern const unsigned long kernel_inittext_offset;
+extern const unsigned long kernel_inittext_size;
 extern const unsigned long kernel_total_size;
 
 unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_addr,
index 5d5e3a95e1f9bf4f51d5191c475fc98639b7725b..4277efb263588abacf92ed6df0bf29e726e99c78 100644 (file)
@@ -227,6 +227,8 @@ SECTIONS
         */
        .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) {
                *(.altinstr_aux)
+               . = ALIGN(PAGE_SIZE);
+               __inittext_end = .;
        }
 
        INIT_DATA_SECTION(16)
index cafc90d4caafa6033a1b80f2d2b0a8893b60c2cd..0d05eac7c72b24871faee3e1e5a95a597d6f905d 100644 (file)
@@ -788,7 +788,9 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry,
 
        *kernel_entry = addr + entry;
 
-       return efi_adjust_memory_range_protection(addr, kernel_text_size);
+       return efi_adjust_memory_range_protection(addr, kernel_text_size) ?:
+              efi_adjust_memory_range_protection(addr + kernel_inittext_offset,
+                                                 kernel_inittext_size);
 }
 
 static void __noreturn enter_kernel(unsigned long kernel_addr,