Commit Graph

9530 Commits

Author SHA1 Message Date
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
Alex Crawford bacbed2c07 gpt: minor cleanup 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
Michael Marineau d1270a2ba3 gpt: clean up little-endian crc32 computation
- Remove problematic cast from *uint8_t to *uint32_t (alignment issue).
 - Remove dynamic allocation and associated error handling paths.
 - Match parameter ordering to existing grub_crypto_hash function.
2018-03-29 22:18:53 -04:00
Matthew Garrett a5693087f0 Measure kernel + initrd
Measure the kernel and initrd when loaded on UEFI systems
2018-03-29 22:18:53 -04:00
Matthew Garrett 2db9e60640 Core TPM support
Add support for performing basic TPM measurements. Right now this only
supports extending PCRs statically and only on UEFI and BIOS systems, but
will measure all modules as they're loaded.
2018-03-29 22:18:53 -04:00
Matthew Garrett 57b4382f0c Fix race in EFI validation
The Secure Boot code currently reads the kernel from disk, validates the
signature and then reads it from disk again. A sufficiently exciting storage
device could modify the kernel between these two events and trigger the
execution of an untrusted kernel. Avoid re-reading it in order to ensure
this isn't a problem, and in the process speed up boot by not reading the
kernel twice.
2018-03-29 22:18:53 -04:00
Matthew Garrett 03b547c21e Add verity hash passthrough
Read the verity hash from the kernel binary and pass it to the running
system via the kernel command line
2018-03-29 22:18:53 -04:00
Matthew Garrett 250af4351d Add efi getenv command
Add a command to obtain the contents of EFI firmware variables.
2018-03-29 22:18:53 -04:00
Matthew Garrett f4d00290ed Fail validation if we can't find shim and Secure Boot is enabled
If grub is signed with a key that's in the trusted EFI keyring, an attacker
can point a boot entry at grub rather than at shim and grub will fail to
locate the shim verification protocol. This would then allow booting an
arbitrary kernel image. Fail validation if Secure Boot is enabled and we
can't find the shim protocol in order to prevent this.
2018-03-29 22:18:53 -04:00
Michael Marineau 67475f53e0 gpt: add search by partition label and uuid commands
Builds on the existing filesystem search code. Only for GPT right now.
2018-03-29 22:18:53 -04:00
Michael Marineau febf4666fb tests: add some partitions to the gpt unit test data 2018-03-29 22:18:52 -04:00
Michael Marineau ffb13159f1 gpt: switch partition names to a 16 bit type
In UEFI/GPT strings are UTF-16 so use a uint16 to make dealing with the
string practical.
2018-03-29 22:18:52 -04:00
Michael Marineau d9bdbc1048 gpt: move gpt guid printing function to common library 2018-03-29 22:18:52 -04:00
Michael Marineau f8f6f790aa gpt: split out checksum recomputation
For basic data modifications the full repair function is overkill.
2018-03-29 22:18:52 -04:00
Michael Marineau 508b02fc8a gpt: new gptprio.next command for selecting priority based partitions
Basic usage would look something like this:

    gptprio.next -d usr_dev -u usr_uuid
    linuxefi ($usr_dev)/boot/vmlinuz mount.usr=PARTUUID=$usr_uuid

After booting the system should set the 'successful' bit on the
partition that was used.
2018-03-29 22:18:52 -04:00
Michael Marineau 2cd009dffe gpt: add a new generic GUID type
In order to do anything with partition GUIDs they need to be stored in a
proper structure like the partition type GUIDs. Additionally add an
initializer macro to simplify defining both GUID types.
2018-03-29 22:18:52 -04:00
Michael Marineau c1151f761f tests: fix path to words file on Gentoo/CoreOS
By default there isn't a linux.words file, but there is words.
2018-03-29 22:18:52 -04:00
Michael Marineau 5e1829d414 gpt: add write function and gptrepair command
The first hint of something practical, a command that can restore any of
the GPT structures from the alternate location. New test case must run
under QEMU because the loopback device used by the other unit tests does
not support writing.
2018-03-29 22:18:52 -04:00
Michael Marineau dab6fac705 gpt: add new repair function to sync up primary and backup tables. 2018-03-29 22:18:52 -04:00
Michael Marineau 3d066264ac gpt: consolidate crc32 computation code
The gcrypt API is overly verbose, wrap it up in a helper function to
keep this rather common operation easy to use.
2018-03-29 22:18:52 -04:00
Michael Marineau 94f04a532d gpt: record size of of the entries table
The size of the entries table will be needed later when writing it back
to disk. Restructure the entries reading code to flow a little better.
2018-03-29 22:18:52 -04:00
Michael Marineau c26743a145 gpt: rename misnamed header location fields
The header location fields refer to 'this header' and 'alternate header'
respectively, not 'primary header' and 'backup header'. The previous
field names are backwards for the backup header.
2018-03-29 22:18:52 -04:00
Michael Marineau f69a9e0fdc gpt: start new GPT module
This module is a new implementation for reading GUID Partition Tables
which is much stricter than the existing part_gpt module and exports GPT
data directly instead of the generic grub_partition structure. It will
be the basis for modules that need to read/write/update GPT data.

The current code does nothing more than read and verify the table.
2018-03-29 22:18:52 -04:00