Go to file
Javier Martinez Canillas 89d72301aa shim: Update EFI_LOADED_IMAGE with the second stage loader file path
When shim loads the second stage loader (e.g: GRUB) the FilePath field of
the EFI_LOADED_IMAGE structure isn't updated with the path of the loaded
binary. So it still contains the file path of the shim binary.

This isn't a problem since the file path is currently not used. But should
be used to set the DevicePath field of the EFI_IMAGE_LOAD_EVENT structure
that is logged when measuring the PE/COFF binaries. In that case the TPM
Event Log will have an incorrect file path for the measured binary, i.e:

$ hexdump -Cv /sys/kernel/security/tpm0/binary_bios_measurements
...
00000a50  00 00 00 00 00 00 04 04  34 00 5c 00 45 00 46 00  |........4.\.E.F.|
00000a60  49 00 5c 00 72 00 65 00  64 00 68 00 61 00 74 00  |I.\.r.e.d.h.a.t.|
00000a70  5c 00 73 00 68 00 69 00  6d 00 78 00 36 00 34 00  |\.s.h.i.m.x.6.4.|
00000a80  2e 00 65 00 66 00 69 00  00 00 7f ff 04 00 00 00  |..e.f.i.........|
00000a90  00 00 00 00 00 00 af 08  00 00 00 0d 00 00 00 b5  |................|
00000aa0  cd d0 8f bb 16 31 e2 80  8b e8 58 75 c9 89 18 95  |.....1....Xu....|
00000ab0  d2 de 15 15 00 00 00 67  72 75 62 5f 63 6d 64 20  |.......grub_cmd |
00000ac0  73 65 74 20 70 61 67 65  72 3d 31 00 08 00 00 00  |set pager=1.....|
...

So update the EFI_LOADED_IMAGE structure with the second stage loader file
path to have the correct value in the log, i.e:

