Skip to content

Commit e563bc3

Browse files
martinezjaviervathpela
authored andcommitted
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 <[email protected]> Reviewed-by: Maran Wilson [email protected] Tested-by: Maran Wilson [email protected]
1 parent a625fa5 commit e563bc3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

shim.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,21 +2116,32 @@ get_load_option_optional_data(UINT8 *data, UINTN data_size,
21162116
return EFI_SUCCESS;
21172117
}
21182118

2119-
static int is_our_path(EFI_LOADED_IMAGE *li, CHAR16 *path, UINTN len)
2119+
static int is_our_path(EFI_LOADED_IMAGE *li, CHAR16 *path)
21202120
{
21212121
CHAR16 *dppath = NULL;
2122+
CHAR16 *PathName = NULL;
2123+
EFI_STATUS efi_status;
21222124
int ret = 1;
21232125

21242126
dppath = DevicePathToStr(li->FilePath);
21252127
if (!dppath)
21262128
return 0;
21272129

2130+
efi_status = generate_path_from_image_path(li, path, &PathName);
2131+
if (EFI_ERROR(efi_status)) {
2132+
perror(L"Unable to generate path %s: %r\n", path,
2133+
efi_status);
2134+
goto done;
2135+
}
2136+
21282137
dprint(L"dppath: %s\n", dppath);
21292138
dprint(L"path: %s\n", path);
2130-
if (StrnCaseCmp(dppath, path, len))
2139+
if (StrnCaseCmp(dppath, PathName, strlen(dppath)))
21312140
ret = 0;
21322141

2142+
done:
21332143
FreePool(dppath);
2144+
FreePool(PathName);
21342145
return ret;
21352146
}
21362147

@@ -2319,7 +2330,7 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
23192330
23202331
* which is just cruel... So yeah, just don't use it.
23212332
*/
2322-
if (strings == 1 && is_our_path(li, start, loader_len))
2333+
if (strings == 1 && is_our_path(li, start))
23232334
return EFI_SUCCESS;
23242335

23252336
/*

0 commit comments

Comments
 (0)