From nobody Wed Feb 11 04:17:55 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68D693C00BD; Thu, 8 Jan 2026 09:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767864492; cv=none; b=NEPEksHlfT2n1gKFUOrKnABqYofYy5byZN5ehi14eIne7E+OmeFXW66yTsg1SmBvIcyVTRAqMzJ55w3Io8OQXB9jRbrThk5GdQ/lrzlHKKle9V3L1CQdBBksh0Rv6vfIzahV8r0X/Fa8dG1GRkGCYce6QLRmUvH4UIiMjU3i7qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767864492; c=relaxed/simple; bh=y7+ntK2Mt9pILeLN4kBUmNH8SM9X4UPDlejQNxGasJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C6w/ukgLkqUTiFV+MYZ5uXlkV0xDQLhd2NWCtIF06q6MqfoM7V0JdcuT0i/xWFs1wM8+4s3tT66RKIv4PqYYOj9whNvhlH8TqC5MdmylH0+HrODYuAw/VRVhr+EmynwIJoYbw8/s2Jnr1duIOMRdCAZcGNFaK4ASHBpFCDbQq/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OsC3ggSJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OsC3ggSJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86249C116C6; Thu, 8 Jan 2026 09:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767864489; bh=y7+ntK2Mt9pILeLN4kBUmNH8SM9X4UPDlejQNxGasJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsC3ggSJUJoRtalHOVJReVeodhSqFx019MuAGLoupQYSBgGSW6nES1QJvHzLr9UNG 7ae3prPAfNetXGub/D1Ak/AY3lbQZ7diNheQEWgZNjxHgt0XUPMiY4DVX3+ypWGeSj KfFPD+0wkU3/EhL4R8rksiQtymz0AU7R5mP8H4ZslvtvOLEHT0oGBIPFOGxpUGrE2n 3GmdDCcBwr8uU18MTMzYl7ZaqfjGDc9DcQJdqA0wW5fbkjOjSNU3QW2MA0KyncaauB kNMx5t9jDdX+T8JIIH2lg5zJKipNnPUwZKX4iNYSL4LC3QU91uk3cpB2agkDRxFh6G fuXFFFCURtp6A== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , Kees Cook , Uros Bizjak , Brian Gerst , linux-hardening@vger.kernel.org Subject: [RFC/RFT PATCH 05/19] x86/efistub: Simplify early remapping of kernel text Date: Thu, 8 Jan 2026 09:25:32 +0000 Message-ID: <20260108092526.28586-26-ardb@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260108092526.28586-21-ardb@kernel.org> References: <20260108092526.28586-21-ardb@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4107; i=ardb@kernel.org; h=from:subject; bh=y7+ntK2Mt9pILeLN4kBUmNH8SM9X4UPDlejQNxGasJ4=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JITO+gvfZrNboPT8O+zuI83B0R2Z+WBL0aYdFw5Fk9cv7e IJMp13oKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNRzWJkaE+NzTzx4LFJ72y9 KyUfjLiPSvKvemDzovpr6OR3lR335BkZJrmuWvF1z503r0zXc6mFMGzeu2997tegCYqft7wKOeJ nxQQA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the kernel's .text, .rodata and .inittext are all covered by a single ELF segment, there is no need to remap .inittext separately. Instead, remap the entire region in a single call. This remapping is needed because the EFI stub hands over to the core kernel while running in long mode, using the page tables provided by the firmware. Recent so-called 'MS secured core' (tm) PCs are more strict when it comes to separating writable from executable mappings, and so for compatibility with such systems, any code that may be callable during early boot (i.e., before the kernel switches to its own page tables) must be remapped executable explicitly. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/misc.c | 4 +--- arch/x86/include/asm/boot.h | 2 -- arch/x86/kernel/vmlinux.lds.S | 2 -- drivers/firmware/efi/libstub/x86-stub.c | 4 +--- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index 68f9d7a1683b..bc071bdcd11e 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -76,7 +76,7 @@ LDFLAGS_vmlinux +=3D -T hostprogs :=3D mkpiggy HOST_EXTRACFLAGS +=3D -I$(srctree)/tools/include =20 -sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|__inittext_end\|__bss_start\|_end\)$$/\#define VO_\2 _AC= (0x\1,UL)/p' +sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__data_se= gment_start\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' =20 quiet_cmd_voffset =3D VOFFSET $@ cmd_voffset =3D $(NM) $< | sed -n $(sed-voffset) > $@ diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index d37569e7ee10..1ea419cf88fe 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -329,9 +329,7 @@ static size_t parse_elf(void *output) return ehdr.e_entry - LOAD_PHYSICAL_ADDR; } =20 -const unsigned long kernel_text_size =3D VO___start_rodata - VO__text; -const unsigned long kernel_inittext_offset =3D VO__sinittext - VO__text; -const unsigned long kernel_inittext_size =3D VO___inittext_end - VO__sinit= text; +const unsigned long kernel_text_size =3D VO___data_segment_start - VO__tex= t; const unsigned long kernel_total_size =3D VO__end - VO__text; =20 static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4); diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index f7b67cb73915..02b23aa78955 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -82,8 +82,6 @@ #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; =20 unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_= addr, diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 1dee2987c42b..6772fe9a9957 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -196,8 +196,6 @@ SECTIONS */ .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) { *(.altinstr_aux) - . =3D ALIGN(PAGE_SIZE); - __inittext_end =3D .; } =20 DATA_SEGMENT_START diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index cef32e2c82d8..ffe30ef73fda 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -890,9 +890,7 @@ static efi_status_t efi_decompress_kernel(unsigned long= *kernel_entry, =20 *kernel_entry =3D addr + entry; =20 - return efi_adjust_memory_range_protection(addr, kernel_text_size) ?: - efi_adjust_memory_range_protection(addr + kernel_inittext_offset, - kernel_inittext_size); + return efi_adjust_memory_range_protection(addr, kernel_text_size); } =20 static void __noreturn enter_kernel(unsigned long kernel_addr, --=20 2.47.3