Blame SOURCES/0004-Add-support-for-Linux-EFI-stub-loading.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Matthew Garrett <mjg@redhat.com>
8e15ce
Date: Tue, 10 Jul 2012 11:58:52 -0400
8e15ce
Subject: [PATCH] Add support for Linux EFI stub loading.
8e15ce
8e15ce
Also:
8e15ce
8e15ce
commit 71c843745f22f81e16d259e2e19c99bf3c1855c1
8e15ce
Author: Colin Watson <cjwatson@ubuntu.com>
8e15ce
Date:   Tue Oct 23 10:40:49 2012 -0400
8e15ce
8e15ce
Don't allow insmod when secure boot is enabled.
8e15ce
8e15ce
Hi,
8e15ce
8e15ce
Fedora's patch to forbid insmod in UEFI Secure Boot environments is fine
8e15ce
as far as it goes.  However, the insmod command is not the only way that
8e15ce
modules can be loaded.  In particular, the 'normal' command, which
8e15ce
implements the usual GRUB menu and the fully-featured command prompt,
8e15ce
will implicitly load commands not currently loaded into memory.  This
8e15ce
permits trivial Secure Boot violations by writing commands implementing
8e15ce
whatever you want to do and pointing $prefix at the malicious code.
8e15ce
8e15ce
I'm currently test-building this patch (replacing your current
8e15ce
grub-2.00-no-insmod-on-sb.patch), but this should be more correct.  It
8e15ce
moves the check into grub_dl_load_file.
8e15ce
---
8e15ce
 grub-core/Makefile.core.def       |  16 +-
8e15ce
 grub-core/kern/dl.c               |  21 +++
8e15ce
 grub-core/kern/efi/efi.c          |  28 ++++
8e15ce
 grub-core/kern/efi/mm.c           |  32 ++++
8e15ce
 grub-core/loader/arm64/linux.c    | 118 +++++++-------
8e15ce
 grub-core/loader/arm64/xen_boot.c |   1 -
8e15ce
 grub-core/loader/efi/linux.c      |  70 ++++++++
8e15ce
 grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++
8e15ce
 grub-core/loader/i386/pc/linux.c  |  10 +-
8e15ce
 include/grub/arm/linux.h          |   9 +
8e15ce
 include/grub/arm64/linux.h        |   9 +
8e15ce
 include/grub/efi/efi.h            |   7 +-
8e15ce
 include/grub/efi/linux.h          |  31 ++++
8e15ce
 13 files changed, 618 insertions(+), 69 deletions(-)
8e15ce
 create mode 100644 grub-core/loader/efi/linux.c
8e15ce
 create mode 100644 grub-core/loader/i386/efi/linux.c
8e15ce
 create mode 100644 include/grub/efi/linux.h
8e15ce
8e15ce
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
8e15ce
index 8022e1c0a79..45d3edaa4dc 100644
8e15ce
--- a/grub-core/Makefile.core.def
8e15ce
+++ b/grub-core/Makefile.core.def
8e15ce
@@ -1734,13 +1734,6 @@ module = {
8e15ce
   enable = i386_pc;
8e15ce
 };
8e15ce
 
