Skip to content

Commit

Permalink
shim: Don't parse load options if invoked from removable media path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
julian-klode authored and vathpela committed Oct 12, 2021
1 parent 9dca459 commit 01ae161
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BUILDING
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Variables you could set to customize the build:
shim has already verified the kernel when shim loaded the kernel as the
second stage loader. In such a case, and only in this case, you should
use DISABLE_EBS_PROTECTION=y to build.
- DISABLE_REMOVABLE_LOAD_OPTIONS
Do not parse load options when invoked as boot*.efi. This prevents boot
failures because of unexpected data in boot entries automatically generated
by firmware. It breaks loading non-default second-stage loaders when invoked
via that path, and requires using a binary named shim*.efi (or really anything
else).
- REQUIRE_TPM
if tpm logging or extends return an error code, treat that as a fatal error.
- ARCH
Expand Down
4 changes: 4 additions & 0 deletions Make.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ ifneq ($(origin DISABLE_EBS_PROTECTION), undefined)
DEFINES += -DDISABLE_EBS_PROTECTION
endif
ifneq ($(origin DISABLE_REMOVABLE_LOAD_OPTIONS), undefined)
DEFINES += -DDISABLE_REMOVABLE_LOAD_OPTIONS
endif
LIB_GCC = $(shell $(CC) $(ARCH_CFLAGS) -print-libgcc-file-name)
EFI_LIBS = -lefi -lgnuefi --start-group Cryptlib/libcryptlib.a Cryptlib/OpenSSL/libopenssl.a --end-group $(LIB_GCC)
FORMAT ?= --target efi-app-$(ARCH)
Expand Down
11 changes: 11 additions & 0 deletions shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,17 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle)
return efi_status;
}

#if defined(DISABLE_REMOVABLE_LOAD_OPTIONS)
/*
* boot services build very strange load options, and we might misparse them,
* causing boot failures on removable media.
*/
if (is_removable_media_path(li)) {
dprint("Invoked from removable media path, ignoring boot options");
return EFI_SUCCESS;
}
#endif

efi_status = parse_load_options(li);
if (EFI_ERROR(efi_status)) {
perror (L"Failed to get load options: %r\n", efi_status);
Expand Down

0 comments on commit 01ae161

Please sign in to comment.