Commit Graph

9566 Commits

Author SHA1 Message Date
Andrew Jeddeloh 93fb3dac4a
Merge pull request #53 from lucab/ups/suse-tpm
loader/i386: fix out of bound memory copy on non-UEFI linux
2018-04-09 16:10:40 -07:00
Luca Bruno 03e5ce1441
loader/i386: fix out of bound memory copy on non-UEFI linux
Ref: https://bugzilla.opensuse.org/show_bug.cgi?id=1029187
Ref: https://build.opensuse.org/package/rdiff/openSUSE:Factory/grub2?linkrev=base&rev=159
2018-04-09 17:58:38 +00:00
David Michael f8e0a62fba
Merge pull request #51 from dm0-/2.02-coreos
Make our GRUB fork maintainable
2018-04-02 19:53:12 -04:00
Dennis Chen 81911402ce Remove the deprecated 'Event' struct
'Event' struct will be not used any more, instead we use the
'TCG_PCR_EVENT', so this patch remove the older 'Event' data struct.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
2018-03-29 22:18:54 -04:00
Dennis Chen 1e08408cde Fix the build issue in TPM module
The original code use deprecated 'Event' data structure with the wrong
member variable names, which result in the build error. This patch
fix it by using 'TCG_PCR_EVENT'.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
2018-03-29 22:18:54 -04:00
Dennis Chen 0f7291e018 Prototype fixing for (*hash_log_extend_event)
According to the section 6.6.1 'Prototype' in 'TCG EFI Protocol Spec',
the 3rd parameter of the (*hash_log_extend_event) should be
'EFI_PHYSICAL_ADDRESS' which is 'grub_efi_physical_address_t' in the
real implementation. So this patch drop the pointer mark '*' from this
prototype.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
2018-03-29 22:18:54 -04:00
1337ninja fefd7d6acf Fix use after free 2018-03-29 22:18:54 -04:00
Benjamin Gilbert 3626296357 Fix missing VERITY_HASH_OFFSET on amd64 2018-03-29 22:18:54 -04:00
Geoff Levand df45313e15 loader: Add arm64 verity
Signed-off-by: Geoff Levand <geoff@infradead.org>
2018-03-29 22:18:54 -04:00
Geoff Levand 330cb8e74d loader: Move verity-hash.h to include
Signed-off-by: Geoff Levand <geoff@infradead.org>
2018-03-29 22:18:54 -04:00
Geoff Levand e7254abd7d loader: verity-hash.h fixups
o Add some comments.
o Change image buffer type to (const void *).
o Add new macro VERITY_CMDLINE_LENGTH.

Signed-off-by: Geoff Levand <geoff@infradead.org>
2018-03-29 22:18:54 -04:00
Michael Marineau 2b62e81a73 loader: add support for passing verity hash to xen kernels
This only supports DomU Linux bzImage, ignoring bare ELF images and
Dom0 Xen+Linux but those cases are not applicable to us on CoreOS.
2018-03-29 22:18:54 -04:00
Michael Marineau 55dd139eda loader: validate cmdline string length before appending verity arg 2018-03-29 22:18:54 -04:00
Matthew Garrett 976501a7d4 Make TPM errors less fatal
Handle TPM errors, and stop trying to use the TPM once we hit one.
2018-03-29 22:18:54 -04:00
Michael Marineau eb28d32081 gpt: write backup GPT first, skip if inaccessible.
Writing the primary GPT before the backup may lead to a confusing
situation: booting a freshly updated system could consistently fail and
next boot will fall back to the old system if writing the primary works
but writing the backup fails. If the backup is written first and fails
the primary is left in the old state so the next boot will re-try and
possibly fail in the exact same way. Making that repeatable should make
it easier for users to identify the error.

