[PATCH 5/7] LoongArch: Change initrd allocation to top-down

Youling Tang youling.tang at linux.dev
Fri Aug 29 02:10:38 PDT 2025


From: Youling Tang <tangyouling at kylinios.cn>

When loading a secondary kernel with KASLR enabled, the randomized relocation
of the kernel image may overlap the initrd memory region, causing data corruption
and boot failure. This occurs because KASLR dynamically shifts the kernel's load
address, which could accidentally target the initrd's pre-allocated space.

Modify the initrd allocation strategy from bottom-up to top-down within the
reserved memory region. By placing the initrd at higher addresses first, we
minimize the risk of the relocated kernel overwriting it.

Reported-by: Chenghao Duan <duanchenghao at kylinos.cn>
Signed-off-by: Youling Tang <tangyouling at kylinios.cn>
---
 kexec/arch/loongarch/kexec-loongarch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c
index c335e0b..32cd484 100644
--- a/kexec/arch/loongarch/kexec-loongarch.c
+++ b/kexec/arch/loongarch/kexec-loongarch.c
@@ -317,7 +317,7 @@ int loongarch_load_other_segments(struct kexec_info *info, unsigned long hole_mi
 		initrd_base = add_buffer(info, initrd_buf, initrd_size,
 					initrd_size, sizeof(void *),
 					_ALIGN_UP(initrd_min,
-						pagesize), hole_max, 1);
+						pagesize), hole_max, -1);
 		dbgprintf("initrd_base: %lx, initrd_size: %lx\n", initrd_base, initrd_size);
 
 		cmdline_add_initrd(cmdline, initrd_base, initrd_size);
-- 
2.34.1




More information about the kexec mailing list