summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2021-03-09Don't use WCHAR even when we're assigning wide string literalsPeter Jones
Note that there are still some occurrences of WCHAR in Cryptlib/OpenSSL/, but they're only built on win32 platforms we don't support. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09Switch to using -std=gnu11Peter Jones
There's no actual reason we're using -std=gnu89, but it means we get the "gnu89-inline" semantics, which we would prefer to have to specify manually when we want it, if ever, which so far we don't. This also allows us to use some saner syntax without having to nerf various -W options and similar later, and enables some language features that are pretty useful, but that's just icing. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09More minor makefile cleanupsPeter Jones
This patch does some makefile cleanups, to fix the parts that are actually just bad that the previous patch left in for clarity: - removes -fno-builtin . This flag is implied by -ffreestanding , which we use everywhere. - gets rid of the two places where ARM has their own -O flags for no real reason. Note that this will make those use -Os instead of -O2. - export VERBOSE and DEBUG if they're set. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09static analysis: make our build targets work betterPeter Jones
This improves our static analysis targets by making them work better with our make variables, and inhibits the use of ccache while building those. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09Minor OpenSSL fixesPeter Jones
These are all the NULL pointer dereferences (which all appear to be, at worst, very difficult to hit) that gcc -fanalyzer finds in our OpenSSL code. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09Re-organize a bunch of CFLAGS-related makefile bitsPeter Jones
Some of our makefile bits are a mess, as you may have noticed, making changes to them difficult to review. This patch attempts to make some parts of them vaguely less of a mess, in order to facilitate review of follow-up changes. To so it: - coalesces feature flags, optimizations, -W{no-,}, -W{no-}error, include directives, and define/undefine directives into (mostly) separate groups. - exports them as appropriate so the sub-makes can use them - Makes sure we have -Wextra -Werror everywhere, but adds -Wno-foo and -Wno-error=foo directives at the appropriate places to keep the net warnings the same. - makes the arch defines in Cryptlib and Cryptlib/OpenSSL use the appropriate ones, with no attempt to make them less stupid, without changing the overall order. - coalesces the various includes, with no attempt to make them less stupid, without changing the overall order. - One giant glaring whitespace fix in Cryptlib/OpenSSL/Makefile Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09CI: show our compilation when it failsPeter Jones
We've been using "make -s", silent mode, which doesn't show us what commands were invoked. Silent make means we can't see what goes wrong when the wrong compiler or linker is getting invoked, or when it's being invoked wrong. This changes the CI to run it again without -s when it fails. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09CI: try to update submodulesPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-09Set the section flags for .sbatGary Lin
When using "objcopy -O binary", it silently drops the sections without "alloc" or "load" or the sections with "unload". Since we didn't set any section flags for .sbat, it just contains the "readonly" flag and objcopy ignored the section totally when generating EFI images for ARM32 and AArch64. This commit sets the common read-only data section flags to .sbat so that objcopy would always copy the section to the final EFI image. Signed-off-by: Gary Lin <glin@suse.com>
2021-03-09Add get_variable_size()/set_variable()del_variable() wrappers.Peter Jones
This get_variable_size() implementation success in either of two cases: - EFI_SUCCESS with *lenp == 0 if the variable isn't found - EFI_SUCCESS with *lenp > 0 on success In the event of other errors, it returns them to you. There's nothing particularly interesting about the set_variable() or del_variable() implementation here. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-03-06Restore loaded image of shim at Exit()Gary Lin
When grub2 invoked Exit() in AArch64 AAVMF, the VM crashed with the following messsages: Unloading driver at 0x000B7D7B000 Synchronous Exception at 0x00000000BF5D5E68 AllocatePool: failed to allocate 800 bytes Synchronous Exception at 0x00000000BF5D5E68 The similar error also showed when I modified MokManager to call gBS->Exit() at the end of efi_main(). However, if MokManager just returned, the error never showed. One significant difference is whether the loaded image was restored or not, and the firmware seems to need the original ImageBase pointer to do clean-up. To avoid the potential crash, this commit adds restore_loaded_image() so that we can restore the loaded image both in start_image() and do_exit(). Signed-off-by: Gary Lin <glin@suse.com>
2021-02-25Fix column size check in SBAT variable parsing.Thomas Frauendorfer | Miray Software
Fix a typo that inverted the check that validates that a CSV column is not empty. Signed-off-by: Thomas Frauendorfer | Miray Software <tf@miray.de>
2021-02-25sbat: Don't assume VirtualSize == SizeOfRawDataChris Coulson
The current code rejects the .sbat section if the VirtualSize and SizeOfRawData fields of the section header aren't the same, but this is too strict. The VirtualSize corresponds to the size of the SBAT metadata and isn't necessarily a multiple of the file alignment. The on-disk size (SizeOfRawData) is a multiple of the file alignment and is zero padded. Make sure that the on-disk size is at least as large as virtual size, and ignore the .sbat section if it isn't. This should fix https://github.com/rhboot/shim/issues/281. Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
2021-02-25SBAT: update the raw Markdown to look less terriblePaul Moore
The raw text of the SBAT.md file is a bit of a mess, this patch attempts to introduce some consistentcy to the text without affecting the rendered Markdown. The only content change was the addition of a missing period ('.') at the end of sentence/paragraph; all of the other changes were purely formatting changes. Signed-off-by: Paul Moore <pmoore2@cisco.com>
2021-02-25SBAT: fix some typos in the SBAT docsPaul Moore
Signed-off-by: Paul Moore <pmoore2@cisco.com>
2021-02-25sbat: fix the residual "resource section" for SBATGary Lin
Signed-off-by: Gary Lin <glin@suse.com>
2021-02-25Fix two errant 'shim,0' outdated sbat cases.Peter Jones
Two places we missed still have 0 for an sbat version - one doc and one in our data csv. This fixes those. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25sbat: fix the gcc warningsGary Lin
This commit fixes the following gcc warnings for casting. sbat.c: In function 'verify_single_entry': sbat.c:157:13: error: pointer targets in passing argument 1 of 'strcmp' differ in signedness [-Werror=pointer-sign] if (strcmp(entry->component_name, sbat_var_entry->component_name) == 0) { ^~~~~ In file included from Cryptlib/Include/string.h:15:0, from sbat.c:7: Cryptlib/Include/OpenSslSupport.h:299:16: note: expected 'const char *' but argument is of type 'const CHAR8 * {aka const unsigned char *}' int strcmp (const char *, const char *); ^~~~~~ sbat.c:157:36: error: pointer targets in passing argument 2 of 'strcmp' differ in signedness [-Werror=pointer-sign] if (strcmp(entry->component_name, sbat_var_entry->component_name) == 0) { ^~~~~~~~~~~~~~ In file included from Cryptlib/Include/string.h:15:0, from sbat.c:7: Cryptlib/Include/OpenSslSupport.h:299:16: note: expected 'const char *' but argument is of type 'const CHAR8 * {aka const unsigned char *}' int strcmp (const char *, const char *); ^~~~~~ sbat.c:165:19: error: pointer targets in passing argument 1 of 'AsciiStrDecimalToUintn' differ in signedness [-Werror=pointer-sign] sbat_gen = atoi(entry->component_generation); ^ Cryptlib/Include/OpenSslSupport.h:380:66: note: in definition of macro 'atoi' #define atoi(nptr) AsciiStrDecimalToUintn(nptr) ^~~~ In file included from Cryptlib/Include/OpenSslSupport.h:21:0, from Cryptlib/Include/string.h:15, from sbat.c:7: Cryptlib/Library/BaseLib.h:9:7: note: expected 'const char *' but argument is of type 'const CHAR8 * {aka const unsigned char *}' UINTN AsciiStrDecimalToUintn(const char *String); ^~~~~~~~~~~~~~~~~~~~~~ In file included from Cryptlib/Include/string.h:15:0, from sbat.c:7: sbat.c:166:23: error: pointer targets in passing argument 1 of 'AsciiStrDecimalToUintn' differ in signedness [-Werror=pointer-sign] sbat_var_gen = atoi(sbat_var_entry->component_generation); ^ Cryptlib/Include/OpenSslSupport.h:380:66: note: in definition of macro 'atoi' #define atoi(nptr) AsciiStrDecimalToUintn(nptr) ^~~~ In file included from Cryptlib/Include/OpenSslSupport.h:21:0, from Cryptlib/Include/string.h:15, from sbat.c:7: Cryptlib/Library/BaseLib.h:9:7: note: expected 'const char *' but argument is of type 'const CHAR8 * {aka const unsigned char *}' UINTN AsciiStrDecimalToUintn(const char *String); ^~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [<builtin>: sbat.o] Error 1 Signed-off-by: Gary Lin <glin@suse.com>
2021-02-25Make verify_sbat() more testablePeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Fix-up and enable a bunch of .sbat section parsing tests.Peter Jones
This brings all the tests Chris Co wrote about parsing the .sbat section back. Some of the actual test functions became redundant, and some new ones were needed, but all of the actual test cases should be represented here. Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Add initial sbat unit testing codeChris Co
[currently #if 0'd to oblivion by pjones] Signed-off-by: Chris Co <chrco@microsoft.com>
2021-02-25Add test cases for our CSV parser.Peter Jones
This does a couple of straightforward tests on our CSV parser, and then for good measure it does two with random data - one that's just random data, one that's had all the zeros changed to nonzero values. Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Add a tester for our string functions.Peter Jones
Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25make 'make test' able to run unit test harnessesPeter Jones
This adds a couple of make targets to do unit tests that are linked to libc: test-FOO : builds and runs test-FOO for any test-FOO.c test : builds and runs all test-FOO tests Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25SBAT: make our SBAT variable parser use the CSV parserPeter Jones
This makes our SBAT variable parser use the generic CSV parser, and also changes its API slightly to produce a more testable intermediate interface. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25SBAT: make our sbat section parser use the csv parserPeter Jones
This makes the .sbat section parser use parse_csv_data(). It also re-names a couple of the structs, because they were still too easy to get lost in. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Add a stand-alone CSV parser.Peter Jones
This adds a simple to use, one-function-call CSV parser that takes a blob of data and gives you a linked list with an array of values. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Fix our debuginfo paths hopefullyPeter Jones
2021-02-25includes: include all gnu-efi includes at one place.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Move is_utf8_bom() to str.hPeter Jones
This moves is_utf8_bom() to str.h, and also adds two #defines, UTF8_BOM and UTF8_BOM_SIZE. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Add a list_size() primitivePeter Jones
This adds list_size(), which tells us how many elements are in a list. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Tidy up our string primitives...Peter Jones
This adds constraints some of our compilers can check to all of our string primitives, as well as adding implementations of: - strdup - strdup - stpcpy - stpcpy - strnchrnul - strchrnul with a limit - strntoken - a tokenizer Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Fix all the places we need UNUSED on arguments.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25compiler.h: fix a typo and add some more function attribute macrosPeter Jones
This fixes the ifndef guard on NONNULL and __CONCAT3 and adds definitions for: - __CONCAT() for a##b with the intermediate tokenization step - ALLOCFUNC for __malloc__ - DEPRECATED for __deprecated__ - PURE for __pure__ - RETURNS_NONNULL for __nonnull__ Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Make 'make fanalyzer' targetsPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-25Move the coverity and scan-build makefiles out of the top directoryPeter Jones
I'm adding even more of this stuff, and it's feeling pretty cluttered, so this moves the scan-build and coverity makefiles into include/, where we'll see them less. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-22SBAT: mirror SBAT to SbatRT and extend to PCR7 + logPeter Jones
This adds SBAT to our table of variables to mirror with our MoK state. Currently it mirrors "SBAT" to a variable named "SbatRT", both using the SHIM GUID. Currently we enforce the current policy WRT these variables: - we always delete SbatRT if it's present, for a couple of reasons: - If we got here either something created it before us during boot, which isn't a thing we believe anything should be doing, or it's an NV variable, which it shouldn't be. - we want to raise the error if it's NV+Authenticated - we always delete SBAT (and do not mirror it) if it either - doesn't have BS|NV set or - does have RT set - we're requiring !RT because we can't actually tell if it's an authenticated variable or not, and we want to get the error if RT is set and it is authenticated, because that means we've lost the race between us and an attacker to create it. - we always measure SBAT into PCR7 and add a log extension with the measured hash Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-22Document struct mok_state_variable better.Peter Jones
Add a pile of documentation comments to help remember what all the fields in our mok mirroring structure do. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-22tpm: minor cleanup: use EV_IPL not 0xdPeter Jones
This does two things: - consolidates all our TPM event type #defines to one place - uses EV_IPL instead of hard-coding 0xd Signed-off-by: Peter Jones <pjones@redhat.com>
2021-02-22Drop --set-section-alignment from Makefile since linker ALIGN(4096)Jan Setje-Eilers
already enforces the alignment, clarify that objcopy only needs to do the alignment in the SBAT spec.
2021-02-22Fix bashisms in Make.coveritySteve McIntyre
Not everybody uses bash as /bin/sh, and the scripting here is safe just using single brackets. Signed-off-by: Steve McIntyre <93sam@debian.org>
2021-02-21Change changelog to shut lintian upSteve McIntyre
2021-02-21Remove artifacts that upstream installs that we don't useSteve McIntyre
... to keep debhelper from complaining
2021-02-21Add new patch cast-CHAR8-string-handling.patchSteve McIntyre
Cast CHAR8 strings to use (const char *) when using string functions Looks like gnu-efi definitions of CHAR8 are problematic
2021-02-21Trivial change to remove bashisms in Make.coveritySteve McIntyre
2021-02-21Remove all our old patches, no longer needed:Steve McIntyre
- avoid_null_vsprint.patch - check_null_sn_ln.patch - fixup_git.patch - uname.patch - use_compare_mem_gcc9.patch
2021-02-21Switch to using gcc-10 rather than gcc-9. Closes: #978521Steve McIntyre
2021-02-21Switch to newer upstream "release" 15+1613861442.888f5b5Steve McIntyre
Many many updates, but caring mainly about SBAT support
2021-02-21Update upstream source from tag 'upstream/15+1613861442.888f5b5'Steve McIntyre
Update to upstream version '15+1613861442.888f5b5' with Debian dir 15b0853a73144b1f8571ce2bebc2eea68af4a8e3
2021-02-20Add --set-section-alignment '.sbat=512' to objcopy command lineupstream/15+1613861442.888f5b5Jan Setje-Eilers