chengshan / rpms / kernel

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