nalika / rpms / grub2

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