From: Youling Tang <youling.tang@linux.dev>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>, Baoquan He <bhe@redhat.com>,
Yao Zi <ziyao@disroot.org>,
kexec@lists.infradead.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, youling.tang@linux.dev,
Youling Tang <tangyouling@kylinos.cn>,
stable@vger.kernel.org
Subject: [PATCH v4 6/7] LoongArch: Automatically disable kaslr when the kernel loads from kexec_file
Date: Wed, 3 Sep 2025 11:00:59 +0800 [thread overview]
Message-ID: <20250903030100.196744-7-youling.tang@linux.dev> (raw)
In-Reply-To: <20250903030100.196744-1-youling.tang@linux.dev>
From: Youling Tang <tangyouling@kylinos.cn>
Automatically disable kaslr when the kernel loads from kexec_file.
kexec_file loads the secondary kernel image to a non-linked address,
inherently providing KASLR-like randomization.
However, on LoongArch where System RAM may be non-contiguous, enabling
KASLR for the second kernel could relocate it to an invalid memory
region and cause boot failure. Thus, we disable KASLR when
"kexec_file" is detected in the command line.
To ensure compatibility with older kernels loaded via kexec_file,
this patch need be backported to stable branches.
Cc: stable@vger.kernel.org
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
arch/loongarch/kernel/relocate.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c
index 50c469067f3a..4c097532cb88 100644
--- a/arch/loongarch/kernel/relocate.c
+++ b/arch/loongarch/kernel/relocate.c
@@ -140,6 +140,10 @@ static inline __init bool kaslr_disabled(void)
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
return true;
+ str = strstr(boot_command_line, "kexec_file");
+ if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
+ return true;
+
#ifdef CONFIG_HIBERNATION
str = strstr(builtin_cmdline, "nohibernate");
if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
--
2.43.0
next prev parent reply other threads:[~2025-09-03 3:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 3:00 [PATCH v4 0/7] Add kexec_file support for LoongArch Youling Tang
2025-09-03 3:00 ` [PATCH v4 1/7] LoongArch: Add struct loongarch_image_header for kernel image Youling Tang
2025-09-03 3:00 ` [PATCH v4 2/7] LoongArch: Add preparatory infrastructure for kexec_file Youling Tang
2025-09-03 3:00 ` [PATCH v4 3/7] LoongArch/kexec_file: Support loading EFI binary file Youling Tang
2025-09-03 3:00 ` [PATCH v4 4/7] LoongArch/kexec_file: Support loading ELF " Youling Tang
2025-09-03 3:00 ` [PATCH v4 5/7] LoongArch/kexec_file: Add crash dump support Youling Tang
2025-09-03 3:00 ` Youling Tang [this message]
2025-09-03 3:01 ` [PATCH v4 7/7] LoongArch: Enable CONFIG_KEXEC_FILE Youling Tang
2025-09-21 14:03 ` [PATCH v4 0/7] Add kexec_file support for LoongArch Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250903030100.196744-7-youling.tang@linux.dev \
--to=youling.tang@linux.dev \
--cc=bhe@redhat.com \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=tangyouling@kylinos.cn \
--cc=ziyao@disroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.