8e15ce
-
8e15ce
-module = {
8e15ce
-  name = linux16;
8e15ce
-  common = loader/i386/pc/linux.c;
8e15ce
-  enable = x86;
8e15ce
-};
8e15ce
-
8e15ce
 module = {
8e15ce
   name = ntldr;
8e15ce
   i386_pc = loader/i386/pc/ntldr.c;
8e15ce
@@ -1796,7 +1789,9 @@ module = {
8e15ce
 
8e15ce
 module = {
8e15ce
   name = linux;
8e15ce
-  x86 = loader/i386/linux.c;
8e15ce
+  i386_pc = loader/i386/pc/linux.c;
8e15ce
+  x86_64_efi = loader/i386/efi/linux.c;
8e15ce
+  i386_efi = loader/i386/efi/linux.c;
8e15ce
   i386_xen_pvh = loader/i386/linux.c;
8e15ce
   xen = loader/i386/xen.c;
8e15ce
   i386_pc = lib/i386/pc/vesa_modes_table.c;
8e15ce
@@ -1811,9 +1806,14 @@ module = {
8e15ce
   arm64 = loader/arm64/linux.c;
8e15ce
   riscv32 = loader/riscv/linux.c;
8e15ce
   riscv64 = loader/riscv/linux.c;
8e15ce
+  emu = loader/emu/linux.c;
8e15ce
+  fdt = lib/fdt.c;
8e15ce
+
8e15ce
   common = loader/linux.c;
8e15ce
   common = lib/cmdline.c;
8e15ce
   enable = noemu;
8e15ce
+
8e15ce
+  efi = loader/efi/linux.c;
8e15ce
 };
8e15ce
 
8e15ce
 module = {
8e15ce
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
8e15ce
index 48f8a79073d..b7149370950 100644
8e15ce
--- a/grub-core/kern/dl.c
8e15ce
+++ b/grub-core/kern/dl.c
8e15ce
@@ -38,6 +38,14 @@
8e15ce
 #define GRUB_MODULES_MACHINE_READONLY
8e15ce
 #endif
8e15ce
 
8e15ce
+#ifdef GRUB_MACHINE_EMU
8e15ce
+#include <sys/mman.h>
8e15ce
+#endif
8e15ce
+
8e15ce
+#ifdef GRUB_MACHINE_EFI
8e15ce
+#include <grub/efi/efi.h>
8e15ce
+#endif
8e15ce
+
8e15ce
 
8e15ce
 
8e15ce
 #pragma GCC diagnostic ignored "-Wcast-align"
8e15ce
@@ -695,6 +703,19 @@ grub_dl_load_file (const char *filename)
8e15ce
   void *core = 0;
8e15ce
   grub_dl_t mod = 0;
8e15ce
 
8e15ce
+#ifdef GRUB_MACHINE_EFI
8e15ce
+  if (grub_efi_secure_boot ())
8e15ce
+    {
8e15ce
+#if 0
8e15ce
+      /* This is an error, but grub2-mkconfig still generates a pile of
8e15ce
+       * insmod commands, so emitting it would be mostly just obnoxious. */
8e15ce
+      grub_error (GRUB_ERR_ACCESS_DENIED,
8e15ce
+		  "Secure Boot forbids loading module from %s", filename);
8e15ce
+#endif
8e15ce
+      return 0;
8e15ce
+    }
8e15ce
+#endif
8e15ce
+
8e15ce
   grub_boot_time ("Loading module %s", filename);
8e15ce
 
8e15ce
   file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
8e15ce
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
8e15ce
index 8cff7be0289..35b8f670602 100644
8e15ce
--- a/grub-core/kern/efi/efi.c
8e15ce
+++ b/grub-core/kern/efi/efi.c
8e15ce
@@ -286,6 +286,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
8e15ce
   return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
8e15ce
 }
8e15ce
 
8e15ce
+grub_efi_boolean_t
8e15ce
+grub_efi_secure_boot (void)
8e15ce
+{
8e15ce
+  grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
8e15ce
+  grub_size_t datasize;
8e15ce
+  char *secure_boot = NULL;
8e15ce
+  char *setup_mode = NULL;
8e15ce
+  grub_efi_boolean_t ret = 0;
8e15ce
+
8e15ce
+  secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
8e15ce
+
8e15ce
+  if (datasize != 1 || !secure_boot)
8e15ce
+    goto out;
8e15ce
+
8e15ce
+  setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
8e15ce
+
8e15ce
+  if (datasize != 1 || !setup_mode)
8e15ce
+    goto out;
8e15ce
+
8e15ce
+  if (*secure_boot && !*setup_mode)
8e15ce
+    ret = 1;
8e15ce
+
8e15ce
+ out:
8e15ce
+  grub_free (secure_boot);
8e15ce
+  grub_free (setup_mode);
8e15ce
+  return ret;
8e15ce
+}
8e15ce
+
8e15ce
 #pragma GCC diagnostic ignored "-Wcast-align"
8e15ce
 
8e15ce
 /* Search the mods section from the PE32/PE32+ image. This code uses
8e15ce
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
8e15ce
index 9838fb2f50d..f6aef0ef649 100644
8e15ce
--- a/grub-core/kern/efi/mm.c
8e15ce
+++ b/grub-core/kern/efi/mm.c
8e15ce
@@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
8e15ce
     }
8e15ce
 }
8e15ce
 
8e15ce
+/* Allocate pages below a specified address */
8e15ce
+void *
8e15ce
+grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
8e15ce
+			     grub_efi_uintn_t pages)
8e15ce
+{
8e15ce
+  grub_efi_status_t status;
8e15ce
+  grub_efi_boot_services_t *b;
8e15ce
+  grub_efi_physical_address_t address = max;
8e15ce
+
8e15ce
+  if (max > 0xffffffff)
8e15ce
+    return 0;
8e15ce
+
8e15ce
+  b = grub_efi_system_table->boot_services;
8e15ce
+  status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
8e15ce
+
8e15ce
+  if (status != GRUB_EFI_SUCCESS)
8e15ce
+    return 0;
8e15ce
+
8e15ce
+  if (address == 0)
8e15ce
+    {
8e15ce
+      /* Uggh, the address 0 was allocated... This is too annoying,
8e15ce
+	 so reallocate another one.  */
8e15ce
+      address = max;
8e15ce
+      status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
8e15ce
+      grub_efi_free_pages (0, pages);
8e15ce
+      if (status != GRUB_EFI_SUCCESS)
8e15ce
+	return 0;
8e15ce
+    }
8e15ce
+
8e15ce
+  return (void *) ((grub_addr_t) address);
8e15ce
+}
8e15ce
+
8e15ce
 /* Allocate pages. Return the pointer to the first of allocated pages.  */
8e15ce
 void *
8e15ce
 grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
8e15ce
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
8e15ce
index ef3e9f9444c..a312c668685 100644
8e15ce
--- a/grub-core/loader/arm64/linux.c
8e15ce
+++ b/grub-core/loader/arm64/linux.c
8e15ce
@@ -29,6 +29,7 @@
8e15ce
 #include <grub/efi/efi.h>
8e15ce
 #include <grub/efi/fdtload.h>
8e15ce
 #include <grub/efi/memory.h>
8e15ce
+#include <grub/efi/linux.h>
8e15ce
 #include <grub/efi/pe32.h>
8e15ce
 #include <grub/i18n.h>
8e15ce
 #include <grub/lib/cmdline.h>
8e15ce
@@ -41,6 +42,7 @@ static int loaded;
8e15ce
 
8e15ce
 static void *kernel_addr;
8e15ce
 static grub_uint64_t kernel_size;
8e15ce
+static grub_uint32_t handover_offset;
8e15ce
 
8e15ce
 static char *linux_args;
8e15ce
 static grub_uint32_t cmdline_size;
8e15ce
@@ -67,7 +69,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
8e15ce
 static grub_err_t
8e15ce
 finalize_params_linux (void)
8e15ce
 {
8e15ce
-  int node, retval;
8e15ce
+  grub_efi_loaded_image_t *loaded_image = NULL;
8e15ce
+  int node, retval, len;
8e15ce
 
8e15ce
   void *fdt;
8e15ce
 
8e15ce
@@ -102,79 +105,70 @@ finalize_params_linux (void)
8e15ce
   if (grub_fdt_install() != GRUB_ERR_NONE)
8e15ce
     goto failure;
8e15ce
 
8e15ce
-  return GRUB_ERR_NONE;
8e15ce
-
8e15ce
-failure:
8e15ce
-  grub_fdt_unload();
8e15ce
-  return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
8e15ce
-}
8e15ce
-
8e15ce
-grub_err_t
8e15ce
-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
8e15ce
-{
8e15ce
-  grub_efi_memory_mapped_device_path_t *mempath;
8e15ce
-  grub_efi_handle_t image_handle;
8e15ce
-  grub_efi_boot_services_t *b;
8e15ce
-  grub_efi_status_t status;
8e15ce
-  grub_efi_loaded_image_t *loaded_image;
8e15ce
-  int len;
8e15ce
-
8e15ce
-  mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
8e15ce
-  if (!mempath)
8e15ce
-    return grub_errno;
8e15ce
-
8e15ce
-  mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
8e15ce
-  mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
8e15ce
-  mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
8e15ce
-  mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
8e15ce
-  mempath[0].start_address = addr;
8e15ce
-  mempath[0].end_address = addr + size;
8e15ce
-
8e15ce
-  mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
8e15ce
-  mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
8e15ce
-  mempath[1].header.length = sizeof (grub_efi_device_path_t);
8e15ce
-
8e15ce
-  b = grub_efi_system_table->boot_services;
8e15ce
-  status = b->load_image (0, grub_efi_image_handle,
8e15ce
-			  (grub_efi_device_path_t *) mempath,
8e15ce
-			  (void *) addr, size, &image_handle);
8e15ce
-  if (status != GRUB_EFI_SUCCESS)
8e15ce
-    return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
8e15ce
-
8e15ce
-  grub_dprintf ("linux", "linux command line: '%s'\n", args);
8e15ce
+  grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
8e15ce
+                fdt);
8e15ce
 
8e15ce
   /* Convert command line to UCS-2 */
8e15ce
-  loaded_image = grub_efi_get_loaded_image (image_handle);
8e15ce
+  loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
8e15ce
+  if (!loaded_image)
8e15ce
+    goto failure;
8e15ce
+
8e15ce
   loaded_image->load_options_size = len =
8e15ce
-    (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
8e15ce
+    (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t);
8e15ce
   loaded_image->load_options =
8e15ce
     grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
8e15ce
   if (!loaded_image->load_options)
8e15ce
-    return grub_errno;
8e15ce
+    return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
8e15ce
 
8e15ce
   loaded_image->load_options_size =
8e15ce
     2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
8e15ce
-			    (grub_uint8_t *) args, len, NULL);
8e15ce
+                           (grub_uint8_t *) linux_args, len, NULL);
8e15ce
 
8e15ce
-  grub_dprintf ("linux", "starting image %p\n", image_handle);
8e15ce
-  status = b->start_image (image_handle, 0, NULL);
8e15ce
+  return GRUB_ERR_NONE;
8e15ce
 
8e15ce
-  /* When successful, not reached */
8e15ce
-  b->unload_image (image_handle);
8e15ce
-  grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
8e15ce
-		       GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
8e15ce
+failure:
8e15ce
+  grub_fdt_unload();
8e15ce
+  return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
8e15ce
+}
8e15ce
 
