All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi/libstub: Avoid physical address 0x0 when doing random allocation
@ 2025-03-14 11:08 Ard Biesheuvel
  2025-03-14 11:18 ` Ilias Apalodimas
  0 siblings, 1 reply; 2+ messages in thread
From: Ard Biesheuvel @ 2025-03-14 11:08 UTC (permalink / raw)
  To: linux-efi; +Cc: Ard Biesheuvel, Ben Schneider, Ilias Apalodimas

From: Ard Biesheuvel <ardb@kernel.org>

Ben reports spurious EFI zboot failures on a system where physical RAM
starts at 0x0. When doing random memory allocation from the EFI stub on
such a platform, a random seed of 0x0 (which means no entropy source is
available) will result in the allocation to be placed at address 0x0 if
sufficient space is available.

When this allocation is subsequently passed on to the decompression
code, the 0x0 address is mistaken for NULL and the code complains and
gives up.

So avoid address 0x0 when doing random allocation, and set the minimum
address to the minimum alignment.

Reported-by: Ben Schneider <ben@bens.haus>
Tested-by: Ben Schneider <ben@bens.haus>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/randomalloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index 5a732018be36..fd80b2f3233a 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -75,6 +75,10 @@ efi_status_t efi_random_alloc(unsigned long size,
 	if (align < EFI_ALLOC_ALIGN)
 		align = EFI_ALLOC_ALIGN;
 
+	/* Avoid address 0x0, as it can be mistaken for NULL */
+	if (alloc_min == 0)
+		alloc_min = align;
+
 	size = round_up(size, EFI_ALLOC_ALIGN);
 
 	/* count the suitable slots in each memory map entry */
-- 
2.49.0.rc1.451.g8f38331e32-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] efi/libstub: Avoid physical address 0x0 when doing random allocation
  2025-03-14 11:08 [PATCH] efi/libstub: Avoid physical address 0x0 when doing random allocation Ard Biesheuvel
@ 2025-03-14 11:18 ` Ilias Apalodimas
  0 siblings, 0 replies; 2+ messages in thread
From: Ilias Apalodimas @ 2025-03-14 11:18 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-efi, Ard Biesheuvel, Ben Schneider

On Fri, 14 Mar 2025 at 13:08, Ard Biesheuvel <ardb+git@google.com> wrote:
>
> From: Ard Biesheuvel <ardb@kernel.org>
>
> Ben reports spurious EFI zboot failures on a system where physical RAM
> starts at 0x0. When doing random memory allocation from the EFI stub on
> such a platform, a random seed of 0x0 (which means no entropy source is
> available) will result in the allocation to be placed at address 0x0 if
> sufficient space is available.
>
> When this allocation is subsequently passed on to the decompression
> code, the 0x0 address is mistaken for NULL and the code complains and
> gives up.
>
> So avoid address 0x0 when doing random allocation, and set the minimum
> address to the minimum alignment.
>
> Reported-by: Ben Schneider <ben@bens.haus>
> Tested-by: Ben Schneider <ben@bens.haus>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  drivers/firmware/efi/libstub/randomalloc.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
> index 5a732018be36..fd80b2f3233a 100644
> --- a/drivers/firmware/efi/libstub/randomalloc.c
> +++ b/drivers/firmware/efi/libstub/randomalloc.c
> @@ -75,6 +75,10 @@ efi_status_t efi_random_alloc(unsigned long size,
>         if (align < EFI_ALLOC_ALIGN)
>                 align = EFI_ALLOC_ALIGN;
>
> +       /* Avoid address 0x0, as it can be mistaken for NULL */
> +       if (alloc_min == 0)
> +               alloc_min = align;
> +
>         size = round_up(size, EFI_ALLOC_ALIGN);
>
>         /* count the suitable slots in each memory map entry */
> --
> 2.49.0.rc1.451.g8f38331e32-goog
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-14 11:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-14 11:08 [PATCH] efi/libstub: Avoid physical address 0x0 when doing random allocation Ard Biesheuvel
2025-03-14 11:18 ` Ilias Apalodimas

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.