2012-11-22 22:04:35

by Kasatkin, Dmitry

[permalink] [raw]
Subject: [PATCH 0/2] ima: policy search speedup

Hello,

Here is two patches for policy search speedup.

First patch adds additional features flags to superblock.
Second - implementation for IMA.

Two months ago I was asking about it on mailing lists.
Suggestion was not to use s_flags, but e.g. s_feature_flags.

Any objections about such approach?

Thanks,
Dmitry

Dmitry Kasatkin (2):
vfs: new super block feature flags attribute
ima: skip policy search for never appraised or measured files

include/linux/fs.h | 4 ++++
security/integrity/ima/ima_api.c | 8 ++------
security/integrity/ima/ima_policy.c | 20 +++++++++++++++++---
security/integrity/integrity.h | 3 +++
4 files changed, 26 insertions(+), 9 deletions(-)

--
1.7.10.4


2012-11-22 21:55:11

by Kasatkin, Dmitry

[permalink] [raw]
Subject: [PATCH 2/2] ima: skip policy search for never appraised or measured files

Certain file system types and partitions will never be measured or
appraised by IMA depending on the policy. For example, pseudo file
systems are never measured and appraised. In current implementation
policy will be checked again and again. It happens thousands times
per second. That is absolute waste of CPU and may be battery resources.

This patch uses new super block SF_IMA_DISABLED flag. IMA set the
SF_IMA_DISABLED flag when file system will not be measured and
appraised and test this flag during subsequent calls to skip policy
search.

Signed-off-by: Dmitry Kasatkin <[email protected]>
---
security/integrity/ima/ima_api.c | 8 ++------
security/integrity/ima/ima_policy.c | 20 +++++++++++++++++---
security/integrity/integrity.h | 3 +++
3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
index b356884..2156020 100644
--- a/security/integrity/ima/ima_api.c
+++ b/security/integrity/ima/ima_api.c
@@ -114,12 +114,8 @@ err_out:
*/
int ima_get_action(struct inode *inode, int mask, int function)
{
- int flags = IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE;
-
- if (!ima_appraise)
- flags &= ~IMA_APPRAISE;
-
- return ima_match_policy(inode, function, mask, flags);
+ return ima_match_policy(inode, function, mask,
+ IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE);
}

int ima_must_measure(struct inode *inode, int mask, int function)
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index c7dacd2..a68ea55 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -22,7 +22,6 @@
/* flags definitions */
#define IMA_FUNC 0x0001
#define IMA_MASK 0x0002
-#define IMA_FSMAGIC 0x0004
#define IMA_UID 0x0008
#define IMA_FOWNER 0x0010

@@ -198,7 +197,16 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
int flags)
{
struct ima_rule_entry *entry;
- int action = 0, actmask = flags | (flags << 1);
+ int all_actions = (flags == IMA_DO_MASK);
+ int action = 0, actmask;
+
+ if (inode->i_sb->s_feature_flags & SF_IMA_DISABLED)
+ return 0;
+
+ if (!ima_appraise)
+ flags &= ~IMA_APPRAISE;
+
+ actmask = flags | (flags << 1);

list_for_each_entry(entry, ima_rules, list) {

@@ -208,6 +216,7 @@ 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);
@@ -217,7 +226,12 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
if (!actmask)
break;
}
-
+ if (all_actions && (action & IMA_FS_MASK)) {
+ action &= ~IMA_FS_MASK;
+ /* dont_measure, dont_audit and dont_appraise */
+ if (!action)
+ inode->i_sb->s_feature_flags |= SF_IMA_DISABLED;
+ }
return action;
}

diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
index e9db763..d67d867 100644
--- a/security/integrity/integrity.h
+++ b/security/integrity/integrity.h
@@ -26,7 +26,10 @@
#define IMA_AUDITED 0x0080

/* iint cache flags */
+#define IMA_ACTION_FLAGS 0xff00
#define IMA_DIGSIG 0x0100
+#define IMA_FSMAGIC 0x0200
+#define IMA_FS_MASK IMA_FSMAGIC

#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT)
#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED \
--
1.7.10.4

2012-11-22 22:04:53

by Kasatkin, Dmitry

[permalink] [raw]
Subject: [PATCH 1/2] vfs: new super block feature flags attribute

This patch introduces new super block attribute flag s_feature_flags
and SF_IMA_DISABLED flag. This flag will be used by Integrity Measurement
Architecture (IMA). Name suggested by Bruce Fields.

Certain file system types and partitions will never be measured or
appraised by IMA depending on the policy. For example, pseudo file
systems are never measured and appraised. In current implementation
policy will be checked again and again. It happens thousands times
per second. That is absolute waste of CPU and may be battery resources.

IMA will set the SF_IMA_DISABLED flag when file system will not be measured
and appraised and test this flag during subsequent calls to skip policy search.

Signed-off-by: Dmitry Kasatkin <[email protected]>
---
include/linux/fs.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index b33cfc9..0bef2b2 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1321,6 +1321,8 @@ struct super_block {

/* Being remounted read-only */
int s_readonly_remount;
+
+ unsigned long s_feature_flags;
};

/* superblock cache pruning functions */
@@ -1746,6 +1748,8 @@ struct super_operations {

#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)

+#define SF_IMA_DISABLED 0x0001
+
extern void __mark_inode_dirty(struct inode *, int);
static inline void mark_inode_dirty(struct inode *inode)
{
--
1.7.10.4

2012-11-27 13:42:17

by Kasatkin, Dmitry

[permalink] [raw]
Subject: Re: [PATCH 0/2] ima: policy search speedup

Hello,

Any thoughts about this proposal?

- Dmitry

On Thu, Nov 22, 2012 at 11:54 PM, Dmitry Kasatkin
<[email protected]> wrote:
> Hello,
>
> Here is two patches for policy search speedup.
>
> First patch adds additional features flags to superblock.
> Second - implementation for IMA.
>
> Two months ago I was asking about it on mailing lists.
> Suggestion was not to use s_flags, but e.g. s_feature_flags.
>
> Any objections about such approach?
>
> Thanks,
> Dmitry
>
> Dmitry Kasatkin (2):
> vfs: new super block feature flags attribute
> ima: skip policy search for never appraised or measured files
>
> include/linux/fs.h | 4 ++++
> security/integrity/ima/ima_api.c | 8 ++------
> security/integrity/ima/ima_policy.c | 20 +++++++++++++++++---
> security/integrity/integrity.h | 3 +++
> 4 files changed, 26 insertions(+), 9 deletions(-)
>
> --
> 1.7.10.4
>