8e15ce
-  return grub_errno;
8e15ce
+static void
8e15ce
+free_params (void)
8e15ce
+{
8e15ce
+  grub_efi_loaded_image_t *loaded_image = NULL;
8e15ce
+
8e15ce
+  loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
8e15ce
+  if (loaded_image)
8e15ce
+    {
8e15ce
+      if (loaded_image->load_options)
8e15ce
+       grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options,
8e15ce
+                            GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
8e15ce
+      loaded_image->load_options = NULL;
8e15ce
+      loaded_image->load_options_size = 0;
8e15ce
+    }
8e15ce
+}
8e15ce
+
8e15ce
+grub_err_t
8e15ce
+grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args)
8e15ce
+{
8e15ce
+  grub_err_t retval;
8e15ce
+
8e15ce
+  retval = finalize_params_linux ();
8e15ce
+  if (retval != GRUB_ERR_NONE)
8e15ce
+    return grub_errno;
8e15ce
+
8e15ce
+  grub_dprintf ("linux", "linux command line: '%s'\n", args);
8e15ce
+
8e15ce
+  retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr);
8e15ce
+
8e15ce
+  /* Never reached... */
8e15ce
+  free_params();
8e15ce
+  return retval;
8e15ce
 }
8e15ce
 
8e15ce
 static grub_err_t
