File 0006-tpm-Measure-kernel-and-initrd-on-BIOS-systems.patch of Package grub2

From f0b411214ccc309f2f126d558e2777469d538ca2 Mon Sep 17 00:00:00 2001
From: Matthew Garrett <mjg59@coreos.com>
Date: Sun, 9 Aug 2015 16:28:29 -0700
Subject: [PATCH 06/11] Measure kernel and initrd on BIOS systems

Measure the kernel and initrd when loaded on BIOS systems
---
 grub-core/loader/i386/linux.c    | 5 +++++
 grub-core/loader/i386/pc/linux.c | 3 +++
 grub-core/loader/linux.c         | 2 ++
 3 files changed, 10 insertions(+)

Index: grub-2.02~beta3/grub-core/loader/i386/linux.c
===================================================================
--- grub-2.02~beta3.orig/grub-core/loader/i386/linux.c
+++ grub-2.02~beta3/grub-core/loader/i386/linux.c
@@ -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,10 @@ grub_cmd_linux (grub_command_t cmd __att
       goto fail;
     }
 
+  grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Kernel");
+
   grub_memcpy (&lh, kernel, sizeof (lh));
+
   kernel_offset = sizeof (lh);
 
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
@@ -1025,6 +1029,7 @@ grub_cmd_linux (grub_command_t cmd __att
 
   len = prot_file_size;
   grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
+  kernel_offset += len;
 
   if (grub_errno == GRUB_ERR_NONE)
     {
Index: grub-2.02~beta3/grub-core/loader/i386/pc/linux.c
===================================================================
--- grub-2.02~beta3.orig/grub-core/loader/i386/pc/linux.c
+++ grub-2.02~beta3/grub-core/loader/i386/pc/linux.c
@@ -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,8 @@ grub_cmd_linux (grub_command_t cmd __att
       goto fail;
     }
 
+  grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel");
+
   grub_memcpy (&lh, kernel, sizeof (lh));
   kernel_offset = sizeof (lh);
 
Index: grub-2.02~beta3/grub-core/loader/linux.c
===================================================================
--- grub-2.02~beta3.orig/grub-core/loader/linux.c
+++ grub-2.02~beta3/grub-core/loader/linux.c
@@ -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,7 @@ grub_initrd_load (struct grub_linux_init
 	  grub_initrd_close (initrd_ctx);
 	  return grub_errno;
 	}
+      grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Initrd");
       ptr += cursize;
     }
   if (newc)