Skip to content

Commit cb16dfe

Browse files
committed
efi/libstub: Avoid physical address 0x0 when doing random allocation
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. Cc: <stable@vger.kernel.org> Reported-by: Ben Schneider <ben@bens.haus> Tested-by: Ben Schneider <ben@bens.haus> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent e3cf2d9 commit cb16dfe

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/firmware/efi/libstub/randomalloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ efi_status_t efi_random_alloc(unsigned long size,
7575
if (align < EFI_ALLOC_ALIGN)
7676
align = EFI_ALLOC_ALIGN;
7777

78+
/* Avoid address 0x0, as it can be mistaken for NULL */
79+
if (alloc_min == 0)
80+
alloc_min = align;
81+
7882
size = round_up(size, EFI_ALLOC_ALIGN);
7983

8084
/* count the suitable slots in each memory map entry */

0 commit comments

Comments
 (0)