8e15ce
 grub_linux_boot (void)
8e15ce
 {
8e15ce
-  if (finalize_params_linux () != GRUB_ERR_NONE)
8e15ce
-    return grub_errno;
8e15ce
-
8e15ce
-  return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
8e15ce
-                                          kernel_size, linux_args));
8e15ce
+  return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args));
8e15ce
 }
8e15ce
 
8e15ce
 static grub_err_t
8e15ce
@@ -288,6 +282,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
8e15ce
 {
8e15ce
   grub_file_t file = 0;
8e15ce
   struct linux_arch_kernel_header lh;
8e15ce
+  struct grub_armxx_linux_pe_header *pe;
8e15ce
   grub_err_t err;
8e15ce
 
8e15ce
   grub_dl_ref (my_mod);
8e15ce
@@ -333,6 +328,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
8e15ce
 
8e15ce
   grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
8e15ce
 
8e15ce
+  if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size))
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]);
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
8e15ce
+  handover_offset = pe->opt.entry_addr;
8e15ce
+
8e15ce
   cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
8e15ce
   linux_args = grub_malloc (cmdline_size);
8e15ce
   if (!linux_args)
8e15ce
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
8e15ce
index 22cc25eccd9..d9b7a9ba400 100644
8e15ce
--- a/grub-core/loader/arm64/xen_boot.c
8e15ce
+++ b/grub-core/loader/arm64/xen_boot.c
8e15ce
@@ -266,7 +266,6 @@ xen_boot (void)
8e15ce
     return err;
8e15ce
 
8e15ce
   return grub_arch_efi_linux_boot_image (xen_hypervisor->start,
8e15ce
-					  xen_hypervisor->size,
8e15ce
 					  xen_hypervisor->cmdline);
8e15ce
 }
8e15ce
 
