Commit Graph

14 Commits

Author SHA1 Message Date
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
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
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
Peter Jones
63f7943dbe mirror_one_mok_variable(): round allocation up to a full page
The code currently computes the size of the MoK variable in ram and
rounds up to a full page, but then actually allocates the exact size,
rather than the rounded up version.  This should be completely safe, but
the intent was to round up to at least the page size boundary, and to
always guarantee rounding up /some/, to ensure extra 0-bytes at the end
of the buffer.

Signed-off-by: Peter Jones <pjones@redhat.com>
2020-08-04 12:49:30 -04:00
Peter Jones
65be350308 Implement lennysz's suggestions for MokListRT
Signed-off-by: Peter Jones <pjones@redhat.com>
2020-07-25 22:14:08 -04:00
Peter Jones
fecc2dfb8e Also use a config table to mirror mok variables.
Everything was going just fine until I made a vendor_db with 17kB of
sha256 sums in it.  And then the same source tree that had worked fine
without that threw errors and failed all over the place.  I wrote some
code to diagnose the problem, and of course it was a failure in
mirroring MokList to MokListRT.

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

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

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

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

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

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

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

The config table is a packed array of this struct:

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

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

It's installed with this guid:

c451ed2b-9694-45d3-baba-ed9f8988a389

Anything that can go wrong will.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream: not yet, I don't want people to read this before Wednesday.
Signed-off-by: Peter Jones <pjones@redhat.com>
2020-07-25 22:14:08 -04:00
Peter Jones
dd3a5d7125 Add support for vendor_db built-in shim authorized list.
Potential new signing strategies ( for example signing grub, fwupdate
and vmlinuz with separate certificates ) require shim to support a
vendor provided bundle of trusted certificates and hashes, which allows
shim to trust EFI binaries matching either certificate by signature or
hash in the vendor_db.  Functionality is similar to vendor_dbx.

This also improves the mirroring quite a bit.
Upstream: pr#206
2020-07-23 22:22:04 -04:00
Peter Jones
e8a04c1d84 Remove a couple of incorrect license claims.
A certain someone's default editor template leaked in to a couple of
source files, and claims they're GPL licensed.  They're not.

Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 476cbff1110
2020-07-23 20:53:24 -04:00
Peter Jones
ff890cf452 mok: minor cleanups
Signed-off-by: Peter Jones <pjones@redhat.com>
Upstream-commit-id: 617b9007668
2020-07-23 20:52:12 -04:00
Gary Lin
3d62232feb 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
2020-07-23 20:52:12 -04:00
Peter Jones
ff6e5cda13 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
2020-07-23 20:52:12 -04:00
Gary Lin
f748139695 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
2020-07-23 20:52:12 -04:00
Patrick Uiterwijk
ac0400b202 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
2020-07-23 20:52:12 -04:00
Peter Jones
4181a16f62 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>
2018-03-12 16:21:43 -04:00