diff options
| author | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2014-11-05 07:53:55 -0500 |
|---|---|---|
| committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2015-06-16 08:18:44 -0400 |
| commit | 4351c294b8c1028077280f761e158d167b592974 (patch) | |
| tree | cc7dface0ae4de97545e26df97a42171034e9443 /security | |
| parent | 139069eff7388407f19794384c42a534d618ccd7 (diff) | |
ima: extend "mask" policy matching support
The current "mask" policy option matches files opened as MAY_READ,
MAY_WRITE, MAY_APPEND or MAY_EXEC. This patch extends the "mask"
option to match files opened containing one of these modes. For
example, "mask=^MAY_READ" would match files opened read-write.
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Signed-off-by: Dr. Greg Wettstein <gw@idfusion.org>
Cc: stable@vger.kernel.org
Diffstat (limited to 'security')
| -rw-r--r-- | security/integrity/ima/ima_policy.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 525301cf7d90..b3a2038ed424 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #define IMA_UID 0x0008 | 27 | #define IMA_UID 0x0008 |
| 28 | #define IMA_FOWNER 0x0010 | 28 | #define IMA_FOWNER 0x0010 |
| 29 | #define IMA_FSUUID 0x0020 | 29 | #define IMA_FSUUID 0x0020 |
| 30 | #define IMA_INMASK 0x0040 | ||
| 30 | #define IMA_EUID 0x0080 | 31 | #define IMA_EUID 0x0080 |
| 31 | 32 | ||
| 32 | #define UNKNOWN 0 | 33 | #define UNKNOWN 0 |
| @@ -187,6 +188,9 @@ static bool ima_match_rules(struct ima_rule_entry *rule, | |||
| 187 | if ((rule->flags & IMA_MASK) && | 188 | if ((rule->flags & IMA_MASK) && |
| 188 | (rule->mask != mask && func != POST_SETATTR)) | 189 | (rule->mask != mask && func != POST_SETATTR)) |
| 189 | return false; | 190 | return false; |
| 191 | if ((rule->flags & IMA_INMASK) && | ||
| 192 | (!(rule->mask & mask) && func != POST_SETATTR)) | ||
| 193 | return false; | ||
| 190 | if ((rule->flags & IMA_FSMAGIC) | 194 | if ((rule->flags & IMA_FSMAGIC) |
| 191 | && rule->fsmagic != inode->i_sb->s_magic) | 195 | && rule->fsmagic != inode->i_sb->s_magic) |
| 192 | return false; | 196 | return false; |
| @@ -448,6 +452,7 @@ static void ima_log_string(struct audit_buffer *ab, char *key, char *value) | |||
| 448 | static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) | 452 | static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) |
| 449 | { | 453 | { |
| 450 | struct audit_buffer *ab; | 454 | struct audit_buffer *ab; |
| 455 | char *from; | ||
| 451 | char *p; | 456 | char *p; |
| 452 | int result = 0; | 457 | int result = 0; |
| 453 | 458 | ||
| @@ -538,18 +543,23 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) | |||
| 538 | if (entry->mask) | 543 | if (entry->mask) |
| 539 | result = -EINVAL; | 544 | result = -EINVAL; |
| 540 | 545 | ||
| 541 | if ((strcmp(args[0].from, "MAY_EXEC")) == 0) | 546 | from = args[0].from; |
| 547 | if (*from == '^') | ||
| 548 | from++; | ||
| 549 | |||
| 550 | if ((strcmp(from, "MAY_EXEC")) == 0) | ||
| 542 | entry->mask = MAY_EXEC; | 551 | entry->mask = MAY_EXEC; |
| 543 | else if (strcmp(args[0].from, "MAY_WRITE") == 0) | 552 | else if (strcmp(from, "MAY_WRITE") == 0) |
| 544 | entry->mask = MAY_WRITE; | 553 | entry->mask = MAY_WRITE; |
| 545 | else if (strcmp(args[0].from, "MAY_READ") == 0) | 554 | else if (strcmp(from, "MAY_READ") == 0) |
| 546 | entry->mask = MAY_READ; | 555 | entry->mask = MAY_READ; |
| 547 | else if (strcmp(args[0].from, "MAY_APPEND") == 0) | 556 | else if (strcmp(from, "MAY_APPEND") == 0) |
| 548 | entry->mask = MAY_APPEND; | 557 | entry->mask = MAY_APPEND; |
| 549 | else | 558 | else |
| 550 | result = -EINVAL; | 559 | result = -EINVAL; |
| 551 | if (!result) | 560 | if (!result) |
| 552 | entry->flags |= IMA_MASK; | 561 | entry->flags |= (*args[0].from == '^') |
| 562 | ? IMA_INMASK : IMA_MASK; | ||
| 553 | break; | 563 | break; |
| 554 | case Opt_fsmagic: | 564 | case Opt_fsmagic: |
| 555 | ima_log_string(ab, "fsmagic", args[0].from); | 565 | ima_log_string(ab, "fsmagic", args[0].from); |