8e15ce
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
8e15ce
new file mode 100644
8e15ce
index 00000000000..c24202a5dd1
8e15ce
--- /dev/null
8e15ce
+++ b/grub-core/loader/efi/linux.c
8e15ce
@@ -0,0 +1,70 @@
8e15ce
+/*
8e15ce
+ *  GRUB  --  GRand Unified Bootloader
8e15ce
+ *  Copyright (C) 2014 Free Software Foundation, Inc.
8e15ce
+ *
8e15ce
+ *  GRUB is free software: you can redistribute it and/or modify
8e15ce
+ *  it under the terms of the GNU General Public License as published by
8e15ce
+ *  the Free Software Foundation, either version 3 of the License, or
8e15ce
+ *  (at your option) any later version.
8e15ce
+ *
8e15ce
+ *  GRUB is distributed in the hope that it will be useful,
8e15ce
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8e15ce
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8e15ce
+ *  GNU General Public License for more details.
8e15ce
+ *
8e15ce
+ *  You should have received a copy of the GNU General Public License
8e15ce
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8e15ce
+ */
8e15ce
+
8e15ce
+#include <grub/err.h>
8e15ce
+#include <grub/mm.h>
8e15ce
+#include <grub/types.h>
8e15ce
+#include <grub/cpu/linux.h>
8e15ce
+#include <grub/efi/efi.h>
8e15ce
+#include <grub/efi/pe32.h>
8e15ce
+#include <grub/efi/linux.h>
8e15ce
+
8e15ce
+#define SHIM_LOCK_GUID \
8e15ce
+ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} }
8e15ce
+
8e15ce
+struct grub_efi_shim_lock
8e15ce
+{
8e15ce
+  grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size);
8e15ce
+};
8e15ce
+typedef struct grub_efi_shim_lock grub_efi_shim_lock_t;
8e15ce
+
8e15ce
+grub_efi_boolean_t
8e15ce
+grub_linuxefi_secure_validate (void *data, grub_uint32_t size)
8e15ce
+{
8e15ce
+  grub_efi_guid_t guid = SHIM_LOCK_GUID;
8e15ce
+  grub_efi_shim_lock_t *shim_lock;
8e15ce
+
8e15ce
+  shim_lock = grub_efi_locate_protocol(&guid, NULL);
8e15ce
+
8e15ce
+  if (!shim_lock)
8e15ce
+    return 1;
8e15ce
+
8e15ce
+  if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS)
8e15ce
+    return 1;
8e15ce
+
8e15ce
+  return 0;
8e15ce
+}
8e15ce
+
8e15ce
+#pragma GCC diagnostic push
8e15ce
+#pragma GCC diagnostic ignored "-Wcast-align"
8e15ce
+
8e15ce
+typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
8e15ce
+
8e15ce
+grub_err_t
8e15ce
+grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
8e15ce
+		     void *kernel_params)
8e15ce
+{
8e15ce
+  handover_func hf;
8e15ce
+
8e15ce
+  hf = (handover_func)((char *)kernel_addr + offset);
8e15ce
+  hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
8e15ce
+
8e15ce
+  return GRUB_ERR_BUG;
8e15ce
+}
8e15ce
+
8e15ce
+#pragma GCC diagnostic pop
8e15ce
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
8e15ce
new file mode 100644
8e15ce
index 00000000000..bb2616a8092
8e15ce
--- /dev/null
8e15ce
+++ b/grub-core/loader/i386/efi/linux.c
8e15ce
@@ -0,0 +1,335 @@
8e15ce
+/*
8e15ce
+ *  GRUB  --  GRand Unified Bootloader
8e15ce
+ *  Copyright (C) 2012  Free Software Foundation, Inc.
8e15ce
+ *
8e15ce
+ *  GRUB is free software: you can redistribute it and/or modify
8e15ce
+ *  it under the terms of the GNU General Public License as published by
8e15ce
+ *  the Free Software Foundation, either version 3 of the License, or
8e15ce
+ *  (at your option) any later version.
8e15ce
+ *
8e15ce
+ *  GRUB is distributed in the hope that it will be useful,
8e15ce
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8e15ce
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8e15ce
+ *  GNU General Public License for more details.
8e15ce
+ *
8e15ce
+ *  You should have received a copy of the GNU General Public License
8e15ce
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8e15ce
+ */
8e15ce
+
8e15ce
+#include <grub/loader.h>
8e15ce
+#include <grub/file.h>
8e15ce
+#include <grub/err.h>
8e15ce
+#include <grub/types.h>
8e15ce
+#include <grub/mm.h>
8e15ce
+#include <grub/cpu/linux.h>
8e15ce
+#include <grub/command.h>
8e15ce
+#include <grub/i18n.h>
8e15ce
+#include <grub/lib/cmdline.h>
8e15ce
+#include <grub/efi/efi.h>
8e15ce
+#include <grub/efi/linux.h>
8e15ce
+
8e15ce
+GRUB_MOD_LICENSE ("GPLv3+");
8e15ce
+
8e15ce
+static grub_dl_t my_mod;
8e15ce
+static int loaded;
8e15ce
+static void *kernel_mem;
8e15ce
+static grub_uint64_t kernel_size;
8e15ce
+static grub_uint8_t *initrd_mem;
8e15ce
+static grub_uint32_t handover_offset;
8e15ce
+struct linux_kernel_params *params;
8e15ce
+static char *linux_cmdline;
8e15ce
+
8e15ce
+#define BYTES_TO_PAGES(bytes)   (((bytes) + 0xfff) >> 12)
8e15ce
+
8e15ce
+static grub_err_t
8e15ce
+grub_linuxefi_boot (void)
8e15ce
+{
8e15ce
+  int offset = 0;
8e15ce
+
8e15ce
+#ifdef __x86_64__
8e15ce
+  offset = 512;
8e15ce
+#endif
8e15ce
+  asm volatile ("cli");
8e15ce
+
8e15ce
+  return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset,
8e15ce
+			      params);
8e15ce
+}
8e15ce
+
8e15ce
+static grub_err_t
8e15ce
+grub_linuxefi_unload (void)
8e15ce
+{
8e15ce
+  grub_dl_unref (my_mod);
8e15ce
+  loaded = 0;
8e15ce
+  if (initrd_mem)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
8e15ce
+			 BYTES_TO_PAGES(params->ramdisk_size));
8e15ce
+  if (linux_cmdline)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
8e15ce
+			 linux_cmdline,
8e15ce
+			 BYTES_TO_PAGES(params->cmdline_size + 1));
8e15ce
+  if (kernel_mem)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
8e15ce
+			 BYTES_TO_PAGES(kernel_size));
8e15ce
+  if (params)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
8e15ce
+			 BYTES_TO_PAGES(16384));
8e15ce
+  return GRUB_ERR_NONE;
8e15ce
+}
8e15ce
+
8e15ce
+static grub_err_t
8e15ce
+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
8e15ce
+                 int argc, char *argv[])
8e15ce
+{
8e15ce
+  grub_file_t *files = 0;
8e15ce
+  int i, nfiles = 0;
8e15ce
+  grub_size_t size = 0;
8e15ce
+  grub_uint8_t *ptr;
8e15ce
+
8e15ce
+  if (argc == 0)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (!loaded)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  files = grub_zalloc (argc * sizeof (files[0]));
8e15ce
+  if (!files)
8e15ce
+    goto fail;
8e15ce
+
8e15ce
+  for (i = 0; i < argc; i++)
8e15ce
+    {
8e15ce
+      files[i] = grub_file_open (argv[i], GRUB_FILE_TYPE_LINUX_INITRD | GRUB_FILE_TYPE_NO_DECOMPRESS);
8e15ce
+      if (! files[i])
8e15ce
+        goto fail;
8e15ce
+      nfiles++;
8e15ce
+      size += ALIGN_UP (grub_file_size (files[i]), 4);
8e15ce
+    }
8e15ce
+
8e15ce
+  initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size));
8e15ce
+  if (!initrd_mem)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  params->ramdisk_size = size;
8e15ce
+  params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem;
8e15ce
+
8e15ce
+  ptr = initrd_mem;
8e15ce
+
8e15ce
+  for (i = 0; i < nfiles; i++)
8e15ce
+    {
8e15ce
+      grub_ssize_t cursize = grub_file_size (files[i]);
8e15ce
+      if (grub_file_read (files[i], ptr, cursize) != cursize)
8e15ce
+        {
8e15ce
+          if (!grub_errno)
8e15ce
+            grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
8e15ce
+                        argv[i]);
8e15ce
+          goto fail;
8e15ce
+        }
8e15ce
+      ptr += cursize;
8e15ce
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
8e15ce
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
8e15ce
+    }
8e15ce
+
8e15ce
+  params->ramdisk_size = size;
8e15ce
+
8e15ce
+ fail:
8e15ce
+  for (i = 0; i < nfiles; i++)
8e15ce
+    grub_file_close (files[i]);
8e15ce
+  grub_free (files);
8e15ce
+
8e15ce
+  if (initrd_mem && grub_errno)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
8e15ce
+			 BYTES_TO_PAGES(size));
8e15ce
+
8e15ce
+  return grub_errno;
8e15ce
+}
8e15ce
+
8e15ce
+static grub_err_t
8e15ce
+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
8e15ce
+		int argc, char *argv[])
8e15ce
+{
8e15ce
+  grub_file_t file = 0;
8e15ce
+  struct linux_i386_kernel_header lh;
8e15ce
+  grub_ssize_t len, start, filelen;
8e15ce
+  void *kernel = NULL;
8e15ce
+
8e15ce
+  grub_dl_ref (my_mod);
8e15ce
+
8e15ce
+  if (argc == 0)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
8e15ce
+  if (! file)
8e15ce
+    goto fail;
8e15ce
+
8e15ce
+  filelen = grub_file_size (file);
8e15ce
+
8e15ce
+  kernel = grub_malloc(filelen);
8e15ce
+
8e15ce
+  if (!kernel)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (grub_file_read (file, kernel, filelen) != filelen)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]);
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (! grub_linuxefi_secure_validate (kernel, filelen))
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"),
8e15ce
+		  argv[0]);
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384));
8e15ce
+
8e15ce
+  if (! params)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  grub_memset (params, 0, 16384);
8e15ce
+
8e15ce
+  grub_memcpy (&lh, kernel, sizeof (lh));
8e15ce
+
8e15ce
+  if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_OS, N_("invalid magic number"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (lh.setup_sects > GRUB_LINUX_MAX_SETUP_SECTS)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_OS, N_("too many setup sectors"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (lh.version < grub_cpu_to_le16 (0x020b))
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_OS, N_("kernel too old"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (!lh.handover_offset)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support EFI handover"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  grub_dprintf ("linux", "setting up cmdline\n");
8e15ce
+  linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
8e15ce
+					 BYTES_TO_PAGES(lh.cmdline_size + 1));
8e15ce
+
8e15ce
+  if (!linux_cmdline)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
8e15ce
+  grub_create_loader_cmdline (argc, argv,
8e15ce
+                              linux_cmdline + sizeof (LINUX_IMAGE) - 1,
8e15ce
+			      lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1),
8e15ce
+			      GRUB_VERIFY_KERNEL_CMDLINE);
8e15ce
+
8e15ce
+  lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
8e15ce
+
8e15ce
+  handover_offset = lh.handover_offset;
8e15ce
+
8e15ce
+  start = (lh.setup_sects + 1) * 512;
8e15ce
+  len = grub_file_size(file) - start;
8e15ce
+
8e15ce
+  kernel_mem = grub_efi_allocate_pages_max(lh.pref_address,
8e15ce
+					   BYTES_TO_PAGES(lh.init_size));
8e15ce
+
8e15ce
+  if (!kernel_mem)
8e15ce
+    kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
8e15ce
+					     BYTES_TO_PAGES(lh.init_size));
8e15ce
+
8e15ce
+  if (!kernel_mem)
8e15ce
+    {
8e15ce
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
8e15ce
+      goto fail;
8e15ce
+    }
8e15ce
+
8e15ce
+  grub_memcpy (kernel_mem, (char *)kernel + start, len);
8e15ce
+  grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
8e15ce
+  loaded=1;
8e15ce
+
8e15ce
+  lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
8e15ce
+  grub_memcpy (params, &lh, 2 * 512);
8e15ce
+
8e15ce
+  params->type_of_loader = 0x21;
8e15ce
+
8e15ce
+ fail:
8e15ce
+
8e15ce
+  if (file)
8e15ce
+    grub_file_close (file);
8e15ce
+
8e15ce
+  if (kernel)
8e15ce
+    grub_free (kernel);
8e15ce
+
8e15ce
+  if (grub_errno != GRUB_ERR_NONE)
8e15ce
+    {
8e15ce
+      grub_dl_unref (my_mod);
8e15ce
+      loaded = 0;
8e15ce
+    }
8e15ce
+
8e15ce
+  if (linux_cmdline && !loaded)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
8e15ce
+			 linux_cmdline,
8e15ce
+			 BYTES_TO_PAGES(lh.cmdline_size + 1));
8e15ce
+
8e15ce
+  if (kernel_mem && !loaded)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
8e15ce
+			 BYTES_TO_PAGES(kernel_size));
8e15ce
+
8e15ce
+  if (params && !loaded)
8e15ce
+    grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
8e15ce
+			 BYTES_TO_PAGES(16384));
8e15ce
+
8e15ce
+  return grub_errno;
8e15ce
+}
8e15ce
+
8e15ce
+static grub_command_t cmd_linux, cmd_initrd;
8e15ce
+static grub_command_t cmd_linuxefi, cmd_initrdefi;
8e15ce
+
8e15ce
+GRUB_MOD_INIT(linux)
8e15ce
+{
8e15ce
+  cmd_linux =
8e15ce
+    grub_register_command ("linux", grub_cmd_linux,
8e15ce
+                           0, N_("Load Linux."));
8e15ce
+  cmd_linuxefi =
8e15ce
+    grub_register_command ("linuxefi", grub_cmd_linux,
8e15ce
+                           0, N_("Load Linux."));
8e15ce
+  cmd_initrd =
8e15ce
+    grub_register_command ("initrd", grub_cmd_initrd,
8e15ce
+                           0, N_("Load initrd."));
8e15ce
+  cmd_initrdefi =
8e15ce
+    grub_register_command ("initrdefi", grub_cmd_initrd,
8e15ce
+                           0, N_("Load initrd."));
8e15ce
+  my_mod = mod;
8e15ce
+}
8e15ce
+
8e15ce
+GRUB_MOD_FINI(linux)
8e15ce
+{
8e15ce
+  grub_unregister_command (cmd_linux);
8e15ce
+  grub_unregister_command (cmd_linuxefi);
8e15ce
+  grub_unregister_command (cmd_initrd);
8e15ce
+  grub_unregister_command (cmd_initrdefi);
8e15ce
+}
8e15ce
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
8e15ce
index 2a299520160..8be4c3b3f48 100644
8e15ce
--- a/grub-core/loader/i386/pc/linux.c
8e15ce
+++ b/grub-core/loader/i386/pc/linux.c
8e15ce
@@ -474,14 +474,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
8e15ce
   return grub_errno;
