dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0130-Measure-kernel-and-initrd-on-BIOS-systems.patch

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