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:20:58 -0700
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] Rework linux16 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 int it
|
|
|
|
before pulling out the individual blocks later on.
|
|
|
|
---
|
|
|
|
grub-core/loader/i386/pc/linux.c | 34 +++++++++++++++++++++-------------
|
|
|
|
1 file changed, 21 insertions(+), 13 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
|
2018-07-17 14:20:54 +00:00
|
|
|
index a3c87cf2fc2..caa76bee8af 100644
|
2016-03-04 18:32:29 +00:00
|
|
|
--- a/grub-core/loader/i386/pc/linux.c
|
|
|
|
+++ b/grub-core/loader/i386/pc/linux.c
|
2018-07-17 14:20:54 +00:00
|
|
|
@@ -123,13 +123,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
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;
|
2016-03-04 18:32:29 +00:00
|
|
|
grub_uint8_t setup_sects;
|
|
|
|
- grub_size_t real_size;
|
|
|
|
+ grub_size_t real_size, kernel_offset = 0;
|
|
|
|
grub_ssize_t len;
|
|
|
|
int i;
|
|
|
|
char *grub_linux_prot_chunk;
|
|
|
|
int grub_linux_is_bzimage;
|
|
|
|
grub_addr_t grub_linux_prot_target;
|
|
|
|
grub_err_t err;
|
|
|
|
+ grub_uint8_t *kernel = NULL;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
2018-07-17 14:20:54 +00:00
|
|
|
@@ -143,7 +144,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-17 14:20:54 +00:00
|
|
|
@@ -151,6 +160,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-17 14:20:54 +00:00
|
|
|
@@ -314,13 +326,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
grub_memmove (grub_linux_real_chunk, &lh, sizeof (lh));
|
|
|
|
|
|
|
|
len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
|
|
|
|
- if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len)
|
|
|
|
- {
|
|
|
|
- if (!grub_errno)
|
|
|
|
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
|
- argv[0]);
|
|
|
|
- goto fail;
|
|
|
|
- }
|
|
|
|
+ grub_memcpy (grub_linux_real_chunk + sizeof (lh), kernel + kernel_offset,
|
|
|
|
+ len);
|
|
|
|
+ kernel_offset += len;
|
|
|
|
|
2018-07-10 19:08:14 +00:00
|
|
|
if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
|
2016-03-04 18:32:29 +00:00
|
|
|
|| grub_le_to_cpu16 (lh.version) < 0x0200)
|
2018-07-17 14:20:54 +00:00
|
|
|
@@ -355,10 +363,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
2016-03-04 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
len = grub_linux16_prot_size;
|
|
|
|
- if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size)
|
|
|
|
- != (grub_ssize_t) grub_linux16_prot_size && !grub_errno)
|
|
|
|
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
|
|
|
- argv[0]);
|
|
|
|
+ grub_memcpy (grub_linux_prot_chunk, kernel + kernel_offset, len);
|
|
|
|
+ kernel_offset += len;
|
|
|
|
|
|
|
|
if (grub_errno == GRUB_ERR_NONE)
|
|
|
|
{
|
2018-07-17 14:20:54 +00:00
|
|
|
@@ -368,6 +374,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);
|
|
|
|
|