15a207
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a207
From: Matthew Garrett <mjg59@coreos.com>
15a207
Date: Sun, 9 Aug 2015 16:28:29 -0700
15a207
Subject: [PATCH] Measure kernel and initrd on BIOS systems
15a207
15a207
Measure the kernel and initrd when loaded on BIOS systems
15a207
---
15a207
 grub-core/loader/i386/linux.c    | 5 +++++
15a207
 grub-core/loader/i386/pc/linux.c | 3 +++
15a207
 grub-core/loader/linux.c         | 2 ++
15a207
 3 files changed, 10 insertions(+)
15a207
15a207
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
15a207
index c84747ea857..94526966e8a 100644
15a207
--- a/grub-core/loader/i386/linux.c
15a207
+++ b/grub-core/loader/i386/linux.c
15a207
@@ -36,6 +36,7 @@
15a207
 #include <grub lib="" cmdline.h="">
15a207
 #include <grub linux.h="">
15a207
 #include <grub efi="" sb.h="">
15a207
+#include <grub tpm.h="">
15a207
 
15a207
 GRUB_MOD_LICENSE ("GPLv3+");
15a207
 
15a207
@@ -724,7 +725,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
15a207
       goto fail;
15a207
     }
15a207
 
15a207
+  grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "Linux Kernel");
15a207
+
15a207
   grub_memcpy (&lh, kernel, sizeof (lh));
15a207
+
15a207
   kernel_offset = sizeof (lh);
15a207
 
15a207
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
15a207
@@ -1038,6 +1042,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
15a207
 
15a207
   len = prot_file_size;
15a207
   grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
15a207
+  kernel_offset += len;
15a207
 
15a207
   if (grub_errno == GRUB_ERR_NONE)
15a207
     {
15a207
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
15a207
index 783a3cd93bc..15544230763 100644
15a207
--- a/grub-core/loader/i386/pc/linux.c
15a207
+++ b/grub-core/loader/i386/pc/linux.c
15a207
@@ -36,6 +36,7 @@
15a207
 #include <grub lib="" cmdline.h="">
15a207
 #include <grub linux.h="">
15a207
 #include <grub efi="" sb.h="">
15a207
+#include <grub tpm.h="">
15a207
 
15a207
 GRUB_MOD_LICENSE ("GPLv3+");
15a207
 
15a207
@@ -161,6 +162,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
15a207
       goto fail;
15a207
     }
15a207
 
15a207
+  grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "BIOS Linux Kernel");
15a207
+
15a207
   grub_memcpy (&lh, kernel, sizeof (lh));
15a207
   kernel_offset = sizeof (lh);
15a207
 
15a207
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
15a207
index be6fa0f4d45..3005c0d19c9 100644
15a207
--- a/grub-core/loader/linux.c
15a207
+++ b/grub-core/loader/linux.c
15a207
@@ -4,6 +4,7 @@
15a207
 #include <grub misc.h="">
15a207
 #include <grub file.h="">
15a207
 #include <grub mm.h="">
15a207
+#include <grub tpm.h="">
15a207
 
15a207
 struct newc_head
15a207
 {
15a207
@@ -288,6 +289,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
15a207
 	  grub_initrd_close (initrd_ctx);
15a207
 	  return grub_errno;
15a207
 	}
15a207
+      grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "Linux Initrd");
15a207
       ptr += cursize;
15a207
     }
15a207
   if (newc)