]> git.proxmox.com Git - efi-boot-shim.git/log
efi-boot-shim.git
3 years agofix nit
Jan Setje-Eilers [Thu, 18 Feb 2021 00:24:04 +0000 (16:24 -0800)]
fix nit

Co-authored-by: Christopher Co <christopher.co@microsoft.com>
3 years agofix nit
Jan Setje-Eilers [Thu, 18 Feb 2021 00:23:55 +0000 (16:23 -0800)]
fix nit

Co-authored-by: Christopher Co <christopher.co@microsoft.com>
3 years agofix not
Jan Setje-Eilers [Thu, 18 Feb 2021 00:23:14 +0000 (16:23 -0800)]
fix not

Co-authored-by: Christopher Co <christopher.co@microsoft.com>
3 years agoSBAT: Fix all the docs examples to start with version 1
Peter Jones [Tue, 16 Feb 2021 20:22:18 +0000 (15:22 -0500)]
SBAT: Fix all the docs examples to start with version 1

Since we have atol() but not strtoul(), we need to make all versions
positive integers.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoSBAT: make the variable be CSV in our spec.
Peter Jones [Tue, 16 Feb 2021 20:15:47 +0000 (15:15 -0500)]
SBAT: make the variable be CSV in our spec.

We noticed that we'd originally specified the SBAT variable as binary
records, but talked as if they're CSV.  Woops.  Anyway, this makes them
CSV, which also means they don't need the size field.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agosbat: add minor fixes to parse_sbat
Chris Co [Tue, 16 Feb 2021 06:21:12 +0000 (06:21 +0000)]
sbat: add minor fixes to parse_sbat

Add parameter checking to parse_sbat().

Set end pointer to be sbat_base + sbat_size - 1. We directly
dereference the end pointer but this is technically outside of
our sbat_base buffer range.

Remove current and end while loops that account for extra CRLF
or LF characters before and after the .sbat section. We will
rely on automated tooling to verify the .sbat section is sane.

Remove the overwriting of *(end - 1) with '\0'. This behavior
causes a segfault in the unit test. parse_sbat_entry() expects
a very specific pattern "_,_,_,_,_,_\n" for every entry and uses
strchrnul() to process each individual field. When *(end - 1)='\0'
is present, it short-circuits the final \n and causes the final
get_sbat_field() to return NULL, thereby setting current = NULL.

Eventually parse_sbat attempts to access current in the do-while
condition and the segfault happens.

Signed-off-by: Chris Co <chrco@microsoft.com>
3 years agosbat: use correct type for parse_sbat_var() return value
Javier Martinez Canillas [Tue, 16 Feb 2021 09:55:27 +0000 (10:55 +0100)]
sbat: use correct type for parse_sbat_var() return value

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agosbat: remove unused buffer parameter in parse_sbat() function
Javier Martinez Canillas [Tue, 16 Feb 2021 09:55:22 +0000 (10:55 +0100)]
sbat: remove unused buffer parameter in parse_sbat() function

It's a left over from an early implementation that was never cleaned.

Reported-by: Christopher Co <christopher.co@microsoft.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agosbat: clang-format the whole thing.
Peter Jones [Sat, 13 Feb 2021 17:01:47 +0000 (12:01 -0500)]
sbat: clang-format the whole thing.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoUse gcc -Os instead of -O0.
Peter Jones [Fri, 22 Nov 2019 21:14:23 +0000 (16:14 -0500)]
Use gcc -Os instead of -O0.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoRename check_{white,black}list to check_{allow,deny}list
Chris Coulson [Fri, 3 Jul 2020 00:47:51 +0000 (01:47 +0100)]
Rename check_{white,black}list to check_{allow,deny}list

v2 - updated for conflicts and to include documentation (pjones)

3 years agoAdd ENABLE_SHIM_DEVEL config to change what our debug variable name is
Peter Jones [Wed, 27 Jan 2021 17:14:01 +0000 (12:14 -0500)]
Add ENABLE_SHIM_DEVEL config to change what our debug variable name is

Currently, if you have two boot entries, say one for
\EFI\fedora\shimx64.efi and one for \EFI\devel\shimx64.efi, and you set
the efi variable SHIM_DEBUG=1, both of these will trigger, and you need
to write your debugging scripts to allow each of the builds to continue.

This is a pain.

This patch makes it so on your development build, it will instead check
SHIM_DEVEL_DEBUG, thus meaning you can have it pause for a debugger only
on the development branch and not the OS you need to boot to scp in a
new development build.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoMake the variable name and pointer const in all of our efi vars functions
Peter Jones [Wed, 27 Jan 2021 17:10:44 +0000 (12:10 -0500)]
Make the variable name and pointer const in all of our efi vars functions

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoMake httpboot.c always get built.
Peter Jones [Fri, 22 Nov 2019 20:14:22 +0000 (15:14 -0500)]
Make httpboot.c always get built.

This is a backport from devel of:

  commit 634fd72ac6a6c6c9010c32506d524586826a8637
  Author: Peter Jones <pjones@redhat.com>
  Date:   Fri Nov 22 15:14:22 2019 -0500

      Make httpboot.c always get built.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix a bunch of trivial trailing whitespace issues.
Peter Jones [Sun, 14 Feb 2021 16:21:27 +0000 (11:21 -0500)]
Fix a bunch of trivial trailing whitespace issues.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoconsole: Fix a typo in the EFI warning list in gnu-efi
Peter Jones [Mon, 26 Aug 2019 20:12:05 +0000 (16:12 -0400)]
console: Fix a typo in the EFI warning list in gnu-efi

Some versions of gnu-efi have a typo, in which "EFI_WARN_UNKNOWN_GLYPH"
is accidentally "EFI_WARN_UNKOWN_GLYPH".  Work around that, so that we
can use the not-silly one in console.c's list of error and warning
messages.

This is a backport from devel for:

  commit 5f62b22ccd636d326b3229a2b196118701c6f3f7
  Author: Peter Jones <pjones@redhat.com>
  Date:   Mon Aug 26 16:12:05 2019 -0400

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agofallback: show a countdown menu before reset
Gary Lin [Wed, 23 May 2018 10:13:05 +0000 (18:13 +0800)]
fallback: show a countdown menu before reset

Some machines with the faulty firmware may keep booting the default boot
path instead of the boot option we create. To avoid the infinite reset
loop, this commit introduce a countdown screen before fallback resets the
system, so the user can interrupt the system reset and choose to boot
the restored boot option. The "Always continue boot" option creates a
BS+RT+NV variable, FB_NO_REBOOT, to make fallback boot the first boot
option afterward without asking. The user can revert the behavior by
removing the variable.

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

Signed-off-by: Gary Lin <glin@suse.com>
This is a backport from devel of:

  commit da6284569c4b5d60d14e6187f696f54cccb7b3d2
  Author: Gary Lin <glin@suse.com>
  Date:   Wed May 23 18:13:05 2018 +0800

      fallback: show a countdown menu before reset

      Some machines with the faulty firmware may keep booting the default boot
      path instead of the boot option we create. To avoid the infinite reset
      loop, this commit introduce a countdown screen before fallback resets the
      system, so the user can interrupt the system reset and choose to boot
      the restored boot option. The "Always continue boot" option creates a
      BS+RT+NV variable, FB_NO_REBOOT, to make fallback boot the first boot
      option afterward without asking. The user can revert the behavior by
      removing the variable.

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

Signed-off-by: Gary Lin <glin@suse.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoconsole: Move the countdown function to console.c
Gary Lin [Wed, 23 May 2018 08:58:31 +0000 (16:58 +0800)]
console: Move the countdown function to console.c

Move the countdown function from MokManager to console.c to make the
function public

Also make console_save_and_set_mode() and console_restore_mode() public

Signed-off-by: Gary Lin <glin@suse.com>
3 years agolib: move print_crypto_errors() out of console.c
Gary Lin [Fri, 22 Nov 2019 09:22:15 +0000 (17:22 +0800)]
lib: move print_crypto_errors() out of console.c

print_crypto_errors() will pull in the whole openssl library which
bloats the size of fallback.efi. Move the function to an independent
file (lib/print_crypto.c) to reduce the file size of fallback.efi from
1.3MB to 93KB.

Signed-off-by: Gary Lin <glin@suse.com>
3 years agoFix sbsign command usage
Chris Coulson [Wed, 15 Jul 2020 11:16:10 +0000 (12:16 +0100)]
Fix sbsign command usage

The previous make target was passing all of the target's prerequisites
as boot images to sbsign, causing it to fail.

3 years agoMake sure MIN() and MAX() are always defined.
Peter Jones [Thu, 10 Dec 2020 16:24:09 +0000 (11:24 -0500)]
Make sure MIN() and MAX() are always defined.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoMakefile: use fixed build host if SOURCE_DATE_EPOCH is defined
Luca Boccassi [Fri, 15 Feb 2019 21:42:10 +0000 (21:42 +0000)]
Makefile: use fixed build host if SOURCE_DATE_EPOCH is defined

If SOURCE_DATE_EPOCH is defined then we can be reasonably sure the
user wants the build to be fully reproducible, so use a fixed string.
In case of a cross build, using uname -s -m -p -i o will still report
the host's kernel architecture, which will trip some CIs like
Debian's.