$ hexdump -Cv /sys/kernel/security/tpm0/binary_bios_measurements
...
00000a50  00 00 00 00 00 00 04 04  34 00 5c 00 45 00 46 00  |........4.\.E.F.|
00000a60  49 00 5c 00 72 00 65 00  64 00 68 00 61 00 74 00  |I.\.r.e.d.h.a.t.|
00000a70  5c 00 67 00 72 00 75 00  62 00 78 00 36 00 34 00  |\.g.r.u.b.x.6.4.|
00000a80  2e 00 65 00 66 00 69 00  00 00 7f ff 04 00 00 00  |..e.f.i.........|
00000a90  00 00 00 00 00 00 af 08  00 00 00 0d 00 00 00 b5  |................|
00000aa0  cd d0 8f bb 16 31 e2 80  8b e8 58 75 c9 89 18 95  |.....1....Xu....|
00000ab0  d2 de 15 15 00 00 00 67  72 75 62 5f 63 6d 64 20  |.......grub_cmd |
00000ac0  73 65 74 20 70 61 67 65  72 3d 31 00 08 00 00 00  |set pager=1.....|
...

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Upstream-commit-id: cd7d42d493d
2020-07-23 20:53:24 -04:00
Cryptlib Use portable shebangs: /bin/bash -> /usr/bin/env bash 2020-07-23 20:53:24 -04:00
include translate_slashes(): don't write to string literals 2020-07-23 20:53:24 -04:00
lib MokManager: console mode modification for hi-dpi screen devices 2020-07-23 20:53:24 -04:00
.gitignore Add "make scan-build" target. 2018-03-12 16:21:43 -04:00
.syntastic_c_config Fix syntastic config for include/ 2018-03-12 18:00:41 -04:00
.travis.yml .travis.yml: update travis to get newer gnu-efi. 2018-03-23 15:06:32 -04:00
buildid.c buildid: Check the return values of write() calls 2017-09-29 11:10:32 -04:00
BUILDING Document REQUIRE_TPM 2018-03-12 16:21:43 -04:00
cert.S Add support for 32-bit ARM 2014-08-12 10:54:05 -04:00
COPYRIGHT Add copyright file 2012-07-09 11:03:12 -04:00
crypt_blowfish.c Move includes around to clean the source tree up a bit. 2018-03-12 16:21:43 -04:00
elf_aarch64_efi.lds Don't allow anything with a small alignment in our PE files. 2017-04-26 21:52:23 -04:00
elf_arm_efi.lds Don't allow anything with a small alignment in our PE files. 2017-04-26 21:52:23 -04:00
elf_ia32_efi.lds Don't allow anything with a small alignment in our PE files. 2017-04-26 21:52:23 -04:00
elf_ia64_efi.lds Make shim_version live in a special aligned section. 2017-02-23 16:08:42 -05:00
elf_x86_64_efi.lds Don't allow anything with a small alignment in our PE files. 2017-04-26 21:52:23 -04:00
errlog.c VLogError(): Avoid NULL pointer dereferences in (V)Sprint calls 2020-07-23 20:52:12 -04:00
fallback.c Audit get_variable() calls for correct FreePool() use. 2018-04-05 14:49:17 -04:00
httpboot.c translate_slashes(): don't write to string literals 2020-07-23 20:53:24 -04:00
make-certs Use portable shebangs: /bin/bash -> /usr/bin/env bash 2020-07-23 20:53:24 -04:00
Make.coverity Add 'make coverity' target. 2018-03-12 16:21:43 -04:00
Make.defaults Once again, try even harder to get binaries without timestamps in them. 2020-07-23 20:52:12 -04:00
Make.rules Add 'make coverity' target. 2018-03-12 16:21:43 -04:00
Make.scan-build Work around clang bugs for scan-build. 2018-03-15 11:23:26 -04:00
Makefile Once again, try even harder to get binaries without timestamps in them. 2020-07-23 20:52:12 -04:00
model.c Add a model file for coverity. 2018-03-12 16:21:43 -04:00
mok.c mok: minor cleanups 2020-07-23 20:52:12 -04:00
MokManager.c MokManager: avoid -Werror=address-of-packed-member 2020-07-23 20:53:24 -04:00
MokVars.txt Add MokListX to MokVars.txt 2017-08-03 11:00:58 -04:00
netboot.c translate_slashes(): don't write to string literals 2020-07-23 20:53:24 -04:00
PasswordCrypt.c shim: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere. 2018-03-12 16:21:43 -04:00
README Add install targets. 2017-08-11 15:18:39 -04:00
README.fallback README.fallback: correct the path of BOOT.CSV in layout example 2017-07-24 14:12:31 -04:00
README.tpm Add GRUB's PCR Usage to README.tpm 2020-07-23 20:51:49 -04:00
replacements.c console: Add console_print and console_print_at helpers 2018-03-12 18:00:41 -04:00
shim.c shim: Update EFI_LOADED_IMAGE with the second stage loader file path 2020-07-23 20:53:24 -04:00
shim.h shim: Rework pause functions and add read_counter() 2020-07-23 20:52:12 -04:00
testplan.txt Another testplan error. 2014-10-02 01:01:46 -04:00
TODO Add another TODO for shim-16 2018-04-04 16:49:43 -04:00
tpm.c tpm: Don't log duplicate identical events 2020-07-23 20:53:24 -04:00
travis-build.sh travis: Fix a typo 2018-03-14 18:41:59 -04:00
version.c.in Make shim_version live in a special aligned section. 2017-02-23 16:08:42 -05:00
version.h Add ident-like blobs to shim.efi for version checking. 2013-10-03 11:11:09 -04:00

shim is a trivial EFI application that, when run, attempts to open and
execute another application. It will initially attempt to do this via the
standard EFI LoadImage() and StartImage() calls. If these fail (because secure
boot is enabled and the binary is not signed with an appropriate key, for
instance) it will then validate the binary against a built-in certificate. If
this succeeds and if the binary or signing key are not blacklisted then shim
will relocate and execute the binary.

shim will also install a protocol which permits the second-stage bootloader
to perform similar binary validation. This protocol has a GUID as described
in the shim.h header file and provides a single entry point. On 64-bit systems
this entry point expects to be called with SysV ABI rather than MSABI, and
so calls to it should not be wrapped.

On systems with a TPM chip enabled and supported by the system firmware,
shim will extend various PCRs with the digests of the targets it is
loading.  A full list is in the file README.tpm .

To use shim, simply place a DER-encoded public certificate in a file such as
pub.cer and build with "make VENDOR_CERT_FILE=pub.cer".

There are a couple of build options, and a couple of ways to customize the
build, described in BUILDING.