]> git.proxmox.com Git - efi-boot-shim.git/log
efi-boot-shim.git
4 years agoRemove call to TPM2 get_event_log()
Matthew Garrett [Tue, 11 Dec 2018 23:25:44 +0000 (15:25 -0800)]
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

4 years agomok: minor cleanups
Peter Jones [Thu, 31 Jan 2019 19:04:57 +0000 (14:04 -0500)]
mok: minor cleanups

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

4 years agomok: also mirror the build cert to MokListRT
Gary Lin [Wed, 19 Dec 2018 04:40:02 +0000 (12:40 +0800)]
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

4 years agoshim: only include shim_cert.h in shim.c
Gary Lin [Wed, 19 Dec 2018 03:27:42 +0000 (11:27 +0800)]
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

4 years agomok: consolidate mirroring code in a helper instead of using goto
Peter Jones [Thu, 31 Jan 2019 18:45:30 +0000 (13:45 -0500)]
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

4 years agomok: fix the mirroring of RT variables
Gary Lin [Wed, 21 Nov 2018 04:47:43 +0000 (12:47 +0800)]
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

4 years agoMake sure that MOK variables always get mirrored
Patrick Uiterwijk [Mon, 5 Nov 2018 13:51:16 +0000 (14:51 +0100)]
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

4 years agoCryptlib: fix build on 32bit ARM
Peter Korsgaard [Fri, 11 Jan 2019 08:17:42 +0000 (09:17 +0100)]
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

4 years agoMake.default: use correct flags to disable unaligned access for 32 bit ARM
Peter Korsgaard [Thu, 10 Jan 2019 22:34:11 +0000 (23:34 +0100)]
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

4 years agoMakefile: do not run git on clean if there's no .git directory
Luca Boccassi [Mon, 14 Jan 2019 19:29:34 +0000 (19:29 +0000)]
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

4 years agoFix apparent typo in ARM 32-on-64 code
dann frazier [Mon, 14 Jan 2019 22:25:11 +0000 (15:25 -0700)]
Fix apparent typo in ARM 32-on-64 code

The architecture is aarch64, not arch64.

Fixes: 750584c20775 ("Make 64-on-32 maybe work on x86_64.")
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Upstream-commit-id: e9f67aaa75a

4 years agoFix for "Section 0 has negative size" error when loading fbaa64.efi
Maran Wilson [Tue, 7 Aug 2018 22:32:29 +0000 (15:32 -0700)]
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

4 years agoshim: Prevent shim to set itself as a second stage loader
Javier Martinez Canillas [Fri, 7 Sep 2018 13:10:51 +0000 (15:10 +0200)]
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

4 years agoshim: Properly generate absolute paths from relative image paths
Javier Martinez Canillas [Fri, 7 Sep 2018 12:11:02 +0000 (14:11 +0200)]
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

4 years agoFix the compile error of mkdir wrong directory.
TanMing [Tue, 21 Aug 2018 06:25:52 +0000 (02:25 -0400)]
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

4 years agoAdd GRUB's PCR Usage to README.tpm
Peter Jones [Wed, 1 Aug 2018 14:58:09 +0000 (09:58 -0500)]
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

4 years agoshim: Extend invalid reloc size warning message
Paul Menzel [Wed, 23 May 2018 10:32:37 +0000 (12:32 +0200)]
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

4 years agoMokManager: Stop using EFI_VARIABLE_APPEND_WRITE
Gary Lin [Fri, 11 May 2018 08:59:03 +0000 (16:59 +0800)]
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

4 years agoFix typo in debug path in shim.h
Gary Lin [Wed, 23 May 2018 07:15:56 +0000 (15:15 +0800)]
Fix typo in debug path in shim.h

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: a98c20bbdbb

4 years agohttpboot: show the error message for the ChildHandle
Gary Lin [Mon, 28 May 2018 10:03:39 +0000 (18:03 +0800)]
httpboot: show the error message for the ChildHandle

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 0fd3c7e8518

4 years agohttpboot: allow the IPv4 gateway to be empty
Gary Lin [Mon, 28 May 2018 09:42:56 +0000 (17:42 +0800)]
httpboot: allow the IPv4 gateway to be empty

The gateway is not mandatory.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 69089e9c678

4 years agohttpboot: print more messages when it fails to set IP
Gary Lin [Mon, 28 May 2018 09:24:30 +0000 (17:24 +0800)]
httpboot: print more messages when it fails to set IP

We previously only print the return status and it may not be clear
enough in some situations. Print the IP address and the gateway to help
the user to identify the possible errors.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 3abe94516c7

4 years agohttpboot: return EFI_NOT_FOUND when it fails to find the NIC handle
Gary Lin [Mon, 28 May 2018 08:05:38 +0000 (16:05 +0800)]
httpboot: return EFI_NOT_FOUND when it fails to find the NIC handle

httpboot_fetch_buffer() should return EFI_NOT_FOUND to reflect the error
status when get_nic_handle() returns NULL.

Signed-off-by: Gary Lin <glin@suse.com>
Upstream-commit-id: 2be5c7dc4b0

