mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 14:25:52 +00:00
parser: add support for matching based on extended file attributes
Add userland support for matching based on extended file attributes. This leverages DFA based matching already in the kernel: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd Matching is exposed via flags on the profile: /usr/bin/* xattrs=(user.foo=bar user.bar=**) { # ... } Profiles list the set of extended attributes that a file MUST have, and a regex to match the value of that extended attributes. Additional extended attributes on the file don't effect the match. Signed-off-by: Eric Chiang <ericchiang@google.com>
This commit is contained in:
@@ -124,6 +124,44 @@ bool aare_rules::add_rule_vec(int deny, uint32_t perms, uint32_t audit,
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* append_rule is like add_rule, but appends the rule to any existing rules
|
||||
* with a null transition. The appended rule matches with the same permissions
|
||||
* as the rule it's appended to.
|
||||
*
|
||||
* This is used by xattrs matching where, after matching the path, the DFA is
|
||||
* advanced by a null character for each xattr.
|
||||
*/
|
||||
bool aare_rules::append_rule(const char *rule, dfaflags_t flags)
|
||||
{
|
||||
Node *tree = NULL;
|
||||
if (regex_parse(&tree, rule))
|
||||
return false;
|
||||
|
||||
if (flags & DFA_DUMP_RULE_EXPR) {
|
||||
cerr << "rule: ";
|
||||
cerr << rule;
|
||||
cerr << " -> ";
|
||||
tree->dump(cerr);
|
||||
cerr << "\n\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* For each matching state, we want to create an optional path
|
||||
* separated by a null character.
|
||||
*
|
||||
* When matching xattrs, the DFA must end up in an accepting state for
|
||||
* the path, then each value of the xattrs. Using an optional node
|
||||
* lets each rule end up in an accepting state.
|
||||
*/
|
||||
tree = new OptionalNode(new CatNode(new CharNode(0), tree));
|
||||
PermExprMap::iterator it;
|
||||
for (it = expr_map.begin(); it != expr_map.end(); it++) {
|
||||
expr_map[it->first] = new CatNode(it->second, tree);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* create a dfa from the ruleset
|
||||
* returns: buffer contain dfa tables, @size set to the size of the tables
|
||||
* else NULL on failure, @min_match_len set to the shortest string
|
||||
|
Reference in New Issue
Block a user