Skip to contentSkip to conversation

verifiers: Verify commands executed by grub

PATCH In review Matthew Garrett 3 participants 10 messages Nov 29, 2018 – Jan 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 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
index a8502d907..ee299fd0e 100644
@@ -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
index 79022b422..460f2e20a 100644
@@ -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.20.0.rc0.387.gc7a69e6b6c-goog
#1 lore raw

PATCH v3 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   | 333 +++++++++++++++++++++++++++++++++
 grub-core/commands/tpm.c       | 100 ++++++++++
 grub-core/kern/i386/efi/init.c |   1 +
 include/grub/efi/tpm.h         | 199 ++++++++++++++++++++
 include/grub/tpm.h             |  82 ++++++++
 6 files changed, 722 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
index 6e2cc8444..a485f9186 100644
@@ -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 +333 -0

333 lines not on this page · raw message

grub-core/commands/tpm.c new file +100 -0

100 lines not on this page · raw message

grub-core/kern/i386/efi/init.c +1 -0
index a28316cc6..da499aba0 100644
@@ -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 +199 -0

199 lines not on this page · raw message

include/grub/tpm.h new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.20.0.rc0.387.gc7a69e6b6c-goog
Reviewed-by on v3 2/3
#2 lore raw

Re: [PATCH V3 2/3] verifiers: Core TPM support

Quoted 9 lines · Matthew Garrett

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.

Daniel

#3 lore raw

PATCH v3 3/3 verifiers: Add TPM documentation

In reply to Matthew Garrett

Describe 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
index 471d97c95..6bd3783a4 100644
@@ -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.20.0.rc0.387.gc7a69e6b6c-goog
#5 lore raw

Re: [PATCH V3 3/3] verifiers: Add TPM documentation

Quoted 8 lines · Daniel Kiper
Quoted 3 lines · Matthew Garrett

Describe the behaviour of grub when the TPM module is in use.

If there are no objections I will apply the patch series in a week or so.

Pushed. However, I have had to change "enable = efi;" to "enable = x86_64_efi;" in grub-core/Makefile.core.def. Otherwise ARM EFI builds would be broken. I hope that this is not a problem for you.

Daniel

#6 lore raw

Re: [PATCH V3 3/3] verifiers: Add TPM documentation

Quoted 7 lines · Daniel Kiper
Quoted 5 lines · Daniel Kiper
Quoted 3 lines · Matthew Garrett

Describe the behaviour of grub when the TPM module is in use.

Quoted 7 lines
Quoted 3 lines

If there are no objections I will apply the patch series in a week or so.

Pushed. However, I have had to change "enable = efi;" to "enable = x86_64_efi;" in grub-core/Makefile.core.def. Otherwise ARM EFI builds would be broken. I hope that this is not a problem for you.

Hmm, this should have been architecture independent - what was the failure? I can send a followup patch to fix that up.

#7 lore raw

Re: [PATCH V3 3/3] verifiers: Add TPM documentation

Quoted 10 lines · Matthew Garrett
Quoted 9 lines · Daniel Kiper
Quoted 7 lines · Daniel Kiper
Quoted 3 lines · Matthew Garrett

Describe the behaviour of grub when the TPM module is in use.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If there are no objections I will apply the patch series in a week or so.

Pushed. However, I have had to change "enable = efi;" to "enable = x86_64_efi;" in grub-core/Makefile.core.def. Otherwise ARM EFI builds would be broken. I hope that this is not a problem for you.

Hmm, this should have been architecture independent - what was the failure? I can send a followup patch to fix that up.

Please see below. As you can see all non x86_64 EFI builds fail. Failures look the same.

******************************************************************************

./configure --target=aarch64-linux-gnu --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

aarch64-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=ARM64_EFI -nostdinc -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -freg-struct-return -mgeneral-regs-only -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-unwind-tables -Qn -fno-PIE -fno-pie -fno-stack-protector -Wtrampolines -Werror -mcmodel=large -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long unsigned int *}’ but argument is of type  unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^

cc1: all warnings being treated as errors

******************************************************************************

./configure --target=arm-linux-gnueabihf --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=ARM_EFI -nostdinc -isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -freg-struct-return -msoft-float -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-unwind-tables -mthumb-interwork -Qn -fno-PIE -fno-pie -fno-stack-protector -mno-unaligned-access -Wtrampolines -Werror -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long long unsigned int *}’ but argument is of type ‘unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^

cc1: all warnings being treated as errors

