Commit Graph

695 Commits

Author SHA1 Message Date
Peter Jones
76c0447e20 Handle binaries with multiple signatures.
This adds support for multiple signatures.  It first tries validating
the binary by hash, first against our dbx lists, then against our db
lists.  If it isn't allowed or rejected at that step, it continues to
the normal routine of checking all the signatures.

At this point it does *not* reject a binary just because a signature is
by a cert on a dbx list, though that will override any db list that
certificate is listed on.  If at any point any assertion about the
binary or signature list being well-formed fails, the binary is
immediately rejected, though we do allow skipping over signatures
which have an unsupported sig->Hdr.wCertificateType.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#210
2020-07-23 22:22:04 -04:00
Peter Jones
dd3a5d7125 Add support for vendor_db built-in shim authorized list.
Potential new signing strategies ( for example signing grub, fwupdate
and vmlinuz with separate certificates ) require shim to support a
vendor provided bundle of trusted certificates and hashes, which allows
shim to trust EFI binaries matching either certificate by signature or
hash in the vendor_db.  Functionality is similar to vendor_dbx.

This also improves the mirroring quite a bit.
Upstream: pr#206
2020-07-23 22:22:04 -04:00
Peter Jones
7d542805ba Make cert.S not impossible to read.
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#206
2020-07-23 20:53:24 -04:00
Peter Jones
a7f9911b77 Fix a broken tpm type
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212
2020-07-23 20:53:24 -04:00
Peter Jones
c186bdddaa simple_file: fix uninitialized variable/unchecked return
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212
2020-07-23 20:53:24 -04:00
Peter Jones
6df96cdb20 MokManager: fix a wrong allocation failure check.
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212
2020-07-23 20:53:24 -04:00
Peter Jones
d3b7dc54cd Fix some volatile usage gcc whines about.
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212
2020-07-23 20:53:24 -04:00
Peter Jones
7b77bee796 MokManager: fix uninitialized value
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212
2020-07-23 20:53:24 -04:00
Peter Jones
e8a04c1d84 Remove a couple of incorrect license claims.
A certain someone's default editor template leaked in to a couple of
source files, and claims they're GPL licensed.  They're not.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 476cbff1110
2020-07-23 20:53:24 -04:00
Thomas Frauendorfer | Miray Software
9a209af5d8 Check PxeReplyReceived as fallback in netboot
Some mainboards do not update the ProxyOffset dhcp information when using
proxy dhcp and boot menus.
This adds a fallback to check the PxeReply field if no boot information is
found in the v4 dhcp or proxy dhcp information

Upstream-commit-id: cc7ebe0f9f4
2020-07-23 20:53:24 -04:00
noahbliss
633169fe32 Update README.tpm
typo
Upstream-commit-id: bc24c9eb1d4
2020-07-23 20:53:24 -04:00
Peter Jones
dce3659ac3 Fix the license on our buildid extractor.
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 71439f848f6
2020-07-23 20:53:24 -04:00
Javier Martinez Canillas
0a8f7ade76 tpm: Include information about PE/COFF images in the TPM Event Log
The "TCG PC Client Specific Platform Firmware Profile Specification" says
that when measuring a PE/COFF image, the TCG_PCR_EVENT2 structure Event
field MUST contain a UEFI_IMAGE_LOAD_EVENT structure.

