diff options
| author | Eric Snowberg <eric.snowberg@oracle.com> | 2022-01-27 18:03:33 -0500 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2022-05-17 18:30:52 -0400 |
| commit | acfd48f45b9047fc07b0a184feb91ae31aa41a21 (patch) | |
| tree | 447df401ebb405dbee66bc1c90892dc87f16b9ec | |
| parent | bb4b60e800823c1e48220935e3b9180c8c82e1a7 (diff) | |
| download | efi-boot-shim-acfd48f45b9047fc07b0a184feb91ae31aa41a21.tar.gz efi-boot-shim-acfd48f45b9047fc07b0a184feb91ae31aa41a21.zip | |
Abstract out image reading
Separate out image reading from image launch in order to be able to load
an image without executing it.
Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
| -rw-r--r-- | shim.c | 46 |
1 files changed, 30 insertions, 16 deletions
@@ -1053,17 +1053,12 @@ restore_loaded_image(VOID) /* * Load and run an EFI executable */ -EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) +EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath, + CHAR16 *PathName, void **data, int *datasize) { EFI_STATUS efi_status; - EFI_IMAGE_ENTRY_POINT entry_point; - EFI_PHYSICAL_ADDRESS alloc_address; - UINTN alloc_pages; - CHAR16 *PathName = NULL; void *sourcebuffer = NULL; UINT64 sourcesize = 0; - void *data = NULL; - int datasize = 0; /* * We need to refer to the loaded image protocol on the running @@ -1083,7 +1078,7 @@ EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) if (EFI_ERROR(efi_status)) { perror(L"Unable to generate path %s: %r\n", ImagePath, efi_status); - goto done; + return efi_status; } if (findNetboot(shim_li->DeviceHandle)) { @@ -1099,8 +1094,8 @@ EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) efi_status); return efi_status; } - data = sourcebuffer; - datasize = sourcesize; + *data = sourcebuffer; + *datasize = sourcesize; } else if (find_httpboot(shim_li->DeviceHandle)) { efi_status = httpboot_fetch_buffer (image_handle, &sourcebuffer, @@ -1110,26 +1105,45 @@ EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) efi_status); return efi_status; } - data = sourcebuffer; - datasize = sourcesize; + *data = sourcebuffer; + *datasize = sourcesize; } else { /* * Read the new executable off disk */ - efi_status = load_image(shim_li, &data, &datasize, PathName); + efi_status = load_image(shim_li, data, datasize, PathName); if (EFI_ERROR(efi_status)) { perror(L"Failed to load image %s: %r\n", PathName, efi_status); PrintErrors(); ClearErrors(); - goto done; + return efi_status; } } - if (datasize < 0) { + if (*datasize < 0) efi_status = EFI_INVALID_PARAMETER; + + return efi_status; +} + +/* + * Load and run an EFI executable + */ +EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) +{ + EFI_STATUS efi_status; + EFI_IMAGE_ENTRY_POINT entry_point; + EFI_PHYSICAL_ADDRESS alloc_address; + UINTN alloc_pages; + CHAR16 *PathName = NULL; + void *data = NULL; + int datasize; + + efi_status = read_image(image_handle, ImagePath, PathName, &data, + &datasize); + if (EFI_ERROR(efi_status)) goto done; - } /* * We need to modify the loaded image protocol entry before running |
