mirror of
https://git.proxmox.com/git/efi-boot-shim
synced 2025-08-13 19:48:12 +00:00
shim: Prevent shim to set itself as a second stage loader
When shim is invoked from a relative path (e.g: from the UEFI shell), the Loaded Image handle LoadOptions can be set to the binary relative path. But the is_our_path() function only checks if LoadOptions is set to the absolute path of shim to ignore it. So if a relative path is there, shim would set itself as the secondary loader and invoke itself in a loop. To prevent that, use the path in LoadOptions to calculate the absolute path and compare it with the one in the Loader Image handle FilePath. Resolves: bz#1622485 Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Maran Wilson maran.wilson@oracle.com Tested-by: Maran Wilson maran.wilson@oracle.com Upstream-commit-id: e563bc3dcd1
This commit is contained in:
parent
79be2af526
commit
818a0dbd24
17
shim.c
17
shim.c
@ -2086,21 +2086,32 @@ get_load_option_optional_data(UINT8 *data, UINTN data_size,
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_our_path(EFI_LOADED_IMAGE *li, CHAR16 *path, UINTN len)
|
static int is_our_path(EFI_LOADED_IMAGE *li, CHAR16 *path)
|
||||||
{
|
{
|
||||||
CHAR16 *dppath = NULL;
|
CHAR16 *dppath = NULL;
|
||||||
|
CHAR16 *PathName = NULL;
|
||||||
|
EFI_STATUS efi_status;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
dppath = DevicePathToStr(li->FilePath);
|
dppath = DevicePathToStr(li->FilePath);
|
||||||
if (!dppath)
|
if (!dppath)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
efi_status = generate_path_from_image_path(li, path, &PathName);
|
||||||
|
if (EFI_ERROR(efi_status)) {
|
||||||
|
perror(L"Unable to generate path %s: %r\n", path,
|
||||||
|
efi_status);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
dprint(L"dppath: %s\n", dppath);
|
dprint(L"dppath: %s\n", dppath);
|
||||||
dprint(L"path: %s\n", path);
|
dprint(L"path: %s\n", path);
|
||||||
if (StrnCaseCmp(dppath, path, len))
|
if (StrnCaseCmp(dppath, PathName, strlen(dppath)))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
done:
|
||||||
FreePool(dppath);
|
FreePool(dppath);
|
||||||
|
FreePool(PathName);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2289,7 +2300,7 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
|
|||||||
|
|
||||||
* which is just cruel... So yeah, just don't use it.
|
* which is just cruel... So yeah, just don't use it.
|
||||||
*/
|
*/
|
||||||
if (strings == 1 && is_our_path(li, start, loader_len))
|
if (strings == 1 && is_our_path(li, start))
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user