Re: [RFC PATCH 2/3] efi/loongarch: Randomize kernel preferred address for KASLR

hev <[email protected]>
Newsgroups org.kernel.vger.linux-efi,dev.linux.lists.loongarch,org.kernel.vger.linux-kernel
Message-ID <CAHirt9jfnSFQfRHEANGeNGE2JowTcPV1Tz8L4cX=boJ6vSOa7Q@mail.gmail.com>
Hi Lisa,

On Mon, Apr 27, 2026 at 1:08 PM Lisa Robinson <[email protected]> wrote:
>
> Hi Rui
>
> > diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
> > index 9825f5218137..80ba7d69e1b3 100644
> > --- a/drivers/firmware/efi/libstub/loongarch.c
> > +++ b/drivers/firmware/efi/libstub/loongarch.c
> > @@ -38,6 +38,21 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
> >       return EFI_SUCCESS;
> >  }
> >
> > +unsigned long efi_get_kimg_kaslr_address(void)
> > +{
> > +     unsigned int random_offset = 0;
> > +
> > +#ifdef CONFIG_RANDOMIZE_BASE
> > +     if (!efi_nokaslr) {
> > +             efi_get_random_bytes(sizeof(random_offset), (u8 *)&random_offset);
> > +             random_offset ^= (rdtime_l() << 16);
>
> random_offset &= ~(efi_get_kimg_min_align() - 1);

Thanks for pointing that out.

Aligning to 64K here seems preferable. Otherwise, it reduces the entropy.

Thanks,
Rui


>
> > +             random_offset &= (CONFIG_RANDOMIZE_BASE_MAX_OFFSET - 1);
> > +     }
> > +#endif
> > +
> > +     return PHYSADDR(VMLINUX_LOAD_ADDRESS) + random_offset;
> > +}
> > +
> >  unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
> >               efi_loaded_image_t *image)
> >  {
>
> --
> Lisa
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.