ima: enforcing appraise type
Subsystems (3)
v2 cover ima: enforcing appraise type
The IMA-appraisal extension added local integrity validation and enforcement of the measurement against a "good" value stored as an extended attribute 'security.ima'. The initial methods for validating 'security.ima' were hash and digital signature based.
Missing is the ability to specify the validation method required. This patch set addresses this omission, by defining a new policy option 'appraise_type='.
As a result of this change, appraisal rules can now be written on a per hook basis, resulting in different appraisal status results. The 'ima_appraise_tcb' policy appraises all files owned by root. A new hook specific rule could specify that all kernel modules, for example, require a digital signature.
This patchset defines the 'appraise_type' option and caches the appraisal result on a per hook basis.
Changelog v2:
- Minor cleanup as described in patch descriptions
Mimi
Dmitry Kasatkin (1):
ima: added policy support for 'security.ima' type
Mimi Zohar (3):
ima: increase iint flag size
ima: per hook cache integrity appraisal status
ima: differentiate appraise status only for hook specific rules
Documentation/ABI/testing/ima_policy | 4 +- security/integrity/iint.c | 10 ++++- security/integrity/ima/ima.h | 13 +++++- security/integrity/ima/ima_appraise.c | 76 ++++++++++++++++++++++++++++++----- security/integrity/ima/ima_main.c | 25 +++++++----- security/integrity/ima/ima_policy.c | 43 +++++++++++++++++++- security/integrity/integrity.h | 48 +++++++++++++++------- 7 files changed, 181 insertions(+), 38 deletions(-)
Signature · 1 line
1.8.1.rc3
PATCH v2 1/4 ima: added policy support for 'security.ima' type
From: Dmitry Kasatkin <[email protected]>
The 'security.ima' extended attribute may contain either the file data's hash or a digital signature. This patch adds support for requiring a specific extended attribute type. It extends the IMA policy with a new keyword 'appraise_type=imasig'. (Default is hash.)
Changelog v2:
- Fixed Documentation/ABI/testing/ima_policy option syntax Changelog v1:
- Differentiate between 'required' vs. 'actual' extended attribute
--- Documentation/ABI/testing/ima_policy | 4 +++- security/integrity/ima/ima_appraise.c | 5 +++++ security/integrity/ima/ima_main.c | 1 + security/integrity/ima/ima_policy.c | 18 +++++++++++++++++- security/integrity/integrity.h | 2 ++ 5 files changed, 28 insertions(+), 2 deletions(-)
Documentation/ABI/testing/ima_policy +3 -1
@@ -18,10 +18,11 @@ Description: rule format: action [condition ...] action: measure | dont_measure | appraise | dont_appraise | audit - condition:= base | lsm + condition:= base | lsm [option] base: [[func=] [mask=] [fsmagic=] [uid=] [fowner]] lsm: [[subj_user=] [subj_role=] [subj_type=] [obj_user=] [obj_role=] [obj_type=]] + option: [[appraise_type=]] base: func:= [BPRM_CHECK][MMAP_CHECK][FILE_CHECK][MODULE_CHECK] mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
@@ -29,6 +30,7 @@ Description: uid:= decimal value fowner:=decimal value lsm: are LSM specific + option: appraise_type:= [imasig] default policy: # PROC_SUPER_MAGIC
security/integrity/ima/ima_appraise.c +5 -0
@@ -102,6 +102,11 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint,switch (xattr_value->type) {case IMA_XATTR_DIGEST : +if (iint->flags &IMA_DIGSIG_REQUIRED ) { + cause ="IMA signature required" ; + status =INTEGRITY_FAIL ; +break ; + } rc =memcmp (xattr_value->digest, iint->ima_xattr.digest,IMA_DIGEST_SIZE );if (rc) {
security/integrity/ima/ima_main.c +1 -0
@@ -169,6 +169,7 @@ static int process_measurement(struct file *file, const char *filename,* (IMA_MEASURE, IMA_MEASURED, IMA_APPRAISE, IMA_APPRAISED, * IMA_AUDIT, IMA_AUDITED) */ iint->flags |= action; + action &=IMA_DO_MASK ; action &= ~((iint->flags &IMA_DONE_MASK ) >>1 );/* Nothing to do, just return existing appraised status */
security/integrity/ima/ima_policy.c +17 -1
@@ -245,6 +245,8 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,if (!ima_match_rules (entry, inode, func, mask))continue ; + action |= entry->flags &IMA_ACTION_FLAGS ; + action |= entry->action &IMA_DO_MASK ;if (entry->action &IMA_DO_MASK ) actmask &= ~(entry->action | entry->action <<1 );
@@ -318,7 +320,8 @@ enum { Opt_audit, Opt_obj_user, Opt_obj_role, Opt_obj_type, Opt_subj_user, Opt_subj_role, Opt_subj_type, - Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner + Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner, + Opt_appraise_type }; static match_table_t policy_tokens = {
@@ -338,6 +341,7 @@ static match_table_t policy_tokens = { {Opt_fsmagic, "fsmagic=%s"}, {Opt_uid, "uid=%s"}, {Opt_fowner, "fowner=%s"}, + {Opt_appraise_type, "appraise_type=%s"}, {Opt_err, NULL} };
@@ -560,6 +564,18 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)LSM_SUBJ_TYPE , AUDIT_SUBJ_TYPE);break ; +case Opt_appraise_type: +if (entry->action !=APPRAISE ) { + result = -EINVAL ; +break ; + } + +ima_log_string (ab,"appraise_type" , args[0 ].from); +if ((strcmp (args[0 ].from,"imasig" )) ==0 ) + entry->flags |=IMA_DIGSIG_REQUIRED ; +else + result = -EINVAL ; +break ;case Opt_err:ima_log_string (ab,"UNKNOWN" , p); result = -EINVAL ;
security/integrity/integrity.h +2 -0
@@ -26,7 +26,9 @@#define IMA_AUDITED 0x0080/* iint cache flags */ +#define IMA_ACTION_FLAGS 0xff00#define IMA_DIGSIG 0x0100 +#define IMA_DIGSIG_REQUIRED 0x0200#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT)#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED \
Signature · 1 line
1.8.1.rc3
Re: [PATCH v2 1/4] ima: added policy support for 'security.ima' type
On Tue, Jan 22, 2013 at 05:07:31PM -0500, Mimi Zohar wrote:
[..]
Review
Quoted 4 lines
/* iint cache flags */
(quoted diff) +2
-0+#define IMA_ACTION_FLAGS 0xff00 #define IMA_DIGSIG 0x0100 +#define IMA_DIGSIG_REQUIRED 0x0200
Hi Mimi,
IMA_DIGSIG_REQUIRED state does not really have to be stored in iint I guess. This is needed only if we go on to appraise and then we want to make sure digital signatures are present. Once appraisal is done, IMG_DIGSIG will be set and saved in iint->flags but looks like we don't require IMA_DIGSIG_REQUIRED to be saved.
If yes, will it make sense to not save it in iint. There are still 8 bits left unused. We can mark these 8 bits for temporary flags like IMA_DIGSIG_REQUIRED. If that works, I can use same space for defining additional temporary flags like IMA_DIGSIG_SIGNED_ONLY to handle the case of appraise_type=imasig,signed_only. That flag also does not have to be persistent in iint.
Here is a quick patch compile tested only.
Thanks
Vivek
--- security/integrity/ima/ima.h | 5 +++-- security/integrity/ima/ima_appraise.c | 5 +++-- security/integrity/ima/ima_main.c | 8 ++++++-- security/integrity/ima/ima_policy.c | 2 +- security/integrity/integrity.h | 5 ++++- 5 files changed, 17 insertions(+), 8 deletions(-)
security/integrity/integrity.h +4 -1
@@ -28,7 +28,10 @@/* iint cache flags */ #define IMA_ACTION_FLAGS 0xff000000#define IMA_DIGSIG 0x01000000 -#define IMA_DIGSIG_REQUIRED 0x02000000 + +/* Temp flags not stored in iint */ +#define IMA_TEMP_FLAGS 0x00ff0000 +#define IMA_DIGSIG_REQUIRED 0x00010000#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ IMA_APPRAISE_SUBMASK)
security/integrity/ima/ima_main.c +6 -2
@@ -146,7 +146,7 @@ static int process_measurement(struct fistruct integrity_iint_cache *iint;char *pathbuf =NULL ;const char *pathname =NULL ; -int rc = -ENOMEM , action, must_appraise, _func; +int rc = -ENOMEM , action, must_appraise, _func, temp_flags;if (!ima_initialized || !S_ISREG (inode->i_mode))return 0 ;
@@ -174,6 +174,9 @@ static int process_measurement(struct fi* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, * IMA_AUDIT, IMA_AUDITED) */ +/* Temp flags don't have to be stored in iint */ + temp_flags = action &IMA_TEMP_FLAGS ; + action &= ~IMA_TEMP_FLAGS ; iint->flags |= action; action &=IMA_DO_MASK ; action &= ~((iint->flags &IMA_DONE_MASK ) >>1 );
@@ -198,7 +201,8 @@ static int process_measurement(struct fiif (action &IMA_MEASURE )ima_store_measurement (iint, file, pathname);if (action &IMA_APPRAISE_SUBMASK ) - rc =ima_appraise_measurement (_func, iint, file, pathname); + rc =ima_appraise_measurement (_func, iint, file, pathname, + temp_flags);if (action &IMA_AUDIT )ima_audit_measurement (iint, pathname);kfree (pathbuf);
security/integrity/ima/ima_appraise.c +3 -2
@@ -116,7 +116,8 @@ static void ima_cache_flags(struct integ* Return 0 on success, error code otherwise */ int ima_appraise_measurement (int func,struct integrity_iint_cache *iint, -struct file *file,const unsigned char *filename) +struct file *file,const unsigned char *filename, +int flags) {struct dentry *dentry = file->f_dentry;struct inode *inode = dentry->d_inode;
@@ -154,7 +155,7 @@ int ima_appraise_measurement(int func, s }switch (xattr_value->type) {case IMA_XATTR_DIGEST : -if (iint->flags &IMA_DIGSIG_REQUIRED ) { +if (flags &IMA_DIGSIG_REQUIRED ) { cause ="IMA signature required" ; status =INTEGRITY_FAIL ;break ;
security/integrity/ima/ima.h +3 -2
@@ -143,7 +143,7 @@ void ima_delete_rules(void);#ifdef CONFIG_IMA_APPRAISE int ima_appraise_measurement (int func,struct integrity_iint_cache *iint, -struct file *file,const unsigned char *filename); +struct file *file,const unsigned char *filename,int flags);int ima_must_appraise (struct inode *inode,int mask,enum ima_hooks func);void ima_update_xattr (struct integrity_iint_cache *iint,struct file *file); enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint,
@@ -153,7 +153,8 @@ enum integrity_status ima_get_cache_statstatic inline int ima_appraise_measurement (int func,struct integrity_iint_cache *iint,struct file *file, -const unsigned char *filename) +const unsigned char *filename, +int flags) {return INTEGRITY_UNKNOWN ; }
security/integrity/ima/ima_policy.c +1 -1
@@ -267,7 +267,7 @@ int ima_match_policy(struct inode *inodeif (!ima_match_rules (entry, inode, func, mask))continue ; - action |= entry->flags &IMA_ACTION_FLAGS ; + action |= entry->flags &IMA_TEMP_FLAGS ; action |= entry->action &IMA_DO_MASK ;if (entry->action &IMA_APPRAISE )
Re: [PATCH v2 1/4] ima: added policy support for 'security.ima' type
Quoted 16 lines · Vivek Goyal
On Tue, Jan 22, 2013 at 05:07:31PM -0500, Mimi Zohar wrote:
[..]
Review
Quoted 4 lines
/* iint cache flags */
(quoted diff) +2
-0+#define IMA_ACTION_FLAGS 0xff00 #define IMA_DIGSIG 0x0100 +#define IMA_DIGSIG_REQUIRED 0x0200Hi Mimi,
IMA_DIGSIG_REQUIREDstate does not really have to be stored in iint I guess. This is needed only if we go on to appraise and then we want to make sure digital signatures are present. Once appraisal is done,IMG_DIGSIGwill be set and saved iniint->flagsbut looks like we don't requireIMA_DIGSIG_REQUIREDto be saved.
Quoted 6 lines
If yes, will it make sense to not save it in iint. There are still 8 bits left unused. We can mark these 8 bits for temporary flags like
IMA_DIGSIG_REQUIRED. If that works, I can use same space for defining additional temporary flags likeIMA_DIGSIG_SIGNED_ONLYto handle the case of appraise_type=imasig,signed_only. That flag also does not have to be persistent in iint.
Interesting idea. My only concern would be that we're not leaving room for additional hooks (eg. firmware).
thanks,
Mimi
Quoted 122 lines
Here is a quick patch compile tested only.
Thanks
Vivek--- security/integrity/ima/ima.h | 5 +++-- security/integrity/ima/ima_appraise.c | 5 +++-- security/integrity/ima/ima_main.c | 8 ++++++-- security/integrity/ima/ima_policy.c | 2 +- security/integrity/integrity.h | 5 ++++- 5 files changed, 17 insertions(+), 8 deletions(-)Index:
linux-integrity/security/integrity/integrity.h
===================================================================security/integrity/integrity.h +4
-1@@ -28,7 +28,10 @@/* iint cache flags */ #define IMA_ACTION_FLAGS 0xff000000#define IMA_DIGSIG 0x01000000 -#define IMA_DIGSIG_REQUIRED 0x02000000 + +/* Temp flags not stored in iint */ +#define IMA_TEMP_FLAGS 0x00ff0000 +#define IMA_DIGSIG_REQUIRED 0x00010000#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ IMA_APPRAISE_SUBMASK)Index:
linux-integrity/security/integrity/ima/ima_main.c
===================================================================security/integrity/ima/ima_main.c +6
-2@@ -146,7 +146,7 @@ static int process_measurement(struct fistruct integrity_iint_cache *iint;char *pathbuf =NULL ;const char *pathname =NULL ; -int rc = -ENOMEM , action, must_appraise, _func; +int rc = -ENOMEM , action, must_appraise, _func, temp_flags;if (!ima_initialized || !S_ISREG (inode->i_mode))return 0 ;@@ -174,6 +174,9 @@ static int process_measurement(struct fi* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, * IMA_AUDIT, IMA_AUDITED) */ +/* Temp flags don't have to be stored in iint */ + temp_flags = action &IMA_TEMP_FLAGS ; + action &= ~IMA_TEMP_FLAGS ; iint->flags |= action; action &=IMA_DO_MASK ; action &= ~((iint->flags &IMA_DONE_MASK ) >>1 );@@ -198,7 +201,8 @@ static int process_measurement(struct fiif (action &IMA_MEASURE )ima_store_measurement (iint, file, pathname);if (action &IMA_APPRAISE_SUBMASK ) - rc =ima_appraise_measurement (_func, iint, file, pathname); + rc =ima_appraise_measurement (_func, iint, file, pathname, + temp_flags);if (action &IMA_AUDIT )ima_audit_measurement (iint, pathname);kfree (pathbuf);Index:
linux-integrity/security/integrity/ima/ima_appraise.c
===================================================================security/integrity/ima/ima_appraise.c +3
-2@@ -116,7 +116,8 @@ static void ima_cache_flags(struct integ* Return 0 on success, error code otherwise */ int ima_appraise_measurement (int func,struct integrity_iint_cache *iint, -struct file *file,const unsigned char *filename) +struct file *file,const unsigned char *filename, +int flags) {struct dentry *dentry = file->f_dentry;struct inode *inode = dentry->d_inode;@@ -154,7 +155,7 @@ int ima_appraise_measurement(int func, s }switch (xattr_value->type) {case IMA_XATTR_DIGEST : -if (iint->flags &IMA_DIGSIG_REQUIRED ) { +if (flags &IMA_DIGSIG_REQUIRED ) { cause ="IMA signature required" ; status =INTEGRITY_FAIL ;break ;Index:
linux-integrity/security/integrity/ima/ima.h
===================================================================security/integrity/ima/ima.h +3
-2@@ -143,7 +143,7 @@ void ima_delete_rules(void);#ifdef CONFIG_IMA_APPRAISE int ima_appraise_measurement (int func,struct integrity_iint_cache *iint, -struct file *file,const unsigned char *filename); +struct file *file,const unsigned char *filename,int flags);int ima_must_appraise (struct inode *inode,int mask,enum ima_hooks func);void ima_update_xattr (struct integrity_iint_cache *iint,struct file *file); enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint,@@ -153,7 +153,8 @@ enum integrity_status ima_get_cache_statstatic inline int ima_appraise_measurement (int func,struct integrity_iint_cache *iint,struct file *file, -const unsigned char *filename) +const unsigned char *filename, +int flags) {return INTEGRITY_UNKNOWN ; }Index:
linux-integrity/security/integrity/ima/ima_policy.c
===================================================================security/integrity/ima/ima_policy.c +1
-1@@ -267,7 +267,7 @@ int ima_match_policy(struct inode *inodeif (!ima_match_rules (entry, inode, func, mask))continue ; - action |= entry->flags &IMA_ACTION_FLAGS ; + action |= entry->flags &IMA_TEMP_FLAGS ; action |= entry->action &IMA_DO_MASK ;if (entry->action &IMA_APPRAISE )
Re: [PATCH v2 1/4] ima: added policy support for 'security.ima' type
Quoted 24 lines · Mimi Zohar
Quoted 16 lines · Vivek Goyal
On Tue, Jan 22, 2013 at 05:07:31PM -0500, Mimi Zohar wrote:
[..]
Review
Quoted 4 lines
/* iint cache flags */
(quoted diff) +2
-0+#define IMA_ACTION_FLAGS 0xff00 #define IMA_DIGSIG 0x0100 +#define IMA_DIGSIG_REQUIRED 0x0200Hi Mimi,
IMA_DIGSIG_REQUIREDstate does not really have to be stored in iint I guess. This is needed only if we go on to appraise and then we want to make sure digital signatures are present. Once appraisal is done,IMG_DIGSIGwill be set and saved iniint->flagsbut looks like we don't requireIMA_DIGSIG_REQUIREDto be saved.Quoted 6 lines
If yes, will it make sense to not save it in iint. There are still 8 bits left unused. We can mark these 8 bits for temporary flags like
IMA_DIGSIG_REQUIRED. If that works, I can use same space for defining additional temporary flags likeIMA_DIGSIG_SIGNED_ONLYto handle the case of appraise_type=imasig,signed_only. That flag also does not have to be persistent in iint.
Quoted 2 lines
Interesting idea. My only concern would be that we're not leaving room for additional hooks (eg. firmware).
Ok. May be we can employ another 32bit variable and put both of them in a structure to expand it, when firmware hooks come along.
Or I can do that right now, if you like it that way.
I need to move out non-persistent flags from iint flags, otherwise it can happen that conflicting flag might be set from different hooks.
For example, say hypothetically there are too hooks.
appraise fowner=0 func=mmap appraise_type=imasig appraise fowner=0 func=BPRM_CHECK appraise_type=imasig_signed_only
Now this will lead to setting of both IMA_DISGIG_REQUIRED and IMA_DIGSIG_SIGNED_ONLY in iint->flags and that does not mean much in the context of iint.
So by keeping them temporary, these flags become kind of hook specific and then two appraise hook don't conflict with each other.
Thanks
Vivek
Re: [PATCH v2 1/4] ima: added policy support for 'security.ima' type
Quoted 41 lines · Vivek Goyal
Quoted 24 lines · Mimi Zohar
Quoted 16 lines · Vivek Goyal
On Tue, Jan 22, 2013 at 05:07:31PM -0500, Mimi Zohar wrote:
[..]
Review
Quoted 4 lines
/* iint cache flags */
(quoted diff) +2
-0+#define IMA_ACTION_FLAGS 0xff00 #define IMA_DIGSIG 0x0100 +#define IMA_DIGSIG_REQUIRED 0x0200Hi Mimi,
IMA_DIGSIG_REQUIREDstate does not really have to be stored in iint I guess. This is needed only if we go on to appraise and then we want to make sure digital signatures are present. Once appraisal is done,IMG_DIGSIGwill be set and saved iniint->flagsbut looks like we don't requireIMA_DIGSIG_REQUIREDto be saved.Quoted 6 lines
If yes, will it make sense to not save it in iint. There are still 8 bits left unused. We can mark these 8 bits for temporary flags like
IMA_DIGSIG_REQUIRED. If that works, I can use same space for defining additional temporary flags likeIMA_DIGSIG_SIGNED_ONLYto handle the case of appraise_type=imasig,signed_only. That flag also does not have to be persistent in iint.Quoted 2 lines
Interesting idea. My only concern would be that we're not leaving room for additional hooks (eg. firmware).
Ok. May be we can employ another 32bit variable and put both of them in a structure to expand it, when firmware hooks come along.
Or I can do that right now, if you like it that way.
I need to move out non-persistent flags from iint flags, otherwise it can happen that conflicting flag might be set from different hooks.
For example, say hypothetically there are too hooks.
appraise fowner=0 func=mmap appraise_type=imasig appraise fowner=0 func=BPRM_CHECK appraise_type=imasig_signed_only
Quoted 6 lines
Now this will lead to setting of both
IMA_DISGIG_REQUIREDandIMA_DIGSIG_SIGNED_ONLYiniint->flagsand that does not mean much in the context of iint.So by keeping them temporary, these flags become kind of hook specific and then two appraise hook don't conflict with each other.
With the following patches, which James pulled earlier this week, each hook can have a different appraise status.
5a73fcf ima: differentiate appraise status only for hook specific rules d79d72e ima: per hook cache integrity appraisal status f578c08 ima: increase iint flag size
0e5a247 ima: added policy support for 'security.ima' type
thanks,
Mimi
Re: [PATCH v2 1/4] ima: added policy support for 'security.ima' type
On Thu, Jan 31, 2013 at 02:25:11PM -0500, Mimi Zohar wrote:
[..]
Quoted 7 lines
With the following patches, which James pulled earlier this week, each hook can have a different appraise status.
5a73fcf ima: differentiate appraise status only for hook specific rules d79d72e ima: per hook cache integrity appraisal status f578c08 ima: increase iint flag size
0e5a247 ima: added policy support for 'security.ima' type
Yes I understand that. I am not worried about appraise status of each hook. I am only concerned about IMA_DIGSIG_REQUIRED flag which does not belong to iint->flags.
As now I am trying to extend appraise_type to be able to appraise only signed executables and I need one more extra flag to keep track of that state.
If I just use one bit from IMA_ACTION_FLAGS (like IMA_DIGSIG_REQUIRED), say IMA_DIGSIG_SIGNED_ONLY, then we can potentially run into the situation where two different appraise hooks set these two flags separately causing some confusion.
To have written following patch which just uses one bit from IMA_ACTION_FLAGS. But I am not too happy with it. That's why I wanted to move temporary flags out of IMA_ACTION_FLAGS.
Thanks
Vivek
ima: Extend appraise policy to appraise only signed files
Currently appraise policy appraises every file. Allow to configure rules such that one can specify that appraise only signed files and unsinged ones just pass integrity test always.
This patch etends appraise type and one can specify apprasie_type=imasig,signed_only to appraise only signed files.
I think there is one issue here. That is new flag IMA_DIGSIG_SIGNED_ONLY is not hook specific. So if mmap hook says appraise_type=imasig and bprm_check hook says appraise_type=ima_sig,signed_only, I think mmap hook settings will be overidded. As both IMA_DIGSIG_REQUIRED and IMA_DIGSIG_SIGNED_ONLY flags will be set (one from mmap hook and other from bprm_check hook).
I guess to support it we require hook specific flags.
--- security/integrity/ima/ima_appraise.c | 32 ++++++++++++++++++++++++++++---- security/integrity/ima/ima_policy.c | 2 ++ security/integrity/integrity.h | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-)
security/integrity/integrity.h +2 -0
@@ -29,6 +29,8 @@#define IMA_ACTION_FLAGS 0xff000000#define IMA_DIGSIG 0x01000000#define IMA_DIGSIG_REQUIRED 0x02000000 +/* Appraise digital signature only, if present */ +#define IMA_DIGSIG_SIGNED_ONLY 0x04000000#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ IMA_APPRAISE_SUBMASK)
security/integrity/ima/ima_policy.c +2 -0
@@ -598,6 +598,8 @@ static int ima_parse_rule(char *rule, stima_log_string (ab,"appraise_type" , args[0 ].from);if ((strcmp (args[0 ].from,"imasig" )) ==0 ) entry->flags |=IMA_DIGSIG_REQUIRED ; +else if (!strcmp (args[0 ].from,"imasig,signed_only" )) + entry->flags |=IMA_DIGSIG_SIGNED_ONLY ;else result = -EINVAL ;break ;
security/integrity/ima/ima_appraise.c +28 -4
@@ -124,16 +124,27 @@ int ima_appraise_measurement(int func, senum integrity_status status =INTEGRITY_UNKNOWN ;const char *op ="appraise_data" ;char *cause ="unknown" ; -int rc; +int rc, audit_info =0 ;if (!ima_appraise)return 0 ; -if (!inode->i_op->getxattr) +if (!inode->i_op->getxattr) { +/* getxattr not supported. file couldn't have been signed */ +if (iint->flags &IMA_DIGSIG_SIGNED_ONLY ) +return INTEGRITY_PASS ;return INTEGRITY_UNKNOWN ; + } rc =vfs_getxattr_alloc (dentry,XATTR_NAME_IMA , (char **)&xattr_value,0 ,GFP_NOFS );if (rc <=0 ) { +if (rc == -EOPNOTSUPP ) { +/* File system does not have security label support */ +if (iint->flags &IMA_DIGSIG_SIGNED_ONLY ) +return INTEGRITY_PASS ; +return INTEGRITY_UNKNOWN ; + } +if (rc && rc != -ENODATA ) goto out;
@@ -159,6 +170,13 @@ int ima_appraise_measurement(int func, s status =INTEGRITY_FAIL ;break ; } + +if (iint->flags &IMA_DIGSIG_SIGNED_ONLY ) { +/* Appraise happens only for digital signatures */ + status =INTEGRITY_PASS ; +break ; + } + rc =memcmp (xattr_value->digest, iint->ima_xattr.digest,IMA_DIGEST_SIZE );if (rc) {
@@ -197,8 +215,14 @@ out:if (!ima_fix_xattr (dentry, iint)) status =INTEGRITY_PASS ; } -integrity_audit_msg (AUDIT_INTEGRITY_DATA , inode, filename, - op, cause, rc,0 ); +if (status ==INTEGRITY_NOLABEL && + iint->flags &IMA_DIGSIG_SIGNED_ONLY ) { + status =INTEGRITY_PASS ; +/* Don't flood audit logs with skipped appraise */ + audit_info =1 ; + } +integrity_audit_msg (AUDIT_INTEGRITY_DATA , inode, + filename, op, cause, rc, audit_info); }else {ima_cache_flags (iint, func); }
PATCH v2 2/4 ima: increase iint flag size
In reply to Mimi ZoharIn preparation for hook specific appraise status results, increase the iint flags size.
--- security/integrity/integrity.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
security/integrity/integrity.h +12 -12
@@ -16,19 +16,19 @@#include <crypto/sha.h> /* iint action cache flags */ -#define IMA_MEASURE 0x0001 -#define IMA_MEASURED 0x0002 -#define IMA_APPRAISE 0x0004 -#define IMA_APPRAISED 0x0008 -/*#define IMA_COLLECT 0x0010 do not use this flag */ -#define IMA_COLLECTED 0x0020 -#define IMA_AUDIT 0x0040 -#define IMA_AUDITED 0x0080 +#define IMA_MEASURE 0x00000001 +#define IMA_MEASURED 0x00000002 +#define IMA_APPRAISE 0x00000004 +#define IMA_APPRAISED 0x00000008 +/*#define IMA_COLLECT 0x00000010 do not use this flag */ +#define IMA_COLLECTED 0x00000020 +#define IMA_AUDIT 0x00000040 +#define IMA_AUDITED 0x00000080/* iint cache flags */ -#define IMA_ACTION_FLAGS 0xff00 -#define IMA_DIGSIG 0x0100 -#define IMA_DIGSIG_REQUIRED 0x0200 +#define IMA_ACTION_FLAGS 0xff000000 +#define IMA_DIGSIG 0x01000000 +#define IMA_DIGSIG_REQUIRED 0x02000000#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT)#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED \
@@ -50,7 +50,7 @@ struct integrity_iint_cache {struct rb_node rb_node;/* rooted in integrity_iint_tree */ struct inode *inode;/* back pointer to inode in question */ u64 version;/* track inode changes */ -unsigned short flags; +unsigned long flags;struct evm_ima_xattr_data ima_xattr; enum integrity_status ima_status:4; enum integrity_status evm_status:4;
Signature · 1 line
1.8.1.rc3
PATCH v2 3/4 ima: per hook cache integrity appraisal status
In reply to Mimi ZoharWith the new IMA policy 'appraise_type=' option, different hooks can require different methods for appraising a file's integrity.
For example, the existing 'ima_appraise_tcb' policy defines a generic rule, requiring all root files to be appraised, without specfying the appraisal method. A more specific rule could require all kernel modules, for example, to be signed.
appraise fowner=0 func=MODULE_CHECK appraise_type=imasig appraise fowner=0
As a result, the integrity appraisal results for the same inode, but for different hooks, could differ. This patch caches the integrity appraisal results on a per hook basis.
Changelog v2:
- Rename ima_cache_status() to ima_set_cache_status()
- Rename and move get_appraise_status() to ima_get_cache_status() Changelog v0:
- include IMA_APPRAISE/APPRAISED_SUBMASK in IMA_DO/DONE_MASK (Dmitry)
- Support independent MODULE_CHECK appraise status.
- fixed IMA_XXXX_APPRAISE/APPRAISED flags
--- security/integrity/iint.c | 10 ++++- security/integrity/ima/ima.h | 13 ++++++- security/integrity/ima/ima_appraise.c | 71 ++++++++++++++++++++++++++++++----- security/integrity/ima/ima_main.c | 19 ++++++---- security/integrity/ima/ima_policy.c | 22 +++++++++++ security/integrity/integrity.h | 26 +++++++++++-- 6 files changed, 136 insertions(+), 25 deletions(-)
security/integrity/iint.c +8 -2
@@ -72,7 +72,10 @@ static void iint_free(struct integrity_iint_cache *iint) { iint->version =0 ; iint->flags =0UL ; - iint->ima_status =INTEGRITY_UNKNOWN ; + iint->ima_file_status =INTEGRITY_UNKNOWN ; + iint->ima_mmap_status =INTEGRITY_UNKNOWN ; + iint->ima_bprm_status =INTEGRITY_UNKNOWN ; + iint->ima_module_status =INTEGRITY_UNKNOWN ; iint->evm_status =INTEGRITY_UNKNOWN ;kmem_cache_free (iint_cache, iint); }
@@ -149,7 +152,10 @@ static void init_once(void *foo)memset (iint,0 ,sizeof *iint); iint->version =0 ; iint->flags =0UL ; - iint->ima_status =INTEGRITY_UNKNOWN ; + iint->ima_file_status =INTEGRITY_UNKNOWN ; + iint->ima_mmap_status =INTEGRITY_UNKNOWN ; + iint->ima_bprm_status =INTEGRITY_UNKNOWN ; + iint->ima_module_status =INTEGRITY_UNKNOWN ; iint->evm_status =INTEGRITY_UNKNOWN ; }
security/integrity/ima/ima.h +11 -2
@@ -142,13 +142,16 @@ void ima_delete_rules(void);#define IMA_APPRAISE_FIX 0x02#ifdef CONFIG_IMA_APPRAISE -int ima_appraise_measurement (struct integrity_iint_cache *iint, +int ima_appraise_measurement (int func,struct integrity_iint_cache *iint,struct file *file,const unsigned char *filename);int ima_must_appraise (struct inode *inode,int mask,enum ima_hooks func);void ima_update_xattr (struct integrity_iint_cache *iint,struct file *file); +enum integrity_status ima_get_cache_status (struct integrity_iint_cache *iint, +int func);#else -static inline int ima_appraise_measurement (struct integrity_iint_cache *iint, +static inline int ima_appraise_measurement (int func, +struct integrity_iint_cache *iint,struct file *file,const unsigned char *filename) {
@@ -165,6 +168,12 @@ static inline void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file) { } + +static inline enum integrity_status ima_get_cache_status (struct integrity_iint_cache + *iint,int func) +{ +return INTEGRITY_UNKNOWN ; +}#endif /* LSM based policy rules require audit */
security/integrity/ima/ima_appraise.c +62 -9
110 lines not on this page · raw message
security/integrity/ima/ima_main.c +11 -8
@@ -151,8 +151,10 @@ static int process_measurement(struct file *file, const char *filename,if (!ima_initialized || !S_ISREG (inode->i_mode))return 0 ; -/* Determine if in appraise/audit/measurement policy, -* returns IMA_MEASURE, IMA_APPRAISE, IMA_AUDIT bitmask. */ +/* Return an IMA_MEASURE, IMA_APPRAISE, IMA_AUDIT action +* bitmask based on the appraise/audit/measurement policy. +* Included is the appraise submask. +*/ action =ima_get_action (inode, mask, function);if (!action)return 0 ;
@@ -166,16 +168,17 @@ static int process_measurement(struct file *file, const char *filename, goto out;/* Determine if already appraised/measured based on bitmask -* (IMA_MEASURE, IMA_MEASURED, IMA_APPRAISE, IMA_APPRAISED, -* IMA_AUDIT, IMA_AUDITED) */ +* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, +* IMA_AUDIT, IMA_AUDITED) +*/ iint->flags |= action; action &=IMA_DO_MASK ; action &= ~((iint->flags &IMA_DONE_MASK ) >>1 );/* Nothing to do, just return existing appraised status */ if (!action) { -if (iint->flags &IMA_APPRAISED ) - rc = iint->ima_status; +if (must_appraise) + rc =ima_get_cache_status (iint, function); goto out_digsig; }
@@ -191,8 +194,8 @@ static int process_measurement(struct file *file, const char *filename,if (action &IMA_MEASURE )ima_store_measurement (iint, file, pathname); -if (action &IMA_APPRAISE ) - rc =ima_appraise_measurement (iint, file, pathname); +if (action &IMA_APPRAISE_SUBMASK ) + rc =ima_appraise_measurement (function, iint, file, pathname);if (action &IMA_AUDIT )ima_audit_measurement (iint, pathname);kfree (pathbuf);
security/integrity/ima/ima_policy.c +22 -0
@@ -218,6 +218,25 @@ retry:return true; } +/* +* In addition to knowing that we need to appraise the file in general, +* we need to differentiate between calling hooks. +*/ +static int get_subaction (int func) +{ +switch (func) { +case MMAP_CHECK : +return IMA_MMAP_APPRAISE ; +case BPRM_CHECK : +return IMA_BPRM_APPRAISE ; +case MODULE_CHECK : +return IMA_MODULE_APPRAISE ; +case FILE_CHECK : +default : +return IMA_FILE_APPRAISE ; + } +} +/** * ima_match_policy - decision based on LSM and other conditions * @inode: pointer to an inode for which the policy decision is being made
@@ -248,6 +267,9 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask, action |= entry->flags &IMA_ACTION_FLAGS ; action |= entry->action &IMA_DO_MASK ; +if (entry->action &IMA_APPRAISE ) + action |=get_subaction (func); +if (entry->action &IMA_DO_MASK ) actmask &= ~(entry->action | entry->action <<1 );else
security/integrity/integrity.h +22 -4
@@ -30,9 +30,24 @@#define IMA_DIGSIG 0x01000000#define IMA_DIGSIG_REQUIRED 0x02000000 -#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT) -#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED \ - | IMA_COLLECTED) +#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ + IMA_APPRAISE_SUBMASK) +#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \ + IMA_COLLECTED | IMA_APPRAISED_SUBMASK) + +/* iint subaction appraise cache flags */ +#define IMA_FILE_APPRAISE 0x00000100 +#define IMA_FILE_APPRAISED 0x00000200 +#define IMA_MMAP_APPRAISE 0x00000400 +#define IMA_MMAP_APPRAISED 0x00000800 +#define IMA_BPRM_APPRAISE 0x00001000 +#define IMA_BPRM_APPRAISED 0x00002000 +#define IMA_MODULE_APPRAISE 0x00004000 +#define IMA_MODULE_APPRAISED 0x00008000 +#define IMA_APPRAISE_SUBMASK (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \ + IMA_BPRM_APPRAISE | IMA_MODULE_APPRAISE) +#define IMA_APPRAISED_SUBMASK (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \ + IMA_BPRM_APPRAISED | IMA_MODULE_APPRAISED)enum evm_ima_xattr_type {IMA_XATTR_DIGEST =0x01 ,
@@ -52,7 +67,10 @@ struct integrity_iint_cache {u64 version;/* track inode changes */ unsigned long flags;struct evm_ima_xattr_data ima_xattr; - enum integrity_status ima_status:4; + enum integrity_status ima_file_status:4; + enum integrity_status ima_mmap_status:4; + enum integrity_status ima_bprm_status:4; + enum integrity_status ima_module_status:4; enum integrity_status evm_status:4; };
Signature · 1 line
1.8.1.rc3
PATCH v2 4/4 ima: differentiate appraise status only for hook specific rules
In reply to Mimi ZoharDifferent hooks can require different methods for appraising a file's integrity. As a result, an integrity appraisal status is cached on a per hook basis.
Only a hook specific rule, requires the inode to be re-appraised. This patch eliminates unnecessary appraisals.
--- security/integrity/ima/ima_main.c | 9 ++++++--- security/integrity/ima/ima_policy.c | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-)
security/integrity/ima/ima_main.c +6 -3
@@ -146,7 +146,7 @@ static int process_measurement(struct file *file, const char *filename,struct integrity_iint_cache *iint;char *pathbuf =NULL ;const char *pathname =NULL ; -int rc = -ENOMEM , action, must_appraise; +int rc = -ENOMEM , action, must_appraise, _func;if (!ima_initialized || !S_ISREG (inode->i_mode))return 0 ;
@@ -161,6 +161,9 @@ static int process_measurement(struct file *file, const char *filename, must_appraise = action &IMA_APPRAISE ; +/* Is the appraise rule hook specific? */ + _func = (action &IMA_FILE_APPRAISE ) ?FILE_CHECK : function; +mutex_lock (&inode->i_mutex); iint =integrity_inode_get (inode);
@@ -178,7 +181,7 @@ static int process_measurement(struct file *file, const char *filename,/* Nothing to do, just return existing appraised status */ if (!action) {if (must_appraise) - rc =ima_get_cache_status (iint, function); + rc =ima_get_cache_status (iint, _func); goto out_digsig; }
@@ -195,7 +198,7 @@ static int process_measurement(struct file *file, const char *filename,if (action &IMA_MEASURE )ima_store_measurement (iint, file, pathname);if (action &IMA_APPRAISE_SUBMASK ) - rc =ima_appraise_measurement (function, iint, file, pathname); + rc =ima_appraise_measurement (_func, iint, file, pathname);if (action &IMA_AUDIT )ima_audit_measurement (iint, pathname);kfree (pathbuf);
security/integrity/ima/ima_policy.c +6 -3
@@ -220,10 +220,13 @@ retry:/* * In addition to knowing that we need to appraise the file in general, -* we need to differentiate between calling hooks. +* we need to differentiate between calling hooks, for hook specific rules. */ -static int get_subaction (int func) +static int get_subaction (struct ima_rule_entry *rule,int func) { +if (!(rule->flags &IMA_FUNC )) +return IMA_FILE_APPRAISE ; +switch (func) {case MMAP_CHECK :return IMA_MMAP_APPRAISE ;
@@ -268,7 +271,7 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask, action |= entry->action &IMA_DO_MASK ;if (entry->action &IMA_APPRAISE ) - action |=get_subaction (func); + action |=get_subaction (entry, func);if (entry->action &IMA_DO_MASK ) actmask &= ~(entry->action | entry->action <<1 );
Signature · 1 line
1.8.1.rc3