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