This is a backport from devel of:

  commit 11fd3197d21f94b491ccfc1da6d38b14060e62d7
  Author: Luca Boccassi <bluca@debian.org>
  Date:   Fri Feb 15 21:42:10 2019 +0000

      Makefile: use fixed build host if SOURCE_DATE_EPOCH is defined

      If SOURCE_DATE_EPOCH is defined then we can be reasonably sure the
      user wants the build to be fully reproducible, so use a fixed string.
      In case of a cross build, using uname -s -m -p -i o will still report
      the host's kernel architecture, which will trip some CIs like
      Debian's.

Signed-off-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agosrc/netboot.c: remove the execute bit
Gary Lin [Wed, 13 May 2020 07:07:55 +0000 (15:07 +0800)]
src/netboot.c: remove the execute bit

Signed-off-by: Gary Lin <glin@suse.com>
3 years agoSPDX: Clarify the attribution for James's lib/ code
Peter Jones [Sun, 14 Feb 2021 16:22:08 +0000 (11:22 -0500)]
SPDX: Clarify the attribution for James's lib/ code

At the time, this was explicitly contributed under the Tiano license,
even though the original code[0] is LGPLv2.1.

[0]: git://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoSPDX: Clarify the attribution for crypt_blowfish
Peter Jones [Sun, 14 Feb 2021 16:21:43 +0000 (11:21 -0500)]
SPDX: Clarify the attribution for crypt_blowfish

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix up a bunch of our license statements and add SPDX most places
Peter Jones [Fri, 11 Dec 2020 20:54:55 +0000 (15:54 -0500)]
Fix up a bunch of our license statements and add SPDX most places

The license statements in our source files were getting to be a giant
mess, and mostly they all just say the same thing.  I've switched most
of it to SPDX labels, but left copyright statements in place (where they
were not obviously incorrect copy-paste jobs that I did...).

If there's some change here you don't think is valid, let me know and
we can fix it up together.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix typo in a comment
Lisa White [Sat, 8 Feb 2020 19:22:39 +0000 (19:22 +0000)]
Fix typo in a comment

3 years agoConvert README -> README.md
Colin Walters [Tue, 23 Jun 2020 01:57:05 +0000 (01:57 +0000)]
Convert README -> README.md

One of the really great things about Github IMO is how
"front and center" the README file in a repository is (just
compare with Sourceforge).

Github renders it more nicely if the file is declared to be Markdown,
so let's do that.  Add a bit of formatting: using code fences
for code, hyperlinks for other files etc.

I also added a title block from the Fedora package `Summary`
since while I know in theory shim is independent of bootloaders,
let's say what the 95% case is here.

3 years ago.gitignore: ignore .gdbinit
Peter Jones [Wed, 27 Jan 2021 16:54:16 +0000 (11:54 -0500)]
.gitignore: ignore .gdbinit

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years ago.gitignore: add build dirs and shim_cert.h
Peter Jones [Mon, 15 Feb 2021 21:42:46 +0000 (16:42 -0500)]
.gitignore: add build dirs and shim_cert.h

This adds stuff that only ever gets made as an artifact of building
(though build*/ generally doesn't, as of this commit.)

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoRe-alphabetize .gitignore.
Peter Jones [Mon, 15 Feb 2021 21:18:52 +0000 (16:18 -0500)]
Re-alphabetize .gitignore.

This had gotten weird in a couple of ways.  Easy to fix.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoBUILDING: Fix a typo
Nicholas Bishop [Thu, 17 May 2018 23:28:53 +0000 (19:28 -0400)]
BUILDING: Fix a typo

This is a backport from devel for:

  commit 852091d63f73011742c61c976e40f35edd74d598
  Author: Nicholas Bishop <nicholasbishop@gmail.com>
  Date:   Thu May 17 19:28:53 2018 -0400

      Fix typo

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoBUILDING: fix missing DISABLE_EBS_PROTECTION section
Peter Jones [Sun, 14 Feb 2021 22:15:54 +0000 (17:15 -0500)]
BUILDING: fix missing DISABLE_EBS_PROTECTION section

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoREADME: Remove superfluous *and*
Paul Menzel [Wed, 23 May 2018 10:43:45 +0000 (12:43 +0200)]
README: Remove superfluous *and*

3 years agoAdd .cer/.crt/.esl to .gitignore
Peter Jones [Mon, 29 Jun 2020 18:06:34 +0000 (14:06 -0400)]
Add .cer/.crt/.esl to .gitignore

This was previously on devel as:

  commit 2e29c0358888412e9addfb016cc72f6e89ffb536
  Author: Peter Jones <pjones@redhat.com>
  Date:   Mon Jun 29 14:06:34 2020 -0400

  Add .cer/.crt/.esl to .gitignore

But .cer and .crt were added independently in another commit since then.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd screen logs to .gitignore
Peter Jones [Mon, 18 Nov 2019 19:34:38 +0000 (14:34 -0500)]
Add screen logs to .gitignore

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAlso ignore .sw?
Peter Jones [Wed, 4 Sep 2019 15:01:48 +0000 (11:01 -0400)]
Also ignore .sw?

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoIgnore *.hash
Jia Zhang [Tue, 30 Oct 2018 13:33:22 +0000 (21:33 +0800)]
Ignore *.hash

*.hash should be ignored by git status if ENABLE_SHIM_HASH is
configured.

Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com>
3 years agoAdd mm/fb hashing to TODO, put that and related things under 'Reproducible builds'
Mathieu Trudel-Lapierre [Tue, 21 Aug 2018 18:43:12 +0000 (14:43 -0400)]
Add mm/fb hashing to TODO, put that and related things under 'Reproducible builds'

3 years agoAdd fallback boot loop detection to TODO
Peter Jones [Wed, 1 Aug 2018 15:04:14 +0000 (11:04 -0400)]
Add fallback boot loop detection to TODO

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd some *more* TODO tasks.
Peter Jones [Fri, 13 Apr 2018 19:17:58 +0000 (15:17 -0400)]
Add some *more* TODO tasks.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd another unfortunate TODO entry.
Peter Jones [Thu, 12 Apr 2018 19:08:09 +0000 (15:08 -0400)]
Add another unfortunate TODO entry.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd some more TODOs for shim 16
Peter Jones [Tue, 10 Apr 2018 16:36:12 +0000 (12:36 -0400)]
Add some more TODOs for shim 16

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoTry to make scan-build.mk work without scan-build installed.
Peter Jones [Mon, 7 Dec 2020 19:30:37 +0000 (14:30 -0500)]
Try to make scan-build.mk work without scan-build installed.

3 years agoTry to make coverity.mk work without cov-build installed.
Peter Jones [Mon, 7 Dec 2020 19:30:37 +0000 (14:30 -0500)]
Try to make coverity.mk work without cov-build installed.

3 years agoWe're not using travis-build.sh any more.
Peter Jones [Fri, 11 Dec 2020 20:32:56 +0000 (15:32 -0500)]
We're not using travis-build.sh any more.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agosbat: make the includes work like everything else.
Peter Jones [Mon, 15 Feb 2021 17:24:33 +0000 (12:24 -0500)]
sbat: make the includes work like everything else.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoadd an ascii strndup() implementation.
Peter Jones [Sat, 13 Feb 2021 18:14:02 +0000 (13:14 -0500)]
add an ascii strndup() implementation.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoget_variable: always allocate a NUL character at the end.
Peter Jones [Sat, 13 Feb 2021 18:02:14 +0000 (13:02 -0500)]
get_variable: always allocate a NUL character at the end.

Sometimes we're loading structures that are parsed in string-like ways,
but can't necessarily be trusted to be zero-terminated.  Solve that by
making sure we always have enough aligned, trailing zero bytes to always
have at least one NUL character, no matter which character type is being
parsed.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd some linked list primitives.
Peter Jones [Sat, 13 Feb 2021 15:36:44 +0000 (10:36 -0500)]
Add some linked list primitives.

This adds basic linked list structures, initializers, and iterators.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd an example SBAT workflow document
Peter Jones [Sat, 13 Feb 2021 00:35:28 +0000 (01:35 +0100)]
Add an example SBAT workflow document

Add a file that contains example workflows for SBAT and better illustrate
what type of content is expected to be present in both the .sbat section
and the SBAT authenticated EFI variable.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd Secure Boot Advanced Targeting (SBAT) specification document
Jan Setje-Eilers [Fri, 12 Feb 2021 23:46:36 +0000 (00:46 +0100)]
Add Secure Boot Advanced Targeting (SBAT) specification document

SBAT is a new Generation Number Based Revocation meant to replace the DBX
Revocation List Files mechanism. It is more flexible and allow to revoke
sets of binaries, instead of having to list all of them as with the DBX.

Metadata that includes the vendor, product family, product, component,
version and generation are added to artifacts in a .sbat section. This
is protected by the digital signature and so it cannot be tampered.

Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Gary Lin <glin@suse.com>
3 years agoSBAT: parse a copy of the table that's got a NUL at the end
Peter Jones [Wed, 10 Feb 2021 01:02:26 +0000 (20:02 -0500)]
SBAT: parse a copy of the table that's got a NUL at the end

Right now we allocate the PE file's contents in RW memory, but hopefully
that won't always be the case.  Our SBAT parsing, however, very much
expects to be able to edit it.  We also don't actually know that shim's
.sbat section is loaded r/w, so we can't necessarily write there.

This patch copies the SBAT data to its own buffer, plus one NUL byte at
the end, so we can always be sure that will work.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd a function to parse the SBAT metadata from the .sbat section
Javier Martinez Canillas [Wed, 10 Feb 2021 00:26:46 +0000 (01:26 +0100)]
Add a function to parse the SBAT metadata from the .sbat section

Parse the SBAT [0] Version-Based Revocation Metadata that's contained in a
.sbat data section of the loaded PE binary. This information is used along
with data in a SBAT variable to determine if a EFI binary has been revoked.

[0]: https://github.com/rhboot/shim/blob/sbat/SBAT.md

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agoAdd the beginning of .sbat parsing stuff
Peter Jones [Wed, 2 Dec 2020 05:05:16 +0000 (00:05 -0500)]
Add the beginning of .sbat parsing stuff

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd some more PE helpers we need for SBAT
Peter Jones [Wed, 2 Dec 2020 19:29:14 +0000 (14:29 -0500)]
Add some more PE helpers we need for SBAT

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoRefactor some PE handling code
Peter Jones [Wed, 2 Dec 2020 19:01:10 +0000 (14:01 -0500)]
Refactor some PE handling code

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoMove a bunch of PE-related stuff out of shim.c
Peter Jones [Wed, 2 Dec 2020 18:59:38 +0000 (13:59 -0500)]
Move a bunch of PE-related stuff out of shim.c

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoincludes: add strchra() and strchrnula() impls
Peter Jones [Tue, 9 Feb 2021 18:39:48 +0000 (13:39 -0500)]
includes: add strchra() and strchrnula() impls

Unfortunately GNU-EFI doesn't currently implement ascii versions of
strchr() or strchrnul(), and we kind of need them, so add an
implementation here for now.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoRemove my .syntastic_c_config, it doesn't belong in the repo.
Peter Jones [Thu, 31 Jan 2019 19:53:10 +0000 (14:53 -0500)]
Remove my .syntastic_c_config, it doesn't belong in the repo.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoefi bins: add an easy way for vendors to add .sbat data
Peter Jones [Fri, 12 Feb 2021 17:41:41 +0000 (12:41 -0500)]
efi bins: add an easy way for vendors to add .sbat data

In cases where we accept vendor shim binaries with additional patches,
it may become necessary to identify those builds with additional SBAT
data.  When we consider such patches, we should be proactive in asking
vendors to include that data in the .sbat sections of their trusted EFI
binaries.

This patch adds any data in data/sbat.*.csv (after a quick sanitizing
pass) after data/sbat.csv in the .sbat section, so that no changes to
the upstream data/sbat.csv are ever required.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd a .sbat section to EFI binaries
Javier Martinez Canillas [Fri, 12 Feb 2021 15:29:16 +0000 (16:29 +0100)]
Add a .sbat section to EFI binaries

The Secure Boot Advanced Targeting (SBAT) [0] is a Generation Number Based
Revocation mechanism that is meant to replace the DBX revocation file list.

Binaries must contain a .sbat data section that has a set entries, each of
them consisting of UTF-8 strings as comma separated values. Allow to embed
this information into the fwupd EFI binary at build time.

The SBAT metadata must contain at least two entries. One that defines the
SBAT version used and another one that defines the component generation.

This patch adds a sbat.csv that contains these two entries and downstream
users can override if additional entries are needed due changes that make
them diverge from upstream code and potentially add other vulnerabilities.

The same SBAT metadata is added to the fallback and MOK manager binaries
because these are built from the same shim source. These need to have SBAT
metadata as well to be booted if a .sbat section is mandatory.

[0]: https://github.com/rhboot/shim/blob/sbat/SBAT.md

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agogithub workflows: add the sbat branch to one PR builds run for
Peter Jones [Fri, 5 Feb 2021 21:00:26 +0000 (16:00 -0500)]
github workflows: add the sbat branch to one PR builds run for

This adds the "sbat" branch to the list of branches where a build is
done if a PR is submitted against that branch.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agogithub workflows: Unify the x86 pull request build rules steps
Peter Jones [Fri, 5 Feb 2021 21:00:15 +0000 (16:00 -0500)]
github workflows: Unify the x86 pull request build rules steps

This makes each of the f32/f33/f34 distro builds use the same steps to
do the build, as well as making each of them build both x64 and ia32
targets.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix pe.h -> peimage.h in /both/ places.
Peter Jones [Mon, 1 Feb 2021 21:17:58 +0000 (16:17 -0500)]
Fix pe.h -> peimage.h in /both/ places.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoRenaming PeImage.h to pe.h wasn't actually a good idea.
Peter Jones [Fri, 29 Jan 2021 23:45:00 +0000 (18:45 -0500)]
Renaming PeImage.h to pe.h wasn't actually a good idea.

I renamed PeImage.h to pe.h when I de-capitalized them, but this turns
out to be a bad idea because we already have a pe.h on the SBAT branch.
Woops.

This moves it to peimage.h

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoWork around some clang-format oddnesses
Peter Jones [Fri, 29 Jan 2021 20:27:26 +0000 (15:27 -0500)]
Work around some clang-format oddnesses

In the version of clang-format I've got locally[0],
WhitespaceSensitiveMacros seems to only work sometimes.  That means that
if we ever run it on some particular things, it could seriously mess up
a bunch of our debugging output.  That's not great.

In this patch, I've gone ahead and run clang-format on all the macros
that use __LINE__, which are the obvious places this is dangerous, and
then audited the result and fixed anything that's broken (including a
couple of places where it was already broken.)

