]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
UBUNTU: SAUCE: (efi-lockdown) efi: Add an EFI_SECURE_BOOT flag to indicate secure...
authorDavid Howells <dhowells@redhat.com>
Tue, 27 Feb 2018 10:04:55 +0000 (10:04 +0000)
committerPaolo Pisati <paolo.pisati@canonical.com>
Mon, 16 Sep 2019 13:06:45 +0000 (15:06 +0200)
UEFI machines can be booted in Secure Boot mode.  Add an EFI_SECURE_BOOT
flag that can be passed to efi_enabled() to find out whether secure boot is
enabled.

Move the switch-statement in x86's setup_arch() that inteprets the
secure_boot boot parameter to generic code and set the bit there.

Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
cc: linux-efi@vger.kernel.org
Signed-off-by: Jeremy Cline <jcline@redhat.com>
(cherry picked from commit 80cc4bec33ca9429c01082ef9ad51c9f2cbc3f23
 git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
arch/x86/kernel/setup.c
drivers/firmware/efi/Makefile
drivers/firmware/efi/secureboot.c [new file with mode: 0644]
include/linux/efi.h

index bbe35bf879f57e1af06a9105ce7d3f31cbc3f895..7e528b6af86bc7d8edae70f85fcdb4d77d97ee16 100644 (file)
@@ -1179,19 +1179,7 @@ void __init setup_arch(char **cmdline_p)
        /* Allocate bigger log buffer */
        setup_log_buf(1);
 
-       if (efi_enabled(EFI_BOOT)) {
-               switch (boot_params.secure_boot) {
-               case efi_secureboot_mode_disabled:
-                       pr_info("Secure boot disabled\n");
-                       break;
-               case efi_secureboot_mode_enabled:
-                       pr_info("Secure boot enabled\n");
-                       break;
-               default:
-                       pr_info("Secure boot could not be determined\n");
-                       break;
-               }
-       }
+       efi_set_secure_boot(boot_params.secure_boot);
 
        reserve_initrd();
 
index d2d0d20306200eedece2d5de4e708e70a9bbb16c..a2447837d2801d735a01e579230e0b3c8ee1d683 100644 (file)
@@ -24,6 +24,7 @@ obj-$(CONFIG_EFI_FAKE_MEMMAP)         += fake_mem.o
 obj-$(CONFIG_EFI_BOOTLOADER_CONTROL)   += efibc.o
 obj-$(CONFIG_EFI_TEST)                 += test/
 obj-$(CONFIG_EFI_DEV_PATH_PARSER)      += dev-path-parser.o
+obj-$(CONFIG_EFI)                      += secureboot.o
 obj-$(CONFIG_APPLE_PROPERTIES)         += apple-properties.o
 
 arm-obj-$(CONFIG_EFI)                  := arm-init.o arm-runtime.o
diff --git a/drivers/firmware/efi/secureboot.c b/drivers/firmware/efi/secureboot.c
new file mode 100644 (file)
index 0000000..9070055
--- /dev/null
@@ -0,0 +1,38 @@
+/* Core kernel secure boot support.
+ *
+ * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/efi.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
+
+/*
+ * Decide what to do when UEFI secure boot mode is enabled.
+ */
+void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
+{
+       if (efi_enabled(EFI_BOOT)) {
+               switch (mode) {
+               case efi_secureboot_mode_disabled:
+                       pr_info("Secure boot disabled\n");
+                       break;
+               case efi_secureboot_mode_enabled:
+                       set_bit(EFI_SECURE_BOOT, &efi.flags);
+                       pr_info("Secure boot enabled\n");
+                       break;
+               default:
+                       pr_warning("Secure boot could not be determined (mode %u)\n",
+                                  mode);
+                       break;
+               }
+       }
+}
index 088c1b0ab89a47156d7b53a7bfd3cb7dad884298..e0b39b826c40020fdb52ab2971287d10bbd99ff0 100644 (file)
@@ -1203,6 +1203,14 @@ extern int __init efi_setup_pcdp_console(char *);
 #define EFI_DBG                        8       /* Print additional debug info at runtime */
 #define EFI_NX_PE_DATA         9       /* Can runtime data regions be mapped non-executable? */
 #define EFI_MEM_ATTR           10      /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
+#define EFI_SECURE_BOOT                11      /* Are we in Secure Boot mode? */
+
+enum efi_secureboot_mode {
+       efi_secureboot_mode_unset,
+       efi_secureboot_mode_unknown,
+       efi_secureboot_mode_disabled,
+       efi_secureboot_mode_enabled,
+};
 
 #ifdef CONFIG_EFI
 /*
@@ -1215,6 +1223,8 @@ static inline bool efi_enabled(int feature)
 extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
 
 extern bool efi_is_table_address(unsigned long phys_addr);
+
+extern void __init efi_set_secure_boot(enum efi_secureboot_mode mode);
 #else
 static inline bool efi_enabled(int feature)
 {
@@ -1233,6 +1243,8 @@ static inline bool efi_is_table_address(unsigned long phys_addr)
 {
        return false;
 }
+
+static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {}
 #endif
 
 extern int efi_status_to_err(efi_status_t status);
@@ -1625,12 +1637,6 @@ static inline bool efi_runtime_disabled(void) { return true; }
 extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
 extern unsigned long efi_call_virt_save_flags(void);
 
-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);
 
 #ifdef CONFIG_RESET_ATTACK_MITIGATION