8e15ce
 }
8e15ce
 
8e15ce
-static grub_command_t cmd_linux, cmd_initrd;
8e15ce
+static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16;
8e15ce
 
8e15ce
 GRUB_MOD_INIT(linux16)
8e15ce
 {
8e15ce
   cmd_linux =
8e15ce
+    grub_register_command ("linux", grub_cmd_linux,
8e15ce
+			   0, N_("Load Linux."));
8e15ce
+  cmd_linux16 =
8e15ce
     grub_register_command ("linux16", grub_cmd_linux,
8e15ce
 			   0, N_("Load Linux."));
8e15ce
   cmd_initrd =
8e15ce
+    grub_register_command ("initrd", grub_cmd_initrd,
8e15ce
+			   0, N_("Load initrd."));
8e15ce
+  cmd_initrd16 =
8e15ce
     grub_register_command ("initrd16", grub_cmd_initrd,
8e15ce
 			   0, N_("Load initrd."));
8e15ce
   my_mod = mod;
8e15ce
@@ -490,5 +496,7 @@ GRUB_MOD_INIT(linux16)
8e15ce
 GRUB_MOD_FINI(linux16)
8e15ce
 {
8e15ce
   grub_unregister_command (cmd_linux);
8e15ce
+  grub_unregister_command (cmd_linux16);
8e15ce
   grub_unregister_command (cmd_initrd);
8e15ce
+  grub_unregister_command (cmd_initrd16);
8e15ce
 }
8e15ce
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
8e15ce
index bcd5a7eb186..b582f67f661 100644
8e15ce
--- a/include/grub/arm/linux.h
8e15ce
+++ b/include/grub/arm/linux.h
8e15ce
@@ -20,6 +20,7 @@
8e15ce
 #ifndef GRUB_ARM_LINUX_HEADER
8e15ce
 #define GRUB_ARM_LINUX_HEADER 1
8e15ce
 
8e15ce
+#include <grub/efi/pe32.h>
8e15ce
 #include "system.h"
8e15ce
 
8e15ce
 #define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818
8e15ce
@@ -34,9 +35,17 @@ struct linux_arm_kernel_header {
8e15ce
   grub_uint32_t hdr_offset;
8e15ce
 };
8e15ce
 
8e15ce
+struct grub_arm_linux_pe_header
8e15ce
+{
8e15ce
+  grub_uint32_t magic;
8e15ce
+  struct grub_pe32_coff_header coff;
8e15ce
+  struct grub_pe32_optional_header opt;
8e15ce
+};
8e15ce
+
8e15ce
 #if defined(__arm__)
8e15ce
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
8e15ce
 # define linux_arch_kernel_header linux_arm_kernel_header
8e15ce
+# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
8e15ce
 #endif
8e15ce
 
8e15ce
 #if defined GRUB_MACHINE_UBOOT
8e15ce
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
8e15ce
index 7e22b4ab699..ea030312df3 100644
8e15ce
--- a/include/grub/arm64/linux.h
8e15ce
+++ b/include/grub/arm64/linux.h
8e15ce
@@ -19,6 +19,7 @@
8e15ce
 #ifndef GRUB_ARM64_LINUX_HEADER
8e15ce
 #define GRUB_ARM64_LINUX_HEADER 1
8e15ce
 
8e15ce
+#include <grub/efi/pe32.h>
8e15ce
 #include <grub/types.h>
8e15ce
 
8e15ce
 #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
8e15ce
@@ -38,9 +39,17 @@ struct linux_arm64_kernel_header
8e15ce
   grub_uint32_t hdr_offset;	/* Offset of PE/COFF header */
8e15ce
 };
