From: Youling Tang <youling.tang@linux.dev>
To: Simon Horman <horms@verge.net.au>
Cc: kexec@lists.infradead.org, Huacai Chen <chenhuacai@kernel.org>,
youling.tang@linux.dev, Youling Tang <tangyouling@kylinios.cn>,
Chenghao Duan <duanchenghao@kylinos.cn>
Subject: [PATCH 5/7] LoongArch: Change initrd allocation to top-down
Date: Fri, 29 Aug 2025 17:10:38 +0800 [thread overview]
Message-ID: <20250829091040.35827-6-youling.tang@linux.dev> (raw)
In-Reply-To: <20250829091040.35827-1-youling.tang@linux.dev>
From: Youling Tang <tangyouling@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@kylinos.cn>
Signed-off-by: Youling Tang <tangyouling@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
next prev parent reply other threads:[~2025-08-29 10:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 9:10 [PATCH 0/7] Fix and improve the LoongArch implementation Youling Tang
2025-08-29 9:10 ` [PATCH 1/7] kexec: Handle removal of multiple 'crashkernel' parameters Youling Tang
2025-08-29 9:10 ` [PATCH 2/7] LoongArch: Fix comments Youling Tang
2025-08-29 9:10 ` [PATCH 3/7] LoongArch: Terminate the cmdline string using '\0' Youling Tang
2025-08-29 9:10 ` [PATCH 4/7] LoongArch: Enforce relocatable kernel check for crash dump Youling Tang
2025-08-29 9:10 ` Youling Tang [this message]
2025-08-29 9:10 ` [PATCH 6/7] LoongArch: Fix the use of loongarch_image_header in ELF format Youling Tang
2025-08-29 9:10 ` [PATCH 7/7] LoongArch: Add pe_hdr->machine check for pei format images Youling Tang
2025-08-29 9:19 ` [PATCH 0/7] Fix and improve the LoongArch implementation Youling Tang
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=20250829091040.35827-6-youling.tang@linux.dev \
--to=youling.tang@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=duanchenghao@kylinos.cn \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
--cc=tangyouling@kylinios.cn \
/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.