nalika / rpms / grub2

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