diff options
author | Dmitry Kasatkin <dmitry.kasatkin@intel.com> | 2012-09-03 16:23:13 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2013-02-06 10:40:29 -0500 |
commit | 85865c1fa189fcba49089e6254a0226f2269bebc (patch) | |
tree | e3bcc153e1218302a3bccd30f55295361396a781 /security | |
parent | 74de66842473bdafa798010e58f1999ec70a8983 (diff) |
ima: add policy support for file system uuid
The IMA policy permits specifying rules to enable or disable
measurement/appraisal/audit based on the file system magic number.
If, for example, the policy contains an ext4 measurement rule,
the rule is enabled for all ext4 partitions.
Sometimes it might be necessary to enable measurement/appraisal/audit
only for one partition and disable it for another partition of the
same type. With the existing IMA policy syntax, this can not be done.
This patch provides support for IMA policy rules to specify the file
system by its UUID (eg. fsuuid=397449cd-687d-4145-8698-7fed4a3e0363).
For partitions not being appraised, it might be a good idea to mount
file systems with the 'noexec' option to prevent executing non-verified
binaries.
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/integrity/ima/ima_policy.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 4adcd0f8c1dd..23f49e37a957 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/magic.h> | 16 | #include <linux/magic.h> |
17 | #include <linux/parser.h> | 17 | #include <linux/parser.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/genhd.h> | ||
19 | 20 | ||
20 | #include "ima.h" | 21 | #include "ima.h" |
21 | 22 | ||
@@ -25,6 +26,7 @@ | |||
25 | #define IMA_FSMAGIC 0x0004 | 26 | #define IMA_FSMAGIC 0x0004 |
26 | #define IMA_UID 0x0008 | 27 | #define IMA_UID 0x0008 |
27 | #define IMA_FOWNER 0x0010 | 28 | #define IMA_FOWNER 0x0010 |
29 | #define IMA_FSUUID 0x0020 | ||
28 | 30 | ||
29 | #define UNKNOWN 0 | 31 | #define UNKNOWN 0 |
30 | #define MEASURE 0x0001 /* same as IMA_MEASURE */ | 32 | #define MEASURE 0x0001 /* same as IMA_MEASURE */ |
@@ -45,6 +47,7 @@ struct ima_rule_entry { | |||
45 | enum ima_hooks func; | 47 | enum ima_hooks func; |
46 | int mask; | 48 | int mask; |
47 | unsigned long fsmagic; | 49 | unsigned long fsmagic; |
50 | u8 fsuuid[16]; | ||
48 | kuid_t uid; | 51 | kuid_t uid; |
49 | kuid_t fowner; | 52 | kuid_t fowner; |
50 | struct { | 53 | struct { |
@@ -172,6 +175,9 @@ static bool ima_match_rules(struct ima_rule_entry *rule, | |||
172 | if ((rule->flags & IMA_FSMAGIC) | 175 | if ((rule->flags & IMA_FSMAGIC) |
173 | && rule->fsmagic != inode->i_sb->s_magic) | 176 | && rule->fsmagic != inode->i_sb->s_magic) |
174 | return false; | 177 | return false; |
178 | if ((rule->flags & IMA_FSUUID) && | ||
179 | memcmp(rule->fsuuid, inode->i_sb->s_uuid, sizeof(rule->fsuuid))) | ||
180 | return false; | ||
175 | if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid)) | 181 | if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid)) |
176 | return false; | 182 | return false; |
177 | if ((rule->flags & IMA_FOWNER) && !uid_eq(rule->fowner, inode->i_uid)) | 183 | if ((rule->flags & IMA_FOWNER) && !uid_eq(rule->fowner, inode->i_uid)) |
@@ -346,7 +352,7 @@ enum { | |||
346 | Opt_obj_user, Opt_obj_role, Opt_obj_type, | 352 | Opt_obj_user, Opt_obj_role, Opt_obj_type, |
347 | Opt_subj_user, Opt_subj_role, Opt_subj_type, | 353 | Opt_subj_user, Opt_subj_role, Opt_subj_type, |
348 | Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner, | 354 | Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner, |
349 | Opt_appraise_type | 355 | Opt_appraise_type, Opt_fsuuid |
350 | }; | 356 | }; |
351 | 357 | ||
352 | static match_table_t policy_tokens = { | 358 | static match_table_t policy_tokens = { |
@@ -364,6 +370,7 @@ static match_table_t policy_tokens = { | |||
364 | {Opt_func, "func=%s"}, | 370 | {Opt_func, "func=%s"}, |
365 | {Opt_mask, "mask=%s"}, | 371 | {Opt_mask, "mask=%s"}, |
366 | {Opt_fsmagic, "fsmagic=%s"}, | 372 | {Opt_fsmagic, "fsmagic=%s"}, |
373 | {Opt_fsuuid, "fsuuid=%s"}, | ||
367 | {Opt_uid, "uid=%s"}, | 374 | {Opt_uid, "uid=%s"}, |
368 | {Opt_fowner, "fowner=%s"}, | 375 | {Opt_fowner, "fowner=%s"}, |
369 | {Opt_appraise_type, "appraise_type=%s"}, | 376 | {Opt_appraise_type, "appraise_type=%s"}, |
@@ -519,6 +526,19 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) | |||
519 | if (!result) | 526 | if (!result) |
520 | entry->flags |= IMA_FSMAGIC; | 527 | entry->flags |= IMA_FSMAGIC; |
521 | break; | 528 | break; |
529 | case Opt_fsuuid: | ||
530 | ima_log_string(ab, "fsuuid", args[0].from); | ||
531 | |||
532 | if (memchr_inv(entry->fsuuid, 0x00, | ||
533 | sizeof(entry->fsuuid))) { | ||
534 | result = -EINVAL; | ||
535 | break; | ||
536 | } | ||
537 | |||
538 | part_pack_uuid(args[0].from, entry->fsuuid); | ||
539 | entry->flags |= IMA_FSUUID; | ||
540 | result = 0; | ||
541 | break; | ||
522 | case Opt_uid: | 542 | case Opt_uid: |
523 | ima_log_string(ab, "uid", args[0].from); | 543 | ima_log_string(ab, "uid", args[0].from); |
524 | 544 | ||