public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Lisa Robinson <lisa@bytefly.space>
To: r@hev.cc
Cc: ardb@kernel.org, chenhuacai@kernel.org,
	ilias.apalodimas@linaro.org, kernel@xen0n.name,
	linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
	loongarch@lists.linux.dev, Lisa Robinson <lisa@bytefly.space>
Subject: Re: [RFC PATCH 2/3] efi/loongarch: Randomize kernel preferred address for KASLR
Date: Mon, 27 Apr 2026 05:07:35 +0000	[thread overview]
Message-ID: <20260427050735.3410-1-lisa@bytefly.space> (raw)
In-Reply-To: <20260426120231.532644-3-r@hev.cc>

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);

> +		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

  reply	other threads:[~2026-04-27  5:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-26 12:02 [RFC PATCH 0/3] LoongArch: Move KASLR to EFI stub to avoid initrd overlap WANG Rui
2026-04-26 12:02 ` [RFC PATCH 1/3] LoongArch: Allow rdtime_h and rdtime_l in 64-bit builds WANG Rui
2026-04-26 12:02 ` [RFC PATCH 2/3] efi/loongarch: Randomize kernel preferred address for KASLR WANG Rui
2026-04-27  5:07   ` Lisa Robinson [this message]
2026-04-27  7:49     ` hev
2026-04-26 12:02 ` [RFC PATCH 3/3] LoongArch: Remove KASLR handling from relocate_kernel WANG Rui

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=20260427050735.3410-1-lisa@bytefly.space \
    --to=lisa@bytefly.space \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kernel@xen0n.name \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=r@hev.cc \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox