efi/libstub: Avoid physical address 0x0 when doing random allocation
PATCH 1/1 efi/libstub: Avoid physical address 0x0 when doing random allocation
From: Ard Biesheuvel <[email protected]>
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.
--- drivers/firmware/efi/libstub/randomalloc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/firmware/efi/libstub/randomalloc.c +4 -0
@@ -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 */
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Quoted 40 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
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 of0x0(which means no entropy source is available) will result in the allocation to be placed at address0x0if sufficient space is available.When this allocation is subsequently passed on to the decompression code, the
0x0address is mistaken for NULL and the code complains and gives up.So avoid address
0x0when doing random allocation, and set the minimum address to the minimum alignment.Reported-by Ben Schneider <[email protected]>Tested-by Ben Schneider <[email protected]>Cc Ilias Apalodimas <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/firmware/efi/libstub/randomalloc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/firmware/efi/libstub/randomalloc.c +4
-1@@ -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 */ --
Quoted 2 lines
2.49.0.rc1.451.g8f38331e32-goog