Commit 2ab47dae authored by John Johansen's avatar John Johansen

apparmor: modify audit rule support to support profile stacks

Allows for audit rules, where a rule could specify a profile stack
A//&B, while extending the current semantic so if the label specified
in the audit rule is a subset of the secid it is considered a match.

Eg. if the secid resolves to the label stack A//&B//&C

Then an audit rule specifying a label of

  A - would match
  B - would match
  C - would match
  D - would not
  A//&B - would match as a subset
  A//&C - would match as a subset
  B//&C - would match as a subset
  A//&B//&C - would match

  A//&D - would not match, because while A does match, D is also
  specified and does not

Note: audit rules are currently assumed to be coming from the root
namespace.
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent e79c26d0
...@@ -165,7 +165,7 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa, ...@@ -165,7 +165,7 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
} }
struct aa_audit_rule { struct aa_audit_rule {
char *profile; struct aa_label *label;
}; };
void aa_audit_rule_free(void *vrule) void aa_audit_rule_free(void *vrule)
...@@ -173,7 +173,8 @@ void aa_audit_rule_free(void *vrule) ...@@ -173,7 +173,8 @@ void aa_audit_rule_free(void *vrule)
struct aa_audit_rule *rule = vrule; struct aa_audit_rule *rule = vrule;
if (rule) { if (rule) {
kfree(rule->profile); if (!IS_ERR(rule->label))
aa_put_label(rule->label);
kfree(rule); kfree(rule);
} }
} }
...@@ -196,13 +197,11 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule) ...@@ -196,13 +197,11 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
if (!rule) if (!rule)
return -ENOMEM; return -ENOMEM;
rule->profile = kstrdup(rulestr, GFP_KERNEL); /* Currently rules are treated as coming from the root ns */
rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr,
if (!rule->profile) { GFP_KERNEL, true, false);
kfree(rule); if (IS_ERR(rule->label))
return -ENOMEM; return PTR_ERR(rule->label);
}
*vrule = rule; *vrule = rule;
return 0; return 0;
...@@ -229,8 +228,6 @@ int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule, ...@@ -229,8 +228,6 @@ int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
{ {
struct aa_audit_rule *rule = vrule; struct aa_audit_rule *rule = vrule;
struct aa_label *label; struct aa_label *label;
struct label_it i;
struct aa_profile *profile;
int found = 0; int found = 0;
label = aa_secid_to_label(sid); label = aa_secid_to_label(sid);
...@@ -238,12 +235,8 @@ int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule, ...@@ -238,12 +235,8 @@ int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
if (!label) if (!label)
return -ENOENT; return -ENOENT;
label_for_each(i, label, profile) { if (aa_label_is_subset(label, rule->label))
if (strcmp(rule->profile, profile->base.hname) == 0) { found = 1;
found = 1;
break;
}
}
switch (field) { switch (field) {
case AUDIT_SUBJ_ROLE: case AUDIT_SUBJ_ROLE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment