dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone
f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Matthew Garrett <mjg59@coreos.com>
f725e3
Date: Tue, 14 Jul 2015 16:58:51 -0700
f725e3
Subject: [PATCH] Fix race in EFI validation
f725e3
f725e3
---
f725e3
 grub-core/loader/i386/efi/linux.c | 44 ++++++++++-----------------------------
f725e3
 1 file changed, 11 insertions(+), 33 deletions(-)
f725e3
f725e3
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
f725e3
index e5b778577f9..7ccf32d9d45 100644
f725e3
--- a/grub-core/loader/i386/efi/linux.c
f725e3
+++ b/grub-core/loader/i386/efi/linux.c
f725e3
@@ -154,7 +154,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
f725e3
   grub_file_t file = 0;
f725e3
   struct linux_kernel_header lh;
f725e3
   grub_ssize_t len, start, filelen;
f725e3
-  void *kernel;
f725e3
+  void *kernel = NULL;
f725e3
 
f725e3
   grub_dl_ref (my_mod);
f725e3
 
f725e3
@@ -191,10 +191,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
f725e3
       goto fail;
f725e3
     }
f725e3
 
f725e3
-  grub_file_seek (file, 0);
f725e3
-
f725e3
-  grub_free(kernel);
f725e3
-
f725e3
   params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384));
f725e3
 
f725e3
   if (! params)
f725e3
@@ -203,15 +199,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
f725e3
       goto fail;
f725e3
     }
f725e3
 
f725e3
-  memset (params, 0, 16384);
f725e3
+  grub_memset (params, 0, 16384);
f725e3
 
f725e3
-  if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
f725e3
-    {
f725e3
-      if (!grub_errno)
f725e3
-	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
f725e3
-		    argv[0]);
f725e3
-      goto fail;
f725e3
-    }
f725e3
+  grub_memcpy (&lh, kernel, sizeof (lh));
f725e3
 
f725e3
   if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
f725e3
     {
f725e3
@@ -271,27 +261,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
f725e3
       goto fail;
f725e3
     }
f725e3
 
f725e3
-  if (grub_file_seek (file, start) == (grub_off_t) -1)
f725e3
-    {
f725e3
-      grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
f725e3
-		  argv[0]);
f725e3
-      goto fail;
f725e3
-    }
f725e3
+  grub_memcpy (kernel_mem, (char *)kernel + start, len);
f725e3
+  grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
f725e3
+  loaded=1;
f725e3
 
f725e3
-  if (grub_file_read (file, kernel_mem, len) != len && !grub_errno)
f725e3
-    {
f725e3
-      grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
f725e3
-		  argv[0]);
f725e3
-    }
f725e3
-
f725e3
-  if (grub_errno == GRUB_ERR_NONE)
f725e3
-    {
f725e3
-      grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
f725e3
-      loaded = 1;
f725e3
-      lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
f725e3
-    }
f725e3
-
f725e3
-  memcpy(params, &lh, 2 * 512);
f725e3
+  lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
f725e3
+  grub_memcpy (params, &lh, 2 * 512);
f725e3
 
f725e3
   params->type_of_loader = 0x21;
f725e3
 
f725e3
@@ -300,6 +275,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
f725e3
   if (file)
f725e3
     grub_file_close (file);
f725e3
 
f725e3
+  if (kernel)
f725e3
+    grub_free (kernel);
f725e3
+
f725e3
   if (grub_errno != GRUB_ERR_NONE)
f725e3
     {
f725e3
       grub_dl_unref (my_mod);