Skip to contentSkip to conversation

Support for TPM measurements on UEFI systems

PATCH New Matthew Garrett 4 participants 24 messages Jan 24, 2017 – Feb 7, 2017

lore
Share & tools
lore
#0 lore raw

This patchset adds support for measuring components of grub and what it's loading into the TPM. It supports both TPM 1.2 and 2.0 devices via the standard UEFI protocols.

#1 lore raw

PATCH 1/7 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.

---
 grub-core/Makefile.am        |   1 +
 grub-core/Makefile.core.def  |   3 +
 grub-core/kern/dl.c          |   4 +
 grub-core/kern/efi/tpm.c     | 282 +++++++++++++++++++++++++++++++++++++++++++
 grub-core/kern/i386/pc/tpm.c | 145 ++++++++++++++++++++++
 grub-core/kern/tpm.c         |  19 +++
 include/grub/efi/tpm.h       | 153 +++++++++++++++++++++++
 include/grub/tpm.h           |  94 +++++++++++++++
 8 files changed, 701 insertions(+)
 create mode 100644 grub-core/kern/efi/tpm.c
 create mode 100644 grub-core/kern/i386/pc/tpm.c
 create mode 100644 grub-core/kern/tpm.c
 create mode 100644 include/grub/efi/tpm.h
 create mode 100644 include/grub/tpm.h
grub-core/Makefile.am +1 -0
index 04e9395..23ce9e9 100644
@@ -92,6 +92,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/tpm.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
 
 if COND_i386_pc
grub-core/Makefile.core.def +3 -0
index f6b6f38..90a43bb 100644
@@ -126,6 +126,7 @@ kernel = {
   common = kern/rescue_parser.c;
   common = kern/rescue_reader.c;
   common = kern/term.c;
+  common = kern/tpm.c;
 
   noemu = kern/compiler-rt.c;
   noemu = kern/mm.c;
@@ -173,6 +174,7 @@ kernel = {
   efi = term/efi/console.c;
   efi = kern/acpi.c;
   efi = kern/efi/acpi.c;
+  efi = kern/efi/tpm.c;
   i386_coreboot = kern/i386/pc/acpi.c;
   i386_multiboot = kern/i386/pc/acpi.c;
   i386_coreboot = kern/acpi.c;
@@ -219,6 +221,7 @@ kernel = {
 
   i386_pc = kern/i386/pc/init.c;
   i386_pc = kern/i386/pc/mmap.c;
+  i386_pc = kern/i386/pc/tpm.c;
   i386_pc = term/i386/pc/console.c;
 
   i386_qemu = bus/pci.c;
grub-core/kern/dl.c +4 -0
index e394cd9..29ee00a 100644
@@ -32,6 +32,7 @@
 #include <grub/env.h>
 #include <grub/cache.h>
 #include <grub/i18n.h>
+#include <grub/tpm.h>
 
 /* Platforms where modules are in a readonly area of memory.  */
 #if defined(GRUB_MACHINE_QEMU)
@@ -712,6 +713,9 @@ grub_dl_load_file (const char *filename)
      opens of the same device.  */
   grub_file_close (file);
 
+  grub_tpm_measure(core, size, GRUB_BINARY_PCR, "grub_module", filename);
+  grub_print_error();
+
   mod = grub_dl_load_core (core, size);
   grub_free (core);
   if (! mod)
grub-core/kern/efi/tpm.c new file +282 -0

282 lines not on this page · raw message

grub-core/kern/i386/pc/tpm.c new file +145 -0

145 lines not on this page · raw message

grub-core/kern/tpm.c new file +19 -0
new file mode 100644
index 0000000..e5e8fce
@@ -0,0 +1,19 @@
+#include <grub/err.h>
+#include <grub/i18n.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/tpm.h>
+#include <grub/term.h>
+
+grub_err_t
+grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
+		  const char *kind, const char *description)
+{
+  grub_err_t ret;
+  char *desc = grub_xasprintf("%s %s", kind, description);
+  if (!desc)
+    return GRUB_ERR_OUT_OF_MEMORY;
+  ret = grub_tpm_log_event(buf, size, pcr, desc);
+  grub_free(desc);
+  return ret;
+}
include/grub/efi/tpm.h new file +153 -0

153 lines not on this page · raw message

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

94 lines not on this page · raw message

Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/7 Rework linux command

In reply to Matthew Garrett

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.

---
 grub-core/loader/i386/linux.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
grub-core/loader/i386/linux.c +21 -13
index b15b8cc..5e54ec9 100644
@@ -680,12 +680,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   grub_file_t file = 0;
   struct linux_kernel_header lh;
   grub_uint8_t setup_sects;
-  grub_size_t real_size, prot_size, prot_file_size;
+  grub_size_t real_size, prot_size, prot_file_size, kernel_offset;
   grub_ssize_t len;
   int i;
   grub_size_t align, min_align;
   int relocatable;
   grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR;
+  grub_uint8_t *kernel = NULL;
 
   grub_dl_ref (my_mod);
 
@@ -699,7 +700,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (! file)
     goto fail;
 
-  if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
+  len = grub_file_size (file);
+  kernel = grub_malloc (len);
+  if (!kernel)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
+      goto fail;
+    }
+
+  if (grub_file_read (file, kernel, len) != len)
     {
       if (!grub_errno)
 	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
@@ -707,6 +716,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
+  grub_memcpy (&lh, kernel, sizeof (lh));
+  kernel_offset = sizeof (lh);
+
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
     {
       grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
@@ -806,13 +818,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   linux_params.ps_mouse = linux_params.padding10 =  0;
 
   len = sizeof (linux_params) - sizeof (lh);
-  if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len)
-    {
-      if (!grub_errno)
-	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
-		    argv[0]);
-      goto fail;
-    }
+
+  grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len);
+  kernel_offset += len;
 
   linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE;
 
