From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out28-173.mail.aliyun.com (out28-173.mail.aliyun.com [115.124.28.173]) (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 F1DB233A00C for ; Mon, 26 Jan 2026 13:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434529; cv=none; b=Ys6ScABY03wzhOH5bJ2/YSC11Nl1cRq/SxtsAGgORL8GKlqCQBECzUiS+2bfSihKomkq7PAC/N19nWFTJXU/PcknwJpP/Qo9xTTpOZtbCWifXKafFL88IJHiccU52eJDgvPi9YO4n8Tkhn7+3fyL5097dfMg2vNm0tJb98m2Q+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434529; c=relaxed/simple; bh=5SeNbuZmdTZ5OiHmZFa3XuHcrkC2Rd+UmOf6VjV0dbY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PtjV6zTCMMjxjavXVvaGqr5+PdMyW0PueeFwiqW/5UazzNF+5cQb7gkQLotBXJWvsv3Rtwka4qGtB0qoNrah6MfeW2lsaF7WNNwgeJizcPj7mdoblYEE6fKkSj95AzzaqMEEPKbvA8V1fq+TLNFNEBrXLVQpfion5kn4dyxf7C0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=gMwNPKSR; arc=none smtp.client-ip=115.124.28.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="gMwNPKSR" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434518; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EUFZPihEfz/fncyKdMh9AsZHIUnCljxK4T+gNK+kZwk=; b=gMwNPKSRoWPqvorcUyrIHEplhefn4xaX3686NBbqfptrokbf3WECTxggZ86GW2v1jn2GfbkOxRA2Fzcb7jSHpJM9dnpE0GNcsHyunGg40IO3qg6H3O6fjd9eyhbjoWqjT+Dz4irJkfBsmAH2tRVmiXk1G+aZ0ufu1OpmFKdqWNk= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gGHqk0X_1769434515 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:35:16 +0800 From: Hou Wenlong To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Hou Wenlong , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Boris Ostrovsky , Ard Biesheuvel , Nathan Chancellor , Masahiro Yamada , Vitaly Kuznetsov , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Brian Gerst , Josh Poimboeuf , Andrew Morton , Alexander Graf , Joel Granados , Thomas Huth , Uros Bizjak , Kiryl Shutsemau , Pawan Gupta , Guenter Roeck , "Xin Li (Intel)" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , xen-devel@lists.xenproject.org Subject: [RFC PATCH 0/5] x86/boot: Allow to perform randomization for uncompressed kernel image Date: Mon, 26 Jan 2026 21:33:50 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi all, This RFC patch series introduces relocatable uncompressed kernel image, which is allowed to perform kerenl image virtual address randomization in 64-bit booting entry instead of decompression phase. - Background Currently, kernel image virtual address randomization is only performed during the decompression phase. However, in certain scenarios, such as secure container environments (e.g., Kata Containers), to speed up the boot process, the system may boot directly from an uncompressed kernel image. In such cases, virtual address randomization cannot be executed. Although the security enhancement provided by KASLR is limited, there is still a potential demand to allow uncompressed kernel images to perform virtual address randomization (for example, future support for x86 PIE). - Approaches Currently, the x86 kernel uses static compilation, but it retains relocation information through the '--emit-relocs' option, which is then simplified into a relocation table using 'relocs' tool. To enable virtual address randomization for uncompressed kernel images, relocation information is required, and there are several possible approaches: 1) Who will perform the randomization: VMM: The VMM reads vmlinux.relocs after loading vmlinux to perform randomization. This would require additional modifications to the VMM, and vmlinux.relocs needs to be packaged when shipping. Kernel: The kernel performs randomization itself at the kernel entry point, requiring no modifications to the VMM. 2) relocation information format: vmlinux.relocs: It only contains the necessary relocation entries and is simplified, making it small enough. However, it is a format defined within the kernel that was previously used only internally and is not part of the ABI. rela.* sections: It is the standard ELF ABI, but it contains RIP-relative relocation entries, which are more common in kernel, causing the kernel image to be larger. - Implementation The final implementation of this plan extends the 'relocs' tool to allow the insertion of relocation information into a reserved section of the kernel (referencing the MIPS implementation). This enables the reading of that information and subsequent execution of relocations when booting directly from an uncompressed kernel. Currently, this implementation is only available for 64-bit and has been tested with both PVH entry booting and standard 64-bit Linux entry. And the default reserve size is 1MB for now, which is enough for defconfig. - TODO Clean up the decompression KASLR code to allow it to be shared with the booting phase. Thanks! Hou Wenlong (5): x86/relocs: Cleanup cmdline options x86/relocs: Insert relocations into input file x86: Allow to build relocatable uncompressed kernel binary x86/boot: Perform virtual address relocation in kernel entry x86/boot: Use '.data.relocs' section for performing relocations during decompression arch/x86/Kconfig | 20 ++++++ arch/x86/Makefile.postlink | 33 +++++++++ arch/x86/boot/compressed/Makefile | 6 +- arch/x86/boot/compressed/misc.c | 8 +++ arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/kaslr.c | 116 ++++++++++++++++++++++++++++++ arch/x86/include/asm/setup.h | 1 + arch/x86/kernel/head_64.S | 7 ++ arch/x86/kernel/vmlinux.lds.S | 20 ++++++ arch/x86/lib/cmdline.c | 6 ++ arch/x86/lib/kaslr.c | 5 ++ arch/x86/platform/pvh/head.S | 15 +++- arch/x86/tools/relocs.c | 64 ++++++++++++++--- arch/x86/tools/relocs.h | 15 ++-- arch/x86/tools/relocs_common.c | 24 ++++--- 15 files changed, 309 insertions(+), 32 deletions(-) create mode 100644 arch/x86/Makefile.postlink create mode 100644 arch/x86/boot/startup/kaslr.c -- 2.31.1