LoongArch: Automatically disable kaslr if boot from kexec_file

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>
This commit is contained in:
Youling Tang 2025-10-02 22:39:08 +08:00 committed by Huacai Chen
parent 1bcca8620a
commit c8168b4faf
1 changed files with 4 additions and 0 deletions

View 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;
}