[0] random:~/devel/github.com/shim/clang-format$ clang-format --version
    clang-format version 11.0.0 (Fedora 11.0.0-2.fc33)

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAlways use lower case for our local include file names.
Peter Jones [Fri, 29 Jan 2021 20:11:18 +0000 (15:11 -0500)]
Always use lower case for our local include file names.

clang-format doesn't allow you to specify an include sort order, and
just assumes asciibetical is a pretty good order, which doesn't work as
well as you would hope.

This makes them all lower case so they don't need to be re-sorted.

I also went through and checked that we're using quoted local includes
at all the appropriate places.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAdd a .clang-format file.
Peter Jones [Fri, 29 Jan 2021 19:01:28 +0000 (14:01 -0500)]
Add a .clang-format file.

There's clearly not enough conformance to a single coding style here.
To some extent that can't really change - I don't intend to adopt edk2's
style for the main codebase, but re-formatting the code we borrow from
edk2 would be insane.

This commit adds a .clang-format file, to be used on new files as such:

clang-format --style=file -i foo.c

It can also be used when new free-standing code is added to existing
files, using the clang-format --lines= option.

The starting style in this is pretty close to the Linux kernel style,
with a couple of minor modifications.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoshim: compile time option to bypass the ExitBootServices() check
Paul Moore [Thu, 29 Oct 2020 13:49:36 +0000 (09:49 -0400)]
shim: compile time option to bypass the ExitBootServices() check

