Skip to content

Commit 2ab47da

Browse files
committed
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: John Johansen <john.johansen@canonical.com>
1 parent e79c26d commit 2ab47da

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

‎security/apparmor/audit.c‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,16 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
165165
}
166166

167167
struct aa_audit_rule {
168-
char *profile;
168+
struct aa_label *label;
169169
};
170170

171171
void aa_audit_rule_free(void *vrule)
172172
{
173173
struct aa_audit_rule *rule = vrule;
174174

175175
if (rule) {
176-
kfree(rule->profile);
176+
if (!IS_ERR(rule->label))
177+
aa_put_label(rule->label);
177178
kfree(rule);
178179
}
179180
}
@@ -196,13 +197,11 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
196197
if (!rule)
197198
return -ENOMEM;
198199

199-
rule->profile = kstrdup(rulestr, GFP_KERNEL);
200-
201-
if (!rule->profile) {
202-
kfree(rule);
203-
return -ENOMEM;
204-
}
205-
200+
/* Currently rules are treated as coming from the root ns */
201+
rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr,
202+
GFP_KERNEL, true, false);
203+
if (IS_ERR(rule->label))
204+
return PTR_ERR(rule->label);
206205
*vrule = rule;
207206

208207
return 0;
@@ -229,21 +228,15 @@ int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
229228
{
230229
struct aa_audit_rule *rule = vrule;
231230
struct aa_label *label;
232-
struct label_it i;
233-
struct aa_profile *profile;
234231
int found = 0;
235232

236233
label = aa_secid_to_label(sid);
237234

238235
if (!label)
239236
return -ENOENT;
240237

241-
label_for_each(i, label, profile) {
242-
if (strcmp(rule->profile, profile->base.hname) == 0) {
243-
found = 1;
244-
break;
245-
}
246-
}
238+
if (aa_label_is_subset(label, rule->label))
239+
found = 1;
247240

248241
switch (field) {
249242
case AUDIT_SUBJ_ROLE:

0 commit comments

Comments
 (0)