8e15ce
 
8e15ce
+struct grub_arm64_linux_pe_header
8e15ce
+{
8e15ce
+  grub_uint32_t magic;
8e15ce
+  struct grub_pe32_coff_header coff;
8e15ce
+  struct grub_pe64_optional_header opt;
8e15ce
+};
8e15ce
+
8e15ce
 #if defined(__aarch64__)
8e15ce
 # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
8e15ce
 # define linux_arch_kernel_header linux_arm64_kernel_header
8e15ce
+# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
8e15ce
 #endif
8e15ce
 
8e15ce
 #endif /* ! GRUB_ARM64_LINUX_HEADER */
8e15ce
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
8e15ce
index 83d958f9945..6295df85f3f 100644
8e15ce
--- a/include/grub/efi/efi.h
8e15ce
+++ b/include/grub/efi/efi.h
8e15ce
@@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,
8e15ce
 				      grub_efi_uintn_t pages);
8e15ce
 void *
8e15ce
 EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
8e15ce
+void *
8e15ce
+EXPORT_FUNC(grub_efi_allocate_pages_max) (grub_efi_physical_address_t max,
8e15ce
+					  grub_efi_uintn_t pages);
8e15ce
 void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
8e15ce
 				       grub_efi_uintn_t pages);
8e15ce
 grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);