Additionally if the firmware and OS disagree on the disk size, making
the backup inaccessible to GRUB, then just skip writing the backup.
When this happens the automatic call to `coreos-setgoodroot` after boot
will take care of repairing the backup.
2018-03-29 22:18:54 -04:00
Michael Marineau 176fe49cf0 gpt: rename and update documentation for grub_gpt_update
The function now does more than just recompute checksums so give it a
more general name to reflect that.
2018-03-29 22:18:54 -04:00
Michael Marineau edd01f055a gpt: report all revalidation errors
Before returning an error that the primary or backup GPT is invalid push
the existing error onto the stack so the user will be told what is bad.
2018-03-29 22:18:54 -04:00
Michael Marineau 7b25acebc3 gpt: read entries table at the same time as the header
I personally think this reads easier. Also has the side effect of
directly comparing the primary and backup tables instead of presuming
they are equal if the crc32 matches.
2018-03-29 22:18:54 -04:00
Michael Marineau f19f5cc49d gpt: include backup-in-sync check in revalidation 2018-03-29 22:18:54 -04:00
Michael Marineau 285368e375 gpt: always revalidate when recomputing checksums
This ensures all code modifying GPT data include the same sanity check
that repair does. If revalidation fails the status flags are left in the
appropriate state.
2018-03-29 22:18:54 -04:00
Michael Marineau f1f618740d gpt: selectively update fields during repair
Just a little cleanup/refactor to skip touching data we don't need to.
2018-03-29 22:18:54 -04:00
Michael Marineau 753dd92013 gpt: be more careful about relocating backup header
The header was being relocated without checking the new location is
actually safe. If the BIOS thinks the disk is smaller than the OS then
repair may relocate the header into allocated space, failing the final
validation check. So only move it if the disk has grown.

Additionally, if the backup is valid then we can assume its current
location is good enough and leave it as-is.
2018-03-29 22:18:54 -04:00
Michael Marineau 34652e500d gpt: check header and entries status bits together
Use the new status function which checks *_HEADER_VALID and
*_ENTRIES_VALID bits together. It doesn't make sense for the header and
entries bits to mismatch so don't allow for it.
2018-03-29 22:18:54 -04:00
Michael Marineau 2aeadda529 gpt: do not use an enum for status bit values 2018-03-29 22:18:54 -04:00
Michael Marineau 38cc185319 gpt: allow repair function to noop
Simplifies usage a little.
2018-03-29 22:18:54 -04:00
Michael Marineau a794435ae9 gpt: use inline functions for checking status bits
This should prevent bugs like 6078f836 and 4268f3da.
2018-03-29 22:18:54 -04:00
Michael Marineau 4af1d7a8b7 gptrepair: fix status checking
None of these status bit checks were correct. Fix and simplify.
2018-03-29 22:18:54 -04:00
Vito Caputo 2ed905dc03 gpt: add helper for picking a valid header
Eliminate some repetition in primary vs. backup header acquisition.
2018-03-29 22:18:54 -04:00
Michael Marineau 1d358a2061 gpt: prefer disk size from header over firmware
The firmware and the OS may disagree on the disk configuration and size.
Although such a setup should be avoided users are unlikely to know about
the problem, assuming everything behaves like the OS. Tolerate this as
best we can and trust the reported on-disk location over the firmware
when looking for the backup GPT. If the location is inaccessible report
the error as best we can and move on.
2018-03-29 22:18:54 -04:00
Michael Marineau 72b178950d gpt: fix partition table indexing and validation
Portions of the code attempted to handle the fact that GPT entries on
disk may be larger than the currently defined struct while others
assumed the data could be indexed by the struct size directly. This
never came up because no utility uses a size larger than 128 bytes but
for the sake of safety we need to do this by the spec.
2018-03-29 22:18:54 -04:00
Michael Marineau 3a3e45823d fix checking alternate_lba 2018-03-29 22:18:54 -04:00
Michael Marineau d457364d1d gptprio_test: check GPT is repaired when appropriate 2018-03-29 22:18:54 -04:00
Michael Marineau 9af98c2bfd gptrepair_test: fix typo in cleanup trap 2018-03-29 22:18:54 -04:00
Michael Marineau 297b317850 tpm: fix warnings when compiling for platforms other than pc and efi 2018-03-29 22:18:54 -04:00
Michael Marineau b1ef48849c gpt: properly detect and repair invalid tables
GPT_BOTH_VALID is 4 bits so simple a boolean check is not sufficient.
This broken condition allowed gptprio to trust bogus disk locations in
headers that were marked invalid causing arbitrary disk corruption.
2018-03-29 22:18:54 -04:00
Michael Marineau 2cb9b7fcaa fwconfig: fix unused argument warning 2018-03-29 22:18:53 -04:00
Michael Marineau fa18d3a292 gpt: refuse to write to sector 0 2018-03-29 22:18:53 -04:00
Michael Marineau f6b89ec315 gpt: improve validation of GPT headers
Adds basic validation of all the disk locations in the headers, reducing
the chance of corrupting weird locations on disk.
2018-03-29 22:18:53 -04:00
Michael Marineau 99959fa2fb gpt: add verbose debug logging 2018-03-29 22:18:53 -04:00
Michael Marineau 66ec5893d7 biosdisk: add verbose debug logging 2018-03-29 22:18:53 -04:00
Michael Marineau 6d4ea47541 gpt: do not use disk sizes GRUB will reject as invalid later on
GRUB assumes that no disk is ever larger than 1EiB and rejects
reads/writes to such locations. Unfortunately this is not conveyed in
the usual way with the special GRUB_DISK_SIZE_UNKNOWN value.
2018-03-29 22:18:53 -04:00
Nick Owens 94731a80d7 net: add client arch and fix user class/terminator
send client arch in bootp requests, for now BIOS and x64/aarch64 EFI is
supported.

