Commit Graph

3705 Commits

Author SHA1 Message Date
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 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 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
Matthew Garrett fd0a4f5881 Send a user class identifier in bootp requests
It's helpful to determine that a request was sent by grub in order to permit
the server to provide different information at different stages of the boot
process. Send GRUB2 as a type 77 DHCP option when sending bootp packets in
order to make this possible.
2018-03-29 22:18:53 -04:00
Matthew Garrett 0987f9d173 Allow non-default ports for HTTP requests
Add support for passing ports in HTTP requests. This takes the form of:
(http,serverip:portnum)/file
2018-03-29 22:18:53 -04:00
Matthew Garrett 2ed8170c6f Allow passing of trusted keys via variables
Add support for adding gpg keys to the trusted database with a new command
called "trust_var". This takes the contents of a variable (in ascii-encoded
hex) and interprets it as a gpg public key.
2018-03-29 22:18:53 -04:00
Matthew Garrett d779b3e0fc Fix hex representation of binary variable contents
The getenv code was mishandling the conversion of binary to hex. Grub's
sprintf() doesn't seem to support the full set of format conversions, so
fix this in the nasty way.
2018-03-29 22:18:53 -04:00
Matthew Garrett 3d995d8c97 Add smbios command
Incorporate the smbios command from
https://raw.githubusercontent.com/dm0-/gnuxc/master/patches/grub-2.02~beta2-smbios-module.patch
so we can extract the machine UUID and serial number.
2018-03-29 22:18:53 -04:00
Matthew Garrett 357f451338 Add fwconfig command
Add a command to read values from the qemu fwcfg store. This allows data
to be passed from the qemu command line to grub.

Example use:

echo '(hd0,1)' >rootdev
qemu -fw_cfg opt/rootdev,file=rootdev

fwconfig opt/rootdev root
2018-03-29 22:18:53 -04:00
Matthew Garrett 3cb28afab6 Measure multiboot images and modules 2018-03-29 22:18:53 -04:00
Alex Crawford 1545295ad4 gpt: add search by disk uuid command 2018-03-29 22:18:53 -04:00
Matthew Garrett 206172d9f1 Measure commands
Measure each command executed by grub, which includes script execution.
2018-03-29 22:18:53 -04:00
Matthew Garrett 7f587ef7f9 Measure the kernel commandline
Measure the kernel commandline to ensure that it hasn't been modified
2018-03-29 22:18:53 -04:00
Matthew Garrett 5433dc99b3 Measure kernel and initrd on BIOS systems
Measure the kernel and initrd when loaded on BIOS systems
2018-03-29 22:18:53 -04:00
Matthew Garrett bccf37f527 Rework linux16 command
We want a single buffer that contains the entire kernel image in order to
perform a TPM measurement. Allocate one and copy the entire kernel int it
before pulling out the individual blocks later on.
2018-03-29 22:18:53 -04:00
Matthew Garrett 794c5b35d0 Rework linux command
We want a single buffer that contains the entire kernel image in order to
perform a TPM measurement. Allocate one and copy the entire kernel into it
before pulling out the individual blocks later on.
2018-03-29 22:18:53 -04:00
Matthew Garrett 6b79d94608 Add BIOS boot measurement
Measure the on-disk grub core on BIOS systems - unlike UEFI, the firmware
can't do this stage for us.
2018-03-29 22:18:53 -04:00