@@ -871,7 +879,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   /* The other parameters are filled when booting.  */
 
-  grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
+  kernel_offset = real_size + GRUB_DISK_SECTOR_SIZE;
 
   grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
 		(unsigned) real_size, (unsigned) prot_size);
@@ -1016,9 +1024,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 			      - (sizeof (LINUX_IMAGE) - 1));
 
   len = prot_file_size;
-  if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
-    grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
-		argv[0]);
+  grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
 
   if (grub_errno == GRUB_ERR_NONE)
     {
@@ -1029,6 +1035,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
  fail:
 
+  grub_free (kernel);
+
   if (file)
     grub_file_close (file);
 
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/7 Rework linux16 command

In reply to Matthew Garrett

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.

---
 grub-core/loader/i386/pc/linux.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
grub-core/loader/i386/pc/linux.c +21 -13
index a293b17..1ac9cd1 100644
@@ -123,13 +123,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   grub_file_t file = 0;
   struct linux_kernel_header lh;
   grub_uint8_t setup_sects;
-  grub_size_t real_size;
+  grub_size_t real_size, kernel_offset = 0;
   grub_ssize_t len;
   int i;
   char *grub_linux_prot_chunk;
   int grub_linux_is_bzimage;
   grub_addr_t grub_linux_prot_target;
   grub_err_t err;
+  grub_uint8_t *kernel = NULL;
 
   grub_dl_ref (my_mod);
 
@@ -143,7 +144,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (! file)
     goto fail;
 
-  if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
+  len = grub_file_size (file);
+  kernel = grub_malloc (len);
+  if (!kernel)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
+      goto fail;
+    }
+
+  if (grub_file_read (file, kernel, len) != len)
     {
       if (!grub_errno)
 	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
@@ -151,6 +160,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
+  grub_memcpy (&lh, kernel, sizeof (lh));
+  kernel_offset = sizeof (lh);
+
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
     {
       grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
@@ -314,13 +326,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   grub_memmove (grub_linux_real_chunk, &lh, sizeof (lh));
 
   len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
-  if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len)
-    {
-      if (!grub_errno)
-	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
-		    argv[0]);
-      goto fail;
-    }
+  grub_memcpy (grub_linux_real_chunk + sizeof (lh), kernel + kernel_offset,
+	       len);
+  kernel_offset += len;
 
   if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
       || grub_le_to_cpu16 (lh.version) < 0x0200)
@@ -355,10 +363,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   }
 
   len = grub_linux16_prot_size;
