potatogim / rpms / kernel

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