On systems where a second stage bootloader is not used, and the Linux
Kernel is booted directly from shim, shim's ExitBootServices() hook
can cause problems as the kernel never calls the shim's verification
protocol.  In this case calling the shim verification protocol is
unnecessary and redundant as shim has already verified the kernel
when shim loaded the kernel as the second stage loader.

This functionality is disabled by default and must be enabled via the
DISABLE_EBS_PROTECTION macro/define at build time.

Signed-off-by: Paul Moore <pmoore2@cisco.com>
3 years agoTry to kick the github PR workflow...
Peter Jones [Fri, 11 Dec 2020 23:12:36 +0000 (18:12 -0500)]
Try to kick the github PR workflow...

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoSplit up push and PR CI/CD and build all patches in series on PRs
Peter Jones [Thu, 10 Dec 2020 20:10:11 +0000 (15:10 -0500)]
Split up push and PR CI/CD and build all patches in series on PRs

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoUse github actions for CI builds
Peter Jones [Thu, 3 Dec 2020 18:16:34 +0000 (13:16 -0500)]
Use github actions for CI builds

This could still use a bit of work, but it's better than Travis
failing...

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix incorrect allocation size for EV_EFI_BOOT_SERVICES_APPLICATION events
James Bottomley [Thu, 15 Oct 2020 23:38:52 +0000 (19:38 -0400)]
Fix incorrect allocation size for EV_EFI_BOOT_SERVICES_APPLICATION events

sizeof(EFI_IMAGE_LOAD_EVENT) needs to represent the size of the header
so we can add the actual device path size to it to compute the event.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agohexdump.h: fix arithmetic error.
Peter Jones [Thu, 30 Jul 2020 18:34:22 +0000 (14:34 -0400)]
hexdump.h: fix arithmetic error.

When I modified the hexdumper to help debug MokListRT mirroring not
working because of PcdMaxVolatileVariableSize being tiny, I
inadvertently added something that is effectively:

