ima: Namespacing IMA
Subsystems (9)
v4 cover ima: Namespacing IMA
This patch set implements an IMA namespace data structure that gets created by first writing a '1' into IMA's securityfs unshare file at /sys/kernel/security/ima/unshare and then by clone(). This patch set lays down the foundation for namespacing the different aspects of IMA (eg. IMA-audit, IMA-measurement, IMA-appraisal).
The original PoC patches created a new CLONE_NEWIMA flag to explicitly control when a new IMA namespace should be created. The previously posted version 2 of this series had it hooked on the mount namespace, which was regarded as inappropriate. The subsequent v3 tied it to the creation of a user namespace. Based on comments, we elected to now again create an independent IMA namespace through the above mentioned securityfs file.
The first patch creates the ima_namespace data, while the second patch puts the iint->flags in the namespace. The third patch introduces an audit message type for IMA policy rules. The fourth patch introduces a new IMA policy rule attribute 'ns' making rules only applicable to child IMA namespaces. The last patch uses the flags for namespacing the IMA-audit messages, enabling the same file to be audited each time it is accessed in a new namespace.
Stefan
Mehmet Kayaalp (2):
ima: Add ns_status for storing namespaced iint data
ima: namespace audit status flags
Mimi Zohar (1):
ima: differentiate auditing policy rules from "audit" actions
Stefan Berger (1):
ima: extend IMA audit policy rules with attribute to audit namespaces
Yuqiong Sun (1):
ima: Add IMA namespace support
fs/proc/namespaces.c | 3 + include/linux/ima.h | 53 +++++++++ include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 1 + include/linux/sched.h | 6 + include/linux/user_namespace.h | 1 + include/uapi/linux/audit.h | 3 +- init/Kconfig | 11 ++ kernel/fork.c | 5 + kernel/nsproxy.c | 25 ++++- kernel/ucount.c | 1 + security/integrity/ima/Makefile | 3 +- security/integrity/ima/ima.h | 82 +++++++++++++- security/integrity/ima/ima_api.c | 14 ++- security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_fs.c | 55 ++++++++++ security/integrity/ima/ima_init.c | 4 + security/integrity/ima/ima_init_ima_ns.c | 51 +++++++++ security/integrity/ima/ima_main.c | 18 ++- security/integrity/ima/ima_ns.c | 183 +++++++++++++++++++++++++++++++ security/integrity/ima/ima_ns_status.c | 133 ++++++++++++++++++++++ security/integrity/ima/ima_policy.c | 77 ++++++++++++- 22 files changed, 712 insertions(+), 21 deletions(-) create mode 100644 security/integrity/ima/ima_init_ima_ns.c create mode 100644 security/integrity/ima/ima_ns.c create mode 100644 security/integrity/ima/ima_ns_status.c
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC PATCH v4 1/5 ima: Add IMA namespace support
From: Yuqiong Sun <suny-r/[email protected]>
Add a new CONFIG_IMA_NS config option that enables one to create a new IMA namespace. We do this by writing a file into IMA's new securityfs 'unshare' file, which will have a new child process get the IMA namespace. We create the IMA namespace when a user writes a boolean '1' into this file and we cache the IMA namespace on the task_struct and take it from there upon the next clone().
Currently, the iam_ns contains no useful IMA data but only a dummy inter- face. This patch creates the framework for namespacing the different as- pects of IMA (eg. IMA-audit, IMA-measurement, IMA-appraisal).
At this point one can create and activate a new IMA namespace by writing a '1' into IMA's unshare file and subsequently creating a new process. The 'ls -l' shows that the IMA namespace inode number temporarily changes while the new IMA namespace is active after it was set up.
ls -l /proc/self/ns/ima
echo 1 > /sys/kernel/security/ima/unshare
ls -l /proc/self/ns/ima
ls -l /proc/self/ns/ima
Changelog:
v4:
* Use IMA's securityfs to spawn a new namespace using unshare file
v3:
* Use CLONE_NEWUSER instead of CLONE_NEWNS flag
v2:
* Moved ima_init_ns and related functions into own file that is always compiled; init_ima_ns will always be there
* Fixed putting of imans->parent
* Move IMA namespace creation from nsproxy into mount namespace code; get rid of procfs operations for IMA namespace
v1:
* Use CLONE_NEWNS instead of a new CLONE_NEWIMA flag
* Use existing ima.h headers
* Move the ima_namespace.c to security/integrity/ima/ima_ns.c
* Fix typo INFO->INO
* Each namespace free's itself, removed recursively free'ing until init_ima_ns from free_ima_ns()
--- fs/proc/namespaces.c | 3 + include/linux/ima.h | 50 ++++++++++ include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 1 + include/linux/sched.h | 6 ++ include/linux/user_namespace.h | 1 + init/Kconfig | 8 ++ kernel/fork.c | 5 + kernel/nsproxy.c | 25 ++++- kernel/ucount.c | 1 + security/integrity/ima/Makefile | 3 +- security/integrity/ima/ima.h | 32 ++++++ security/integrity/ima/ima_fs.c | 55 +++++++++++ security/integrity/ima/ima_init.c | 4 + security/integrity/ima/ima_init_ima_ns.c | 40 ++++++++ security/integrity/ima/ima_ns.c | 162 +++++++++++++++++++++++++++++++ 16 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 security/integrity/ima/ima_init_ima_ns.c create mode 100644 security/integrity/ima/ima_ns.c
fs/proc/namespaces.c +3 -0
@@ -33,6 +33,9 @@ static const struct proc_ns_operations *ns_entries[] = {#ifdef CONFIG_CGROUPS &cgroupns_operations,#endif +#ifdef CONFIG_IMA_NS + &imans_operations, +#endif }; static const char *proc_ns_get_link(struct dentry *dentry,
include/linux/ima.h +50 -0
54 lines not on this page · raw message
include/linux/nsproxy.h +2 -0
@@ -10,6 +10,7 @@ struct uts_namespace;struct ipc_namespace ;struct pid_namespace ;struct cgroup_namespace ; +struct ima_namespace ;struct fs_struct ;/*
@@ -36,6 +37,7 @@ struct nsproxy {struct pid_namespace *pid_ns_for_children;struct net *net_ns;struct cgroup_namespace *cgroup_ns; +struct ima_namespace *ima_ns; };extern struct nsproxy init_nsproxy;
include/linux/proc_ns.h +1 -0
@@ -32,6 +32,7 @@ extern const struct proc_ns_operations pidns_for_children_operations;extern const struct proc_ns_operations userns_operations;extern const struct proc_ns_operations mntns_operations;extern const struct proc_ns_operations cgroupns_operations; +extern const struct proc_ns_operations imans_operations;/* * We always define these enumerators
include/linux/sched.h +6 -0
@@ -53,6 +53,7 @@ struct sighand_struct;struct signal_struct ;struct task_delay_info ;struct task_group ; +struct ima_namespace ;/* * Task state bitmask. NOTE! These bits are also
@@ -1100,6 +1101,11 @@ struct task_struct {void *security;#endif +#ifdef CONFIG_IMA_NS +/* child process will spawn a new IMA namespace */ +bool ima_ns_for_child; +#endif +/* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct.
include/linux/user_namespace.h +1 -0
@@ -49,6 +49,7 @@ enum ucount_type {UCOUNT_INOTIFY_INSTANCES ,UCOUNT_INOTIFY_WATCHES , #endif +UCOUNT_IMA_NAMESPACES , UCOUNT_COUNTS, };
init/Kconfig +8 -0
@@ -932,6 +932,14 @@ config NET_NS Allow user space to create what appear to be multiple instances of the network stack. +config IMA_NS + bool "IMA namespace" + depends on IMA + default n + help + Allow the creation of IMA namespaces. Namespaced IMA data + enables having IMA features work separately in each IMA namespace. + endif # NAMESPACES config SCHED_AUTOGROUP
kernel/fork.c +5 -0
@@ -91,6 +91,7 @@#include <linux/kcov.h> #include <linux/livepatch.h> #include <linux/thread_info.h> +#include <linux/ima.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -834,6 +835,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) tsk->fail_nth =0 ;#endif +#ifdef CONFIG_IMA_NS + orig->ima_ns_for_child = false; +#endif +return tsk; free_stack:
kernel/nsproxy.c +24 -1
@@ -27,6 +27,7 @@#include <linux/syscalls.h> #include <linux/cgroup.h> #include <linux/perf_event.h> +#include <linux/ima.h> static struct kmem_cache *nsproxy_cachep;
@@ -44,6 +45,9 @@ struct nsproxy init_nsproxy = {#ifdef CONFIG_CGROUPS .cgroup_ns = &init_cgroup_ns,#endif +#ifdef CONFIG_IMA_NS + .ima_ns = &init_ima_ns, +#endif };static inline struct nsproxy *create_nsproxy (void )
@@ -67,6 +71,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags, {struct nsproxy *new_nsp;int err; +bool copy_ima = false; new_nsp =create_nsproxy ();if (!new_nsp)
@@ -110,8 +115,21 @@ static struct nsproxy *create_new_namespaces(unsigned long flags, goto out_net; } +#ifdef CONFIG_IMA_NS + copy_ima = tsk->ima_ns_for_child; + tsk->ima_ns_for_child = false; +#endif + new_nsp->ima_ns =copy_ima_ns (copy_ima, user_ns, + tsk->nsproxy->ima_ns); +if (IS_ERR (new_nsp->ima_ns)) { + err =PTR_ERR (new_nsp->ima_ns); + goto out_ima; + } +return new_nsp; +out_ima: +put_net (new_nsp->net_ns); out_net:put_cgroup_ns (new_nsp->cgroup_ns); out_cgroup:
@@ -143,7 +161,11 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)if (likely (!(flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC |CLONE_NEWPID |CLONE_NEWNET | -CLONE_NEWCGROUP )))) { +CLONE_NEWCGROUP ))) +#ifdef CONFIG_IMA_NS + &&likely (!tsk->ima_ns_for_child) +#endif + ) {get_nsproxy (old_ns);return 0 ; }
@@ -182,6 +204,7 @@ void free_nsproxy(struct nsproxy *ns)put_pid_ns (ns->pid_ns_for_children);put_cgroup_ns (ns->cgroup_ns);put_net (ns->net_ns); +put_ima_ns (ns->ima_ns);kmem_cache_free (nsproxy_cachep, ns); }
kernel/ucount.c +1 -0
@@ -79,6 +79,7 @@ static struct ctl_table user_table[] = {UCOUNT_ENTRY ("max_inotify_instances" ),UCOUNT_ENTRY ("max_inotify_watches" ), #endif + UCOUNT_ENTRY("max_ima_namespaces"), { } };#endif /* CONFIG_SYSCTL */
security/integrity/ima/Makefile +2 -1
@@ -7,7 +7,8 @@ obj-$(CONFIG_IMA) += ima.o ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ - ima_policy.o ima_template.o ima_template_lib.o + ima_policy.o ima_template.o ima_template_lib.o ima_init_ima_ns.o ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o +ima-$(CONFIG_IMA_NS) += ima_ns.o ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o
security/integrity/ima/ima.h +32 -0
@@ -24,6 +24,7 @@#include <linux/hash.h> #include <linux/tpm.h> #include <linux/audit.h> +#include <linux/ima.h> #include <crypto/hash_info.h> #include "../integrity.h"
@@ -291,6 +292,10 @@ static inline int ima_read_xattr(struct dentry *dentry,#endif /* CONFIG_IMA_APPRAISE */ +int ima_ns_init (void ); +struct ima_namespace ; +int ima_init_namespace (struct ima_namespace *ns); +/* LSM based policy rules require audit */ #ifdef CONFIG_IMA_LSM_RULES
@@ -313,6 +318,33 @@ static inline int security_filter_rule_match(u32 secid, u32 field, u32 op, }#endif /* CONFIG_IMA_LSM_RULES */ +static inline struct ima_namespace *to_ima_ns (struct ns_common *ns) +{ + return container_of(ns, struct ima_namespace, ns); +} + +#ifdef CONFIG_IMA_NS + +extern const struct proc_ns_operations imans_operations; + +struct ima_namespace *copy_ima (struct user_namespace *user_ns, +struct ima_namespace *old_ns); + + +static inline struct ima_namespace *get_current_ns (void ) +{ +return current->nsproxy->ima_ns; +} + +#else + +static inline struct ima_namespace *get_current_ns (void ) +{ +return &init_ima_ns; +} + +#endif /* CONFIG_IMA_NS */ +#ifdef CONFIG_IMA_READ_POLICY #define POLICY_FILE_FLAGS (S_IWUSR | S_IRUSR)#else
security/integrity/ima/ima_fs.c +55 -0
78 lines not on this page · raw message
security/integrity/ima/ima_init.c +4 -0
@@ -137,5 +137,9 @@ int __init ima_init(void)ima_init_policy (); + rc =ima_ns_init (); +if (rc !=0 ) +return rc; +return ima_fs_init (); }
security/integrity/ima/ima_init_ima_ns.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2016-2018 IBM Corporation +* Author: +* Yuqiong Sun <suny-r/[email protected]> +* Stefan Berger <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, version 2 of the License. +*/ + +#include <linux/export.h> +#include <linux/user_namespace.h> +#include <linux/proc_ns.h> +#include <linux/ima.h> + +#include "ima.h" + +int ima_init_namespace (struct ima_namespace *ns) +{ +#ifdef CONFIG_IMA_NS + ns->ns.ops = &imans_operations; +return ns_alloc_inum (&ns->ns); +#else +return 0 ; +#endif +} + +int __init ima_ns_init (void ) +{ +return ima_init_namespace (&init_ima_ns); +} + +struct ima_namespace init_ima_ns = { + .kref =KREF_INIT (1 ), + .user_ns = &init_user_ns, + .ucounts =NULL , + .parent =NULL , +}; +EXPORT_SYMBOL (init_ima_ns);
security/integrity/ima/ima_ns.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC PATCH v4 2/5 ima: Add ns_status for storing namespaced iint data
In reply to Stefan BergerFrom: Mehmet Kayaalp <[email protected]>
This patch adds an rbtree to the IMA namespace structure that stores a namespaced version of iint->flags in ns_status struct. Similar to the integrity_iint_cache, both the iint ns_struct are looked up using the inode pointer value. The lookup, allocate, and insertion code is also similar, except ns_struct is not free'd when the inode is free'd. Instead, the lookup verifies the i_ino and i_generation fields are also a match. This could be replaced by a lazy clean up of the rbtree.
Changelog:
v2:
* fixed tree traversal in __ima_ns_status_find()
--- include/linux/ima.h | 3 + security/integrity/ima/Makefile | 2 +- security/integrity/ima/ima.h | 21 +++++ security/integrity/ima/ima_init_ima_ns.c | 17 +++- security/integrity/ima/ima_ns.c | 1 + security/integrity/ima/ima_ns_status.c | 133 +++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 security/integrity/ima/ima_ns_status.c
include/linux/ima.h +3 -0
@@ -112,6 +112,9 @@ struct ima_namespace {struct ucounts *ucounts;struct ns_common ns;struct ima_namespace *parent; +struct rb_root ns_status_tree; +rwlock_t ns_status_lock; +struct kmem_cache *ns_status_cache; };extern struct ima_namespace init_ima_ns;
security/integrity/ima/Makefile +1 -1
@@ -9,6 +9,6 @@ obj-$(CONFIG_IMA) += ima.o ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ ima_policy.o ima_template.o ima_template_lib.o ima_init_ima_ns.o ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o -ima-$(CONFIG_IMA_NS) += ima_ns.o +ima-$(CONFIG_IMA_NS) += ima_ns.o ima_ns_status.o ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o
security/integrity/ima/ima.h +21 -0
@@ -129,6 +129,14 @@ static inline void ima_load_kexec_buffer(void) {}*/ extern bool ima_canonical_fmt; +struct ns_status { +struct rb_node rb_node; +struct inode *inode; +ino_t i_ino; +u32 i_generation; +unsigned long flags; +}; +/* Internal IMA function definitions */ int ima_init (void );int ima_fs_init (void );
@@ -296,6 +304,17 @@ int ima_ns_init(void);struct ima_namespace ;int ima_init_namespace (struct ima_namespace *ns); +#ifdef CONFIG_IMA_NS +struct ns_status *ima_get_ns_status (struct ima_namespace *ns, +struct inode *inode); +#else +static inline struct ns_status *ima_get_ns_status (struct ima_namespace *ns, +struct inode *inode) +{ +return NULL ; +} +#endif /* CONFIG_IMA_NS */ +/* LSM based policy rules require audit */ #ifdef CONFIG_IMA_LSM_RULES
@@ -336,6 +355,8 @@ static inline struct ima_namespace *get_current_ns(void) return current->nsproxy->ima_ns; } +void free_ns_status_cache (struct ima_namespace *ns); +#else static inline struct ima_namespace *get_current_ns (void )
security/integrity/ima/ima_init_ima_ns.c +14 -3
@@ -13,17 +13,28 @@#include <linux/user_namespace.h> #include <linux/proc_ns.h> #include <linux/ima.h> +#include <linux/slab.h> #include "ima.h" int ima_init_namespace (struct ima_namespace *ns) { +int ret =0 ; + + ns->ns_status_tree =RB_ROOT ; +rwlock_init (&ns->ns_status_lock); + ns->ns_status_cache =KMEM_CACHE (ns_status,SLAB_PANIC ); +if (!ns->ns_status_cache) +return -ENOMEM ; +#ifdef CONFIG_IMA_NS ns->ns.ops = &imans_operations; -return ns_alloc_inum (&ns->ns); -#else -return 0 ; + ret =ns_alloc_inum (&ns->ns); +if (ret) +kmem_cache_destroy (ns->ns_status_cache);#endif + +return ret; }int __init ima_ns_init (void )
security/integrity/ima/ima_ns.c +1 -0
@@ -101,6 +101,7 @@ static void destroy_ima_ns(struct ima_namespace *ns)put_user_ns (ns->user_ns);ns_free_inum (&ns->ns);dec_ima_namespaces (ns->ucounts); +free_ns_status_cache (ns);kfree (ns); }
security/integrity/ima/ima_ns_status.c new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC PATCH v4 3/5 ima: differentiate auditing policy rules from "audit" actions
In reply to Stefan BergerFrom: Mimi Zohar <[email protected]>
The AUDIT_INTEGRITY_RULE is used for auditing IMA policy rules and the IMA "audit" policy action. This patch defines AUDIT_INTEGRITY_POLICY to reflect the IMA policy rules.
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
include/uapi/linux/audit.h +2 -1
@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */
security/integrity/ima/ima_policy.c +1 -1
@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
Signature · 1 line
2.14.3
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Hi Stefan,
Quoted 7 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.Signed-off-by Mimi Zohar <[email protected]>
We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. ?Based on the IMA policy rule aspect of the discussions [1], ?I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. ?The sooner we make this change and upstream it, the better.
[1]?https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 24 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 8 lines
security/integrity/ima/ima_policy.c +1
-1@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Quoted 9 lines · Mimi Zohar
Hi Stefan,
Quoted 6 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.
Quoted 5 lines
Quoted 1 line
Signed-off-by Mimi Zohar <[email protected]>We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. ?Based on the IMA policy rule aspect of the discussions [1], ?I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
Is your patch below still valid for splitting it up into 'two distinct audit record types' ?
Quoted 38 lines
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. ?The sooner we make this change and upstream it, the better.
[1]?https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 27 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ;
Quoted 5 lines
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 5 lines
security/integrity/ima/ima_policy.c +1
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Quoted 10 lines · Stefan Berger
Quoted 9 lines · Mimi Zohar
Hi Stefan,
Quoted 6 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Mimi Zohar <[email protected]>We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. ?Based on the IMA policy rule aspect of the discussions [1], ?I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
Is your patch below still valid for splitting it up into 'two distinct audit record types' ?
We need to separate the IMA policy audit rules from the IMA-audit messages. ?As we're changing the audit numbers, we need to take into account Richard's and Steve's comments about the IMA policy record format at the same time.
This patch is incomplete and needs to address their comments.
Mimi
Quoted 38 lines
Quoted 38 lines
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. ?The sooner we make this change and upstream it, the better.
[1]?https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 27 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ;
Quoted 7 lines
Quoted 5 lines
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 5 lines
security/integrity/ima/ima_policy.c +1
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 2496f165-67f7-304d-08a0-ea8eedd3c3d4-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Quoted 10 lines · Stefan Berger
Quoted 9 lines · Mimi Zohar
Hi Stefan,
Quoted 6 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Mimi Zohar <[email protected]>We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. Based on the IMA policy rule aspect of the discussions [1], I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
Is your patch below still valid for splitting it up into 'two distinct audit record types' ?
We need to separate the IMA policy audit rules from the IMA-audit messages. As we're changing the audit numbers, we need to take into account Richard's and Steve's comments about the IMA policy record format at the same time.
This patch is incomplete and needs to address their comments.
Mimi
Quoted 38 lines
Quoted 38 lines
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. The sooner we make this change and upstream it, the better.
[1] https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 27 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ;
Quoted 7 lines
Quoted 5 lines
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 5 lines
security/integrity/ima/ima_policy.c +1
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): 1526391655.3937.151.camel-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Quoted 9 lines · Mimi Zohar
Hi Stefan,
Quoted 6 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.
Quoted 5 lines
Quoted 1 line
Signed-off-by Mimi Zohar <[email protected]>We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. Based on the IMA policy rule aspect of the discussions [1], I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
Is your patch below still valid for splitting it up into 'two distinct audit record types' ?
Quoted 38 lines
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. The sooner we make this change and upstream it, the better.
[1] https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 27 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ;
Quoted 5 lines
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 5 lines
security/integrity/ima/ima_policy.c +1
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): 20180511144230.75384-4-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [RFC PATCH v4 3/5] ima: differentiate auditing policy rules from "audit" actions
Hi Stefan,
Quoted 7 lines · Stefan Berger
From: Mimi Zohar <[email protected]>
The
AUDIT_INTEGRITY_RULEis used for auditing IMA policy rules and the IMA "audit" policy action. This patch definesAUDIT_INTEGRITY_POLICYto reflect the IMA policy rules.Signed-off-by Mimi Zohar <[email protected]>
We do need to separate out auditing the IMA policy rules from the "IMA-audit" messages. Based on the IMA policy rule aspect of the discussions [1], I would really appreciate if you could work with Richard and Steve on the new IMA policy rule audit format.
This change can be upstreamed independently of either the IMA namespacing or the audit containerid patch sets. The sooner we make this change and upstream it, the better.
[1] https://www.redhat.com/archives/linux-audit/2018-March/msg00092.html
thanks,
Mimi
Quoted 24 lines
--- include/uapi/linux/audit.h | 3 ++- security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)include/uapi/linux/audit.h +2
-1@@ -146,7 +146,8 @@#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ #define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ #define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_RULE 1805/* IMA "audit" action policy msgs */ +#define AUDIT_INTEGRITY_POLICY 1806/* IMA policy rules */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */ security/integrity/ima/ima_policy.c +0
-0
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 625
Quoted 8 lines
security/integrity/ima/ima_policy.c +1
-1@@ -619,7 +619,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)bool uid_token;int result =0 ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_RULE ); + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_INTEGRITY_POLICY ); entry->uid =INVALID_UID ; entry->fowner =INVALID_UID ;
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
RFC PATCH v4 4/5 ima: extend IMA audit policy rules with attribute to audit namespaces
In reply to Stefan BergerIntroduce a policy rule attribute called 'ns' that indicates that a rule is supposed to apply to child namespaces of an IMA namespace. We support this 'ns' attribute only for IMA-audit for now. IMA-measurement will get support for this in a future version.
If 'uid=...' appears in a policy rule that has the 'ns' attribute, the uid in that rule is relative to the current user namespace. If it is missing, then the uid is relative to the user namespace that owns the IMA namespace the policy is in. So we have to now map the uid's and do that with the appropriate user namespace depending on the availability of the 'ns' attribute. After that we can use the mapped uid for uid comparisons.
--- security/integrity/ima/ima.h | 5 ++- security/integrity/ima/ima_api.c | 6 ++- security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_main.c | 3 +- security/integrity/ima/ima_policy.c | 75 +++++++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 10 deletions(-)
security/integrity/ima/ima.h +3 -2
@@ -201,7 +201,8 @@ enum ima_hooks {/* LIM API function definitions */ int ima_get_action (struct inode *inode,int mask, -enum ima_hooks func,int *pcr); +enum ima_hooks func,int *pcr, +struct ima_namespace *ns);int ima_must_measure (struct inode *inode,int mask,enum ima_hooks func); int ima_collect_measurement(struct integrity_iint_cache *iint, struct file *file, void *buf, loff_t size,
@@ -222,7 +223,7 @@ const char *ima_d_path(const struct path *path, char **pathbuf, char *filename);/* IMA policy related functions */ int ima_match_policy (struct inode *inode,enum ima_hooks func,int mask, -int flags,int *pcr); +int flags,int *pcr,struct ima_namespace *ns);void ima_init_policy (void );void ima_update_policy (void );void ima_update_policy_flag (void );
security/integrity/ima/ima_api.c +4 -2
@@ -162,6 +162,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,* MAY_APPEND) * @func: caller identifier * @pcr: pointer filled in if matched measure policy sets pcr= +* @ns: the IMA namespace we are currently in * * The policy is defined in terms of keypairs: * subj=, obj=, type=, func=, mask=, fsmagic=
@@ -173,13 +174,14 @@ void ima_add_violation(struct file *file, const unsigned char *filename,* Returns IMA_MEASURE, IMA_APPRAISE mask. * */ -int ima_get_action (struct inode *inode,int mask,enum ima_hooks func,int *pcr) +int ima_get_action (struct inode *inode,int mask,enum ima_hooks func,int *pcr, +struct ima_namespace *ns) {int flags =IMA_MEASURE |IMA_AUDIT |IMA_APPRAISE |IMA_HASH ; flags &= ima_policy_flag; -return ima_match_policy (inode, func, mask, flags, pcr); +return ima_match_policy (inode, func, mask, flags, pcr, ns); }/*
security/integrity/ima/ima_appraise.c +1 -1
@@ -54,7 +54,7 @@ int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func)return 0 ;return ima_match_policy (inode, func, mask,IMA_APPRAISE |IMA_HASH , -NULL ); +NULL ,get_current_ns ()); } static int ima_fix_xattr(struct dentry *dentry,
security/integrity/ima/ima_main.c +2 -1
@@ -190,7 +190,8 @@ static int process_measurement(struct file *file, char *buf, loff_t size,* bitmask based on the appraise/audit/measurement policy. * Included is the appraise submask. */ - action =ima_get_action (inode, mask, func, &pcr); + action =ima_get_action (inode, mask, func, &pcr,get_current_ns ()); + violation_check = ((func ==FILE_CHECK || func ==MMAP_CHECK ) && (ima_policy_flag &IMA_MEASURE ));if (!action && !violation_check)
security/integrity/ima/ima_policy.c +71 -4
141 lines not on this page · raw message
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20180511144230.75384-1-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
RFC PATCH v4 4/5 ima: extend IMA audit policy rules with attribute to audit namespaces
Introduce a policy rule attribute called 'ns' that indicates that a rule is supposed to apply to child namespaces of an IMA namespace. We support this 'ns' attribute only for IMA-audit for now. IMA-measurement will get support for this in a future version.
If 'uid=...' appears in a policy rule that has the 'ns' attribute, the uid in that rule is relative to the current user namespace. If it is missing, then the uid is relative to the user namespace that owns the IMA namespace the policy is in. So we have to now map the uid's and do that with the appropriate user namespace depending on the availability of the 'ns' attribute. After that we can use the mapped uid for uid comparisons.
--- security/integrity/ima/ima.h | 5 ++- security/integrity/ima/ima_api.c | 6 ++- security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_main.c | 3 +- security/integrity/ima/ima_policy.c | 75 +++++++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 10 deletions(-)
security/integrity/ima/ima.h +3 -2
@@ -201,7 +201,8 @@ enum ima_hooks {/* LIM API function definitions */ int ima_get_action (struct inode *inode,int mask, -enum ima_hooks func,int *pcr); +enum ima_hooks func,int *pcr, +struct ima_namespace *ns);int ima_must_measure (struct inode *inode,int mask,enum ima_hooks func); int ima_collect_measurement(struct integrity_iint_cache *iint, struct file *file, void *buf, loff_t size,
@@ -222,7 +223,7 @@ const char *ima_d_path(const struct path *path, char **pathbuf, char *filename);/* IMA policy related functions */ int ima_match_policy (struct inode *inode,enum ima_hooks func,int mask, -int flags,int *pcr); +int flags,int *pcr,struct ima_namespace *ns);void ima_init_policy (void );void ima_update_policy (void );void ima_update_policy_flag (void );
security/integrity/ima/ima_api.c +4 -2
@@ -162,6 +162,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,* MAY_APPEND) * @func: caller identifier * @pcr: pointer filled in if matched measure policy sets pcr= +* @ns: the IMA namespace we are currently in * * The policy is defined in terms of keypairs: * subj=, obj=, type=, func=, mask=, fsmagic=
@@ -173,13 +174,14 @@ void ima_add_violation(struct file *file, const unsigned char *filename,* Returns IMA_MEASURE, IMA_APPRAISE mask. * */ -int ima_get_action (struct inode *inode,int mask,enum ima_hooks func,int *pcr) +int ima_get_action (struct inode *inode,int mask,enum ima_hooks func,int *pcr, +struct ima_namespace *ns) {int flags =IMA_MEASURE |IMA_AUDIT |IMA_APPRAISE |IMA_HASH ; flags &= ima_policy_flag; -return ima_match_policy (inode, func, mask, flags, pcr); +return ima_match_policy (inode, func, mask, flags, pcr, ns); }/*
security/integrity/ima/ima_appraise.c +1 -1
@@ -54,7 +54,7 @@ int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func)return 0 ;return ima_match_policy (inode, func, mask,IMA_APPRAISE |IMA_HASH , -NULL ); +NULL ,get_current_ns ()); } static int ima_fix_xattr(struct dentry *dentry,
security/integrity/ima/ima_main.c +2 -1
@@ -190,7 +190,8 @@ static int process_measurement(struct file *file, char *buf, loff_t size,* bitmask based on the appraise/audit/measurement policy. * Included is the appraise submask. */ - action =ima_get_action (inode, mask, func, &pcr); + action =ima_get_action (inode, mask, func, &pcr,get_current_ns ()); + violation_check = ((func ==FILE_CHECK || func ==MMAP_CHECK ) && (ima_policy_flag &IMA_MEASURE ));if (!action && !violation_check)
security/integrity/ima/ima_policy.c +71 -4
141 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC PATCH v4 5/5 ima: namespace audit status flags
In reply to a message not in the archiveFrom: Mehmet Kayaalp <[email protected]>
The iint cache stores whether the file is measured, appraised, audited etc. This patch moves the IMA_AUDITED flag into the per-namespace ns_status, enabling IMA audit mechanism to audit the same file each time it is accessed in a new namespace.
The ns_status is not looked up if the CONFIG_IMA_NS is disabled or if any of the IMA_NS_STATUS_ACTIONS (currently only IMA_AUDIT) is not enabled.
Read and write operations on the iint flags is replaced with function calls. For reading, iint_flags() returns the bitwise AND of iint->flags and ns_status->flags. The ns_status flags are masked with IMA_NS_STATUS_FLAGS (currently only IMA_AUDITED). Similarly set_iint_flags() only writes the masked portion to the ns_status flags, while the iint flags is set as before. The ns_status parameter added to ima_audit_measurement() is used with the above functions to query and set the ns_status flags.
Changelog:
v2:
* fixed flag calculation in iint_flags()
--- init/Kconfig | 3 +++ security/integrity/ima/ima.h | 24 +++++++++++++++++++++++- security/integrity/ima/ima_api.c | 8 +++++--- security/integrity/ima/ima_main.c | 15 ++++++++++++--- security/integrity/ima/ima_ns.c | 20 ++++++++++++++++++++ 5 files changed, 63 insertions(+), 7 deletions(-)
init/Kconfig +3 -0
@@ -939,6 +939,9 @@ config IMA_NS help Allow the creation of IMA namespaces. Namespaced IMA data enables having IMA features work separately in each IMA namespace. + Currently, only the audit status flags are stored in the namespace, + which allows the same file to be audited each time it is accessed + in a new namespace. endif # NAMESPACES
security/integrity/ima/ima.h +23 -1
@@ -212,7 +212,8 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,struct evm_ima_xattr_data *xattr_value, int xattr_len, int pcr);void ima_audit_measurement (struct integrity_iint_cache *iint, -const unsigned char *filename); +const unsigned char *filename, +struct ns_status *status);int ima_alloc_init_template (struct ima_event_data *event_data,struct ima_template_entry **entry); int ima_store_template(struct ima_template_entry *entry, int violation,
@@ -301,6 +302,9 @@ static inline int ima_read_xattr(struct dentry *dentry,#endif /* CONFIG_IMA_APPRAISE */ +#define IMA_NS_STATUS_ACTIONS IMA_AUDIT +#define IMA_NS_STATUS_FLAGS IMA_AUDITED +int ima_ns_init (void );struct ima_namespace ;int ima_init_namespace (struct ima_namespace *ns);
@@ -308,12 +312,30 @@ int ima_init_namespace(struct ima_namespace *ns);#ifdef CONFIG_IMA_NS struct ns_status *ima_get_ns_status (struct ima_namespace *ns,struct inode *inode); +unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status); +unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status,unsigned long flags);#else static inline struct ns_status *ima_get_ns_status (struct ima_namespace *ns,struct inode *inode) {return NULL ; } + +static inline unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status) +{ +return iint->flags; +} + +static inline unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status, +unsigned long flags) +{ + iint->flags = flags; +return flags; +}#endif /* CONFIG_IMA_NS */ /* LSM based policy rules require audit */
security/integrity/ima/ima_api.c +5 -3
@@ -307,15 +307,17 @@ void ima_store_measurement(struct integrity_iint_cache *iint, }void ima_audit_measurement (struct integrity_iint_cache *iint, -const unsigned char *filename) +const unsigned char *filename, +struct ns_status *status) {struct audit_buffer *ab;char hash[(iint->ima_hash->length *2 ) +1 ];const char *algo_name = hash_algo_name[iint->ima_hash->algo];char algo_hash[sizeof (hash) +strlen (algo_name) +2 ];int i; +unsigned long flags =iint_flags (iint, status); -if (iint->flags &IMA_AUDITED ) +if (flags &IMA_AUDITED )return ;for (i =0 ; i < iint->ima_hash->length; i++)
@@ -336,7 +338,7 @@ void ima_audit_measurement(struct integrity_iint_cache *iint,audit_log_task_info (ab, current);audit_log_end (ab); - iint->flags |=IMA_AUDITED ; +set_iint_flags (iint, status, flags |IMA_AUDITED ); }/*
security/integrity/ima/ima_main.c +12 -3
@@ -172,6 +172,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size, {struct inode *inode =file_inode (file);struct integrity_iint_cache *iint =NULL ; +struct ns_status *status =NULL ;struct ima_template_desc *template_desc;char *pathbuf =NULL ;char filename[NAME_MAX ];
@@ -182,6 +183,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size,int xattr_len =0 ;bool violation_check;enum hash_algo hash_algo; +unsigned long flags;if (!ima_policy_flag || !S_ISREG (inode->i_mode))return 0 ;
@@ -209,6 +211,12 @@ static int process_measurement(struct file *file, char *buf, loff_t size, iint =integrity_inode_get (inode);if (!iint) rc = -ENOMEM ; + +if (!rc && (action &IMA_NS_STATUS_ACTIONS )) { + status =ima_get_ns_status (get_current_ns (), inode); +if (IS_ERR (status)) + rc =PTR_ERR (status); + } }if (!rc && violation_check)
@@ -238,9 +246,10 @@ static int process_measurement(struct file *file, char *buf, loff_t size,* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, * IMA_AUDIT, IMA_AUDITED) */ - iint->flags |= action; + flags =iint_flags (iint, status); + flags =set_iint_flags (iint, status, flags | action); action &=IMA_DO_MASK ; - action &= ~((iint->flags & (IMA_DONE_MASK ^IMA_MEASURED )) >>1 ); + action &= ~((flags & (IMA_DONE_MASK ^IMA_MEASURED )) >>1 );/* If target pcr is already measured, unset IMA_MEASURE action */ if ((action &IMA_MEASURE ) && (iint->measured_pcrs & (0x1 << pcr)))
@@ -290,7 +299,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size,inode_unlock (inode); }if (action &IMA_AUDIT ) -ima_audit_measurement (iint, pathname); +ima_audit_measurement (iint, pathname, status);if ((file->f_flags &O_DIRECT ) && (iint->flags &IMA_PERMIT_DIRECTIO )) rc =0 ;
security/integrity/ima/ima_ns.c +20 -0
@@ -114,6 +114,26 @@ void free_ima_ns(struct kref *kref)destroy_ima_ns (ns); } +unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status) +{ +if (!status) +return iint->flags; + +return (iint->flags & ~IMA_NS_STATUS_FLAGS ) | + (status->flags &IMA_NS_STATUS_FLAGS ); +} + +unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status,unsigned long flags) +{ + iint->flags = flags; +if (status) + status->flags = flags &IMA_NS_STATUS_FLAGS ; + +return flags; +} +static struct ns_common *imans_get (struct task_struct *task) {struct ima_namespace *ns =NULL ;
Signature · 1 line
2.14.3
RFC PATCH v4 5/5 ima: namespace audit status flags
In reply to Stefan BergerFrom: Mehmet Kayaalp <[email protected]>
The iint cache stores whether the file is measured, appraised, audited etc. This patch moves the IMA_AUDITED flag into the per-namespace ns_status, enabling IMA audit mechanism to audit the same file each time it is accessed in a new namespace.
The ns_status is not looked up if the CONFIG_IMA_NS is disabled or if any of the IMA_NS_STATUS_ACTIONS (currently only IMA_AUDIT) is not enabled.
Read and write operations on the iint flags is replaced with function calls. For reading, iint_flags() returns the bitwise AND of iint->flags and ns_status->flags. The ns_status flags are masked with IMA_NS_STATUS_FLAGS (currently only IMA_AUDITED). Similarly set_iint_flags() only writes the masked portion to the ns_status flags, while the iint flags is set as before. The ns_status parameter added to ima_audit_measurement() is used with the above functions to query and set the ns_status flags.
Changelog:
v2:
* fixed flag calculation in iint_flags()
--- init/Kconfig | 3 +++ security/integrity/ima/ima.h | 24 +++++++++++++++++++++++- security/integrity/ima/ima_api.c | 8 +++++--- security/integrity/ima/ima_main.c | 15 ++++++++++++--- security/integrity/ima/ima_ns.c | 20 ++++++++++++++++++++ 5 files changed, 63 insertions(+), 7 deletions(-)
init/Kconfig +3 -0
@@ -939,6 +939,9 @@ config IMA_NS help Allow the creation of IMA namespaces. Namespaced IMA data enables having IMA features work separately in each IMA namespace. + Currently, only the audit status flags are stored in the namespace, + which allows the same file to be audited each time it is accessed + in a new namespace. endif # NAMESPACES
security/integrity/ima/ima.h +23 -1
@@ -212,7 +212,8 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,struct evm_ima_xattr_data *xattr_value, int xattr_len, int pcr);void ima_audit_measurement (struct integrity_iint_cache *iint, -const unsigned char *filename); +const unsigned char *filename, +struct ns_status *status);int ima_alloc_init_template (struct ima_event_data *event_data,struct ima_template_entry **entry); int ima_store_template(struct ima_template_entry *entry, int violation,
@@ -301,6 +302,9 @@ static inline int ima_read_xattr(struct dentry *dentry,#endif /* CONFIG_IMA_APPRAISE */ +#define IMA_NS_STATUS_ACTIONS IMA_AUDIT +#define IMA_NS_STATUS_FLAGS IMA_AUDITED +int ima_ns_init (void );struct ima_namespace ;int ima_init_namespace (struct ima_namespace *ns);
@@ -308,12 +312,30 @@ int ima_init_namespace(struct ima_namespace *ns);#ifdef CONFIG_IMA_NS struct ns_status *ima_get_ns_status (struct ima_namespace *ns,struct inode *inode); +unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status); +unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status,unsigned long flags);#else static inline struct ns_status *ima_get_ns_status (struct ima_namespace *ns,struct inode *inode) {return NULL ; } + +static inline unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status) +{ +return iint->flags; +} + +static inline unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status, +unsigned long flags) +{ + iint->flags = flags; +return flags; +}#endif /* CONFIG_IMA_NS */ /* LSM based policy rules require audit */
security/integrity/ima/ima_api.c +5 -3
@@ -307,15 +307,17 @@ void ima_store_measurement(struct integrity_iint_cache *iint, }void ima_audit_measurement (struct integrity_iint_cache *iint, -const unsigned char *filename) +const unsigned char *filename, +struct ns_status *status) {struct audit_buffer *ab;char hash[(iint->ima_hash->length *2 ) +1 ];const char *algo_name = hash_algo_name[iint->ima_hash->algo];char algo_hash[sizeof (hash) +strlen (algo_name) +2 ];int i; +unsigned long flags =iint_flags (iint, status); -if (iint->flags &IMA_AUDITED ) +if (flags &IMA_AUDITED )return ;for (i =0 ; i < iint->ima_hash->length; i++)
@@ -336,7 +338,7 @@ void ima_audit_measurement(struct integrity_iint_cache *iint,audit_log_task_info (ab, current);audit_log_end (ab); - iint->flags |=IMA_AUDITED ; +set_iint_flags (iint, status, flags |IMA_AUDITED ); }/*
security/integrity/ima/ima_main.c +12 -3
@@ -172,6 +172,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size, {struct inode *inode =file_inode (file);struct integrity_iint_cache *iint =NULL ; +struct ns_status *status =NULL ;struct ima_template_desc *template_desc;char *pathbuf =NULL ;char filename[NAME_MAX ];
@@ -182,6 +183,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size,int xattr_len =0 ;bool violation_check;enum hash_algo hash_algo; +unsigned long flags;if (!ima_policy_flag || !S_ISREG (inode->i_mode))return 0 ;
@@ -209,6 +211,12 @@ static int process_measurement(struct file *file, char *buf, loff_t size, iint =integrity_inode_get (inode);if (!iint) rc = -ENOMEM ; + +if (!rc && (action &IMA_NS_STATUS_ACTIONS )) { + status =ima_get_ns_status (get_current_ns (), inode); +if (IS_ERR (status)) + rc =PTR_ERR (status); + } }if (!rc && violation_check)
@@ -238,9 +246,10 @@ static int process_measurement(struct file *file, char *buf, loff_t size,* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, * IMA_AUDIT, IMA_AUDITED) */ - iint->flags |= action; + flags =iint_flags (iint, status); + flags =set_iint_flags (iint, status, flags | action); action &=IMA_DO_MASK ; - action &= ~((iint->flags & (IMA_DONE_MASK ^IMA_MEASURED )) >>1 ); + action &= ~((flags & (IMA_DONE_MASK ^IMA_MEASURED )) >>1 );/* If target pcr is already measured, unset IMA_MEASURE action */ if ((action &IMA_MEASURE ) && (iint->measured_pcrs & (0x1 << pcr)))
@@ -290,7 +299,7 @@ static int process_measurement(struct file *file, char *buf, loff_t size,inode_unlock (inode); }if (action &IMA_AUDIT ) -ima_audit_measurement (iint, pathname); +ima_audit_measurement (iint, pathname, status);if ((file->f_flags &O_DIRECT ) && (iint->flags &IMA_PERMIT_DIRECTIO )) rc =0 ;
security/integrity/ima/ima_ns.c +20 -0
@@ -114,6 +114,26 @@ void free_ima_ns(struct kref *kref)destroy_ima_ns (ns); } +unsigned long iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status) +{ +if (!status) +return iint->flags; + +return (iint->flags & ~IMA_NS_STATUS_FLAGS ) | + (status->flags &IMA_NS_STATUS_FLAGS ); +} + +unsigned long set_iint_flags (struct integrity_iint_cache *iint, +struct ns_status *status,unsigned long flags) +{ + iint->flags = flags; +if (status) + status->flags = flags &IMA_NS_STATUS_FLAGS ; + +return flags; +} +static struct ns_common *imans_get (struct task_struct *task) {struct ima_namespace *ns =NULL ;
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html