4 years agoLet MokManager follow a MokTimeout var for timeout length for the prompt
Mathieu Trudel-Lapierre [Thu, 5 Jul 2018 15:28:12 +0000 (11:28 -0400)]
Let MokManager follow a MokTimeout var for timeout length for the prompt

This timeout can have the values [-1,0..0x7fff]; where -1 means "no timeout",
with MokManager going directly to the menu, and is capped to 0x7fff to avoid
unecessary long timeouts. The default remains 10, which will be used whenever
the MokTimeout variable isn't set.

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Upstream-commit-id: 93708c11083

4 years agoMakefiles: ensure -m32 gets propogated to our gcc parameter queries
Peter Jones [Thu, 12 Apr 2018 17:24:48 +0000 (13:24 -0400)]
Makefiles: ensure -m32 gets propogated to our gcc parameter queries

'gcc -print-file-name=include' and 'gcc -print-libgcc-file-name' both
need -m32 when we're building 32-on-64 on some distros, so ensure that
gets propogated correctly.

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

4 years agoMake some things dprint() instead of console_print()
Peter Jones [Tue, 10 Apr 2018 16:36:34 +0000 (12:36 -0400)]
Make some things dprint() instead of console_print()

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

6 years agoBump version to 15
Peter Jones [Thu, 22 Mar 2018 21:38:59 +0000 (17:38 -0400)]
Bump version to 15

6 years agoAudit get_variable() calls for correct FreePool() use.
Peter Jones [Thu, 5 Apr 2018 18:09:37 +0000 (14:09 -0400)]
Audit get_variable() calls for correct FreePool() use.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix get_variable() usage in setup_verbosity()
Peter Jones [Thu, 5 Apr 2018 17:50:37 +0000 (13:50 -0400)]
Fix get_variable() usage in setup_verbosity()

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake setup_console(-1) do GetMode() and call it from setup_verbosity()
Peter Jones [Thu, 5 Apr 2018 17:50:18 +0000 (13:50 -0400)]
Make setup_console(-1) do GetMode() and call it from setup_verbosity()

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake handle_image() use console_print() not console_notify() on success
Peter Jones [Thu, 5 Apr 2018 17:48:58 +0000 (13:48 -0400)]
Make handle_image() use console_print() not console_notify() on success

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix lib/ rebuild-on-change dependencies in the Makefile
Peter Jones [Thu, 5 Apr 2018 17:30:59 +0000 (13:30 -0400)]
Fix lib/ rebuild-on-change dependencies in the Makefile

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoGet rid of dprinta(), it's useless
Peter Jones [Thu, 5 Apr 2018 17:02:10 +0000 (13:02 -0400)]
Get rid of dprinta(), it's useless

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agotpm_log_event_raw(): be more careful about EFI_NOT_FOUND
Peter Jones [Wed, 4 Apr 2018 20:48:43 +0000 (16:48 -0400)]
tpm_log_event_raw(): be more careful about EFI_NOT_FOUND

Don't return EFI_NOT_FOUND from tpm_log_event*() unless we're in
REQUIRE_TPM mode.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake the 'something has gone seriously wrong' message less ambiguous
Peter Jones [Wed, 4 Apr 2018 16:31:23 +0000 (12:31 -0400)]
Make the 'something has gone seriously wrong' message less ambiguous

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoread_header(): fix the case where signatures have been removed.
Peter Jones [Wed, 4 Apr 2018 20:47:33 +0000 (16:47 -0400)]
read_header(): fix the case where signatures have been removed.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd another TODO for shim-16
Peter Jones [Wed, 4 Apr 2018 16:31:30 +0000 (12:31 -0400)]
Add another TODO for shim-16

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd some TODO items for shim-16
Peter Jones [Fri, 23 Mar 2018 18:12:49 +0000 (14:12 -0400)]
Add some TODO items for shim-16

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years ago.travis.yml: update travis to get newer gnu-efi.
Peter Jones [Fri, 23 Mar 2018 19:06:19 +0000 (15:06 -0400)]
.travis.yml: update travis to get newer gnu-efi.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoRevert "Allow shim to handle multiple trusted certificates"
Peter Jones [Fri, 23 Mar 2018 17:54:53 +0000 (13:54 -0400)]
Revert "Allow shim to handle multiple trusted certificates"

This was merged before it was really ready - verify_trusted_cert needs
to check each certificate against vendor_dbx, "dbx", and "MokListX", or
else it can enable a blacklisted certificate accidentally.

This reverts commit 8721bbe6fb1bfdfbc8bd16e05673929e4cbbdedc.

6 years agoRevert "MokManager: stop using StrnCat"
Peter Jones [Tue, 20 Mar 2018 20:27:42 +0000 (16:27 -0400)]
Revert "MokManager: stop using StrnCat"

This reverts commit 6aa5a62515d62139a2d3b34626fac8910e864a3d.

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

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix i386 pointer type error.
Peter Jones [Mon, 19 Mar 2018 18:27:58 +0000 (14:27 -0400)]
Fix i386 pointer type error.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAvoid a minor scan-build complaint.
Peter Jones [Thu, 15 Mar 2018 15:21:22 +0000 (11:21 -0400)]
Avoid a minor scan-build complaint.

