2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-04 18:32:29 +00:00
|
|
|
From: Matthew Garrett <mjg59@coreos.com>
|
|
|
|
Date: Sun, 9 Aug 2015 16:12:39 -0700
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] Rework linux command
|
2016-03-04 18:32:29 +00:00
|
|
|
|
|
|
|
We want a single buffer that contains the entire kernel image in order to
|
|
|
|
perform a TPM measurement. Allocate one and copy the entire kernel into it
|
|
|
|
before pulling out the individual blocks later on.
|
|
|
|
---
|
2018-07-17 14:20:54 +00:00
|
|
|
grub-core/loader/i386/linux.c | 37 ++++++++++++++++++++++++-------------
|
|
|
|
1 file changed, 24 insertions(+), 13 deletions(-)
|
2016-03-04 18:32:29 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
|
2018-07-27 16:57:04 +00:00
|
|
|
index 9b53d3168f9..f7186be4002 100644
|
2016-03-04 18:32:29 +00:00
|
|
|
--- a/grub-core/loader/i386/linux.c
|
|
|
|
+++ b/grub-core/loader/i386/linux.c
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -685,13 +685,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2018-07-17 14:20:54 +00:00
|
|
|
{
|
2016-03-04 18:32:29 +00:00
|
|
|
grub_file_t file = 0;
|
2018-07-10 19:08:14 +00:00
|
|
|
struct linux_i386_kernel_header lh;
|
2018-07-17 14:20:54 +00:00
|
|
|
+ grub_uint8_t *linux_params_ptr;
|
2016-03-04 18:32:29 +00:00
|
|
|
grub_uint8_t setup_sects;
|
|
|
|
- grub_size_t real_size, prot_size, prot_file_size;
|
|
|
|
+ grub_size_t real_size, prot_size, prot_file_size, kernel_offset;
|
|
|
|
grub_ssize_t len;
|
|
|
|
int i;
|
|
|
|
grub_size_t align, min_align;
|
|
|
|
int relocatable;
|
|
|
|
grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR;
|
|
|
|
+ grub_uint8_t *kernel = NULL;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -705,7 +707,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
if (! file)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
|
|
|
|
+ len = grub_file_size (file);
|
|
|
|
+ kernel = grub_malloc (len);
|
|
|
|
+ if (!kernel)
|
|
|
|
+ {
|
|
|
|
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (grub_file_read (file, kernel, len) != len)
|
|
|
|
{
|
|
|
|
if (!grub_errno)
|
|
|
|
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -713,6 +723,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
|
|
|
+ kernel_offset = sizeof (lh);
|
|
|
|
+
|
|
|
|
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
|
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -804,6 +817,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2018-07-17 14:20:54 +00:00
|
|
|
preferred_address))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
+
|
|
|
|
grub_memset (&linux_params, 0, sizeof (linux_params));
|
|
|
|
grub_memcpy (&linux_params.setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1);
|
|
|
|
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -812,13 +826,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
linux_params.ps_mouse = linux_params.padding10 = 0;
|
|
|
|
|
|
|
|
len = sizeof (linux_params) - sizeof (lh);
|
|
|
|
- if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len)
|
|
|
|
- {
|
|
|
|
- if (!grub_errno)
|
|
|
|
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
|
- argv[0]);
|
|
|
|
- goto fail;
|
|
|
|
- }
|
|
|
|
+
|
2018-07-17 14:20:54 +00:00
|
|
|
+ linux_params_ptr = (void *)&linux_params;
|
|
|
|
+ grub_memcpy (linux_params_ptr + sizeof (lh), kernel + kernel_offset, len);
|
2016-03-04 18:32:29 +00:00
|
|
|
+ kernel_offset += len;
|
|
|
|
|
|
|
|
linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE;
|
|
|
|
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -877,7 +888,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
|
|
|
|
/* The other parameters are filled when booting. */
|
|
|
|
|
|
|
|
- grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
|
|
|
|
+ kernel_offset = real_size + GRUB_DISK_SECTOR_SIZE;
|
|
|
|
|
|
|
|
grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
|
|
|
|
(unsigned) real_size, (unsigned) prot_size);
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -1025,9 +1036,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
- (sizeof (LINUX_IMAGE) - 1));
|
|
|
|
|
|
|
|
len = prot_file_size;
|
|
|
|
- if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
|
|
|
|
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
|
- argv[0]);
|
|
|
|
+ grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
|
|
|
|
|
|
|
|
if (grub_errno == GRUB_ERR_NONE)
|
|
|
|
{
|
2018-07-27 16:57:04 +00:00
|
|
|
@@ -1038,6 +1047,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
+ grub_free (kernel);
|
|
|
|
+
|
|
|
|
if (file)
|
|
|
|
grub_file_close (file);
|
|
|
|
|