-  if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size)
-      != (grub_ssize_t) grub_linux16_prot_size && !grub_errno)
-    grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
-		argv[0]);
+  grub_memcpy (grub_linux_prot_chunk, kernel + kernel_offset, len);
+  kernel_offset += len;
 
   if (grub_errno == GRUB_ERR_NONE)
     {
@@ -368,6 +374,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
  fail:
 
+  grub_free (kernel);
+
   if (file)
     grub_file_close (file);
 
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/7 Measure kernel and initrd

In reply to Matthew Garrett

Measure the kernel and initrd at load time

---
 grub-core/loader/i386/linux.c    | 6 ++++++
 grub-core/loader/i386/pc/linux.c | 4 ++++
 grub-core/loader/linux.c         | 3 +++
 3 files changed, 13 insertions(+)
grub-core/loader/i386/linux.c +6 -0
index 5e54ec9..6d8d3d6 100644
@@ -35,6 +35,7 @@
 #include <grub/i18n.h>
 #include <grub/lib/cmdline.h>
 #include <grub/linux.h>
+#include <grub/tpm.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -716,7 +717,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
+  grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Linux Kernel");
+  grub_print_error();
+
   grub_memcpy (&lh, kernel, sizeof (lh));
+
   kernel_offset = sizeof (lh);
 
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
@@ -1025,6 +1030,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   len = prot_file_size;
   grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
+  kernel_offset += len;
 
   if (grub_errno == GRUB_ERR_NONE)
     {
grub-core/loader/i386/pc/linux.c +4 -0
index 1ac9cd1..c6197a1 100644
@@ -35,6 +35,7 @@
 #include <grub/i386/floppy.h>
 #include <grub/lib/cmdline.h>
 #include <grub/linux.h>
+#include <grub/tpm.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -160,6 +161,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
+  grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "BIOS Linux Kernel");
+  grub_print_error();
+
   grub_memcpy (&lh, kernel, sizeof (lh));
   kernel_offset = sizeof (lh);
 
grub-core/loader/linux.c +3 -0
index be6fa0f..8b5e6e0 100644
@@ -4,6 +4,7 @@
 #include <grub/misc.h>
 #include <grub/file.h>
 #include <grub/mm.h>
+#include <grub/tpm.h>
 
 struct newc_head
 {
@@ -288,6 +289,8 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
 	  grub_initrd_close (initrd_ctx);
 	  return grub_errno;
 	}
+      grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Linux Initrd");
+      grub_print_error();
       ptr += cursize;
     }
   if (newc)
Signature · 1 line
2.9.3
#5 lore raw

PATCH 5/7 Measure the kernel commandline

In reply to Matthew Garrett

Measure the kernel commandline to ensure that it hasn't been modified

---
 grub-core/lib/cmdline.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
grub-core/lib/cmdline.c +5 -1
index d5e10ee..055b7aa 100644
@@ -19,6 +19,7 @@
 
 #include <grub/lib/cmdline.h>
 #include <grub/misc.h>
+#include <grub/tpm.h>
 
 static unsigned int check_arg (char *c, int *has_space)
 {
@@ -67,7 +68,7 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
 {
   int i, space;
   unsigned int arg_size;
-  char *c;
+  char *c, *orig = buf;
 
   for (i = 0; i < argc; i++)
     {
@@ -104,5 +105,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
 
   *buf = 0;
 
+  grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_BINARY_PCR, "grub_kernel_cmdline", "Kernel Commandline");
+  grub_print_error();
+
   return i;
 }
Signature · 1 line
2.9.3
#6 lore raw

PATCH 6/7 Measure commands

In reply to Matthew Garrett

From: Matthew Garrett <[email protected]>

Measure each command executed by grub, which includes script execution.

---
 grub-core/script/execute.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
grub-core/script/execute.c +23 -2
index a8502d9..cf99410 100644
@@ -27,6 +27,7 @@
 #include <grub/normal.h>
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
+#include <grub/tpm.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,25 @@ 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_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_ASCII_PCR, "grub_cmd", cmdstring);
+  grub_print_error();
+  grub_free(cmdstring);
   invert = 0;
   argc = argv.argc - 1;
   args = argv.args + 1;
Signature · 1 line
2.9.3
#7 lore raw

PATCH 7/7 Measure multiboot images and modules

In reply to Matthew Garrett
---
 grub-core/loader/i386/multiboot_mbi.c | 4 ++++
 grub-core/loader/multiboot.c          | 3 +++
 grub-core/loader/multiboot_mbi2.c     | 4 ++++
 3 files changed, 11 insertions(+)
grub-core/loader/i386/multiboot_mbi.c +4 -0
index fd7b41b..42372bf 100644
@@ -36,6 +36,7 @@
 #include <grub/net.h>
 #include <grub/i18n.h>
 #include <grub/lib/cmdline.h>
+#include <grub/tpm.h>
 
 #ifdef GRUB_MACHINE_EFI
 #include <grub/efi/efi.h>
@@ -173,6 +174,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
       return grub_errno;
     }
 
