verifiers: Verify commands executed by grub
PATCH 1/3 verifiers: Verify commands executed by grub
From: Matthew Garrett <[email protected]>
Pass all commands executed by grub to the verifiers layer. Most verifiers will ignore this, but some (such as the TPM verifier) want to be able to measure and log each command executed in order to ensure that the boot state is as expected.
--- grub-core/script/execute.c | 27 ++++++++++++++++++++++++--- include/grub/verify.h | 1 + 2 files changed, 25 insertions(+), 3 deletions(-)
grub-core/script/execute.c +24 -3
@@ -27,6 +27,7 @@#include <grub/normal.h> #include <grub/extcmd.h> #include <grub/i18n.h> +#include <grub/verify.h> /* Max digits for a char is 3 (0xFF is 255), similarly for an int it is sizeof (int) * 3, and one extra for a possible -ve sign. */
@@ -929,8 +930,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)grub_err_t ret =0 ;grub_script_function_t func =0 ;char errnobuf[18 ]; -char *cmdname; -int argc; +char *cmdname, *cmdstring; +int argc, offset =0 , cmdlen =0 ; +unsigned int i;char **args;int invert;struct grub_script_argv argv = {0 ,0 ,0 };
@@ -939,6 +941,26 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0 ])return grub_errno; +for (i =0 ; i < argv.argc; i++) + { + cmdlen +=grub_strlen (argv.args[i]) +1 ; + } + + cmdstring =grub_malloc (cmdlen); +if (!cmdstring) + { +return grub_error (GRUB_ERR_OUT_OF_MEMORY , +N_ ("cannot allocate command buffer" )); + } + +for (i =0 ; i < argv.argc; i++) + { + offset +=grub_snprintf (cmdstring + offset, cmdlen - offset,"%s " , + argv.args[i]); + } + cmdstring[cmdlen -1 ] ='\0' ; +grub_verify_string (cmdstring,GRUB_VERIFY_COMMAND ); +grub_free (cmdstring); invert =0 ; argc = argv.argc -1 ; args = argv.args +1 ;
@@ -1163,4 +1185,3 @@ grub_script_execute (struct grub_script *script)return grub_script_execute_cmd (script->cmd); } -
include/grub/verify.h +1 -0
@@ -31,6 +31,7 @@ enum grub_verify_string_type {GRUB_VERIFY_KERNEL_CMDLINE ,GRUB_VERIFY_MODULE_CMDLINE , + GRUB_VERIFY_COMMAND, };struct grub_file_verifier
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog
PATCH 2/3 verifiers: Core TPM support
From: Matthew Garrett <[email protected]>
Add support for performing basic TPM measurements. Right now this only supports extending PCRs statically and only on UEFI. In future we might want to have some sort of mechanism for choosing which events get logged to which PCRs, but this seems like a good default policy and we can wait to see whether anyone has a use case before adding more complexity.
--- grub-core/Makefile.core.def | 7 + grub-core/commands/efi/tpm.c | 310 +++++++++++++++++++++++++++++++++ grub-core/commands/tpm.c | 87 +++++++++ grub-core/kern/i386/efi/init.c | 1 + include/grub/efi/tpm.h | 153 ++++++++++++++++ include/grub/tpm.h | 74 ++++++++ 6 files changed, 632 insertions(+) create mode 100644 grub-core/commands/efi/tpm.c create mode 100644 grub-core/commands/tpm.c create mode 100644 include/grub/efi/tpm.h create mode 100644 include/grub/tpm.h
grub-core/Makefile.core.def +7 -0
@@ -2377,6 +2377,13 @@ module = { common = commands/testspeed.c; }; +module = { + name = tpm; + common = commands/tpm.c; + efi = commands/efi/tpm.c; + enable = efi; +}; + module = { name = tr; common = commands/tr.c;
grub-core/commands/efi/tpm.c new file +310 -0
310 lines not on this page · raw message
grub-core/commands/tpm.c new file +87 -0
87 lines not on this page · raw message
grub-core/kern/i386/efi/init.c +1 -0
@@ -27,6 +27,7 @@#include <grub/efi/efi.h> #include <grub/i386/tsc.h> #include <grub/loader.h> +#include <grub/tpm.h> void grub_machine_init (void )
include/grub/efi/tpm.h new file +153 -0
153 lines not on this page · raw message
include/grub/tpm.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog
PATCH 3/3 verifiers: Add TPM documentation
In reply to Matthew GarrettDescribe the behaviour of grub when the TPM module is in use.
--- docs/grub.texi | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
docs/grub.texi +38 -0
@@ -5545,6 +5545,7 @@ environment variables and commands are listed in the same order. * Authentication and authorisation:: Users and access control * Using digital signatures:: Booting digitally signed code * UEFI secure boot and shim:: Booting digitally signed PE files +* Measured Boot:: Measuring boot components @end menu @node Authentication and authorisation
@@ -5721,6 +5722,43 @@ mentioned requirements are enforced by the shim_lock module. And itself it is a persistent module which means that it cannot be unloaded if it was loaded into the memory. +@node Measured Boot +@section Measuring boot components + +If the tpm module is loaded and the platform has a Trusted Platform Module +installed, GRUB will log each command executed and each file loaded into the +TPM event log and extend the PCR values in the TPM correspondingly. All events +will be logged into the PCR described below with a type of EV_IPL and an +event description as described below. + +@multitable @columnfractions 0.3 0.1 0.6 +@headitem Event type @tab PCR @tab Description +@item Command +@tab 8 +@tab All executed commands (including those from configuration files) will be +logged and measured as entered with a prefix of ``grub_cmd: `` +@item Module command line +@tab 8 +@tab Any command line passed to a kernel module will be logged and measured as +entered with a prefix of ``module_cmdline: `` +@item Kernel command line +@tab 8 +@tab Any command line passed to a kernel will be logged and measured as entered +with a prefix of ``kernel_cmdline: '' +@item Files +@tab 9 +@tab Any file read by GRUB will be logged and measured with a descriptive text +corresponding to the filename. +@end multitable + +GRUB will not measure its own @file{core.img} - it is expected that firmware +will carry this out. GRUB will also not perform any measurements until the +tpm module is loaded. As such it is recommended that the tpm module be built +into @file{core.img} in order to avoid a potential gap in measurement between +@file{core.img} being loaded and the tpm module being loaded. + +Measured boot is currently only supported on EFI platforms. + @node Platform limitations @chapter Platform limitations
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog