Skip to content

Commit 01ae161

Browse files
julian-klodevathpela
authored andcommitted
shim: Don't parse load options if invoked from removable media path
We see various reports of boot failures because the generated boot entries contain garbage/tagging that we do not expect, and that we then parse as a second stage boot loader.
1 parent 9dca459 commit 01ae161

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

BUILDING

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Variables you could set to customize the build:
4545
shim has already verified the kernel when shim loaded the kernel as the
4646
second stage loader. In such a case, and only in this case, you should
4747
use DISABLE_EBS_PROTECTION=y to build.
48+
- DISABLE_REMOVABLE_LOAD_OPTIONS
49+
Do not parse load options when invoked as boot*.efi. This prevents boot
50+
failures because of unexpected data in boot entries automatically generated
51+
by firmware. It breaks loading non-default second-stage loaders when invoked
52+
via that path, and requires using a binary named shim*.efi (or really anything
53+
else).
4854
- REQUIRE_TPM
4955
if tpm logging or extends return an error code, treat that as a fatal error.
5056
- ARCH

Make.defaults

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ ifneq ($(origin DISABLE_EBS_PROTECTION), undefined)
153153
DEFINES += -DDISABLE_EBS_PROTECTION
154154
endif
155155
156+
ifneq ($(origin DISABLE_REMOVABLE_LOAD_OPTIONS), undefined)
157+
DEFINES += -DDISABLE_REMOVABLE_LOAD_OPTIONS
158+
endif
159+
156160
LIB_GCC = $(shell $(CC) $(ARCH_CFLAGS) -print-libgcc-file-name)
157161
EFI_LIBS = -lefi -lgnuefi --start-group Cryptlib/libcryptlib.a Cryptlib/OpenSSL/libopenssl.a --end-group $(LIB_GCC)
158162
FORMAT ?= --target efi-app-$(ARCH)

shim.c

+11
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,17 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
11701170
return efi_status;
11711171
}
11721172

1173+
#if defined(DISABLE_REMOVABLE_LOAD_OPTIONS)
1174+
/*
1175+
* boot services build very strange load options, and we might misparse them,
1176+
* causing boot failures on removable media.
1177+
*/
1178+
if (is_removable_media_path(li)) {
1179+
dprint("Invoked from removable media path, ignoring boot options");
1180+
return EFI_SUCCESS;
1181+
}
1182+
#endif
1183+
11731184
efi_status = parse_load_options(li);
11741185
if (EFI_ERROR(efi_status)) {
11751186
perror (L"Failed to get load options: %r\n", efi_status);

0 commit comments

Comments
 (0)