+  grub_tpm_measure((unsigned char*)buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename);
+  grub_print_error();
+
   header = find_header (buffer, len);
 
   if (header == 0)
grub-core/loader/multiboot.c +3 -0
index bd9d5b3..a97ed87 100644
@@ -42,6 +42,7 @@
 #include <grub/video.h>
 #include <grub/memory.h>
 #include <grub/i18n.h>
+#include <grub/tpm.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -424,6 +425,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
     }
 
   grub_file_close (file);
+  grub_tpm_measure (module, size, GRUB_BINARY_PCR, "grub_multiboot", argv[0]);
+  grub_print_error();
   return GRUB_ERR_NONE;
 }
 
grub-core/loader/multiboot_mbi2.c +4 -0
index b0679a9..c62ced3 100644
@@ -36,6 +36,7 @@
 #include <grub/i18n.h>
 #include <grub/net.h>
 #include <grub/lib/cmdline.h>
+#include <grub/tpm.h>
 
 #if defined (GRUB_MACHINE_EFI)
 #include <grub/efi/efi.h>
@@ -131,6 +132,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 
   COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0);
 
+  grub_tpm_measure ((unsigned char *)mld.buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename);
+  grub_print_error();
+
   header = find_header (mld.buffer, len);
 
   if (header == 0)
Signature · 1 line
2.9.3
#8 lore raw
In reply to Matthew Garrett

For policy reasons we can't put any TPM code into GNU project. Can we use verifiers framework for this rather than custom hooks? This would allow your code to be a single module that can be put into a separate repo rather than a complex patch set. Verifiers framework is in separate branch verifiers. I didn't look into details of patches. This has to be postponed after release

On Tue, 24 Jan 2017, 03:39 Matthew Garrett <[email protected]> wrote:

This patchset adds support for measuring components of grub and what it's loading into the TPM. It supports both TPM 1.2 and 2.0 devices via the standard UEFI protocols.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#9 lore raw
Quoted 5 lines · Vladimir 'phcoder' Serbinenko

For policy reasons we can't put any TPM code into GNU project. Can we use verifiers framework for this rather than custom hooks? This would allow your code to be a single module that can be put into a separate repo rather than a complex patch set. Verifiers framework is in separate branch verifiers. I didn't look into details of patches. This has to be postponed after release

From https://www.gnu.org/philosophy/can-you-trust.html

"Therefore, we conclude that the “Trusted Platform Modules” available for PCs are not dangerous, and there is no reason not to include one in a computer or support it in system software."

There's no problem including TPM support in GNU projects.

#10 lore raw

Ok. Good. Still, can we use verifiers framework ? We can adjust it if needed. Also it's still post-release material

Quoted 25 lines · On Tue, 24 Jan 2017, 04:34 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

For policy reasons we can't put any TPM code into GNU project. Can we use verifiers framework for this rather than custom hooks? This would allow

your

Quoted 1 line

code to be a single module that can be put into a separate repo rather

than

Quoted 1 line

a complex patch set. Verifiers framework is in separate branch

verifiers. I

Quoted 1 line

didn't look into details of patches. This has to be postponed after

release

From https://www.gnu.org/philosophy/can-you-trust.html

"Therefore, we conclude that the “Trusted Platform Modules” available for PCs are not dangerous, and there is no reason not to include one in a computer or support it in system software."

There's no problem including TPM support in GNU projects.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#11 lore raw
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

Ok. Good. Still, can we use verifiers framework ? We can adjust it if needed. Also it's still post-release material

Where's the branch? I wasn't able to find it on Savannah.

#12 lore raw
Quoted 7 lines · On Tue, 24 Jan 2017, 05:14 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

Ok. Good. Still, can we use verifiers framework ? We can adjust it if needed. Also it's still post-release material

Where's the branch? I wasn't able to find it on Savannah.

I must have accidentally deleted it on the server. I'll reupload it when I'll have access to the laptop in question on Monday

Quoted 7 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#13 lore raw
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

I must have accidentally deleted it on the server. I'll reupload it when I'll have access to the laptop in question on Monday

Hi,

Did you have any luck digging this up?

Signature · 1 line
Matthew Garrett | [email protected]
#14 lore raw

Rebased and uploaded to branch phcoder/verifiers.

Le Sat, Feb 4, 2017 à 10:24 PM, Matthew Garrett <[email protected]> a écrit :

Quoted 18 lines
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

I must have accidentally deleted it on the server. I'll reupload it when I'll have access to the laptop in question on Monday

