|
|
f731ee |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
f731ee |
From: Matthew Garrett <mjg59@coreos.com>
|
|
|
f731ee |
Date: Sun, 9 Aug 2015 16:12:39 -0700
|
|
|
f731ee |
Subject: [PATCH] Rework linux command
|
|
|
f731ee |
|
|
|
f731ee |
We want a single buffer that contains the entire kernel image in order to
|
|
|
f731ee |
perform a TPM measurement. Allocate one and copy the entire kernel into it
|
|
|
f731ee |
before pulling out the individual blocks later on.
|
|
|
f731ee |
---
|
|
|
f731ee |
grub-core/loader/i386/linux.c | 34 +++++++++++++++++++++-------------
|
|
|
f731ee |
1 file changed, 21 insertions(+), 13 deletions(-)
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
|
|
|
f731ee |
index bd37c69b5d0..53f74ae0685 100644
|
|
|
f731ee |
--- a/grub-core/loader/i386/linux.c
|
|
|
f731ee |
+++ b/grub-core/loader/i386/linux.c
|
|
|
f731ee |
@@ -682,12 +682,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
grub_file_t file = 0;
|
|
|
f731ee |
struct linux_kernel_header lh;
|
|
|
f731ee |
grub_uint8_t setup_sects;
|
|
|
f731ee |
- grub_size_t real_size, prot_size, prot_file_size;
|
|
|
f731ee |
+ grub_size_t real_size, prot_size, prot_file_size, kernel_offset;
|
|
|
f731ee |
grub_ssize_t len;
|
|
|
f731ee |
int i;
|
|
|
f731ee |
grub_size_t align, min_align;
|
|
|
f731ee |
int relocatable;
|
|
|
f731ee |
grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR;
|
|
|
f731ee |
+ grub_uint8_t *kernel = NULL;
|
|
|
f731ee |
|
|
|
f731ee |
grub_dl_ref (my_mod);
|
|
|
f731ee |
|
|
|
f731ee |
@@ -701,7 +702,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
if (! file)
|
|
|
f731ee |
goto fail;
|
|
|
f731ee |
|
|
|
f731ee |
- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
|
|
|
f731ee |
+ len = grub_file_size (file);
|
|
|
f731ee |
+ kernel = grub_malloc (len);
|
|
|
f731ee |
+ if (!kernel)
|
|
|
f731ee |
+ {
|
|
|
f731ee |
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
|
|
f731ee |
+ goto fail;
|
|
|
f731ee |
+ }
|
|
|
f731ee |
+
|
|
|
f731ee |
+ if (grub_file_read (file, kernel, len) != len)
|
|
|
f731ee |
{
|
|
|
f731ee |
if (!grub_errno)
|
|
|
f731ee |
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
f731ee |
@@ -709,6 +718,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
goto fail;
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
|
|
f731ee |
+ kernel_offset = sizeof (lh);
|
|
|
f731ee |
+
|
|
|
f731ee |
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
|
|
|
f731ee |
{
|
|
|
f731ee |
grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
|
|
|
f731ee |
@@ -808,13 +820,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
linux_params.ps_mouse = linux_params.padding10 = 0;
|
|
|
f731ee |
|
|
|
f731ee |
len = sizeof (linux_params) - sizeof (lh);
|
|
|
f731ee |
- if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len)
|
|
|
f731ee |
- {
|
|
|
f731ee |
- if (!grub_errno)
|
|
|
f731ee |
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
f731ee |
- argv[0]);
|
|
|
f731ee |
- goto fail;
|
|
|
f731ee |
- }
|
|
|
f731ee |
+
|
|
|
f731ee |
+ grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len);
|
|
|
f731ee |
+ kernel_offset += len;
|
|
|
f731ee |
|
|
|
f731ee |
linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE;
|
|
|
f731ee |
|
|
|
f731ee |
@@ -873,7 +881,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
|
|
|
f731ee |
/* The other parameters are filled when booting. */
|
|
|
f731ee |
|
|
|
f731ee |
- grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
|
|
|
f731ee |
+ kernel_offset = real_size + GRUB_DISK_SECTOR_SIZE;
|
|
|
f731ee |
|
|
|
f731ee |
grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
|
|
|
f731ee |
(unsigned) real_size, (unsigned) prot_size);
|
|
|
f731ee |
@@ -1018,9 +1026,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
- (sizeof (LINUX_IMAGE) - 1));
|
|
|
f731ee |
|
|
|
f731ee |
len = prot_file_size;
|
|
|
f731ee |
- if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
|
|
|
f731ee |
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
f731ee |
- argv[0]);
|
|
|
f731ee |
+ grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
|
|
|
f731ee |
|
|
|
f731ee |
if (grub_errno == GRUB_ERR_NONE)
|
|
|
f731ee |
{
|
|
|
f731ee |
@@ -1031,6 +1037,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
f731ee |
|
|
|
f731ee |
fail:
|
|
|
f731ee |
|
|
|
f731ee |
+ grub_free (kernel);
|
|
|
f731ee |
+
|
|
|
f731ee |
if (file)
|
|
|
f731ee |
grub_file_close (file);
|
|
|
f731ee |
|