hexdump(..., char *buf, ..., int position)
{
unsigned long begin = (position % 16);
unsigned long i;
...
for (i = 0; i < begin; i++) {
...
}
...
}

Unfortunately, in c if 0x8 is set in position, that means begin is
0xfffffffffffff8, because signed integer math is horrifying:

include/hexdump.h:99:vhexdumpf() &data[offset]:0x9E77E6BC size-offset:0x14
include/hexdump.h:15:prepare_hex() position:0x9E77E6BC
include/hexdump.h:17:prepare_hex() before:0xFFFFFFFFFFFFFFFC size:0x14
include/hexdump.h:19:prepare_hex() before:0xFFFFFFFFFFFFFFFC after:0x0
include/hexdump.h:21:prepare_hex() buf:0x000000009E77E2BC offset:0 &buf[offset]:0x000000009E77E2BC

Woops.

This could further have been prevented in /some/ cases by simply not
preparing the hexdump buffer when "verbose" is disabled.

This patch makes "pos" be unsigned in all cases, and also checks for
verbose in vhexdumpf() and simply returns if it is 0.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoFix some mokmanager deletion paths
Peter Jones [Mon, 17 Aug 2020 19:47:19 +0000 (15:47 -0400)]
Fix some mokmanager deletion paths

This fixes several codepaths where MokList and MokListX are supposed to
be deleted, but are not.  It also adds debug logging to much of the
deletion codepath.

3 years agoFix buffer overrun due DEFAULT_LOADER length miscalculation
Javier Martinez Canillas [Tue, 8 Sep 2020 10:26:45 +0000 (12:26 +0200)]
Fix buffer overrun due DEFAULT_LOADER length miscalculation

The DEFAULT_LOADER is a UCS-2 string and the StrLen() function returns the
number of UCS-2 encoded characters in the string. But the allocated memory
is in bytes, so only half of the needed memory to store it is allocated.

This leads to a buffer overrun when the StrCpy() function attempts to copy
the DEFAULT_LOADER to the allocated buffer.

Fixes: 354bd9b1931 ("Actually check for errors from set_second_stage()")
Reported-by: Stuart Hayes <stuart_hayes@dell.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3 years agomirror_one_mok_variable(): round allocation up to a full page
Peter Jones [Tue, 4 Aug 2020 16:42:43 +0000 (12:42 -0400)]
mirror_one_mok_variable(): round allocation up to a full page

The code currently computes the size of the MoK variable in ram and
rounds up to a full page, but then actually allocates the exact size,
rather than the rounded up version.  This should be completely safe, but
the intent was to round up to at least the page size boundary, and to
always guarantee rounding up /some/, to ensure extra 0-bytes at the end
of the buffer.

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoImplement lennysz's suggestions for MokListRT
Peter Jones [Sun, 26 Jul 2020 02:13:57 +0000 (22:13 -0400)]
Implement lennysz's suggestions for MokListRT

Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoAlso use a config table to mirror mok variables.
Peter Jones [Fri, 24 Jul 2020 02:09:03 +0000 (22:09 -0400)]
Also use a config table to mirror mok variables.

Everything was going just fine until I made a vendor_db with 17kB of
sha256 sums in it.  And then the same source tree that had worked fine
without that threw errors and failed all over the place.  I wrote some
code to diagnose the problem, and of course it was a failure in
mirroring MokList to MokListRT.

As Patrick noted in 741c61abba7, some systems have obnoxiously low
amounts of variable storage available:

mok.c:550:import_mok_state() BS+RT variable info:
     MaximumVariableStorageSize:0x000000000000DFE4
     RemainingVariableStorageSize:0x000000000000D21C
     MaximumVariableSize:0x0000000000001FC4

The most annoying part is that on at least this edk2 build,
SetVariable() /does actually appear to set the variable/, but it returns
EFI_INVALID_PARAMETER.  I'm not planning on relying on that behavior.

So... yeah, the largest *volatile* (i.e. RAM only) variable this edk2
build will let you create is less than two pages.  It's only got 7.9G
free, so I guess it's feeling like space is a little tight.

We're also not quite preserving that return code well enough for his
workaround to work.

New plan.  We try to create variables the normal way, but we don't
consider not having enough space to be fatal.  In that case, we create
an EFI_SECURITY_LIST with one sha256sum in it, with a value of all 0,
and try to add that so we're sure there's /something/ there that's
innocuous.  On systems where the first SetVariable() /
QueryVariableInfo() lied to us, the correct variable should be there,
otherwise the one with the zero-hash will be.

We then also build a config table to hold this info and install that.

The config table is a packed array of this struct:

struct mok_variable_config_entry {
       CHAR8 name[256];
       UINT64 data_size;
       UINT8 data[];
};

