diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2012-05-25 20:24:12 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-09-21 06:13:24 -0400 |
commit | 8b94eea4bfb8df693c5b35d08b74f13cfb92f3de (patch) | |
tree | 908ffbf4f0bb117ca47346712dc0e57f6434cda1 /security | |
parent | cf9c93526f4517581a9e8f1c0d9093a4c7748ec6 (diff) |
userns: Add user namespace support to IMA
Use kuid's in the IMA rules.
When reporting the current uid in audit logs use from_kuid
to get a usable value.
Cc: Mimi Zohar <zohar@us.ibm.com>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/integrity/ima/ima_audit.c | 5 | ||||
-rw-r--r-- | security/integrity/ima/ima_policy.c | 14 |
2 files changed, 10 insertions, 9 deletions
diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c index 7a57f6769e9c..c586faae8fd6 100644 --- a/security/integrity/ima/ima_audit.c +++ b/security/integrity/ima/ima_audit.c | |||
@@ -39,8 +39,9 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode, | |||
39 | 39 | ||
40 | ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno); | 40 | ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno); |
41 | audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u", | 41 | audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u", |
42 | current->pid, current_cred()->uid, | 42 | current->pid, |
43 | audit_get_loginuid(current), | 43 | from_kuid(&init_user_ns, current_cred()->uid), |
44 | from_kuid(&init_user_ns, audit_get_loginuid(current)), | ||
44 | audit_get_sessionid(current)); | 45 | audit_get_sessionid(current)); |
45 | audit_log_task_context(ab); | 46 | audit_log_task_context(ab); |
46 | audit_log_format(ab, " op="); | 47 | audit_log_format(ab, " op="); |
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 1a9583008aae..c84df05180cb 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c | |||
@@ -39,7 +39,7 @@ struct ima_measure_rule_entry { | |||
39 | enum ima_hooks func; | 39 | enum ima_hooks func; |
40 | int mask; | 40 | int mask; |
41 | unsigned long fsmagic; | 41 | unsigned long fsmagic; |
42 | uid_t uid; | 42 | kuid_t uid; |
43 | struct { | 43 | struct { |
44 | void *rule; /* LSM file metadata specific */ | 44 | void *rule; /* LSM file metadata specific */ |
45 | int type; /* audit type */ | 45 | int type; /* audit type */ |
@@ -71,7 +71,7 @@ static struct ima_measure_rule_entry default_rules[] = { | |||
71 | .flags = IMA_FUNC | IMA_MASK}, | 71 | .flags = IMA_FUNC | IMA_MASK}, |
72 | {.action = MEASURE,.func = BPRM_CHECK,.mask = MAY_EXEC, | 72 | {.action = MEASURE,.func = BPRM_CHECK,.mask = MAY_EXEC, |
73 | .flags = IMA_FUNC | IMA_MASK}, | 73 | .flags = IMA_FUNC | IMA_MASK}, |
74 | {.action = MEASURE,.func = FILE_CHECK,.mask = MAY_READ,.uid = 0, | 74 | {.action = MEASURE,.func = FILE_CHECK,.mask = MAY_READ,.uid = GLOBAL_ROOT_UID, |
75 | .flags = IMA_FUNC | IMA_MASK | IMA_UID}, | 75 | .flags = IMA_FUNC | IMA_MASK | IMA_UID}, |
76 | }; | 76 | }; |
77 | 77 | ||
@@ -112,7 +112,7 @@ static bool ima_match_rules(struct ima_measure_rule_entry *rule, | |||
112 | if ((rule->flags & IMA_FSMAGIC) | 112 | if ((rule->flags & IMA_FSMAGIC) |
113 | && rule->fsmagic != inode->i_sb->s_magic) | 113 | && rule->fsmagic != inode->i_sb->s_magic) |
114 | return false; | 114 | return false; |
115 | if ((rule->flags & IMA_UID) && rule->uid != cred->uid) | 115 | if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid)) |
116 | return false; | 116 | return false; |
117 | for (i = 0; i < MAX_LSM_RULES; i++) { | 117 | for (i = 0; i < MAX_LSM_RULES; i++) { |
118 | int rc = 0; | 118 | int rc = 0; |
@@ -277,7 +277,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry) | |||
277 | 277 | ||
278 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE); | 278 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE); |
279 | 279 | ||
280 | entry->uid = -1; | 280 | entry->uid = INVALID_UID; |
281 | entry->action = UNKNOWN; | 281 | entry->action = UNKNOWN; |
282 | while ((p = strsep(&rule, " \t")) != NULL) { | 282 | while ((p = strsep(&rule, " \t")) != NULL) { |
283 | substring_t args[MAX_OPT_ARGS]; | 283 | substring_t args[MAX_OPT_ARGS]; |
@@ -361,15 +361,15 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry) | |||
361 | case Opt_uid: | 361 | case Opt_uid: |
362 | ima_log_string(ab, "uid", args[0].from); | 362 | ima_log_string(ab, "uid", args[0].from); |
363 | 363 | ||
364 | if (entry->uid != -1) { | 364 | if (uid_valid(entry->uid)) { |
365 | result = -EINVAL; | 365 | result = -EINVAL; |
366 | break; | 366 | break; |
367 | } | 367 | } |
368 | 368 | ||
369 | result = strict_strtoul(args[0].from, 10, &lnum); | 369 | result = strict_strtoul(args[0].from, 10, &lnum); |
370 | if (!result) { | 370 | if (!result) { |
371 | entry->uid = (uid_t) lnum; | 371 | entry->uid = make_kuid(current_user_ns(), (uid_t)lnum); |
372 | if (entry->uid != lnum) | 372 | if (!uid_valid(entry->uid) || (((uid_t)lnum) != lnum)) |
373 | result = -EINVAL; | 373 | result = -EINVAL; |
374 | else | 374 | else |
375 | entry->flags |= IMA_UID; | 375 | entry->flags |= IMA_UID; |