fix a bug introduced in 4d5d7be005bb5c15c07472461b528dea65a58cc6 where
user class was encoded improperly, although this didn't seem to have any
detrimental effects.

properly insert an option terminator.
2018-03-29 22:18:53 -04:00
Nick Owens f441ad6625 set cmddevice when cmdpath is set 2018-03-29 22:18:53 -04:00
Nick Owens 10c77ec6b0 grub-core: enable getenv for all efi targets 2018-03-29 22:18:53 -04:00
Matthew Garrett 6182d13091 Fix event log prefix
We're not passing the prefixed version of the description to the event log.
Fix that.
2018-03-29 22:18:53 -04:00
Matthew Garrett 8e1d90283f Rework TPM measurements
Rework TPM measurements to use fewer PCRs. After discussion with upstream,
it's preferable to avoid using so many PCRs. Instead, measure into PCRs 8
and 9 but use a prefix in the event log to indicate which subsystem carried
out the measurements.
2018-03-29 22:18:53 -04:00
Matthew Garrett f203942ba2 Fix boot when there's no TPM
If the firmware has TPM support but has no TPM, we're jumping to core.img
without popping the registers back onto the stack. Fix that.
2018-03-29 22:18:53 -04:00
Matthew Garrett 3340fc72a6 Don't allocate a new address buffer if we receive multiple responses
The current logic in the DNS resolution code allocates an address buffer
based on the number of addresses in the response packet. If we receive
multiple response packets in response to a single query packet, this means
that we will reallocate a new buffer large enough for only the addresses in
that specific packet, discarding any previous results in the process. Worse,
we still keep track of the *total* number of addresses resolved in response
to this query, not merely the number in the packet being currently processed.
Use realloc() rather than malloc() to avoid overwriting the existing data,
and allocate a buffer large enough for the total set of addresses rather
than merely the number in this specific response.
2018-03-29 22:18:53 -04:00
Matthew Garrett 527cbe513a Tag the bootp request as a DHCP discover 2018-03-29 22:18:53 -04:00
Matthew Garrett 902aec6758 Allow protocol to be separated from host with a semicolon
Some DHCP servers (such as dnsmasq) tokenise parameters with commas, making
it impossible to pass boot files with commas in them. Allow using a semicolon
to separate the protocol from host if a comma wasn't found.
2018-03-29 22:18:53 -04:00