614b7d7
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
614b7d7
From: Jeremy Cline <jcline@redhat.com>
614b7d7
Date: Mon, 30 Sep 2019 21:22:47 +0000
614b7d7
Subject: [PATCH] security: lockdown: expose a hook to lock the kernel down
614b7d7
614b7d7
In order to automatically lock down kernels running on UEFI machines
614b7d7
booted in Secure Boot mode, expose the lock_kernel_down() hook.
614b7d7
614b7d7
Upstream Status: RHEL only
614b7d7
Signed-off-by: Jeremy Cline <jcline@redhat.com>
614b7d7
---
614b7d7
 include/linux/lsm_hook_defs.h | 2 ++
614b7d7
 include/linux/lsm_hooks.h     | 6 ++++++
614b7d7
 include/linux/security.h      | 5 +++++
614b7d7
 security/lockdown/lockdown.c  | 1 +
614b7d7
 security/security.c           | 6 ++++++
614b7d7
 5 files changed, 20 insertions(+)
614b7d7
614b7d7
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
a71ee10
index 2a8c74d99015..0d3129588b78 100644
614b7d7
--- a/include/linux/lsm_hook_defs.h
614b7d7
+++ b/include/linux/lsm_hook_defs.h
9ab9ea2
@@ -383,6 +383,8 @@ LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free_security, struct bpf_prog_aux *aux)
614b7d7
 #endif /* CONFIG_BPF_SYSCALL */
614b7d7
614b7d7
 LSM_HOOK(int, 0, locked_down, enum lockdown_reason what)
614b7d7
+LSM_HOOK(int, 0, lock_kernel_down, const char *where, enum lockdown_reason level)
614b7d7
+
614b7d7
614b7d7
 #ifdef CONFIG_PERF_EVENTS
614b7d7
 LSM_HOOK(int, 0, perf_event_open, struct perf_event_attr *attr, int type)
614b7d7
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
a71ee10
index 9e2e3e63719d..317660f68b4f 100644
614b7d7
--- a/include/linux/lsm_hooks.h
614b7d7
+++ b/include/linux/lsm_hooks.h
9ab9ea2
@@ -1507,6 +1507,12 @@
614b7d7
  *
614b7d7
  *     @what: kernel feature being accessed
614b7d7
  *
614b7d7
+ * @lock_kernel_down
614b7d7
+ * 	Put the kernel into lock-down mode.
614b7d7
+ *
614b7d7
+ * 	@where: Where the lock-down is originating from (e.g. command line option)
614b7d7
+ * 	@level: The lock-down level (can only increase)
614b7d7
+ *
614b7d7
  * Security hooks for perf events
614b7d7
  *
614b7d7
  * @perf_event_open:
614b7d7
diff --git a/include/linux/security.h b/include/linux/security.h
9ab9ea2
index 0a0a03b36a3b..26869f44416b 100644
614b7d7
--- a/include/linux/security.h
614b7d7
+++ b/include/linux/security.h
9ab9ea2
@@ -451,6 +451,7 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
614b7d7
 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
614b7d7
 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
614b7d7
 int security_locked_down(enum lockdown_reason what);
614b7d7
+int security_lock_kernel_down(const char *where, enum lockdown_reason level);
614b7d7
 #else /* CONFIG_SECURITY */
614b7d7
614b7d7
 static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data)
9ab9ea2
@@ -1291,6 +1292,10 @@ static inline int security_locked_down(enum lockdown_reason what)
614b7d7
 {
614b7d7
 	return 0;
614b7d7
 }
614b7d7
+static inline int security_lock_kernel_down(const char *where, enum lockdown_reason level)
614b7d7
+{
614b7d7
+	return 0;
614b7d7
+}
614b7d7
 #endif	/* CONFIG_SECURITY */
614b7d7
9ab9ea2
 #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)
614b7d7
diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c
9ab9ea2
index 87cbdc64d272..18555cf18da7 100644
614b7d7
--- a/security/lockdown/lockdown.c
614b7d7
+++ b/security/lockdown/lockdown.c
614b7d7
@@ -73,6 +73,7 @@ static int lockdown_is_locked_down(enum lockdown_reason what)
614b7d7
614b7d7
 static struct security_hook_list lockdown_hooks[] __lsm_ro_after_init = {
614b7d7
 	LSM_HOOK_INIT(locked_down, lockdown_is_locked_down),
614b7d7
+	LSM_HOOK_INIT(lock_kernel_down, lock_kernel_down),
614b7d7
 };
614b7d7
614b7d7
 static int __init lockdown_lsm_init(void)
614b7d7
diff --git a/security/security.c b/security/security.c
9ab9ea2
index 70a7ad357bc6..23e16e773bc2 100644
614b7d7
--- a/security/security.c
614b7d7
+++ b/security/security.c
9ab9ea2
@@ -2516,6 +2516,12 @@ int security_locked_down(enum lockdown_reason what)
614b7d7
 }
614b7d7
 EXPORT_SYMBOL(security_locked_down);
614b7d7
614b7d7
+int security_lock_kernel_down(const char *where, enum lockdown_reason level)
614b7d7
+{
614b7d7
+	return call_int_hook(lock_kernel_down, 0, where, level);
614b7d7
+}
614b7d7
+EXPORT_SYMBOL(security_lock_kernel_down);
614b7d7
+
614b7d7
 #ifdef CONFIG_PERF_EVENTS
614b7d7
 int security_perf_event_open(struct perf_event_attr *attr, int type)
614b7d7
 {
614b7d7
-- 
a71ee10
2.28.0
614b7d7