ima: define ima_trusted_for hook
Subsystems (5)
Mimi Zohar
maintainerPATCH 1/3 ima: define ima_trusted_for hook
A major interpreter integrity gap exists which allows files read by the interpreter to be executed without measuring the file or verifying the file's signature.
The kernel has no knowledge about the file being read by the interpreter. Only the interpreter knows the context(eg. data, execute) and must be trusted to provide that information accurately.
To close this integrity gap, define an ima_trusted_for hook to allow IMA to measure the file and verify the file's signature based on policy.
Sample policy rules:
measure func=TRUSTED_FOR_CHECK
appraise func=TRUSTED_FOR_CHECK appraise_type=imasig
--- Documentation/ABI/testing/ima_policy | 2 +- security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_main.c | 23 +++++++++++++++++++++++ security/integrity/ima/ima_policy.c | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-)
Documentation/ABI/testing/ima_policy +1 -1
@@ -34,7 +34,7 @@ Description: [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] [KEXEC_CMDLINE] [KEY_CHECK] [CRITICAL_DATA] - [SETXATTR_CHECK] + [SETXATTR_CHECK] [TRUSTED_FOR_CHECK] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value
security/integrity/ima/ima.h +1 -0
@@ -202,6 +202,7 @@ static inline unsigned int ima_hash_key(u8 *digest) hook(KEY_CHECK, key) \ hook(CRITICAL_DATA, critical_data) \ hook(SETXATTR_CHECK, setxattr_check) \ + hook(TRUSTED_FOR_CHECK, trusted_for_check) \ hook(MAX_CHECK, none)#define __ima_hook_enumify (ENUM , str) ENUM,
security/integrity/ima/ima_main.c +23 -0
@@ -26,6 +26,7 @@#include <linux/ima.h> #include <linux/iversion.h> #include <linux/fs.h> +#include <uapi/linux/trusted-for.h> #include "ima.h"
@@ -519,6 +520,28 @@ int ima_file_check(struct file *file, int mask) }EXPORT_SYMBOL_GPL (ima_file_check); +/** +* ima_trusted_for - based on policy, measure/appraise/audit measurement +* @file: pointer to the file to be measured/appraised/audit +* @usage: limit enumeration to TRUSTED_FOR_EXECUTION +* +* Measure/appraise/audit files being executed by an interpreter. +* +* On success return 0. On integrity appraisal error, assuming the file +* is in policy and IMA-appraisal is in enforcing mode, return -EACCES. +*/ +int ima_trusted_for (struct file *file,const enum trusted_for_usage usage) +{ +u32 secid; + +if (usage !=TRUSTED_FOR_EXECUTION ) +return 0 ; + +security_task_getsecid_subj (current, &secid); +return process_measurement (file,current_cred (), secid,NULL , +0 ,MAY_EXEC ,TRUSTED_FOR_CHECK ); +} +static int __ima_inode_hash (struct inode *inode,char *buf,size_t buf_size) {struct integrity_iint_cache *iint;
security/integrity/ima/ima_policy.c +3 -0
@@ -1210,6 +1210,7 @@ static bool ima_validate_rule(struct ima_rule_entry *entry)case POST_SETATTR :case FIRMWARE_CHECK :case POLICY_CHECK : +case TRUSTED_FOR_CHECK : if (entry->flags & ~(IMA_FUNC | IMA_MASK | IMA_FSMAGIC | IMA_UID | IMA_FOWNER | IMA_FSUUID | IMA_INMASK | IMA_EUID | IMA_PCR |
@@ -1423,6 +1424,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)/* PATH_CHECK is for backwards compat */ else if (strcmp(args[0].from, "PATH_CHECK") == 0) entry->func = FILE_CHECK; + else if (strcmp(args[0].from, "TRUSTED_FOR_CHECK") == 0) + entry->func = TRUSTED_FOR_CHECK; else if (strcmp(args[0].from, "MODULE_CHECK") == 0) entry->func = MODULE_CHECK; else if (strcmp(args[0].from, "FIRMWARE_CHECK") == 0)
Signature · 1 line
2.27.0
Mimi Zohar
maintainerPATCH 3/3 security: define a trusted_for hook
Extend the trusted_for syscall to call the security_trusted_for hook, which calls registered LSMs and IMA, instead of calling IMA directly.
---
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(-)
fs/open.c +1 -1
@@ -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);
include/linux/lsm_hook_defs.h +3 -0
@@ -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)
include/linux/lsm_hooks.h +6 -0
@@ -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__);
include/linux/security.h +12 -0
@@ -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 */
security/security.c +10 -0
@@ -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); +}
Signature · 1 line
2.27.0
Mimi Zohar
maintainerPATCH 2/3 fs: extend the trusted_for syscall to call IMA
In reply to Mimi ZoharExtend the trusted_for syscall to call the newly defined ima_trusted_for hook.
--- fs/open.c | 3 +++ include/linux/ima.h | 9 +++++++++ 2 files changed, 12 insertions(+)
fs/open.c +3 -0
@@ -585,6 +585,9 @@ SYSCALL_DEFINE3(trusted_for, const int, fd, const enum trusted_for_usage, usage, err =inode_permission (file_mnt_user_ns (f.file), inode, mask |MAY_ACCESS ); +if (!err) + err =ima_trusted_for (f.file, usage); + out_fd:fdput (f);return err;
include/linux/ima.h +9 -0
@@ -12,12 +12,15 @@#include <linux/security.h> #include <linux/kexec.h> #include <crypto/hash_info.h> +#include <uapi/linux/trusted-for.h> struct linux_binprm ;#ifdef CONFIG_IMA extern enum hash_algo ima_get_current_hash_algo (void );extern int ima_bprm_check (struct linux_binprm *bprm);extern int ima_file_check (struct file *file,int mask); +extern int ima_trusted_for (struct file *file, +const enum trusted_for_usage usage);extern void ima_post_create_tmpfile (struct user_namespace *mnt_userns,struct inode *inode);extern void ima_file_free (struct file *file);
@@ -81,6 +84,12 @@ static inline int ima_file_check(struct file *file, int mask)return 0 ; } +static inline int ima_trusted_for (struct file *file, +const enum trusted_for_usage usage) +{ +return 0 ; +} +static inline void ima_post_create_tmpfile (struct user_namespace *mnt_userns,struct inode *inode) {
Signature · 1 line
2.27.0