]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
efi: Get and store the secure boot status
authorDavid Howells <dhowells@redhat.com>
Mon, 6 Feb 2017 11:22:43 +0000 (11:22 +0000)
committerIngo Molnar <mingo@kernel.org>
Tue, 7 Feb 2017 09:42:10 +0000 (10:42 +0100)
Get the firmware's secure-boot status in the kernel boot wrapper and stash
it somewhere that the main kernel image can find.

The efi_get_secureboot() function is extracted from the ARM stub and (a)
generalised so that it can be called from x86 and (b) made to use
efi_call_runtime() so that it can be run in mixed-mode.

For x86, it is stored in boot_params and can be overridden by the boot
loader or kexec.  This allows secure-boot mode to be passed on to a new
kernel.

Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/1486380166-31868-5-git-send-email-ard.biesheuvel@linaro.org
[ Small readability edits. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Documentation/x86/zero-page.txt
arch/x86/boot/compressed/eboot.c
arch/x86/include/uapi/asm/bootparam.h
arch/x86/kernel/asm-offsets.c
drivers/firmware/efi/libstub/Makefile
drivers/firmware/efi/libstub/arm-stub.c
drivers/firmware/efi/libstub/secureboot.c [new file with mode: 0644]
include/linux/efi.h

index 95a4d34af3fdd799d28046e0b992dcbc049817ce..b8527c6b76461c7ee9446630c5acb4cc65867671 100644 (file)
@@ -31,6 +31,8 @@ Offset        Proto   Name            Meaning
 1E9/001        ALL     eddbuf_entries  Number of entries in eddbuf (below)
 1EA/001        ALL     edd_mbr_sig_buf_entries Number of entries in edd_mbr_sig_buffer
                                (below)
+1EB/001        ALL     kbd_status      Numlock is enabled
+1EC/001        ALL     secure_boot     Secure boot is enabled in the firmware
 1EF/001        ALL     sentinel        Used to detect broken bootloaders
 290/040        ALL     edd_mbr_sig_buffer EDD MBR signatures
 2D0/A00        ALL     e820_map        E820 memory map table
index f99978db6b6fac3f6d2ba75e4b7a3cf2ea182ebc..801c7a158e55938a830e709578be069f3b649c19 100644 (file)
@@ -988,6 +988,13 @@ struct boot_params *efi_main(struct efi_config *c,
        else
                setup_boot_services32(efi_early);
 
+       /*
+        * If the boot loader gave us a value for secure_boot then we use that,
+        * otherwise we ask the BIOS.
+        */
+       if (boot_params->secure_boot == efi_secureboot_mode_unset)
+               boot_params->secure_boot = efi_get_secureboot(sys_table);
+
        setup_graphics(boot_params);
 
        setup_efi_pci(boot_params);
index b10bf319ed206e132e7707f6080da700524450e3..5138dacf8bb8360511f7b3514f8ab0ac1a1e88f8 100644 (file)
@@ -135,7 +135,8 @@ struct boot_params {
        __u8  eddbuf_entries;                           /* 0x1e9 */
        __u8  edd_mbr_sig_buf_entries;                  /* 0x1ea */
        __u8  kbd_status;                               /* 0x1eb */
-       __u8  _pad5[3];                                 /* 0x1ec */
+       __u8  secure_boot;                              /* 0x1ec */
+       __u8  _pad5[2];                                 /* 0x1ed */
        /*
         * The sentinel is set to a nonzero value (0xff) in header.S.
         *
index c62e015b126cf5e3f880ae8ea1c32a19f39d7044..de827d6ac8c2e8ad751eba8699cd1e0ada0e7f4b 100644 (file)
@@ -81,6 +81,7 @@ void common(void) {
 
        BLANK();
        OFFSET(BP_scratch, boot_params, scratch);
+       OFFSET(BP_secure_boot, boot_params, secure_boot);
        OFFSET(BP_loadflags, boot_params, hdr.loadflags);
        OFFSET(BP_hardware_subarch, boot_params, hdr.hardware_subarch);
        OFFSET(BP_version, boot_params, hdr.version);
index 33e0e2f1a730109989c61994bbcd93560e542f03..f7425960f6a57d4d4048e905d4d6b101b333c114 100644 (file)
@@ -28,7 +28,7 @@ OBJECT_FILES_NON_STANDARD     := y
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT                        := n
 
-lib-y                          := efi-stub-helper.o gop.o
+lib-y                          := efi-stub-helper.o gop.o secureboot.o
 
 # include the stub's generic dependencies from lib/ when building for ARM/arm64
 arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c
index 6fca48c9e054b8c82e9b60e188ed6a460a290613..d4056c6be1ec0f029b7c0c457e34ab570356f0c6 100644 (file)
 
 bool __nokaslr;
 
-static int efi_get_secureboot(efi_system_table_t *sys_table_arg)
-{
-       static efi_char16_t const sb_var_name[] = {
-               'S', 'e', 'c', 'u', 'r', 'e', 'B', 'o', 'o', 't', 0 };
-       static efi_char16_t const sm_var_name[] = {
-               'S', 'e', 't', 'u', 'p', 'M', 'o', 'd', 'e', 0 };
-
-       efi_guid_t var_guid = EFI_GLOBAL_VARIABLE_GUID;
-       efi_get_variable_t *f_getvar = sys_table_arg->runtime->get_variable;
-       u8 val;
-       unsigned long size = sizeof(val);
-       efi_status_t status;
-
-       status = f_getvar((efi_char16_t *)sb_var_name, (efi_guid_t *)&var_guid,
-                         NULL, &size, &val);
-
-       if (status != EFI_SUCCESS)
-               goto out_efi_err;
-
-       if (val == 0)
-               return 0;
-
-       status = f_getvar((efi_char16_t *)sm_var_name, (efi_guid_t *)&var_guid,
-                         NULL, &size, &val);
-
-       if (status != EFI_SUCCESS)
-               goto out_efi_err;
-
-       if (val == 1)
-               return 0;
-
-       return 1;
-
-out_efi_err:
-       switch (status) {
-       case EFI_NOT_FOUND:
-               return 0;
-       case EFI_DEVICE_ERROR:
-               return -EIO;
-       case EFI_SECURITY_VIOLATION:
-               return -EACCES;
-       default:
-               return -EINVAL;
-       }
-}
-
 efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
                             void *__image, void **__fh)
 {
@@ -157,7 +111,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
        efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID;
        unsigned long reserve_addr = 0;
        unsigned long reserve_size = 0;
-       int secure_boot = 0;
+       enum efi_secureboot_mode secure_boot;
        struct screen_info *si;
 
        /* Check if we were booted by the EFI firmware */
@@ -227,19 +181,14 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
                pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n");
 
        secure_boot = efi_get_secureboot(sys_table);
-       if (secure_boot > 0)
-               pr_efi(sys_table, "UEFI Secure Boot is enabled.\n");
-
-       if (secure_boot < 0) {
-               pr_efi_err(sys_table,
-                       "could not determine UEFI Secure Boot status.\n");
-       }
 
        /*
-        * Unauthenticated device tree data is a security hazard, so
-        * ignore 'dtb=' unless UEFI Secure Boot is disabled.
+        * Unauthenticated device tree data is a security hazard, so ignore
+        * 'dtb=' unless UEFI Secure Boot is disabled.  We assume that secure
+        * boot is enabled if we can't determine its state.
         */
-       if (secure_boot != 0 && strstr(cmdline_ptr, "dtb=")) {
+       if (secure_boot != efi_secureboot_mode_disabled &&
+           strstr(cmdline_ptr, "dtb=")) {
                pr_efi(sys_table, "Ignoring DTB from command line.\n");
        } else {
                status = handle_cmdline_files(sys_table, image, cmdline_ptr,
diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c
new file mode 100644 (file)
index 0000000..b20b8b4
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Secure boot handling.
+ *
+ * Copyright (C) 2013,2014 Linaro Limited
+ *     Roy Franz <roy.franz@linaro.org
+ * Copyright (C) 2013 Red Hat, Inc.
+ *     Mark Salter <msalter@redhat.com>
+ *
+ * This file is part of the Linux kernel, and is made available under the
+ * terms of the GNU General Public License version 2.
+ */
+#include <linux/efi.h>
+#include <asm/efi.h>
+
+/* BIOS variables */
+static const efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
+static const efi_char16_t const efi_SecureBoot_name[] = {
+       'S', 'e', 'c', 'u', 'r', 'e', 'B', 'o', 'o', 't', 0
+};
+static const efi_char16_t const efi_SetupMode_name[] = {
+       'S', 'e', 't', 'u', 'p', 'M', 'o', 'd', 'e', 0
+};
+
+#define get_efi_var(name, vendor, ...) \
+       efi_call_runtime(get_variable, \
+                        (efi_char16_t *)(name), (efi_guid_t *)(vendor), \
+                        __VA_ARGS__);
+
+/*
+ * Determine whether we're in secure boot mode.
+ */
+enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
+{
+       u8 secboot, setupmode;
+       unsigned long size;
+       efi_status_t status;
+
+       size = sizeof(secboot);
+       status = get_efi_var(efi_SecureBoot_name, &efi_variable_guid,
+                            NULL, &size, &secboot);
+       if (status != EFI_SUCCESS)
+               goto out_efi_err;
+
+       size = sizeof(setupmode);
+       status = get_efi_var(efi_SetupMode_name, &efi_variable_guid,
+                            NULL, &size, &setupmode);
+       if (status != EFI_SUCCESS)
+               goto out_efi_err;
+
+       if (secboot == 0 || setupmode == 1)
+               return efi_secureboot_mode_disabled;
+
+       pr_efi(sys_table_arg, "UEFI Secure Boot is enabled.\n");
+       return efi_secureboot_mode_enabled;
+
+out_efi_err:
+       pr_efi_err(sys_table_arg, "Could not determine UEFI Secure Boot status.\n");
+       if (status == EFI_NOT_FOUND)
+               return efi_secureboot_mode_disabled;
+       return efi_secureboot_mode_unknown;
+}
index d00538a6589999fb15a99ed1ae82f93087709614..94d34e0be24f55477573f48806de2d2817fe9722 100644 (file)
@@ -1480,6 +1480,14 @@ efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
 bool efi_runtime_disabled(void);
 extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
 
+enum efi_secureboot_mode {
+       efi_secureboot_mode_unset,
+       efi_secureboot_mode_unknown,
+       efi_secureboot_mode_disabled,
+       efi_secureboot_mode_enabled,
+};
+enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
+
 /*
  * Arch code can implement the following three template macros, avoiding
  * reptition for the void/non-void return cases of {__,}efi_call_virt():