summaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi/libstub/randomalloc.c
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2023-03-08 00:21:34 +0100
committerArd Biesheuvel <ardb@kernel.org>2023-03-23 15:15:45 +0100
commit0b1d9debe30304f35c1211e6dcdca1935ce67240 (patch)
treeabc1768b13ab8caf800a07bab2e89b6e66b873a3 /drivers/firmware/efi/libstub/randomalloc.c
parentfc3608aaa5751318837e4bbe0282b3836bca5080 (diff)
downloadlinux-stable-0b1d9debe30304f35c1211e6dcdca1935ce67240.tar.gz
linux-stable-0b1d9debe30304f35c1211e6dcdca1935ce67240.tar.bz2
linux-stable-0b1d9debe30304f35c1211e6dcdca1935ce67240.zip
efi/libstub: randomalloc: Return EFI_OUT_OF_RESOURCES on failure
The logic in efi_random_alloc() will iterate over the memory map twice, once to count the number of candidate slots, and another time to locate the chosen slot after randomization. If there is insufficient memory to do the allocation, the second loop will run to completion without actually having located a slot, but we currently return EFI_SUCCESS in this case, as we fail to initialize status to the appropriate error value of EFI_OUT_OF_RESOURCES. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers/firmware/efi/libstub/randomalloc.c')
-rw-r--r--drivers/firmware/efi/libstub/randomalloc.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index 1692d19ae80f..32c7a54923b4 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -101,6 +101,7 @@ efi_status_t efi_random_alloc(unsigned long size,
* to calculate the randomly chosen address, and allocate it directly
* using EFI_ALLOCATE_ADDRESS.
*/
+ status = EFI_OUT_OF_RESOURCES;
for (map_offset = 0; map_offset < map->map_size; map_offset += map->desc_size) {
efi_memory_desc_t *md = (void *)map->map + map_offset;
efi_physical_addr_t target;