scan-build doesn't like it when we assign return values but don't use
them.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoWork around clang bugs for scan-build.
Peter Jones [Thu, 15 Mar 2018 15:13:25 +0000 (11:13 -0400)]
Work around clang bugs for scan-build.

I don't think the x86 binaries clang builds will actually work unless
they just infer -maccumulate-outgoing-args from __attribute__((__ms_abi__),
but it's nice to have the analyzer working.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agotravis: Fix a typo
Peter Jones [Wed, 14 Mar 2018 22:41:59 +0000 (18:41 -0400)]
travis: Fix a typo

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix the working directory we start in.
Peter Jones [Wed, 14 Mar 2018 22:38:34 +0000 (18:38 -0400)]
Fix the working directory we start in.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAdd some configs for CI using github+travis+docker
Peter Jones [Wed, 14 Mar 2018 22:10:48 +0000 (18:10 -0400)]
Add some configs for CI using github+travis+docker

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoAllow shim to handle multiple trusted certificates
Michael Brown [Tue, 13 Mar 2018 23:50:01 +0000 (23:50 +0000)]
Allow shim to handle multiple trusted certificates

Allow shim to perform verification against a list of trusted
certificates by simply concatenating the DER files.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
6 years agoAllow memory allocated by handle_image() to be freed
Michael Brown [Fri, 9 Mar 2018 17:51:09 +0000 (17:51 +0000)]
Allow memory allocated by handle_image() to be freed

There is currently no way for a caller of handle_image() to free the
memory allocated to hold the relocated executable.  Fix by adding the
allocated memory address and number of pages as returned parameters
from handle_image().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
6 years agoRemove global entry_point variable
Michael Brown [Fri, 9 Mar 2018 17:45:26 +0000 (17:45 +0000)]
Remove global entry_point variable

Treat entry_point as a returned parameter from handle_image(), rather
than using a global variable.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
6 years agoDo not modify original image
Michael Brown [Mon, 12 Mar 2018 20:31:37 +0000 (20:31 +0000)]
Do not modify original image

relocate_coff() currently modifies the PE header within the raw data.
This appears to be unnecessary, and causes a verification failure if a
second attempt is made to verify the same data buffer.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
6 years agoMokManager: stop using StrnCat
Hans de Goede [Tue, 13 Mar 2018 08:26:25 +0000 (09:26 +0100)]
MokManager: stop using StrnCat

StrnCat is not available in gnu-efi-3.0.5 (I did not check if it does
actually exists in 3.0.6). Moreover using strcat on a buffer where we've
just done: "buf[0] = '\0'" is a bit silly, we might as well drop the 0
termination and just use strcpy.

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

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
6 years agoconsole: Fix indentation
Hans de Goede [Tue, 13 Mar 2018 07:54:26 +0000 (08:54 +0100)]
console: Fix indentation

The manual merge of the "console: Do not set EFI console to textmode until
something is printed" patch has lead to a bunch of tabs being replaced
with 7 spaces. This commit fixes this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
6 years agoconsole: Do not set EFI console to textmode until something is printed
Hans de Goede [Mon, 12 Mar 2018 16:14:58 +0000 (17:14 +0100)]
console: Do not set EFI console to textmode until something is printed

Remove the setup_console(1) calls from shim and instead make lib/console.c
make that call when necessary. This avoids shim forcing the EFI console to
switch to text-mode if nothing is printed.

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

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
6 years agoconsole: Move setup_console() definition to higher in the file
Hans de Goede [Mon, 12 Mar 2018 16:02:59 +0000 (17:02 +0100)]
console: Move setup_console() definition to higher in the file

This is a preparation patch for making setup_console() private.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
6 years agoconsole: Add console_print and console_print_at helpers
Hans de Goede [Mon, 12 Mar 2018 15:03:38 +0000 (16:03 +0100)]
console: Add console_print and console_print_at helpers

This is a preparation commit for removing the setup_console(1) calls from
MokManager and shim so that we don't force the EFI console to switch to
text-mode.

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

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
6 years agoFix syntastic config for include/
Peter Jones [Mon, 12 Mar 2018 21:46:11 +0000 (17:46 -0400)]
Fix syntastic config for include/

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: Don't overwrite EFI_LOADED_IMAGE's LoadOptions when not needed
Tamas K Lengyel [Sun, 31 Dec 2017 18:03:26 +0000 (11:03 -0700)]
shim: Don't overwrite EFI_LOADED_IMAGE's LoadOptions when not needed

When the firmware is using EFI_LOAD_OPTION to specify options for the secondary
loader, the shim will properly detect that and return in set_second_stage. Later
howerer in handle_image EFI_LOADED_IMAGE is being overwritten with load_option
irrespective of the fact that load_option was never set. This effectively
prevents the EFI_LOAD_OPTION from reaching the secondary loader.

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

Signed-off-by: Tamas K Lengyel <lengyelt@ainfosec.com>
6 years agoMake EFI_INCLUDE path configurable during make
Tamas K Lengyel [Mon, 30 Oct 2017 21:18:12 +0000 (15:18 -0600)]
Make EFI_INCLUDE path configurable during make

Signed-off-by: Tamas K Lengyel <lengyelt@ainfosec.com>
6 years agoMake sure fallback.efi gets errlog.o as well
Peter Jones [Mon, 12 Mar 2018 20:26:07 +0000 (16:26 -0400)]
Make sure fallback.efi gets errlog.o as well

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix a minor merge error.
Peter Jones [Mon, 12 Mar 2018 20:23:49 +0000 (16:23 -0400)]
Fix a minor merge error.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: Make our variable validation and mirroring table driven.
Peter Jones [Wed, 18 Oct 2017 21:33:09 +0000 (17:33 -0400)]
shim: Make our variable validation and mirroring table driven.

This makes it so shim's idea of Mok variables all resides in one table
of data, and we don't need a bunch of nearly identical ad-hoc functions
to handle each of them.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: make everything use a common perror() call.
Peter Jones [Thu, 19 Oct 2017 19:57:32 +0000 (15:57 -0400)]
shim: make everything use a common perror() call.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: Improve the bounds checking of ImageAddress()
Peter Jones [Thu, 19 Oct 2017 17:45:58 +0000 (13:45 -0400)]
shim: Improve the bounds checking of ImageAddress()

Make ImageAddress() directly check for overflow in its math.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: main(): Don't save the value from mok_ignore_db()
Peter Jones [Thu, 19 Oct 2017 15:11:14 +0000 (11:11 -0400)]
shim: main(): Don't save the value from mok_ignore_db()

We don't really care if setting MokIgnoreDB fails; don't save the return.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: generate_hash(): make clang-analyzer not get confused.
Peter Jones [Thu, 19 Oct 2017 17:53:56 +0000 (13:53 -0400)]
shim: generate_hash(): make clang-analyzer not get confused.

clang-analyzer thinks that because we're not checking for NULL from
ImageAddress() it can be NULL, but doesn't realize we've already checked
that value once before.

Check it again, it can't hurt.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: Mitigate a minor clang-analyzer complaint.
Peter Jones [Wed, 18 Oct 2017 19:05:20 +0000 (15:05 -0400)]
shim: Mitigate a minor clang-analyzer complaint.

Clang believes "SumOfBytesHashed" is never used, because the thing that
uses that computed value is #if 0'd currently.

Just swizzle the #if's so that line is also not compiled.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: tpm.c: Make sure old_caps is initialized in tpm2 code.
Peter Jones [Wed, 18 Oct 2017 19:00:31 +0000 (15:00 -0400)]
shim: tpm.c: Make sure old_caps is initialized in tpm2 code.

clang-analyzer caught this.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoDon't use uefi_call_wrapper(), ever.
Peter Jones [Thu, 28 Sep 2017 18:11:51 +0000 (14:11 -0400)]
Don't use uefi_call_wrapper(), ever.

I'm pretty done with typing uefi_call_wrapper() and counting arguments
every time.  Instead, just make the compiler error if we don't have
ms_abi.  Also, make it so nothing can use uefi_call_wrapper() directly.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.
Peter Jones [Thu, 28 Sep 2017 16:23:17 +0000 (12:23 -0400)]
shim: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.

Also consistently name our status variable "efi_status" unless there's a
good reason not to, such as already having another one of those.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: relocate_coff(): get rid of "FixupData" stuff
Peter Jones [Thu, 28 Sep 2017 13:44:46 +0000 (09:44 -0400)]
shim: relocate_coff(): get rid of "FixupData" stuff

"FixupData" in the edk2 tree is a log of the relocations that happened,
which is allocated by the "client" calling relocate, and written into
while it does relocations.  Since we never allocate that log anywhere,
FixupData is always NULL, and so covscan says:

318                        case EFI_IMAGE_REL_BASED_HIGH:
319                                Fixup16   = (UINT16 *) Fixup;
320                                *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16)));
   null: At condition FixupData != NULL, the value of FixupData must be
   NULL.  dead_error_condition: The condition FixupData != NULL cannot
   be true.
