Commit Graph

651 Commits

Author SHA1 Message Date
Javier Martinez Canillas
818a0dbd24 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
2020-07-23 20:52:12 -04:00
Javier Martinez Canillas
79be2af526 shim: Properly generate absolute paths from relative image paths
The generate_path_from_image_path() doesn't properly handle the case when
shim is invoked using a relative path (e.g: from the EFI shell). In that
function, always the last component is stripped from absolute file path
to calculate the dirname, and this is concatenated with the image path.

But if the path is a relative one, the function will wrongly concatenate
the dirname with the relative image path, i.e:

 Shell> FS0:
 FS0:\> cd EFI
 FS0:\EFI\> BOOT\BOOTX64.EFI
 Failed to open \EFI\BOOT\BOOT\BOOTX64.EFI - Not found
 Failed to load image \EFI\BOOT\BOOT\BOOTX64.EFI: Not found
 start_image() returned Not found

Calculate the image path basename and concatenate that with the dirname.

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: a625fa5096c
2020-07-23 20:52:12 -04:00
TanMing
c4e3516e30 Fix the compile error of mkdir wrong directory.
In Ubuntu 14.04, the following code in old Makefile:
  mkdir -p Cryptlib/{Hash,Hmac,Cipher,Rand,Pk,Pem,SysCall}
will create a directory named "{Hash,Hmac,Cipher,Rand,Pk,Pem,SysCall}".

Signed-off-by: Ming Tan <ming.tan@intel.com>
Upstream-commit-id: 39b83455d68
2020-07-23 20:52:12 -04:00
Peter Jones
bd97e72f04 Add GRUB's PCR Usage to README.tpm
This didn't seem to get documented anywhere, and this is as good a place as any.
Upstream-commit-id: 4fab7281a8c
2020-07-23 20:51:49 -04:00
Paul Menzel
956717e2b3 shim: Extend invalid reloc size warning message
Knowing the value of the reloc directory size is helpful for debugging,
cf. issue #131 [1],

[1]: https://github.com/rhboot/shim/issues/131

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Upstream-commit-id: dd3230d07f3
2020-07-23 20:51:18 -04:00
Gary Lin
85c837d67f MokManager: Stop using EFI_VARIABLE_APPEND_WRITE
When writing MokList with EFI_VARIABLE_APPEND_WRITE, some HP laptops
may just return EFI_SUCCESS without writing the content into the flash,
so we have no way to detect if MokList is updated or not. Now we always
read MokList first and write it back with the new content.

