All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] security, efi: Set lockdown if in secure boot mode
@ 2017-05-24 14:45 ` David Howells
  0 siblings, 0 replies; 64+ messages in thread
From: David Howells @ 2017-05-24 14:45 UTC (permalink / raw)
  To: ard.biesheuvel
  Cc: dhowells, matthew.garrett, linux-security-module, linux-efi,
	linux-kernel


Here's a set of patches to institute a "locked-down mode" in the kernel and
to set that mode if the kernel is booted in secure-boot mode.  This can be
enabled with CONFIG_LOCK_DOWN_KERNEL.  If a kernel is locked down, the
lockdown can be lifted by typing SysRq+x on a keyboard attached to the
machine if CONFIG_EFI_ALLOW_SECURE_BOOT_EXIT is enabled.  The exact key can
be configured as 'x' is already taken on some arches.

Inside the kernel, kernel_is_locked_down() is used to check if the kernel
is in lockdown mode.  In lock-down mode, at least the following
restrictions will need to be emplaced:

 (1) No unsigned modules, kexec images or firmware.

 (2) No direct read/write access of the kernel image.  (Shouldn't be able
     to modify it and shouldn't be able to read out crypto data).

 (3) No direct access to devices.  (DMA could be used to access/modify the
     kernel image).

 (4) No manual setting of device register addresses to cause a driver for
     one device to mess around with another device, thereby permitting DMA.

 (5) No storage of unencrypted kernel image to disk (no suspend-to-disk
     without hardware support).

I have patches pending that effect most of the above.  However, the
firmware signature checking is being handled by someone else.  Further, it
has come to light recently that debugfs needs attention, so that isn't done
yet.

Note that the secure boot mode entry doesn't currently work if the kernel
is booted from current i386/x86_64 Grub as there's a bug in Grub whereby it
doesn't initialise the boot_params correctly.  The incorrect initialisation
causes sanitize_boot_params() to be triggered, thereby zapping the secure
boot flag determined by the EFI boot wrapper.

David
---
David Howells (3):
      efi: Move the x86 secure boot switch to generic code
      Add the ability to lock down access to the running kernel image
      efi: Lock down the kernel if booted in secure boot mode

Josh Boyer (1):
      efi: Add EFI_SECURE_BOOT bit

Kyle McMartin (1):
      Add a sysrq option to exit secure boot mode


 arch/x86/include/asm/efi.h        |    2 +
 arch/x86/kernel/setup.c           |   14 ------
 drivers/firmware/efi/Kconfig      |   34 ++++++++++++++++
 drivers/firmware/efi/Makefile     |    1 
 drivers/firmware/efi/secureboot.c |   80 +++++++++++++++++++++++++++++++++++++
 drivers/input/misc/uinput.c       |    1 
 drivers/tty/sysrq.c               |   19 ++++++---
 include/linux/efi.h               |    7 +++
 include/linux/input.h             |    5 ++
 include/linux/kernel.h            |    9 ++++
 include/linux/security.h          |   11 +++++
 include/linux/sysrq.h             |    8 +++-
 kernel/debug/kdb/kdb_main.c       |    2 -
 security/Kconfig                  |   15 +++++++
 security/Makefile                 |    3 +
 security/lock_down.c              |   46 +++++++++++++++++++++
 16 files changed, 236 insertions(+), 21 deletions(-)
 create mode 100644 drivers/firmware/efi/secureboot.c
 create mode 100644 security/lock_down.c

^ permalink raw reply	[flat|nested] 64+ messages in thread
* [PATCH 1/5] efi: Move the x86 secure boot switch to generic code
@ 2017-04-06 12:49 David Howells
  2017-04-06 12:50   ` David Howells
  0 siblings, 1 reply; 64+ messages in thread
From: David Howells @ 2017-04-06 12:49 UTC (permalink / raw)
  To: ard.biesheuvel
  Cc: dhowells, matthew.garrett, linux-security-module, linux-efi,
	linux-kernel

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

Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 arch/x86/kernel/setup.c            |   14 +-------------
 drivers/firmware/efi/Kconfig       |   23 +++++++++++++++++++++++
 drivers/firmware/efi/Makefile      |    3 ++-
 drivers/firmware/efi/secure_boot.c |   34 ++++++++++++++++++++++++++++++++++
 include/linux/efi.h                |    6 ++++++
 5 files changed, 66 insertions(+), 14 deletions(-)
 create mode 100644 drivers/firmware/efi/secure_boot.c

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 4bf0c8926a1c..b89979ffa6e5 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1178,19 +1178,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();
 
diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 2e78b0b96d74..4b902ffbfcf4 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -84,6 +84,29 @@ config EFI_PARAMS_FROM_FDT
 config EFI_RUNTIME_WRAPPERS
 	bool
 
+config EFI_SECURE_BOOT
+	bool "Support UEFI Secure Boot and lock down the kernel in secure boot mode"
+	default n
+	help
+	  UEFI Secure Boot provides a mechanism for ensuring that the firmware
+	  will only load signed bootloaders and kernels.  Secure boot mode may
+	  be determined from EFI variables provided by the BIOS if not
+	  indicated by the boot parameters.
+
+	  Enabling this option turns on support for UEFI secure boot in the
+	  kernel.  This will result in various kernel facilities being locked
+	  away from userspace if the kernel detects that it has been booted in
+	  secure boot mode.  If it hasn't been booted in secure boot mode, or
+	  this cannot be determined, the lock down doesn't occur.
+
+	  The kernel facilities that get locked down include:
+	  - Viewing or changing the kernel's memory
+	  - Directly accessing ioports
+	  - Directly specifying ioports and other hardware parameters to drivers
+	  - Storing the kernel image unencrypted for hibernation
+	  - Loading unsigned modules
+	  - Kexec'ing unsigned images
+
 config EFI_ARMSTUB
 	bool
 
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index ad67342313ed..65969f840685 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -22,7 +22,8 @@ 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_APPLE_PROPERTIES)		+= apple-properties.o
+obj-$(CONFIG_EFI_SECURE_BOOT)		+= secure_boot.o
+obj-$(CONFIG_APPLE_PROPERTIES)		+= apple-properties.oo
 
 arm-obj-$(CONFIG_EFI)			:= arm-init.o arm-runtime.o
 obj-$(CONFIG_ARM)			+= $(arm-obj-y)
diff --git a/drivers/firmware/efi/secure_boot.c b/drivers/firmware/efi/secure_boot.c
new file mode 100644
index 000000000000..cf5bccae15e8
--- /dev/null
+++ b/drivers/firmware/efi/secure_boot.c
@@ -0,0 +1,34 @@
+/* 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.
+ */
+
+#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:
+			pr_info("Secure boot enabled\n");
+			break;
+		default:
+			pr_info("Secure boot could not be determined\n");
+			break;
+		}
+	}
+}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 94d34e0be24f..d8938a780290 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1488,6 +1488,12 @@ enum efi_secureboot_mode {
 };
 enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+void __init efi_set_secure_boot(enum efi_secureboot_mode mode);
+#else
+static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {}
+#endif
+
 /*
  * Arch code can implement the following three template macros, avoiding
  * reptition for the void/non-void return cases of {__,}efi_call_virt():

^ permalink raw reply related	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2017-06-09 19:22 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 14:45 [PATCH 0/5] security, efi: Set lockdown if in secure boot mode David Howells
2017-05-24 14:45 ` David Howells
2017-05-24 14:45 ` David Howells
2017-05-24 14:45 ` [PATCH 1/5] efi: Move the x86 secure boot switch to generic code David Howells
2017-05-24 14:45   ` David Howells
2017-05-26  7:59   ` joeyli
2017-05-26  7:59     ` joeyli
2017-05-24 14:45 ` [PATCH 2/5] efi: Add EFI_SECURE_BOOT bit David Howells
2017-05-24 14:45   ` David Howells
2017-05-24 14:45   ` David Howells
2017-05-26  8:06   ` joeyli
2017-05-26  8:06     ` joeyli
2017-05-24 14:45 ` [PATCH 3/5] Add the ability to lock down access to the running kernel image David Howells
2017-05-24 14:45   ` David Howells
2017-05-24 15:36   ` Casey Schaufler
2017-05-24 15:36     ` Casey Schaufler
2017-05-24 15:36     ` Casey Schaufler
2017-05-25  6:53   ` David Howells
2017-05-25  6:53     ` David Howells
2017-05-25  6:53     ` David Howells
2017-05-25 18:18     ` Casey Schaufler
2017-05-25 18:18       ` Casey Schaufler
2017-05-25 18:18       ` Casey Schaufler
2017-05-26 12:43     ` David Howells
2017-05-26 12:43       ` David Howells
2017-05-26 12:43       ` David Howells
2017-05-26 17:08       ` joeyli
2017-05-26 17:08         ` joeyli
2017-05-26  8:16   ` joeyli
2017-05-26  8:16     ` joeyli
2017-05-26  8:16     ` joeyli
2017-05-24 14:45 ` [PATCH 4/5] efi: Lock down the kernel if booted in secure boot mode David Howells
2017-05-24 14:45   ` David Howells
2017-05-26  8:29   ` joeyli
2017-05-26  8:29     ` joeyli
2017-05-24 14:46 ` [PATCH 5/5] Add a sysrq option to exit " David Howells
2017-05-24 14:46   ` David Howells
2017-05-27  4:06   ` joeyli
2017-05-27  4:06     ` joeyli
2017-05-30 10:49   ` James Morris
2017-05-30 10:49     ` James Morris
2017-05-30 10:49     ` James Morris
2017-05-30 18:57 ` [PATCH 0/5] security, efi: Set lockdown if in " Ard Biesheuvel
2017-05-30 18:57   ` Ard Biesheuvel
2017-05-31  9:23 ` David Howells
2017-05-31  9:23   ` David Howells
2017-05-31  9:23   ` David Howells
2017-05-31 11:39   ` Ard Biesheuvel
2017-05-31 11:39     ` Ard Biesheuvel
2017-05-31 11:39     ` Ard Biesheuvel
2017-05-31 13:33   ` David Howells
2017-05-31 13:33     ` David Howells
2017-05-31 14:06     ` Ard Biesheuvel
2017-05-31 14:06       ` Ard Biesheuvel
2017-06-06  9:34   ` David Howells
2017-06-06  9:34     ` David Howells
2017-06-06  9:34     ` David Howells
2017-06-09 17:33     ` Ard Biesheuvel
2017-06-09 17:33       ` Ard Biesheuvel
2017-06-09 17:33       ` Ard Biesheuvel
2017-06-09 19:22       ` Kees Cook
2017-06-09 19:22         ` Kees Cook
  -- strict thread matches above, loose matches on Subject: below --
2017-04-06 12:49 [PATCH 1/5] efi: Move the x86 secure boot switch to generic code David Howells
2017-04-06 12:50 ` [PATCH 4/5] efi: Lock down the kernel if booted in secure boot mode David Howells
2017-04-06 12:50   ` David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.