summaryrefslogtreecommitdiff
path: root/loader-proto.c
diff options
context:
space:
mode:
authorMate Kukri <mate.kukri@canonical.com>2024-05-24 11:41:04 +0100
committerPeter Jones <pjones@redhat.com>2025-02-11 10:43:37 -0500
commitc57af36e673b34a9b24309f76f105371316c45be (patch)
treeff93643a995255b71b4e749e50eb7fb38031ceda /loader-proto.c
parentfe2ad36cbe13f9f304502d6b803828117593e0a9 (diff)
downloadefi-boot-shim-c57af36e673b34a9b24309f76f105371316c45be.tar.gz
efi-boot-shim-c57af36e673b34a9b24309f76f105371316c45be.zip
loader-proto: Respect optional DevicePath parameter to load_image()
load_image() takes an optional parameter, DevicePath, in addition to the SourceBuffer. Currently in shim_load_image() we don't check to see if it's provided in the case where there's no SourceBuffer, even though it can't work without it. This adds that test and errors in that case, as well as avoiding duplicating it when it's not present. Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Diffstat (limited to 'loader-proto.c')
-rw-r--r--loader-proto.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/loader-proto.c b/loader-proto.c
index f899e594..53d35701 100644
--- a/loader-proto.c
+++ b/loader-proto.c
@@ -165,7 +165,7 @@ out:
static EFI_STATUS EFIAPI
shim_load_image(BOOLEAN BootPolicy, EFI_HANDLE ParentImageHandle,
- EFI_DEVICE_PATH *FilePath, VOID *SourceBuffer,
+ EFI_DEVICE_PATH *DevicePath, VOID *SourceBuffer,
UINTN SourceSize, EFI_HANDLE *ImageHandle)
{
SHIM_LOADED_IMAGE *image;
@@ -176,9 +176,12 @@ shim_load_image(BOOLEAN BootPolicy, EFI_HANDLE ParentImageHandle,
return EFI_UNSUPPORTED;
if (!SourceBuffer || !SourceSize) {
- if (try_load_from_sfs(FilePath, &bprop) == EFI_SUCCESS)
+ if (!DevicePath) /* Both SourceBuffer and DevicePath are NULL */
+ return EFI_NOT_FOUND;
+
+ if (try_load_from_sfs(DevicePath, &bprop) == EFI_SUCCESS)
;
- else if (try_load_from_lf2(FilePath, &bprop) == EFI_SUCCESS)
+ else if (try_load_from_lf2(DevicePath, &bprop) == EFI_SUCCESS)
;
else
/* no buffer given and we cannot load from this device */
@@ -192,16 +195,19 @@ shim_load_image(BOOLEAN BootPolicy, EFI_HANDLE ParentImageHandle,
* Even if we are using a buffer, try populating the
* device_handle and file_path fields the best we can
*/
- bprop.dp = FilePath;
- efi_status = BS->LocateDevicePath(&gEfiDevicePathProtocolGuid,
- &bprop.dp,
- &bprop.hnd);
- if (efi_status != EFI_SUCCESS) {
- /* can't seem to pull apart this DP */
- bprop.dp = FilePath;
- bprop.hnd = NULL;
- }
+ bprop.dp = DevicePath;
+
+ if (bprop.dp) {
+ efi_status = BS->LocateDevicePath(&gEfiDevicePathProtocolGuid,
+ &bprop.dp,
+ &bprop.hnd);
+ if (efi_status != EFI_SUCCESS) {
+ /* can't seem to pull apart this DP */
+ bprop.dp = DevicePath;
+ bprop.hnd = NULL;
+ }
+ }
}
image = AllocatePool(sizeof(*image));
@@ -216,12 +222,19 @@ shim_load_image(BOOLEAN BootPolicy, EFI_HANDLE ParentImageHandle,
image->li.ParentHandle = ParentImageHandle;
image->li.SystemTable = systab;
image->li.DeviceHandle = bprop.hnd;
- image->li.FilePath = DuplicateDevicePath(bprop.dp);
- image->loaded_image_device_path = DuplicateDevicePath(FilePath);
- if (!image->li.FilePath ||
- !image->loaded_image_device_path) {
- efi_status = EFI_OUT_OF_RESOURCES;
- goto free_image;
+ if (bprop.dp) {
+ image->li.FilePath = DuplicateDevicePath(bprop.dp);
+ if (!image->li.FilePath) {
+ efi_status = EFI_OUT_OF_RESOURCES;
+ goto free_image;
+ }
+ }
+ if (DevicePath) {
+ image->loaded_image_device_path = DuplicateDevicePath(DevicePath);
+ if (!image->loaded_image_device_path) {
+ efi_status = EFI_OUT_OF_RESOURCES;
+ goto free_image;
+ }
}
in_protocol = 1;
@@ -305,8 +318,10 @@ shim_start_image(IN EFI_HANDLE ImageHandle, OUT UINTN *ExitDataSize,
NULL);
BS->FreePages(image->alloc_address, image->alloc_pages);
- BS->FreePool(image->li.FilePath);
- BS->FreePool(image->loaded_image_device_path);
+ if (image->li.FilePath)
+ BS->FreePool(image->li.FilePath);
+ if (image->loaded_image_device_path)
+ BS->FreePool(image->loaded_image_device_path);
FreePool(image);
return efi_status;