]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
LoongArch: Automatically disable kaslr if boot from kexec_file
authorYouling Tang <tangyouling@kylinos.cn>
Thu, 2 Oct 2025 14:39:08 +0000 (22:39 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 2 Oct 2025 14:39:08 +0000 (22:39 +0800)
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 may relocate it to an invalid memory region
and cause a 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 should be backported to stable branches.

Cc: stable@vger.kernel.org
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/relocate.c

index 50c469067f3aa37f4f07999221c6254a15e0598e..b5e2312a2fca51d595facb062a3b70ae0e0d48cc 100644 (file)
@@ -166,6 +166,10 @@ static inline __init bool kaslr_disabled(void)
                return true;
 #endif
 
+       str = strstr(boot_command_line, "kexec_file");
+       if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
+               return true;
+
        return false;
 }