Currently an empty UEFI_IMAGE_LOAD_EVENT structure is passed so users only
have the hash of the PE/COFF image, but not information such the file path
of the binary.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Upstream-commit-id: c252b9ee94c
2020-07-23 20:53:24 -04:00
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
Laszlo Ersek
c6bedd5b83 translate_slashes(): don't write to string literals
Currently, all three invocations of the translate_slashes() function may
lead to writes to the string literal that is #defined with the
DEFAULT_LOADER_CHAR macro. According to ISO C99 6.4.5p6, this is undefined
behavior ("If the program attempts to modify such an array, the behavior
is undefined").

This bug crashes shim on e.g. the 64-bit ArmVirtQemu platform ("Data
abort: Permission fault"), where the platform firmware maps the .text
section (which contains the string literal) read-only.

Modify translate_slashes() so that it copies and translates characters
from an input array of "char" to an output array of "CHAR8".

While at it, fix another bug. Before this patch, if translate_slashes()
ever encountered a double backslash (translating it to a single forward
slash), then the output would end up shorter than the input. However, the
output was not NUL-terminated in-place, therefore the original string
length (and according trailing garbage) would be preserved. After this
patch, the NUL-termination on contraction is automatic, as the output
array's contents are indeterminate when entering the function, and so we
must NUL-terminate it anyway.

Fixes: 8e9124227d
Fixes: e62b69a5b0
Fixes: 3d79bcb265
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795654
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Upstream-commit-id: 9813e8bc8b3
2020-07-23 20:53:24 -04:00
Peter Jones
959f5e4e99 Actually check for errors from set_second_stage()
This changes shim_init() to check for errors from set_second_stage().
In order to make that work, it also does the following:

- correctly /always/ allocate second_stage, not sometimes allocate and
  sometimes point at .data
- test for LoadOptionSize == 0 and return success
- print an error message for the failure so we can see it.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 354bd9b1931
2020-07-23 20:53:24 -04:00
Peter Jones
5e6e0792ce Slightly better debugging messages
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 173d35fe8f5
2020-07-23 20:53:24 -04:00
Chris Coulson
58df8d745c tpm: Don't log duplicate identical events
According to the comment in tpm_measure_variable ("Don't measure something that we've already measured"), shim
shouldn't measure duplicate events if they are identical, which also aligns with section 2.3.4.8 of the TCG PC
Client Platform Firmware Profile Specification ("If it has been measured previously, it MUST NOT be measured
again"). This is currently broken because tpm_data_measured() uses the return value of CompareGuid() incorrectly.

Upstream-commit-id: 103adc89ce5
2020-07-23 20:53:24 -04:00
Jonas Witschel
d57e53f3bd MokManager: avoid -Werror=address-of-packed-member
When compiling with GCC 9, there are a couple of errors of the form

MokManager.c: In function ‘write_back_mok_list’:
MokManager.c:1056:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
 1056 |   if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
      |                   ^~~~~~~~~~~~~~~

Copying the member of the packed struct to a temporary variable and
pointing to that variable solves the problem.

Upstream-commit-id: 58532e12e9a
2020-07-23 20:53:24 -04:00
Ivan Hu
55163bc82c MokManager: console mode modification for hi-dpi screen devices
There are lots of hi-dpi laptops nowadays, as doing mok enrollment, the font
is too small to see.
https://bugs.launchpad.net/ubuntu/+source/shim/+bug/1822043

This patch checks if the resolution is larger than Full HD (1920x1080) and
current console output columns and rows is in a good mode. Then swith the
console output to a better mode.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
Upstream-commit-id: cf05af6d899
2020-07-23 20:53:24 -04:00
Chris Coulson
9f80be9f16 tpm: Define EFI_VARIABLE_DATA_TREE as packed
tpm_measure_variable() calculates VarLogSize by adding the size of VarName
and VarData to the size of EFI_VARIABLE_DATA_TREE, and then subtracting
the size of the UnicodeName and VariableData members. This results in a
calculation that is 5 bytes larger than necessary because it doesn't take
in to account the padding of these members. The effect of this is that
shim measures an additional 5 zero bytes when measuring UEFI variables
(at least on 64-bit architectures).

Byte packing EFI_VARIABLE_DATA_TREE fixes this.

Upstream-commit-id: 7e4d3f1c8c7
2020-07-23 20:53:24 -04:00
Chris Coulson
6fd8db6bb3 tpm: Fix off-by-one error when calculating event size
tpm_log_event_raw() allocates a buffer for the EFI_TCG2_EVENT structure
that is one byte larger than necessary, and sets event->Size accordingly.
The result of this is that the event data recorded in the log differs
from the data that is measured to the TPM (it has an extra zero byte
at the end).

Upstream-commit-id: 8a27a4809a6
2020-07-23 20:53:24 -04:00
Bjørn Forsman
07de085dab Use portable shebangs: /bin/bash -> /usr/bin/env bash
Upstream-commit-id: 6a73ca814af
2020-07-23 20:53:24 -04:00
Peter Jones
44b211bcf7 OpenSSL: always provide OBJ_create() with name strings.
Some versions of OpenSSL seem to go back and forth as to whether NULL
for these names are okay.  Don't risk it.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 46b76a01717
2020-07-23 20:53:24 -04:00
Gary Lin
5d30a31fef MokManager: Use CompareMem on MokListNode.Type instead of CompareGuid
Fix the errors from gcc9 '-Werror=address-of-packed-member'

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

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: aaa09b35e73
2020-07-23 20:53:24 -04:00
Peter Jones
c372ec7a25 Fix a use of strlen() instead of Strlen()
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 1870bae7960
2020-07-23 20:53:15 -04:00
Peter Jones
2cbf56b82a Work around stuff -Waddress-of-packed-member finds.
In MokManager we get a lot of these:

../src/MokManager.c:1063:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
 1063 |   if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
      |                   ^~~~~~~~~~~~~~~

The reason for this is that gnu-efi takes EFI_GUID * as its argument
instead of VOID *, and there's nothing telling the compiler that it
doesn't have alignment constraints on the input, so the compiler wants
it to have 16-byte alignment.

Just use CompareMem() for these, as that's all CompareGuid is calling
anyway.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 08c14376b59
2020-07-23 20:52:12 -04:00
Stuart Hayes
b5e10f70c7 Hook exit when shim_lock protocol installed
A recent commit moved where the shim_lock protocol is loaded and
unloaded, but did not move where exit was hooked and unhooked.  Exit
needs to be hooked when the protocol is installed, so that the protocol
will be uninstalled on exit.  Otherwise, the system can crash if, for
example, shim loads grub, the user exits grub, shim is run again, which
installs a second instance of the protocol, and then grub tries to use
the shim_lock protocol that was installed by the first instance of shim.

Signed-off-by: Stuart Hayes <stuart.w.hayes@gmail.com>
Upstream-commit-id: 06c92591e94
2020-07-23 20:52:12 -04:00
Peter Jones
1b382ef850 shim: Rework pause functions and add read_counter()
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: fc6b0bca84e
2020-07-23 20:52:12 -04:00
Peter Jones
10d6e3d90f Once again, try even harder to get binaries without timestamps in them.
$ objdump -x /builddir/build/BUILDROOT/shim-*/usr/share/shim/*/shimx64.efi | grep 'Time/Date'
Time/Date		Thu Jan  1 00:00:08 1970
$ _

"What is despair? I have known it—hear my song. Despair is when you’re
debugging a kernel driver and you look at a memory dump and you see that
a pointer has a value of 7."
 - http://scholar.harvard.edu/files/mickens/files/thenightwatch.pdf

objcopy only knows about -D for some targets.
ld only believes in --no-insert-timestamp in some versions.
dd takes off and nukes the site from orbit.

It's the only way to be sure.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: a4a1fbe728c
2020-07-23 20:52:12 -04:00
Peter Jones
344a8364cb VLogError(): Avoid NULL pointer dereferences in (V)Sprint calls
VLogError() calculates the size of format strings by using calls to
SPrint and VSPrint with a StrSize of 0 and NULL for an output buffer.
Unfortunately, this is an incorrect usage of (V)Sprint. A StrSize
of "0" is special-cased to mean "there is no limit". So, we end up
writing our string to address 0x0. This was discovered because it
causes a crash on ARM where, unlike x86, it does not necessarily
have memory mapped at 0x0.

Avoid the (V)Sprint calls altogether by using (V)PoolPrint, which
handles the size calculation and allocation for us.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fixes: 25f6fd08cd ("try to show errors more usefully.")
[dannf: commit message ]
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Upstream-commit-id: 20e731f423a
2020-07-23 20:52:12 -04:00
Patrick Uiterwijk
95bd1d8800 Make EFI variable copying fatal only on secureboot enabled systems
I have come across systems that are unwilling to reserve enough memory for
a MokListRT big enough for big certificates.
This seems to be the case with firmware implementations that do not support
secureboot, which is probably the reason they went with much lower variable
storage.

This patch set makes sure we can still boot on those systems, by only
making the copy action fatal if the system has secure boot enabled, or if
the error was anything other than EFI_INVALID_PARAMETER.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
Upstream-commit-id: 741c61abba7
2020-07-23 20:52:12 -04:00
Matthew Garrett
cf3f99c3b1 Remove call to TPM2 get_event_log()
Calling the TPM2 get_event_log causes the firmware to start logging
events to the final events table, but implementations may also continue
logging to the boot services event log. Any OS that wishes to
reconstruct the full PCR state must already look at both the final
events log and the boot services event log, so if this call is made
anywhere other than immediately before ExitBootServices() then the OS
must deduplicate events that occur in both, complicating things
immensely.

Linux already has support for copying up the boot services event log
across the ExitBootServices() boundary, so there's no reason to make
this call. Remove it.

Signed-off-by: Matthew Garrett <mjg59@google.com>
Upstream-commit-id: fd7c3bd920b
2020-07-23 20:52:12 -04:00
Peter Jones
ff890cf452 mok: minor cleanups
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 617b9007668
2020-07-23 20:52:12 -04:00
Gary Lin
3d62232feb mok: also mirror the build cert to MokListRT
If the build cert is enabled, we should also mirror it to MokListRT.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: aecbe1f99b6
2020-07-23 20:52:12 -04:00
Gary Lin
7a3638173e shim: only include shim_cert.h in shim.c
The shim_cert array was declared as a static array, and every user of
shim_cert.h would create a shim_cert array for its own and grow the file
size. To remove the unnecessary duplicate shim_cert arrays, this commit
declares shim_cert in shim.c while other users still can access the
array through the external variables: build_cert and build_cert_size.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 4e2d62f0f4e
2020-07-23 20:52:12 -04:00
Peter Jones
ff6e5cda13 mok: consolidate mirroring code in a helper instead of using goto
There's no reason to complicate the logic with a goto here, instead just
pull the logic we're jumping to out to a helper function.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 29c11483101
2020-07-23 20:52:12 -04:00
Gary Lin
f748139695 mok: fix the mirroring of RT variables
When there is no key in MokList, import_mok_state() just skipped MokList
even though it should always mirror the vendor cert. Besides, the faulty
check of 'present' and 'addend' invalidates the mirroring of MokListXRT,
MokSBStateRT, and MokIgnoreDB.

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

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 4b27ae034ba
2020-07-23 20:52:12 -04:00
Patrick Uiterwijk
ac0400b202 Make sure that MOK variables always get mirrored
Without this, if a Mok variable doesn't exist in Boot Services, it will also
not be copied to Runtime, even if we have data to be added to it (vendor cert).
This patch makes sure that if we have extra data to append, we still mirror
the variable.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
Upstream-commit-id: 9ab0d796bdc
2020-07-23 20:52:12 -04:00
Peter Korsgaard
ee832f21c6 Cryptlib: fix build on 32bit ARM
Pass MDE_CPU_ARM, similar to how it is done for the other supported
architectures, otherwise the build fails in:

Cryptlib/Include/OpenSslSupport.h:55:2: error:
 #error Unknown target architecture

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Upstream-commit-id: cb83c14628b
2020-07-23 20:52:12 -04:00
Peter Korsgaard
7f080b30f3 Make.default: use correct flags to disable unaligned access for 32 bit ARM
The GCC flag to disable unaligned access on 32bit ARM is
-mno-unaligned-access, not -mstrict-align (which is used on aarch64):

https://lkml.org/lkml/2018/8/3/294

Otherwise build dies with:
arm-linux-gnueabihf-gcc: error: unrecognized command line option
   ‘-mstrict-align’; did you mean ‘-Wstrict-aliasing’?

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Upstream-commit-id: 41b93358e8c
2020-07-23 20:52:12 -04:00
Luca Boccassi
8544018093 Makefile: do not run git on clean if there's no .git directory
When building in minimal chroot on build workers, like in Debian (where
make clean is called at the beginning of the build process), git will
not be available. Skip the git clean.

Signed-off-by: Luca Boccassi <bluca@debian.org>
Upstream-commit-id: be352762a01
2020-07-23 20:52:12 -04:00
dann frazier
d5b72b322d Fix apparent typo in ARM 32-on-64 code
The architecture is aarch64, not arch64.

Fixes: 750584c207 ("Make 64-on-32 maybe work on x86_64.")
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Upstream-commit-id: e9f67aaa75a
2020-07-23 20:52:12 -04:00
Maran Wilson
3d04aef8d8 Fix for "Section 0 has negative size" error when loading fbaa64.efi
The current code is incorrectly failing to load the fbaa64.efi image found
in Arm servers even though the UEFI shell code is able to properly load
and execute the same image.

The problem is due to the presence of a section header that has zero size
and address and marked "discardable" in the fbaa64.efi image.

Although there is already a check further down in the code to look for
the discardable bit and skip further verification checks if set, we never
get to that point due to the "end < base" check at the start of the loop.

Here is a dump of the fbaa64.efi image as compiled on an Arm machine
from the latest code in this repo:

% # First I used hexedit to change header byte from 'AA' to '86'
% # so that objdump was able to correctly parse the file:
% objdump -x -m aarch64 fbaa64.efi

fbaa64.efi:     file format pei-x86-64
fbaa64.efi
architecture: i386:x86-64, flags 0x00000103:
HAS_RELOC, EXEC_P, D_PAGED
start address 0x0000000000000148

Characteristics 0x20e
        executable
        line numbers stripped
        symbols stripped
        debugging information removed

Time/Date               Wed Dec 31 16:00:00 1969
Magic                   020b    (PE32+)
MajorLinkerVersion      2
MinorLinkerVersion      20
SizeOfCode              000b15d0
SizeOfInitializedData   00000000
SizeOfUninitializedData 00000000
AddressOfEntryPoint     0000000000000148
BaseOfCode              0000000000000148
ImageBase               0000000000000000
SectionAlignment        0000000000000020
FileAlignment           0000000000000008
MajorOSystemVersion     0
MinorOSystemVersion     0
MajorImageVersion       0
MinorImageVersion       0
MajorSubsystemVersion   0
MinorSubsystemVersion   0
Win32Version            00000000
SizeOfImage             000b1718
SizeOfHeaders           00000148
CheckSum                00000000
Subsystem               0000000a        (EFI application)
DllCharacteristics      00000000
SizeOfStackReserve      0000000000000000
SizeOfStackCommit       0000000000000000
SizeOfHeapReserve       0000000000000000
SizeOfHeapCommit        0000000000000000
LoaderFlags             00000000
NumberOfRvaAndSizes     00000006

The Data Directory
Entry 0 0000000000000000 00000000 Export Directory [.edata (or where ever we found it)]
Entry 1 0000000000000000 00000000 Import Directory [parts of .idata]
Entry 2 0000000000000000 00000000 Resource Directory [.rsrc]
Entry 3 0000000000000000 00000000 Exception Directory [.pdata]
Entry 4 0000000000000000 00000000 Security Directory
Entry 5 0000000000000000 00000000 Base Relocation Directory [.reloc]
Entry 6 0000000000000000 00000000 Debug Directory
Entry 7 0000000000000000 00000000 Description Directory
Entry 8 0000000000000000 00000000 Special Directory
Entry 9 0000000000000000 00000000 Thread Storage Directory [.tls]
Entry a 0000000000000000 00000000 Load Configuration Directory
Entry b 0000000000000000 00000000 Bound Import Directory
Entry c 0000000000000000 00000000 Import Address Table Directory
Entry d 0000000000000000 00000000 Delay Import Directory
Entry e 0000000000000000 00000000 CLR Runtime Header
Entry f 0000000000000000 00000000 Reserved

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .reloc        00000000  0000000000000000  0000000000000000  00000000  2**0
                  ALLOC, LOAD, READONLY, DATA
  1 .text         000b15d0  0000000000000148  0000000000000148  00000148  2**4
                  CONTENTS, ALLOC, LOAD, CODE
SYMBOL TABLE:
no symbols

Signed-off-by: Maran Wilson <maran.wilson@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Jack Schwartz <jack.schwartz@oracle.com>
Upstream-commit-id: 6df7a8f5609
2020-07-23 20:52:12 -04:00
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