There will be N+1 entries, and the last entry is all 0 for name and
data_size.  The total allocation size will always be a multiple of 4096.
In the typical RHEL 7.9 case that means it'll be around 5 pages.

It's installed with this guid:

c451ed2b-9694-45d3-baba-ed9f8988a389

Anything that can go wrong will.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: not yet, I don't want people to read this before Wednesday.
Signed-off-by: Peter Jones <pjones@redhat.com>
3 years agoImprove debug output some
Peter Jones [Fri, 24 Jul 2020 00:29:52 +0000 (20:29 -0400)]
Improve debug output some

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#213

3 years agoMake openssl accept the right set of KU/EKUs
Peter Jones [Wed, 22 Jul 2020 23:54:58 +0000 (19:54 -0400)]
Make openssl accept the right set of KU/EKUs

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#211

3 years agoHandle binaries with multiple signatures.
Peter Jones [Thu, 23 Jul 2020 20:32:05 +0000 (16:32 -0400)]
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

3 years agoAdd support for vendor_db built-in shim authorized list.
Peter Jones [Thu, 23 Jul 2020 16:36:56 +0000 (12:36 -0400)]
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

3 years agoMake cert.S not impossible to read.
Peter Jones [Thu, 23 Jul 2020 04:08:30 +0000 (00:08 -0400)]
Make cert.S not impossible to read.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#206

3 years agoFix a broken tpm type
Peter Jones [Fri, 24 Jul 2020 00:35:56 +0000 (20:35 -0400)]
Fix a broken tpm type

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212

3 years agosimple_file: fix uninitialized variable/unchecked return
Peter Jones [Thu, 23 Jul 2020 03:55:44 +0000 (23:55 -0400)]
simple_file: fix uninitialized variable/unchecked return

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212

3 years agoMokManager: fix a wrong allocation failure check.
Peter Jones [Thu, 23 Jul 2020 23:01:27 +0000 (19:01 -0400)]
MokManager: fix a wrong allocation failure check.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212

3 years agoFix some volatile usage gcc whines about.
Peter Jones [Thu, 23 Jul 2020 20:18:52 +0000 (16:18 -0400)]
Fix some volatile usage gcc whines about.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212

3 years agoMokManager: fix uninitialized value
Peter Jones [Thu, 23 Jul 2020 03:53:09 +0000 (23:53 -0400)]
MokManager: fix uninitialized value

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: pr#212

3 years agoRemove a couple of incorrect license claims.
Peter Jones [Thu, 9 Jul 2020 04:24:57 +0000 (00:24 -0400)]
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

3 years agoCheck PxeReplyReceived as fallback in netboot
Thomas Frauendorfer | Miray Software [Wed, 25 Mar 2020 08:19:19 +0000 (09:19 +0100)]
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

3 years agoUpdate README.tpm
noahbliss [Thu, 5 Mar 2020 00:46:28 +0000 (19:46 -0500)]
Update README.tpm

typo
Upstream-commit-id: bc24c9eb1d4

3 years agoFix the license on our buildid extractor.
Peter Jones [Thu, 23 Apr 2020 22:55:34 +0000 (18:55 -0400)]
Fix the license on our buildid extractor.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 71439f848f6

3 years agotpm: Include information about PE/COFF images in the TPM Event Log
Javier Martinez Canillas [Tue, 18 Feb 2020 11:03:17 +0000 (12:03 +0100)]
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

3 years agoshim: Update EFI_LOADED_IMAGE with the second stage loader file path
Javier Martinez Canillas [Tue, 18 Feb 2020 11:03:28 +0000 (12:03 +0100)]
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

3 years agotranslate_slashes(): don't write to string literals
Laszlo Ersek [Tue, 28 Jan 2020 22:33:46 +0000 (23:33 +0100)]
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: 8e9124227d18475d3bc634c33518963fc8db7c98
Fixes: e62b69a5b0b87c6df7a4fc23906134945309e927
Fixes: 3d79bcb2651b9eae809b975b3e03e2f96c067072
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795654
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Upstream-commit-id: 9813e8bc8b3

3 years agoActually check for errors from set_second_stage()
Peter Jones [Mon, 18 Nov 2019 18:58:46 +0000 (13:58 -0500)]
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

3 years agoSlightly better debugging messages
Peter Jones [Mon, 18 Nov 2019 18:59:14 +0000 (13:59 -0500)]
Slightly better debugging messages

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 173d35fe8f5

3 years agotpm: Don't log duplicate identical events
Chris Coulson [Thu, 26 Sep 2019 19:01:01 +0000 (20:01 +0100)]
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