Hi,

Did you have any luck digging this up?

--
Matthew Garrett | [email protected]

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#15 lore raw

See verify.h for the interface. Obviously if you need changes in the API, please say.

Quoted 24 lines · Vladimir 'phcoder' Serbinenko

Rebased and uploaded to branch phcoder/verifiers.

Le Sat, Feb 4, 2017 à 10:24 PM, Matthew Garrett <[email protected]> a écrit :

Quoted 2 lines · Vladimir 'phcoder' Serbinenko

I must have accidentally deleted it on the server. I'll reupload it when I'll have access to the laptop in question on Monday

Hi,

Did you have any luck digging this up?

--
Matthew Garrett | [email protected]

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#16 lore raw
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the API, please say.

I think that's a starting point, but it doesn't seem sufficient for some of the cases I care about. For instance, measuring boot state isn't just about the files that are read - we also need to measure the commands that grub runs and the command line passed to the kernel, for instance. Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into, but I can't think of a good way to do that simply by hooking open. That also seems to make it difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything else.

Signature · 1 line
Matthew Garrett | [email protected]
#17 lore raw

Matthew,

Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the API, please say.

I think that's a starting point, but it doesn't seem sufficient for some of the cases I care about. For instance, measuring boot state isn't just about the files that are read - we also need to measure the commands that grub runs

I'm not sure about measuring the commands that GRUB runs. GRUB's config file is a shell-like language, and measuring that file should give a pretty good indication of its behavior. In the grey area between "what is code?" and "what is data?", making the case that grub.cfg is code seems feasible, which greatly simplifies the work of whatever verifies attestations or binds/seals data. Although, implementations for these two don't really seem to be in conflict so maybe GRUB could be configured one way or the other.