https://github.com/rhboot/shim/issues/105

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: f442c8424b4
2020-07-23 20:51:18 -04:00
Gary Lin
409b59af29 Fix typo in debug path in shim.h
Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: a98c20bbdbb
2020-07-23 20:51:18 -04:00
Gary Lin
c2f645c7cd httpboot: show the error message for the ChildHandle
Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 0fd3c7e8518
2020-07-23 20:51:18 -04:00
Gary Lin
80e52895f2 httpboot: allow the IPv4 gateway to be empty
The gateway is not mandatory.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 69089e9c678
2020-07-23 20:51:18 -04:00
Gary Lin
0ba6c87bdf httpboot: print more messages when it fails to set IP
We previously only print the return status and it may not be clear
enough in some situations. Print the IP address and the gateway to help
the user to identify the possible errors.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 3abe94516c7
2020-07-23 20:51:18 -04:00
Gary Lin
8a66f5571b httpboot: return EFI_NOT_FOUND when it fails to find the NIC handle
httpboot_fetch_buffer() should return EFI_NOT_FOUND to reflect the error
status when get_nic_handle() returns NULL.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 2be5c7dc4b0
2020-07-23 20:51:18 -04:00
Mathieu Trudel-Lapierre
7471867794 Let MokManager follow a MokTimeout var for timeout length for the prompt
This timeout can have the values [-1,0..0x7fff]; where -1 means "no timeout",
with MokManager going directly to the menu, and is capped to 0x7fff to avoid
unecessary long timeouts. The default remains 10, which will be used whenever
the MokTimeout variable isn't set.

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Upstream-commit-id: 93708c11083
2020-07-23 20:51:18 -04:00
Peter Jones
32f7122538 Makefiles: ensure -m32 gets propogated to our gcc parameter queries
'gcc -print-file-name=include' and 'gcc -print-libgcc-file-name' both
need -m32 when we're building 32-on-64 on some distros, so ensure that
gets propogated correctly.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 104d6e54ac7
2020-07-23 20:51:18 -04:00
Peter Jones
1d50318f44 Make some things dprint() instead of console_print()
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: dad59f8c0f36
2020-07-23 20:51:12 -04:00
Peter Jones
51413d1deb Bump version to 15 2018-04-05 14:49:17 -04:00
Peter Jones
77ebb3d676 Audit get_variable() calls for correct FreePool() use.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:49:17 -04:00
Peter Jones
36cf41a616 Fix get_variable() usage in setup_verbosity()
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:49:17 -04:00
Peter Jones
41be168919 Make setup_console(-1) do GetMode() and call it from setup_verbosity()
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:49:17 -04:00
Peter Jones
510474e72d Make handle_image() use console_print() not console_notify() on success
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:49:17 -04:00
Peter Jones
bbaa96cdb2 Fix lib/ rebuild-on-change dependencies in the Makefile
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:49:17 -04:00
Peter Jones
4ffcfdf4da Get rid of dprinta(), it's useless
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-05 14:09:46 -04:00
Peter Jones
15a3480417 tpm_log_event_raw(): be more careful about EFI_NOT_FOUND
Don't return EFI_NOT_FOUND from tpm_log_event*() unless we're in
REQUIRE_TPM mode.

Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-04 16:49:43 -04:00
Peter Jones
9ab48c0c25 Make the 'something has gone seriously wrong' message less ambiguous
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-04 16:49:43 -04:00
Peter Jones
9bee22310e read_header(): fix the case where signatures have been removed.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-04 16:49:43 -04:00
Peter Jones
ccf9e0efab Add another TODO for shim-16
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-04-04 16:49:43 -04:00
Peter Jones
91229b7703 Add some TODO items for shim-16
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-23 15:06:32 -04:00
Peter Jones
23322362f5 .travis.yml: update travis to get newer gnu-efi.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-23 15:06:32 -04:00
Peter Jones
cdbfb5a69e Revert "Allow shim to handle multiple trusted certificates"
This was merged before it was really ready - verify_trusted_cert needs
to check each certificate against vendor_dbx, "dbx", and "MokListX", or
else it can enable a blacklisted certificate accidentally.

This reverts commit 8721bbe6fb.
2018-03-23 13:55:57 -04:00
Peter Jones
f391e44516 Revert "MokManager: stop using StrnCat"
This reverts commit 6aa5a62515.

