Commit Graph

787 Commits

Author SHA1 Message Date
Peter Jones
f1feb3ac04 sbat: drop the struct sbat and just use two variables instead
The struct sbat isn't doing anything and only has two fields so let's pass
pass those two to the functions directly instead of storing it in a struct.

Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-19 14:28:10 -05:00
Peter Jones
146f9d8e8d shim: use an enum for efi_main's error messages.
Numbering the error messages in efi_main directly was a mistake, and the
following patches just make it more apparent.

This makes it an enum so we don't have to re-number at more than one
place when we add or remove them.

Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-19 14:28:10 -05:00
Hai Huang
e3325f8100 Fix EV_EFI_VARIABLE_AUTHORITY event in eventlog
Currently, for an EV_EFI_VARIABLE_AUTHORITY event, the shim puts only
EFI_SIGNATURE_DATA.SignatureData in the VariableData field, but omits
EFI_SIGNATURE_DATA.SignatureOwner. According to reference implementation
in EDK2, the entire EFI_SIGNATURE_DATA is put into the VariableData
field, shown here:
https://github.com/tianocore/edk2/blob/master/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c#L1032
2021-02-19 11:11:31 -05:00
Paul Moore
e5f7b252d8 build: add some basic $EFI_PATH checking
Not all distributions put the crt0-efi-$(ARCH).o file under
$LIB_DIR/gnuefi, some stash it directly in $LIB_DIR.  In an effort
to make the build a bit more user friendly, check if $LIB_DIR/gnuefi
exits before setting $EFI_PATH to that value; if $LIB_DIR/gnuefi does
not exist, fallback to $LIB_DIR for $EFI_PATH.

Signed-off-by: Paul Moore <pmoore2@cisco.com>
2021-02-19 11:09:36 -05:00
Alex Burmashev
e6a7fc11a4 add list_empty to linked list primitives
Signed-off-by: Alex Burmashev <alexander.burmashev@oracle.com>
2021-02-17 19:33:57 -05:00
Alex Burmashev
0287b5a864 strndupa: allocate len + 1, so that \0 is not lost
Signed-off-by: Alex Burmashev <alexander.burmashev@oracle.com>
2021-02-17 19:30:19 -05:00
Peter Jones
07724ab645 Fix an off by one in strnlena()
I wrote a test case for strnlena() and strndupa() and of course both
were off by one in the opposite directions...

... but the next patch obviates the need for them, hopefully, so this
will wind up getting dropped.
2021-02-17 16:27:18 -08:00
Steve McIntyre
066a11164e Fixups after Peter's review 2021-02-17 16:25:44 -08:00
Steve McIntyre
8d189efc03 Second attempt at SBAT doc tweaks 2021-02-17 16:25:44 -08:00
Jan Setje-Eilers
21203630a3 fix nit
Co-authored-by: Christopher Co <christopher.co@microsoft.com>
2021-02-17 16:25:02 -08:00
Jan Setje-Eilers
63d76f2e28 fix nit
Co-authored-by: Christopher Co <christopher.co@microsoft.com>
2021-02-17 16:25:02 -08:00
Jan Setje-Eilers
966d5e6116 fix nit
Co-authored-by: Christopher Co <christopher.co@microsoft.com>
2021-02-17 16:25:02 -08:00
Jan Setje-Eilers
450f49367d fix not
Co-authored-by: Christopher Co <christopher.co@microsoft.com>
2021-02-17 16:25:02 -08:00
Peter Jones
05f8c34e3a 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>
2021-02-17 16:25:02 -08:00
Peter Jones
c26174026b 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>
2021-02-17 16:25:02 -08:00
Chris Co
a18d80ff98 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>
2021-02-16 16:42:27 +01:00
Javier Martinez Canillas
038891bb83 sbat: use correct type for parse_sbat_var() return value
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-02-16 16:42:27 +01:00
Javier Martinez Canillas
d1eb757feb 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>
2021-02-16 16:42:27 +01:00
Peter Jones
0bc2aa4ca8 sbat: clang-format the whole thing.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 16:42:27 +01:00
Peter Jones
4edb31fcfc Use gcc -Os instead of -O0.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 09:12:48 +01:00
Chris Coulson
25c8324637 Rename check_{white,black}list to check_{allow,deny}list
v2 - updated for conflicts and to include documentation (pjones)
2021-02-16 09:12:48 +01:00
Peter Jones
2bdf0dd3a2 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>
2021-02-16 09:12:48 +01:00
Peter Jones
b54d1df1c1 Make the variable name and pointer const in all of our efi vars functions
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 09:12:48 +01:00
Peter Jones
9b0c281db4 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>
2021-02-16 09:12:48 +01:00
Peter Jones
a6c726fc81 Fix a bunch of trivial trailing whitespace issues.
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-16 09:12:48 +01:00
Peter Jones
d230d02f99 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>
2021-02-16 09:12:48 +01:00
Gary Lin
a5db51a52e 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>
2021-02-16 09:12:48 +01:00
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