Commit Graph

760 Commits

Author SHA1 Message Date
Gary Lin
4e111bf1af 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>
2021-02-16 09:12:48 +01:00
Gary Lin
19a147061c 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>
2021-02-16 09:12:48 +01:00
Chris Coulson
16f4f47f5c 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.
2021-02-16 09:12:48 +01:00
Peter Jones
9c64b6278c Make sure MIN() and MAX() are always defined.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 09:12:48 +01:00
Luca Boccassi
8537e0555c 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>
2021-02-16 09:12:48 +01:00
Gary Lin
44c5aac539 src/netboot.c: remove the execute bit
Signed-off-by: Gary Lin <glin@suse.com>
2021-02-16 09:12:48 +01:00
Peter Jones
dd4e3ac5fd 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>
2021-02-16 09:12:48 +01:00
Peter Jones
2b283bb0a1 SPDX: Clarify the attribution for crypt_blowfish
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 09:12:48 +01:00
Peter Jones
aedb8470bd 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>
2021-02-16 09:12:48 +01:00
Lisa White
bc894771f5 Fix typo in a comment 2021-02-16 09:12:48 +01:00
Colin Walters
2616b13645 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.
2021-02-15 17:20:05 -05:00
Peter Jones
f0eb9426aa .gitignore: ignore .gdbinit
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
9bb0860e21 .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>
2021-02-15 17:20:05 -05:00
Peter Jones
e6aaa18538 Re-alphabetize .gitignore.
This had gotten weird in a couple of ways.  Easy to fix.

Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Nicholas Bishop
c941956a59 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>
2021-02-15 17:20:05 -05:00
Peter Jones
0a1bf93d4a BUILDING: fix missing DISABLE_EBS_PROTECTION section
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Paul Menzel
9a960c6e32 README: Remove superfluous *and* 2021-02-15 17:20:05 -05:00
Peter Jones
149a873af5 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>
2021-02-15 17:20:05 -05:00
Peter Jones
a181a29836 Add screen logs to .gitignore
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
15467e7cea Also ignore .sw?
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Jia Zhang
518d9029c2 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>
2021-02-15 17:20:05 -05:00
Mathieu Trudel-Lapierre
545b4a194f Add mm/fb hashing to TODO, put that and related things under 'Reproducible builds' 2021-02-15 17:20:05 -05:00
Peter Jones
d211ab2435 Add fallback boot loop detection to TODO
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
5cd4ec44b8 Add some *more* TODO tasks.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
0024dc9ebf Add another unfortunate TODO entry.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
c5805d535f Add some more TODOs for shim 16
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
e943efbb5f Try to make scan-build.mk work without scan-build installed. 2021-02-15 17:20:05 -05:00
Peter Jones
f16c7dc632 Try to make coverity.mk work without cov-build installed. 2021-02-15 17:20:05 -05:00
Peter Jones
aa48ac96ba We're not using travis-build.sh any more.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 17:20:05 -05:00
Peter Jones
5fb5537fa9 sbat: make the includes work like everything else.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-15 18:40:07 +01:00
Peter Jones
cf7260d432 add an ascii strndup() implementation.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 13:24:06 -05:00
Peter Jones
b0a2ea0caa 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>
2021-02-13 13:15:12 -05:00
Peter Jones
94ad063e94 Add some linked list primitives.
This adds basic linked list structures, initializers, and iterators.

Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 12:58:23 -05:00
Peter Jones
be0612cd77 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>
2021-02-13 11:29:18 -05:00
Jan Setje-Eilers
4eef10a6b3 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>
2021-02-13 11:29:18 -05:00
Peter Jones
6b8ef61a1a 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>
2021-02-13 11:02:59 -05:00
Javier Martinez Canillas
ee8f7ed332 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>
2021-02-13 11:02:59 -05:00
Peter Jones
16732ad128 Add the beginning of .sbat parsing stuff
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 11:02:59 -05:00
Peter Jones
19f3b31f6a Add some more PE helpers we need for SBAT
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 11:02:59 -05:00
Peter Jones
dea41d4c27 Refactor some PE handling code
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 11:02:59 -05:00
Peter Jones
06e98a10f6 Move a bunch of PE-related stuff out of shim.c
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-13 11:02:59 -05:00
Peter Jones
186595864c
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>
2021-02-13 00:04:13 +01:00
Peter Jones
4a4d73f73a
Remove my .syntastic_c_config, it doesn't belong in the repo.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-12 23:53:37 +01:00
Peter Jones
dd70785953 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>
2021-02-12 19:27:21 +01:00
Javier Martinez Canillas
6d13718c80 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>
2021-02-12 12:51:32 -05:00
Peter Jones
aed06cd1b8 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>
2021-02-05 16:30:57 -05:00
Peter Jones
2b53e3d356 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>
2021-02-05 16:30:57 -05:00
Peter Jones
edc08062f1 Fix pe.h -> peimage.h in /both/ places.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-01 16:18:05 -05:00
Peter Jones
1fa0b8d50a 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>
2021-01-29 18:45:00 -05:00
Peter Jones
0172d43507 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>
2021-01-29 18:24:57 -05:00