Re: [PATCH v3 0/3] LoongArch: Move KASLR to EFI stub to avoid initrd overlap
From: Ard Biesheuvel
Date: Wed Apr 29 2026 - 05:17:50 EST
On Wed, 29 Apr 2026, at 07:13, WANG Rui wrote:
> Changes since [v2]:
> * Add a new patch to prevent initrd overlap during relocation.
> * Revert changes to the CONFIG_RANDOMIZE_BASE_MAX_OFFSET range.
>
> Changes since [v1]:
> * Drop the patch "LoongArch: Allow rdtime_h() and rdtime_l() in
> 64-bit builds".
> * Use random_get_entropy() instead of rdtime_l().
>
> This series addresses a potential overlap issue between the kernel
> image and the initrd when KASLR is enabled.
>
> In the normal boot flow, the bootloader is responsible for loading
> both vmlinux and the initrd, and it can guarantee that the two do
> not overlap in memory. However, this assumption only holds as long
> as neither image changes its location afterwards.
>
> The in-kernel KASLR implementation breaks that assumption. When the
> initrd is placed close to the kernel image, randomizing the kernel
> location at runtime may move it into the initrd region, leading to
> memory corruption early during boot.
>
> To fix this, this series moves the KASLR logic out of the kernel
> proper and into the EFI stub. With this change, the final placement
> of both the kernel image and the initrd is determined by the EFI
> memory allocator. This ensures that the two allocations are
> coordinated and cannot overlap.
>
> Functionally, the kernel still supports KASLR as before, but the
> randomization now happens before the kernel is entered, rather than
> during early kernel relocation.
>
> [v2]: https://lore.kernel.org/loongarch/20260428040159.1065822-1-r@xxxxxx
> [v1]: https://lore.kernel.org/loongarch/20260427104721.47724-1-r@xxxxxx
>
> WANG Rui (3):
> efi/loongarch: Randomize kernel preferred address for KASLR
> LoongArch: Skip relocation-time KASLR if it has already been applied
> LoongArch: Avoid initrd overlap during kernel relocation
>
For the series,
Acked-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
Feel free to take the EFI changes via the LoongArch tree.