From b54c3fc9cc4b5af9594dd1ecabbdf80735da6c8d Mon Sep 17 00:00:00 2001 From: mintsuki Date: Mon, 11 Sep 2023 15:31:43 -0500 Subject: [PATCH] protos/chainload: Fix bug that could result in bogus oom errors. Fixes #302 --- common/protos/chainload.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/protos/chainload.c b/common/protos/chainload.c index f0d529a0..594437eb 100644 --- a/common/protos/chainload.c +++ b/common/protos/chainload.c @@ -217,15 +217,13 @@ noreturn void efi_chainload_file(char *config, char *cmdline, struct file_handle EFI_HANDLE efi_part_handle = image->efi_part_handle; - void *_ptr = freadall(image, MEMMAP_RESERVED); + void *ptr = freadall(image, MEMMAP_RESERVED); size_t image_size = image->size; - void *ptr; - status = gBS->AllocatePool(EfiLoaderData, image_size, &ptr); - if (status) - panic(true, "chainload: Allocation failure"); - memcpy(ptr, _ptr, image_size); - pmm_free(_ptr, image->size); + memmap_alloc_range_in(untouched_memmap, &untouched_memmap_entries, + (uintptr_t)ptr, ALIGN_UP(image_size, 4096), + MEMMAP_RESERVED, MEMMAP_USABLE, true, false, true); + fclose(image); term_notready();