(I'm coming at this from the perspective of "gathering golden measurements by just-run-it-and-see considered harmful".)

Quoted 2 lines

and the command line passed to the kernel, for instance.

Agreed.

Quoted 2 lines

Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into,

This is definitely interesting. Re: the scenario above, files could get measured into one place. Commands executed could get measured into another.

Quoted 7 lines

but I can't think of
a good way to do that simply by hooking open. That also seems to make it difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything else.

Best,
-Jon

#18 lore raw
Quoted 7 lines · Jon McCune

I'm not sure about measuring the commands that GRUB runs. GRUB's config file is a shell-like language, and measuring that file should give a pretty good indication of its behavior. In the grey area between "what is code?" and "what is data?", making the case that grub.cfg is code seems feasible, which greatly simplifies the work of whatever verifies attestations or binds/seals data. Although, implementations for these two don't really seem to be in conflict so maybe GRUB could be configured one way or the other.

I'm concerned that the language gives enough flexibility that we don't know that for sure - for instance, if a regularly used command is vulnerable to a buffer overflow, there's no way to determine whether that occurred. Measuring each command before it's executed gives us some further assurance in that respect. Calculating the expected values is still pretty easy, and if they're logged then you can have a regex-based engine for remote validation.

Signature · 1 line
Matthew Garrett | [email protected]
#19 lore raw
Quoted 10 lines · Matthew Garrett
Quoted 2 lines · Jon McCune

I'm not sure about measuring the commands that GRUB runs. GRUB's config file is a shell-like language, and measuring that file should give a

pretty

Quoted 2 lines

good indication of its behavior. In the grey area between "what is code?" and "what is data?", making the case that grub.cfg is code seems

feasible,

Quoted 2 lines

which greatly simplifies the work of whatever verifies attestations or binds/seals data. Although, implementations for these two don't really

Quoted 8 lines

seem

Quoted 1 line

to be in conflict so maybe GRUB could be configured one way or the other.

I'm concerned that the language gives enough flexibility that we don't know that for sure - for instance, if a regularly used command is vulnerable to a buffer overflow, there's no way to determine whether that occurred. Measuring each command before it's executed gives us some further assurance in that respect.

This is a good point. I'd still like to express a preference that it be optional.

Quoted 5 lines

Calculating the expected values is
still pretty easy, and if they're logged then you can have a regex-based engine for remote validation.

Thanks,
-Jon

#20 lore raw
In reply to Jon McCune
Quoted 16 lines · On Mon, 6 Feb 2017, 18:55 Jon McCune <[email protected]> wrote:

Matthew,

On Mon, Feb 6, 2017 at 8:43 AM, Matthew Garrett <[email protected]> wrote:

Quoted 2 lines · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the API, please say.

I think that's a starting point, but it doesn't seem sufficient for some of the cases I care about. For instance, measuring boot state isn't just about the files that are read - we also need to measure the commands that grub runs

Quoted 8 lines

I'm not sure about measuring the commands that GRUB runs. GRUB's config file is a shell-like language, and measuring that file should give a pretty good indication of its behavior. In the grey area between "what is code?" and "what is data?", making the case that grub.cfg is code seems feasible, which greatly simplifies the work of whatever verifies attestations or binds/seals data. Although, implementations for these two don't really seem to be in conflict so maybe GRUB could be configured one way or the other.

Independently of this, it's still useful to have Linux command line to be exposed to verifier if it wants to see it. I can imagine verifier wanting to check Linux command line but not wanting to verify the grub config file.

Quoted 35 lines

(I'm coming at this from the perspective of "gathering golden measurements by just-run-it-and-see considered harmful".)

and the command line passed to the kernel, for instance.

Agreed.

Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into,

This is definitely interesting. Re: the scenario above, files could get measured into one place. Commands executed could get measured into another.

but I can't think of
a good way to do that simply by hooking open. That also seems to make it difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything else.

Best,
-Jon

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#21 lore raw
In reply to Matthew Garrett
Quoted 10 lines · On Mon, 6 Feb 2017, 17:44 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the API, please say.

I think that's a starting point, but it doesn't seem sufficient for some of the cases I care about. For instance, measuring boot state isn't just about the files that are read - we also need to measure the commands that grub runs and the command line passed to the kernel, for instance.

Those can be added as separate non-file verification hooks if they are needed.

Quoted 7 lines

Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into, but I can't think of a good way to do that simply by hooking open. That also seems to make it difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything else.

This branch adds additional parameter to open that indicates what's the file will be used for (kernel, initrd, ...). In which cases doesn't it provide enough context?

Quoted 9 lines

--
Matthew Garrett | [email protected]

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#22 lore raw
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines · On Mon, 6 Feb 2017, 17:44 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the API, please say.

Quoted 7 lines
Quoted 5 lines

I think that's a starting point, but it doesn't seem sufficient for some of the cases I care about. For instance, measuring boot state isn't just about the files that are read - we also need to measure the commands that grub runs and the command line passed to the kernel, for instance.

Those can be added as separate non-file verification hooks if they are needed.

Ok. In that case I think this can probably work. I'll try porting it over.

Quoted 10 lines
Quoted 7 lines

Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into, but I can't think of a good way to do that simply by hooking open. That also seems to make it difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything else.

This branch adds additional parameter to open that indicates what's the file will be used for (kernel, initrd, ...). In which cases doesn't it provide enough context?

Sorry, yes, I missed the previous commit. I think that's enough.

Signature · 1 line
Matthew Garrett | [email protected]
#23 lore raw

Le Mon, Feb 6, 2017 à 11:11 PM, Matthew Garrett <[email protected]> a écrit :

Quoted 14 lines
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 3 lines · On Mon, 6 Feb 2017, 17:44 Matthew Garrett <[email protected]> wrote:
Quoted 1 line · Vladimir 'phcoder' Serbinenko

See verify.h for the interface. Obviously if you need changes in the

API,

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

please say.

I think that's a starting point, but it doesn't seem sufficient for

some

Quoted 1 line
Quoted 1 line

of the cases I care about. For instance, measuring boot state isn't

just

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

about the files that are read - we also need to measure the commands that grub runs and the command line passed to the kernel, for instance.

Those can be added as separate non-file verification hooks if they are needed.

Ok. In that case I think this can probably work. I'll try porting it over.

I added string verification. Now it verifies kernel command line but can be extended to other stuff.

Quoted 25 lines
Quoted 3 lines
Quoted 3 lines

Ideally we'd also have more context available in order to make a better decision about which PCR to measure something into, but I can't think

of

Quoted 1 line
Quoted 1 line

a good way to do that simply by hooking open. That also seems to make

it

Quoted 3 lines
Quoted 3 lines

difficult to implement a handler that should only be verifying some objects - for instance, a UEFI secure boot handler only wants to verify the kernel (or something that's chainloaded) and ignore everything

else.

Quoted 4 lines
Quoted 1 line

This branch adds additional parameter to open that indicates what's the file will be used for (kernel, initrd, ...). In which cases doesn't it provide enough context?

Sorry, yes, I missed the previous commit. I think that's enough.

--
Matthew Garrett | [email protected]

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel