60fd626
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
60fd626
From: David Howells <dhowells@redhat.com>
60fd626
Date: Mon, 30 Sep 2019 21:28:16 +0000
60fd626
Subject: [PATCH] efi: Lock down the kernel if booted in secure boot mode
60fd626
60fd626
UEFI Secure Boot provides a mechanism for ensuring that the firmware
60fd626
will only load signed bootloaders and kernels.  Certain use cases may
60fd626
also require that all kernel modules also be signed.  Add a
60fd626
configuration option that to lock down the kernel - which includes
60fd626
requiring validly signed modules - if the kernel is secure-booted.
60fd626
60fd626
Upstream Status: RHEL only
60fd626
Signed-off-by: David Howells <dhowells@redhat.com>
60fd626
Signed-off-by: Jeremy Cline <jcline@redhat.com>
60fd626
---
60fd626
 arch/x86/kernel/setup.c   |  8 ++++++++
60fd626
 security/lockdown/Kconfig | 13 +++++++++++++
60fd626
 2 files changed, 21 insertions(+)
60fd626
60fd626
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
d5f3205
index 28d43754aeb6..19d57bfc12f9 100644
60fd626
--- a/arch/x86/kernel/setup.c
60fd626
+++ b/arch/x86/kernel/setup.c
60fd626
@@ -18,6 +18,7 @@
60fd626
 #include <linux/sfi.h>
60fd626
 #include <linux/hugetlb.h>
60fd626
 #include <linux/tboot.h>
60fd626
+#include <linux/security.h>
60fd626
 #include <linux/usb/xhci-dbgp.h>
60fd626
60fd626
 #include <uapi/linux/mount.h>
d5f3205
@@ -1105,6 +1106,13 @@ void __init setup_arch(char **cmdline_p)
60fd626
 	if (efi_enabled(EFI_BOOT))
60fd626
 		efi_init();
60fd626
60fd626
+	efi_set_secure_boot(boot_params.secure_boot);
60fd626
+
60fd626
+#ifdef CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT
60fd626
+	if (efi_enabled(EFI_SECURE_BOOT))
60fd626
+		security_lock_kernel_down("EFI Secure Boot mode", LOCKDOWN_INTEGRITY_MAX);
60fd626
+#endif
60fd626
+
60fd626
 	dmi_setup();
60fd626
60fd626
 	/*
60fd626
diff --git a/security/lockdown/Kconfig b/security/lockdown/Kconfig
60fd626
index e84ddf484010..d0501353a4b9 100644
60fd626
--- a/security/lockdown/Kconfig
60fd626
+++ b/security/lockdown/Kconfig
60fd626
@@ -16,6 +16,19 @@ config SECURITY_LOCKDOWN_LSM_EARLY
60fd626
 	  subsystem is fully initialised. If enabled, lockdown will
60fd626
 	  unconditionally be called before any other LSMs.
60fd626
60fd626
+config LOCK_DOWN_IN_EFI_SECURE_BOOT
60fd626
+	bool "Lock down the kernel in EFI Secure Boot mode"
60fd626
+	default n
60fd626
+	depends on EFI && SECURITY_LOCKDOWN_LSM_EARLY
60fd626
+	help
60fd626
+	  UEFI Secure Boot provides a mechanism for ensuring that the firmware
60fd626
+	  will only load signed bootloaders and kernels.  Secure boot mode may
60fd626
+	  be determined from EFI variables provided by the system firmware if
60fd626
+	  not indicated by the boot parameters.
60fd626
+
60fd626
+	  Enabling this option results in kernel lockdown being triggered if
60fd626
+	  EFI Secure Boot is set.
60fd626
+
60fd626
 choice
60fd626
 	prompt "Kernel default lockdown mode"
60fd626
 	default LOCK_DOWN_KERNEL_FORCE_NONE
60fd626
-- 
60fd626
2.26.2
60fd626