Skip to content

Commit 85865c1

Browse files
Dmitry KasatkinMimi Zohar
authored andcommitted
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>
1 parent 74de668 commit 85865c1

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎Documentation/ABI/testing/ima_policy‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ Description:
1919

2020
action: measure | dont_measure | appraise | dont_appraise | audit
2121
condition:= base | lsm [option]
22-
base: [[func=] [mask=] [fsmagic=] [uid=] [fowner]]
22+
base: [[func=] [mask=] [fsmagic=] [fsuuid=] [uid=]
23+
[fowner]]
2324
lsm: [[subj_user=] [subj_role=] [subj_type=]
2425
[obj_user=] [obj_role=] [obj_type=]]
2526
option: [[appraise_type=]]
2627

2728
base: func:= [BPRM_CHECK][MMAP_CHECK][FILE_CHECK][MODULE_CHECK]
2829
mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
2930
fsmagic:= hex value
31+
fsuuid:= file system UUID (e.g 8bcbe394-4f13-4144-be8e-5aa9ea2ce2f6)
3032
uid:= decimal value
3133
fowner:=decimal value
3234
lsm: are LSM specific

‎security/integrity/ima/ima_policy.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/magic.h>
1717
#include <linux/parser.h>
1818
#include <linux/slab.h>
19+
#include <linux/genhd.h>
1920

2021
#include "ima.h"
2122

@@ -25,6 +26,7 @@
2526
#define IMA_FSMAGIC 0x0004
2627
#define IMA_UID 0x0008
2728
#define IMA_FOWNER 0x0010
29+
#define IMA_FSUUID 0x0020
2830

2931
#define UNKNOWN 0
3032
#define MEASURE 0x0001 /* same as IMA_MEASURE */
@@ -45,6 +47,7 @@ struct ima_rule_entry {
4547
enum ima_hooks func;
4648
int mask;
4749
unsigned long fsmagic;
50+
u8 fsuuid[16];
4851
kuid_t uid;
4952
kuid_t fowner;
5053
struct {
@@ -172,6 +175,9 @@ static bool ima_match_rules(struct ima_rule_entry *rule,
172175
if ((rule->flags & IMA_FSMAGIC)
173176
&& rule->fsmagic != inode->i_sb->s_magic)
174177
return false;
178+
if ((rule->flags & IMA_FSUUID) &&
179+
memcmp(rule->fsuuid, inode->i_sb->s_uuid, sizeof(rule->fsuuid)))
180+
return false;
175181
if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid))
176182
return false;
177183
if ((rule->flags & IMA_FOWNER) && !uid_eq(rule->fowner, inode->i_uid))
@@ -346,7 +352,7 @@ enum {
346352
Opt_obj_user, Opt_obj_role, Opt_obj_type,
347353
Opt_subj_user, Opt_subj_role, Opt_subj_type,
348354
Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner,
349-
Opt_appraise_type
355+
Opt_appraise_type, Opt_fsuuid
350356
};
351357

352358
static match_table_t policy_tokens = {
@@ -364,6 +370,7 @@ static match_table_t policy_tokens = {
364370
{Opt_func, "func=%s"},
365371
{Opt_mask, "mask=%s"},
366372
{Opt_fsmagic, "fsmagic=%s"},
373+
{Opt_fsuuid, "fsuuid=%s"},
367374
{Opt_uid, "uid=%s"},
368375
{Opt_fowner, "fowner=%s"},
369376
{Opt_appraise_type, "appraise_type=%s"},
@@ -519,6 +526,19 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
519526
if (!result)
520527
entry->flags |= IMA_FSMAGIC;
521528
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;
522542
case Opt_uid:
523543
ima_log_string(ab, "uid", args[0].from);
524544

0 commit comments

Comments
 (0)