8e15ce
@@ -88,6 +91,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
8e15ce
 				     const grub_efi_guid_t *guid,
8e15ce
 				     void *data,
8e15ce
 				     grub_size_t datasize);
8e15ce
+grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);
8e15ce
 int
8e15ce
 EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
8e15ce
 					     const grub_efi_device_path_t *dp2);
8e15ce
@@ -101,8 +105,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
8e15ce
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
8e15ce
 #include <grub/cpu/linux.h>
8e15ce
 grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh);
8e15ce
-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
8e15ce
-                                           char *args);
8e15ce
+grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args);
8e15ce
 #endif
8e15ce
 
8e15ce
 grub_addr_t grub_efi_modules_addr (void);
8e15ce
diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h
8e15ce
new file mode 100644
8e15ce
index 00000000000..d9ede36773b
8e15ce
--- /dev/null
8e15ce
+++ b/include/grub/efi/linux.h
8e15ce
@@ -0,0 +1,31 @@
8e15ce
+/*
8e15ce
+ *  GRUB  --  GRand Unified Bootloader
8e15ce
+ *  Copyright (C) 2014  Free Software Foundation, Inc.
8e15ce
+ *
8e15ce
+ *  GRUB is free software: you can redistribute it and/or modify
8e15ce
+ *  it under the terms of the GNU General Public License as published by
8e15ce
+ *  the Free Software Foundation, either version 3 of the License, or
8e15ce
+ *  (at your option) any later version.
8e15ce
+ *
8e15ce
+ *  GRUB is distributed in the hope that it will be useful,
8e15ce
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8e15ce
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8e15ce
+ *  GNU General Public License for more details.
8e15ce
+ *
8e15ce
+ *  You should have received a copy of the GNU General Public License
8e15ce
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8e15ce
+ */
8e15ce
+#ifndef GRUB_EFI_LINUX_HEADER
8e15ce
+#define GRUB_EFI_LINUX_HEADER	1
8e15ce
+
8e15ce
+#include <grub/efi/api.h>
8e15ce
+#include <grub/err.h>
8e15ce
+#include <grub/symbol.h>
8e15ce
+
8e15ce
+grub_efi_boolean_t
8e15ce
+EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size);
8e15ce
+grub_err_t
8e15ce
+EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
8e15ce
+				  void *kernel_param);
8e15ce
+
8e15ce
+#endif /* ! GRUB_EFI_LINUX_HEADER */