Blame SOURCES/0215-Fix-race-in-EFI-validation.patch

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