Everything Hans said was correct.  But StrnCat() is in gnu-efi 3.0.8,
and using just StrCpy() here confuses coverity.  I'd rather have a CI
page that's not completely full of chaff, but a little bit of redundancy
in the code.

Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-20 16:28:57 -04:00
Peter Jones
ad6f1747b5 Fix i386 pointer type error.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-19 14:27:58 -04:00
Peter Jones
d737c0273d Avoid a minor scan-build complaint.
scan-build doesn't like it when we assign return values but don't use
them.

Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-15 11:23:26 -04:00
Peter Jones
138deeff23 Work around clang bugs for scan-build.
I don't think the x86 binaries clang builds will actually work unless
they just infer -maccumulate-outgoing-args from __attribute__((__ms_abi__),
but it's nice to have the analyzer working.

Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-15 11:23:26 -04:00
Peter Jones
bfb6bd7b83 travis: Fix a typo
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-14 18:41:59 -04:00
Peter Jones
8843e6e60d Fix the working directory we start in.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-14 18:38:50 -04:00
Peter Jones
06ddb2e8f5 Add some configs for CI using github+travis+docker
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-14 18:10:48 -04:00
Michael Brown
8721bbe6fb Allow shim to handle multiple trusted certificates
Allow shim to perform verification against a list of trusted
certificates by simply concatenating the DER files.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-14 13:48:07 -04:00
Michael Brown
d7daa70e0d Allow memory allocated by handle_image() to be freed
There is currently no way for a caller of handle_image() to free the
memory allocated to hold the relocated executable.  Fix by adding the
allocated memory address and number of pages as returned parameters
from handle_image().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-14 13:47:52 -04:00
Michael Brown
0a4c7d5af3 Remove global entry_point variable
Treat entry_point as a returned parameter from handle_image(), rather
than using a global variable.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-14 13:46:19 -04:00
Michael Brown
5b6253c98e Do not modify original image
relocate_coff() currently modifies the PE header within the raw data.
This appears to be unnecessary, and causes a verification failure if a
second attempt is made to verify the same data buffer.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-14 13:44:45 -04:00
Hans de Goede
6aa5a62515 MokManager: stop using StrnCat
StrnCat is not available in gnu-efi-3.0.5 (I did not check if it does
actually exists in 3.0.6). Moreover using strcat on a buffer where we've
just done: "buf[0] = '\0'" is a bit silly, we might as well drop the 0
termination and just use strcpy.

It seems there also is no StrnCpy in gnu-efi-3.0.5, but we are passing in
a pointer to the end of file_name minus 4, so strcpy will consume only
4 bytes anyways and there is no need for the "n".

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-13 15:40:44 -04:00
Hans de Goede
7faf9e86c3 console: Fix indentation
The manual merge of the "console: Do not set EFI console to textmode until
something is printed" patch has lead to a bunch of tabs being replaced
with 7 spaces. This commit fixes this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-13 15:40:35 -04:00
Hans de Goede
1ff4a36a23 console: Do not set EFI console to textmode until something is printed
Remove the setup_console(1) calls from shim and instead make lib/console.c
make that call when necessary. This avoids shim forcing the EFI console to
switch to text-mode if nothing is printed.

This commit also modifies MokManager to work the same way for consistency,
even though MokManager will always print something.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-12 18:00:41 -04:00
Hans de Goede
42b1d8832f console: Move setup_console() definition to higher in the file
This is a preparation patch for making setup_console() private.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-12 18:00:41 -04:00
Hans de Goede
1fe31ee1b4 console: Add console_print and console_print_at helpers
This is a preparation commit for removing the setup_console(1) calls from
MokManager and shim so that we don't force the EFI console to switch to
text-mode.

This commit replaces all direct calls to Print / PrintAt with calls to
the new helpers (no functional changes) so that we can delay calling
setup_console(1) till the first Print call in a follow-up patch.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-12 18:00:41 -04:00
Peter Jones
d3b7ba1b09 Fix syntastic config for include/
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-12 18:00:41 -04:00
Tamas K Lengyel
38b16b200c shim: Don't overwrite EFI_LOADED_IMAGE's LoadOptions when not needed
When the firmware is using EFI_LOAD_OPTION to specify options for the secondary
loader, the shim will properly detect that and return in set_second_stage. Later
howerer in handle_image EFI_LOADED_IMAGE is being overwritten with load_option
irrespective of the fact that load_option was never set. This effectively
prevents the EFI_LOAD_OPTION from reaching the secondary loader.

Only overwrite EFI_LOADED_IMAGE's LoadOptions when load_option is not NULL
solves the problem.

Signed-off-by: Tamas K Lengyel <lengyelt@ainfosec.com>
2018-03-12 16:59:31 -04:00
Tamas K Lengyel
f29240734b Make EFI_INCLUDE path configurable during make
Signed-off-by: Tamas K Lengyel <lengyelt@ainfosec.com>
2018-03-12 16:57:24 -04:00
Peter Jones
a2f3794356 Make sure fallback.efi gets errlog.o as well
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-12 16:26:07 -04:00
Peter Jones
589819e607 Fix a minor merge error.
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-12 16:23:49 -04:00
Peter Jones
4181a16f62 shim: Make our variable validation and mirroring table driven.
This makes it so shim's idea of Mok variables all resides in one table
of data, and we don't need a bunch of nearly identical ad-hoc functions
to handle each of them.

Signed-off-by: Peter Jones <pjones@redhat.com>
2018-03-12 16:21:43 -04:00