Justin Vreeland 794d92
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Justin Vreeland 794d92
From: Jeremy Cline <jcline@redhat.com>
Justin Vreeland 794d92
Date: Wed, 30 Oct 2019 14:37:49 +0000
Justin Vreeland 794d92
Subject: [PATCH] s390: Lock down the kernel when the IPL secure flag is set
Justin Vreeland 794d92
Justin Vreeland 794d92
Automatically lock down the kernel to LOCKDOWN_CONFIDENTIALITY_MAX if
Justin Vreeland 794d92
the IPL secure flag is set.
Justin Vreeland 794d92
Justin Vreeland 794d92
Upstream Status: RHEL only
Justin Vreeland 794d92
Suggested-by: Philipp Rudo <prudo@redhat.com>
Justin Vreeland 794d92
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Justin Vreeland 794d92
---
Justin Vreeland 794d92
 arch/s390/include/asm/ipl.h | 1 +
Justin Vreeland 794d92
 arch/s390/kernel/ipl.c      | 5 +++++
Justin Vreeland 794d92
 arch/s390/kernel/setup.c    | 4 ++++
Justin Vreeland 794d92
 3 files changed, 10 insertions(+)
Justin Vreeland 794d92
Justin Vreeland 794d92
diff --git a/arch/s390/include/asm/ipl.h b/arch/s390/include/asm/ipl.h
Justin Vreeland 794d92
index 7d5cfdda5277..be66ee5d0437 100644
Justin Vreeland 794d92
--- a/arch/s390/include/asm/ipl.h
Justin Vreeland 794d92
+++ b/arch/s390/include/asm/ipl.h
Justin Vreeland 794d92
@@ -120,6 +120,7 @@ int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
Justin Vreeland 794d92
 			     unsigned char flags, unsigned short cert);
Justin Vreeland 794d92
 int ipl_report_add_certificate(struct ipl_report *report, void *key,
Justin Vreeland 794d92
 			       unsigned long addr, unsigned long len);
Justin Vreeland 794d92
+bool ipl_get_secureboot(void);
Justin Vreeland 794d92
Justin Vreeland 794d92
 /*
Justin Vreeland 794d92
  * DIAG 308 support
Justin Vreeland 794d92
diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
Justin Vreeland 794d92
index 90a2a17239b0..be3b72c53656 100644
Justin Vreeland 794d92
--- a/arch/s390/kernel/ipl.c
Justin Vreeland 794d92
+++ b/arch/s390/kernel/ipl.c
Justin Vreeland 794d92
@@ -2110,3 +2110,8 @@ int ipl_report_free(struct ipl_report *report)
Justin Vreeland 794d92
 }
Justin Vreeland 794d92
Justin Vreeland 794d92
 #endif
Justin Vreeland 794d92
+
Justin Vreeland 794d92
+bool ipl_get_secureboot(void)
Justin Vreeland 794d92
+{
Justin Vreeland 794d92
+	return !!ipl_secure_flag;
Justin Vreeland 794d92
+}
Justin Vreeland 794d92
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
Justin Vreeland 794d92
index e600f6953d7c..4264e01824b3 100644
Justin Vreeland 794d92
--- a/arch/s390/kernel/setup.c
Justin Vreeland 794d92
+++ b/arch/s390/kernel/setup.c
Justin Vreeland 794d92
@@ -49,6 +49,7 @@
Justin Vreeland 794d92
 #include <linux/memory.h>
Justin Vreeland 794d92
 #include <linux/compat.h>
Justin Vreeland 794d92
 #include <linux/start_kernel.h>
Justin Vreeland 794d92
+#include <linux/security.h>
Justin Vreeland 794d92
Justin Vreeland 794d92
 #include <asm/boot_data.h>
Justin Vreeland 794d92
 #include <asm/ipl.h>
Justin Vreeland 794d92
@@ -1085,6 +1086,9 @@ void __init setup_arch(char **cmdline_p)
Justin Vreeland 794d92
Justin Vreeland 794d92
 	log_component_list();
Justin Vreeland 794d92
Justin Vreeland 794d92
+	if (ipl_get_secureboot())
Justin Vreeland 794d92
+		security_lock_kernel_down("Secure IPL mode", LOCKDOWN_INTEGRITY_MAX);
Justin Vreeland 794d92
+
Justin Vreeland 794d92
 	/* Have one command line that is parsed and saved in /proc/cmdline */
Justin Vreeland 794d92
 	/* boot_command_line has been already set up in early.c */
Justin Vreeland 794d92
 	*cmdline_p = boot_command_line;
Justin Vreeland 794d92
-- 
Justin Vreeland 794d92
2.28.0
Justin Vreeland 794d92