[PATCH v1 3/3] security: define a trusted_for hook

Mimi Zohar zohar at linux.ibm.com
Thu Oct 14 13:01:25 UTC 2021


Extend the trusted_for syscall to call the security_trusted_for hook,
which calls registered LSMs and IMA, instead of calling IMA directly.

Signed-off-by: Mimi Zohar <zohar at linux.ibm.com>
---
Mickaël, Casey, assuming there is a need...

 fs/open.c                     |  2 +-
 include/linux/lsm_hook_defs.h |  3 +++
 include/linux/lsm_hooks.h     |  6 ++++++
 include/linux/security.h      | 12 ++++++++++++
 security/security.c           | 10 ++++++++++
 5 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index 4d54e2a727e1..75336ca7020d 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -586,7 +586,7 @@ SYSCALL_DEFINE3(trusted_for, const int, fd, const enum trusted_for_usage, usage,
 			mask | MAY_ACCESS);
 
 	if (!err)
-		err = ima_trusted_for(f.file, usage);
+		err = security_trusted_for(f.file, usage);
 
 out_fd:
 	fdput(f);
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 2adeea44c0d5..f847fc0fd030 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -402,3 +402,6 @@ LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event)
 LSM_HOOK(int, 0, perf_event_read, struct perf_event *event)
 LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
 #endif /* CONFIG_PERF_EVENTS */
+
+LSM_HOOK(int, 0, trusted_for, struct file *file,
+	 const enum trusted_for_usage usage)
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 5c4c5c0602cb..88e4f08f01ca 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1557,6 +1557,12 @@
  * 	Read perf_event security info if allowed.
  * @perf_event_write:
  * 	Write perf_event security info if allowed.
+ *
+ * Security hooks for trusted applications (e.g. interpreters)
+ *
+ * @trusted_for:
+ *	Return kernel file integrity status to trusted application
+ *
  */
 union security_list_options {
 	#define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
diff --git a/include/linux/security.h b/include/linux/security.h
index 5b7288521300..b067e22c8903 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -31,6 +31,7 @@
 #include <linux/err.h>
 #include <linux/string.h>
 #include <linux/mm.h>
+#include <uapi/linux/trusted-for.h>
 
 struct linux_binprm;
 struct cred;
@@ -2038,4 +2039,15 @@ static inline int security_perf_event_write(struct perf_event *event)
 #endif /* CONFIG_SECURITY */
 #endif /* CONFIG_PERF_EVENTS */
 
+#ifdef CONFIG_SECURITY
+extern int security_trusted_for(struct file *file,
+				const enum trusted_for_usage usage);
+#else
+static int security_trusted_for(struct file *file,
+				const enum trusted_for_usage usage)
+{
+	return 0;
+}
+#endif /* CONFIG_SECURITY */
+
 #endif /* ! __LINUX_SECURITY_H */
diff --git a/security/security.c b/security/security.c
index 9ffa9e9c5c55..f8e2a131d5cd 100644
--- a/security/security.c
+++ b/security/security.c
@@ -2625,3 +2625,13 @@ int security_perf_event_write(struct perf_event *event)
 	return call_int_hook(perf_event_write, 0, event);
 }
 #endif /* CONFIG_PERF_EVENTS */
+
+int security_trusted_for(struct file *file, const enum trusted_for_usage usage)
+{
+	int ret;
+
+	ret = call_int_hook(trusted_for, 0, file, usage);
+	if (ret)
+		return ret;
+	return ima_trusted_for(file, usage);
+}
-- 
2.27.0



More information about the Linux-security-module-archive mailing list