******************************************************************************

./configure --target=i386 --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=I386_EFI -m32 -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -march=i386 -m32 -falign-jumps=1 -falign-loops=1 -falign-functions=1 -freg-struct-return -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -fno-dwarf2-cfi-asm -mno-stack-arg-probe -fno-asynchronous-unwind-tables -fno-unwind-tables -Qn -fno-PIE -fno-pie -fno-stack-protector -Wtrampolines -Werror -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long long unsigned int *}’ but argument is of type ‘unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^

cc1: all warnings being treated as errors

******************************************************************************

Daniel

#8 lore raw

Re: [PATCH V3 3/3] verifiers: Add TPM documentation

Quoted 128 lines · Daniel Kiper
Quoted 10 lines · Matthew Garrett
Quoted 9 lines · Daniel Kiper
Quoted 7 lines · Daniel Kiper
Quoted 3 lines · Matthew Garrett

Describe the behaviour of grub when the TPM module is in use.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If there are no objections I will apply the patch series in a week or so.

Pushed. However, I have had to change "enable = efi;" to "enable = x86_64_efi;" in grub-core/Makefile.core.def. Otherwise ARM EFI builds would be broken. I hope that this is not a problem for you.

Hmm, this should have been architecture independent - what was the failure? I can send a followup patch to fix that up.

Please see below. As you can see all non x86_64 EFI builds fail. Failures look the same.

******************************************************************************

./configure --target=aarch64-linux-gnu --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

aarch64-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=ARM64_EFI -nostdinc -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -freg-struct-return -mgeneral-regs-only -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-unwind-tables -Qn -fno-PIE -fno-pie -fno-stack-protector -Wtrampolines -Werror -mcmodel=large -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long unsigned int *}’ but argument is of type  unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^

cc1: all warnings being treated as errors

******************************************************************************

./configure --target=arm-linux-gnueabihf --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=ARM_EFI -nostdinc -isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -freg-struct-return -msoft-float -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-unwind-tables -mthumb-interwork -Qn -fno-PIE -fno-pie -fno-stack-protector -mno-unaligned-access -Wtrampolines -Werror -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long long unsigned int *}’ but argument is of type ‘unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^

cc1: all warnings being treated as errors

******************************************************************************

./configure --target=i386 --with-platform=efi --enable-grub-mkfont --prefix="pwd/grub-dist"

[...]

gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=I386_EFI -m32 -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/6/include -I../include -I../include -DGRUB_FILE=\"commands/efi/tpm.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -march=i386 -m32 -falign-jumps=1 -falign-loops=1 -falign-functions=1 -freg-struct-return -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -fno-dwarf2-cfi-asm -mno-stack-arg-probe -fno-asynchronous-unwind-tables -fno-unwind-tables -Qn -fno-PIE -fno-pie -fno-stack-protector -Wtrampolines -Werror -ffreestanding -MT commands/efi/tpm_module-tpm.o -MD -MP -MF commands/efi/.deps-core/tpm_module-tpm.Tpo -c -o commands/efi/tpm_module-tpm.o test -f 'commands/efi/tpm.c' || echo './'commands/efi/tpm.c
In file included from commands/efi/tpm.c:23:0:
commands/efi/tpm.c: In function ‘grub_tpm1_log_event’:
commands/efi/tpm.c:248:52: error: passing argument 2 of ‘tpm->log_extend_event’ makes integer from pointer without a cast [-Werror=int-conversion]
status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,

                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c:248:52: note: expected ‘grub_efi_physical_address_t {aka long long unsigned int}’ but argument is of type ‘unsigned char *’
   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
                                                    ^
../include/grub/efi/api.h:1698:55: note: in definition of macro ‘efi_call_7’
 #define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
                                                       ^
commands/efi/tpm.c: In function ‘grub_tpm2_log_event’:
commands/efi/tpm.c:298:60: error: passing argument 3 of ‘tpm->hash_log_extend_event’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
commands/efi/tpm.c:298:60: note: expected ‘grub_efi_physical_address_t * {aka long long unsigned int *}’ but argument is of type ‘unsigned char *’
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf,
                                                            ^
../include/grub/efi/api.h:1696:52: note: in definition of macro ‘efi_call_5’
 #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
                                                    ^
Quoted 3 lines

cc1: all warnings being treated as errors

******************************************************************************

Ping?

Daniel

Reviewed-by on v3 1/3
#9 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett

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.

Daniel