321                                if (FixupData != NULL) {
   CID 182859 (#1 of 4): Logically dead code (DEADCODE)dead_error_begin:
   Execution cannot reach this statement: *((UINT16 *)FixupData) =
   *F....
322                                        *(UINT16 *) FixupData = *Fixup16;
323                                        FixupData             = FixupData + sizeof (UINT16);
324                                }
325                                break;

And it's right; all four occurrances are deadcode that never do anything
but confuse the reader.

Kill it with fire.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: check_db_cert_in_ram(): clear openssl errors /before/ returning.
Peter Jones [Wed, 27 Sep 2017 20:26:38 +0000 (16:26 -0400)]
shim: check_db_cert_in_ram(): clear openssl errors /before/ returning.

Covscan says:
455                                        if (IsFound) {
456                                                tpm_measure_variable(dbname, guid, CertSize, Cert->SignatureData);
457                                                return DATA_FOUND;
   CID 182850 (#1 of 1): Structurally dead code (UNREACHABLE)unreachable: This code cannot be reached: drain_openssl_errors();.
458                                                drain_openssl_errors();
459                                        } else {
460                                                LogError(L"AuthenticodeVerify(): %d\n", IsFound);
461                                        }

And, well... woops.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoshim: ensure generate_hash() never operates on a negative (signed) number.
Peter Jones [Wed, 27 Sep 2017 20:23:14 +0000 (16:23 -0400)]
shim: ensure generate_hash() never operates on a negative (signed) number.

Covscan noticed:
746static EFI_STATUS generate_hash (char *data, unsigned int datasize_in,
747                                 PE_COFF_LOADER_IMAGE_CONTEXT *context,
748                                 UINT8 *sha256hash, UINT8 *sha1hash)
749
750{
...
764
    CID 182849 (#1 of 1): Unsigned compared against 0
    (NO_EFFECT)unsigned_compare: This less-than-zero comparison of an
    unsigned value is never true. datasize_in < 0U.
765        if (datasize_in < 0) {
766                perror(L"Invalid data size\n");
767                return EFI_INVALID_PARAMETER;
768        }

And I guess that's a fair point, but some of the callers take the size
as a signed integer.  So we should be handling that on all the input
cases instead of getting that far.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: find_boot_options(): don't leak a file handle.
Peter Jones [Mon, 23 Oct 2017 19:01:53 +0000 (15:01 -0400)]
fallback: find_boot_options(): don't leak a file handle.

If we open it, we have to close it.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.
Peter Jones [Thu, 19 Oct 2017 19:05:18 +0000 (15:05 -0400)]
fallback: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.

Also consistently name our status variable "efi_status" unless there's a
good reason not to, such as already having another one of those.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: find_boot_options(): make the allocation path prettier.
Peter Jones [Wed, 27 Sep 2017 20:13:57 +0000 (16:13 -0400)]
fallback: find_boot_options(): make the allocation path prettier.

Covscan believes all this stuff:

 852                bs = 0;
 853                rc = uefi_call_wrapper(fh2->Read, 3, fh2, &bs, NULL);
    7. Condition rc == (9223372036854775813UL /* 0x8000000000000000UL | 5 */), taking false branch.
    8. Condition rc == 0, taking false branch.
    15. Condition rc == (9223372036854775813UL /* 0x8000000000000000UL | 5 */), taking false branch.
    16. Condition rc == 0, taking true branch.
    17. Condition bs != 0, taking true branch.
    30. Condition rc == (9223372036854775813UL /* 0x8000000000000000UL | 5 */), taking false branch.
    31. Condition rc == 0, taking false branch.
 854                if (rc == EFI_BUFFER_TOO_SMALL ||
 855                                (rc == EFI_SUCCESS && bs != 0)) {
 856                        buffer = AllocateZeroPool(bs);
    18. Condition !buffer, taking false branch.
 857                        if (!buffer) {
 858                                Print(L"Could not allocate memory\n");
 859                                /* sure, this might work, why not? */
 860                                uefi_call_wrapper(fh2->Close, 1, fh2);
 861                                uefi_call_wrapper(fh->Close, 1, fh);
 862                                return EFI_OUT_OF_RESOURCES;
 863                        }
 864
 865                        rc = uefi_call_wrapper(fh2->Read, 3, fh2, &bs, buffer);
 866                }
    9. Condition bs == 0, taking false branch.
    19. Condition bs == 0, taking false branch.
    32. Condition bs == 0, taking false branch.
 867                if (bs == 0)
 868                        break;
 869
    10. Condition (INTN)rc < 0, taking false branch.
    20. Condition (INTN)rc < 0, taking false branch.
    33. Condition (INTN)rc < 0, taking false branch.
 870                if (EFI_ERROR(rc)) {
 871                        Print(L"Could not read \\EFI\\: %d\n", rc);
 872                        if (buffer) {
 873                                FreePool(buffer);
 874                                buffer = NULL;
 875                        }
 876                        uefi_call_wrapper(fh2->Close, 1, fh2);
 877                        uefi_call_wrapper(fh->Close, 1, fh);
 878                        return rc;
 879                }
    34. alias_transfer: Assigning: fi = buffer.
 880                EFI_FILE_INFO *fi = buffer;
 881
    11. Condition !(fi->Attribute & 16), taking false branch.
    21. Condition !(fi->Attribute & 16), taking false branch.
    CID 182858 (#1-3 of 3): Explicit null dereferenced (FORWARD_NULL)35. var_deref_op: Dereferencing null pointer fi.
 882                if (!(fi->Attribute & EFI_FILE_DIRECTORY)) {
 883                        FreePool(buffer);
 884                        buffer = NULL;
 885                        continue;
 886                }

Because it doesn't know that when bs==0, fh2->Read() will return
EFI_BUFFER_TOO_SMALL and set bs to the size we need to allocate, so the
allocation path is always taken.  Instead, handle our exit/error paths
directly there, and make the allocation path nonconditional.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: find_boot_csv(): eliminate dead code.
Peter Jones [Wed, 27 Sep 2017 17:34:29 +0000 (13:34 -0400)]
fallback: find_boot_csv(): eliminate dead code.

Covscan sez:

720        FreePool(buffer);
   assignment: Assigning: buffer = NULL.
721        buffer = NULL;
722
723        CHAR16 *bootcsv=NULL, *bootarchcsv=NULL;
724
725        bs = 0;
726        do {
727                bs = 0;
728                rc = uefi_call_wrapper(fh->Read, 3, fh, &bs, NULL);
729                if (EFI_ERROR(rc) && rc != EFI_BUFFER_TOO_SMALL) {
730                        Print(L"Could not read \\EFI\\%s\\: %d\n", dirname, rc);
   null: At condition buffer, the value of buffer must be NULL.
   dead_error_condition: The condition buffer cannot be true.
731                        if (buffer)
   CID 182851 (#1 of 1): Logically dead code (DEADCODE)dead_error_line:
   Execution cannot reach this statement: FreePool(buffer);.
732                                FreePool(buffer);
733                        return rc;
734                }

And it's right; buffer can never be non-NULL there.  So just take that
out.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: find_boot_csv(): Print the error from try_boot_csv()
Peter Jones [Wed, 27 Sep 2017 17:25:31 +0000 (13:25 -0400)]
fallback: find_boot_csv(): Print the error from try_boot_csv()

Covscan believes the following:

 782        if ((EFI_ERROR(rc) || !bootarchcsv) && bootcsv) {
 783                EFI_FILE_HANDLE fh2;
 784                rc = uefi_call_wrapper(fh->Open, 5, fh, &fh2,
 785                                       bootcsv, EFI_FILE_READ_ONLY, 0);
 786                if (EFI_ERROR(rc) || fh2 == NULL) {
 787                        Print(L"Couldn't open \\EFI\\%s\\%s: %d\n",
 788                              dirname, bootcsv, rc);
 789                } else {
    CID 182829 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
    Assigning value from try_boot_csv(fh2, dirname, bootcsv) to rc here,
    but that stored value is overwritten before it can be used.
 790                        rc = try_boot_csv(fh2, dirname, bootcsv);
 791                        uefi_call_wrapper(fh2->Close, 1, fh2);
 792                }
 793        }
    value_overwrite: Overwriting previous write to rc with value 0UL.
 794        rc = EFI_SUCCESS;
 795
 796        return rc;
 797}

Which isn't untrue, we just don't happen to be using the return code for
anything, before we intentionally return success to our caller.

So that's annoying, but whatever.  Just print the error as well.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: read_file(): limit how big the file can be and still be valid
Peter Jones [Wed, 27 Sep 2017 17:15:13 +0000 (13:15 -0400)]
fallback: read_file(): limit how big the file can be and still be valid

Covscan says:

146        UINTN len = 0;
147        CHAR16 *b = NULL;
   2. tainted_data_argument: Calling function get_file_size taints argument len.
148        rc = get_file_size(fh2, &len);
   3. Condition (INTN)rc < 0, taking false branch.
149        if (EFI_ERROR(rc)) {
150                uefi_call_wrapper(fh2->Close, 1, fh2);
151                return rc;
152        }
153
   4. overflow_assign: Assigning overflowed or truncated value (or a value computed from an overflowed or a truncated value) to b.
   8. overflow: Add operation overflows on operands len and 2UL. Example value for operand: len = 18446744073709551614.
154        b = AllocateZeroPool(len + 2);

Technically we can't handle a file larger than 0xfffffffffffffffd (on
x86_64) because when we try to allocate the buffer to hold it with a
trailing UCS-2 NUL we overflow to 0.  Also our filesystem can't hold a
file bigger than 4GB...  So this is probably actually broken on 32-bit
platforms.

This patch limits it to some handy amount like 1024 * PAGE_SIZE, aka
4MB.

Note that this doesn't appear to be exploitable (at least on edk2-based
firmwares), because AllocateZeroPool() has a minimum granularity of 1
page, so even if you overflow it with a 4GB file, we'll get 1 page out
of it and then try to read 1 byte into it, and then it's just going to
be a parse error on the CSV.  Even if we error on the sentinal UCS-2 NUL
we put at the end, it'll still be inside of the zeroed page, and it still
won't fault or overwrite any meaningful data.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agofallback: handle buffer allocations for fh->GetInfo() prettier.
Peter Jones [Wed, 27 Sep 2017 17:05:16 +0000 (13:05 -0400)]
fallback: handle buffer allocations for fh->GetInfo() prettier.

At all the places we use fh->GetInfo, covscan can't tell that
fh->GetInfo() will return EFI_BUFFER_TOO_SMALL and we'll allocate on the
first try.

If we just explicitly check for "buffer == NULL" as well, covscan
believes we're doing work we don't need to (which is true!)

So instead, put an rc test to return error for everything else there, so
the allocation isn't in a conditional.

Yet another stupid one, but it's easier to nerf it this way than write
the false-positive rule, and it also hardens against incorrect UEFI
implementations (though we've not seen any yet with the problem this
avoids).

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: get rid of struct menu_item, it is unused.
Peter Jones [Mon, 23 Oct 2017 19:18:23 +0000 (15:18 -0400)]
MokManager: get rid of struct menu_item, it is unused.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: Fix a conditional on an uninitialized value in one error path.
Peter Jones [Wed, 18 Oct 2017 21:33:34 +0000 (17:33 -0400)]
MokManager: Fix a conditional on an uninitialized value in one error path.

clang-analyzer says:

MokManager.c:1431:6: warning: Branch condition evaluates to a garbage value
        if (mok)
            ^~~
MokManager.c:1433:6: warning: Branch condition evaluates to a garbage value
        if (del_key)
            ^~~~~~~

And it's right; if we take the first error exit in the function, those
never get initialized.  This patch sets them to NULL to begin with.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: handle mok parameter allocations better.
Peter Jones [Wed, 27 Sep 2017 18:17:20 +0000 (14:17 -0400)]
MokManager: handle mok parameter allocations better.

Covscan daftly claims:

288. var_compare_op: Comparing MokSB to null implies that MokSB might be null.
2330                if (MokSB) {
2331                        menu_strings[i] = L"Change Secure Boot state";
2332                        menu_item[i] = MOK_CHANGE_SB;
2333                        i++;
2334                }
2335
...
2358                choice = console_select(perform_mok_mgmt, menu_strings, 0);
2359                if (choice < 0)
2360                        goto out;
...
2362                switch (menu_item[choice]) {
...
2395                case MOK_CHANGE_SB:
    CID 182841 (#1 of 1): Dereference after null check
    (FORWARD_NULL)293. var_deref_model: Passing null pointer MokSB to
    mok_sb_prompt, which dereferences it. [show details]
2396                        efi_status = mok_sb_prompt(MokSB, MokSBSize);

Which is, of course, entirely false, beause for menu_item[choice] to be
MOK_CHANGE_SB, MokSB must be !NULL.  And then:

    252. Condition efi_status == 0, taking true branch.
2397                        if (efi_status == EFI_SUCCESS)
2398                                MokSB = NULL;

This guarantees it won't be in the list the next time through the loop.

This adds tests for NULLness before mok_sb_prompt(), just to make it
more clear to covscan what's going on.

Also do the same thing for all of:
MOK_CHANGE_SB
MOK_SET_PW
MOK_CHANGE_DB
MOK_ENROLL_MOKX
MOK_DELETE_MOKX

I also Lindent-ed everything I had to touch.

Three other minor errors are also fixed:
1) the loop in enter_mok_menu() leaked the menu allocations each time
   through the loop
2) mok_sb_prompt(), mok_pw_prompt(), and mok_db_prompt() all call
   FreePool() on their respective variables (MokSB, etc), and
   check_mok_request() also calls FreePool() on these.  This sounds
   horrible, but it turns out it's not an issue, because they only free
   them in their EFI_SUCCESS paths, and enter_mok_menu() resets the
   system if any of the mok_XX_prompt() calls actually returned
   EFI_SUCCESS, so we never get back to check_mok_request() for it to do
   its FreePool() calls.
3) the loop in enter_mok_menu() winds up introducing a double free in
   the call to free_menu(), but we also can't hit this bug, because all
   the exit paths from the loop are "goto out" (or return error) rather
   than actually exiting on the loop conditional.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: use EFI_ERROR() instead of comparing to EFI_SUCCESS.
Peter Jones [Wed, 27 Sep 2017 19:19:59 +0000 (15:19 -0400)]
MokManager: use EFI_ERROR() instead of comparing to EFI_SUCCESS.

Also consistently name our status variable "efi_status" unless there's a
good reason not to, such as already having another one of those.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: check_der_suffix(): use StrnCat() on our suffix checker.
Peter Jones [Wed, 27 Sep 2017 14:17:45 +0000 (10:17 -0400)]
MokManager: check_der_suffix(): use StrnCat() on our suffix checker.

We know it's legit already because we computed the pointer from the end,
but covscan gets confused, and we have StrnCat, so we should just use it
anyway.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMokManager: Lindent (and other reformats) the whole file.
Peter Jones [Tue, 26 Sep 2017 21:50:11 +0000 (17:50 -0400)]
MokManager: Lindent (and other reformats) the whole file.

I'm just tired of all the little quirks.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib/shell.c: minor cleanup
Peter Jones [Mon, 12 Mar 2018 20:00:44 +0000 (16:00 -0400)]
lib/shell.c: minor cleanup

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib/simple_file.c: minor cleanup
Peter Jones [Mon, 12 Mar 2018 20:03:26 +0000 (16:03 -0400)]
lib/simple_file.c: minor cleanup

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.
Peter Jones [Thu, 19 Oct 2017 19:02:41 +0000 (15:02 -0400)]
lib: Use EFI_ERROR() instead of comparing to EFI_SUCCESS everywhere.

Also consistently name our status variable "efi_status" unless there's a
good reason not to, such as already having another one of those.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib: find_in_variable_esl(): Fix a tiny nitpick clang-analyze has.
Peter Jones [Thu, 19 Oct 2017 17:22:23 +0000 (13:22 -0400)]
lib: find_in_variable_esl(): Fix a tiny nitpick clang-analyze has.

clang-analyze believes the following:

311 EFI_STATUS
312 variable_enroll_hash(CHAR16 *var, EFI_GUID owner,
313      UINT8 hash[SHA256_DIGEST_SIZE])
314 {
315 EFI_STATUS efi_status;
316
317 efi_status = find_in_variable_esl(var, owner, hash, SHA256_DIGEST_SIZE);
>               Calling 'find_in_variable_esl' →

260 EFI_STATUS
261 find_in_variable_esl(CHAR16* var, EFI_GUID owner, UINT8 *key, UINTN keylen)
262 {
263 UINTN DataSize;
264 UINT8 *Data;
>               ← 'Data' declared without an initial value →
265 EFI_STATUS efi_status;
266
267 efi_status = get_variable(var, &Data, &DataSize, owner);
>               ← Calling 'get_variable' →

237 EFI_STATUS
238 get_variable(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner)
239 {
240 return get_variable_attr(var, data, len, owner, NULL);
> ← Calling 'get_variable_attr' →

213 EFI_STATUS
214 get_variable_attr(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner,
215   UINT32 *attributes)
216 {
217 EFI_STATUS efi_status;
218
219 *len = 0;
220
221 efi_status = GetVariable(var, &owner, NULL, len, NULL);
> ← Calling 'GetVariable' →
> ← Returning from 'GetVariable' →
222 if (efi_status != EFI_BUFFER_TOO_SMALL)
> ← Assuming the condition is true →
> ← Taking true branch →
223 return efi_status;
224
225 *data = AllocateZeroPool(*len);
226 if (!*data)
227 return EFI_OUT_OF_RESOURCES;
228
229 efi_status = GetVariable(var, &owner, attributes, len, *data);
230 if (EFI_ERROR(efi_status)) {
231 FreePool(*data);
232 *data = NULL;
233 }
234 return efi_status;
235 }

And it can't figure out that the first GetVariable() call will, in fact,
always return EFI_BUFFER_TOO_SMALL, and that AllocateZeroPool() will
then *correctly* clobber the two variables we never assigned the value
from.  It also then believes that efi_status might have been returned
/without/ being an error, and thinks that means we'll use the
uninitialized pointer.

This won't happen, but hey, let's make the code better express to the
checker what is intended.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib: simple_file_selector(): remove some dead code.
Peter Jones [Thu, 19 Oct 2017 17:19:34 +0000 (13:19 -0400)]
lib: simple_file_selector(): remove some dead code.

clang-analyzer correctly believes this:

465                             int i;
466
467 i = StrLen(name) - 1;

                                ^ Value stored to 'i' is never read

468
469 for (i = StrLen(name); i > 0; --i) {
470 if (name[i] == '\\')
471 break;
472 }

And it's right; that's completely dead code.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib: simple_file_selector(): simplify the error path to confuse covscan less.
Peter Jones [Wed, 27 Sep 2017 17:45:21 +0000 (13:45 -0400)]
lib: simple_file_selector(): simplify the error path to confuse covscan less.

Because they don't believe code should be defensive against future
changes, covscan believes:

520 out_free:
521        FreePool(dmp);
   CID 182824 (#1 of 1): Dereference before null check
   (REVERSE_INULL)check_after_deref: Null-checking entries suggests that
   it may be null, but it has already been dereferenced on all paths
   leading to the check.
522        if (entries) {
523                free_entries(entries, count);
524                FreePool(entries);
525        }
526 out_free_name:
527        FreePool(name);
528}

Which is technically correct, but still kind of dumb.  So this patch
combines the two error out paths into just being out_free, so that the
first path there is before entries is allocated.  (It also initializes
dmp to NULL and checks that before freeing it.)

I also Lindent-ed that function.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoUse gcc's offsetof() instead of hacking out our own.
Peter Jones [Mon, 23 Oct 2017 19:25:14 +0000 (15:25 -0400)]
Use gcc's offsetof() instead of hacking out our own.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoCryptLib: Add the AsciiStrCpy() decl.
Peter Jones [Fri, 20 Oct 2017 15:37:37 +0000 (11:37 -0400)]
CryptLib: Add the AsciiStrCpy() decl.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoGet rid of all the places we cast to (CHAR16 *[])
Peter Jones [Tue, 26 Sep 2017 22:10:44 +0000 (18:10 -0400)]
Get rid of all the places we cast to (CHAR16 *[])

Lindent gets confused by these, and they're hard to read anyway.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoFix some "if (x < 0)" tests where x is UINTN.
Peter Jones [Tue, 26 Sep 2017 22:16:26 +0000 (18:16 -0400)]
Fix some "if (x < 0)" tests where x is UINTN.

Obviously, these are not correct.  Most of them are just useless; one
can be changed to a more useful test.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoDon't have tons of local guid definitions for no reason at all.
Peter Jones [Thu, 19 Oct 2017 18:43:18 +0000 (14:43 -0400)]
Don't have tons of local guid definitions for no reason at all.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agolib/variables.c: reformat CreateTimeBasedPayload()
Peter Jones [Fri, 27 Oct 2017 13:49:06 +0000 (09:49 -0400)]
lib/variables.c: reformat CreateTimeBasedPayload()

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoClean up efiauthenticated.h a lot.
Peter Jones [Mon, 23 Oct 2017 17:30:11 +0000 (13:30 -0400)]
Clean up efiauthenticated.h a lot.

Signed-off-by: Peter Jones <pjones@redhat.com>
6 years agoMake sure all of our include files have proper guards.
Peter Jones [Mon, 23 Oct 2017 18:26:28 +0000 (14:26 -0400)]
Make sure all of our include files have proper guards.

... and make them all the same formatting too.

Signed-off-by: Peter Jones <pjones@redhat.com>