Qualifier blocks

nesting and conflicts for application developers

A brace block inside a profile applies the qualifiers written in front of it to every rule inside. Blocks nest and their qualifiers combine with those of the rules. Contradicting access types and a priority on a block are errors.

On the map: qualifiers

▶ Watch this deck — 8 scenes, ~6 min

Worth seeing first

01 The same qualifier on line after line

QUALIFIER BLOCKS deny /proc/sys/** w, deny /sys/** w, deny /boot/** w, three rules, three times deny deny { /proc/sys/** w, /sys/** w, /boot/** w, } one qualifier, three rules = the block and the three separate rules compile to the same policy no comma after the closing brace line 34 of the example profile: deny { /proc/sys/** w, /sys/** w, }
Three deny rules on the left, each starting with the word deny. On the right the same three rules inside one deny block: the qualifier, an opening brace, the rules, a closing brace. The two forms compile to the same policy.

QUALIFIERS { RULES } applies the qualifiers to every rule inside the braces. No comma follows the closing brace.

The profile for demo denies writing to a few kernel directories. Three rules, and three times the word deny. A qualifier block lets you say it once. You write the qualifier, an opening brace, the rules just as usual, and a closing brace. The parser gives the qualifier to every rule inside, so the block and the three separate rules compile to the same policy. One detail: there's no comma after the closing brace. A block isn't a rule. It's a container for rules. The example profile already uses this shape.

Details and sources

Details

  • A qualifier block is QUALIFIERS { RULES } inside a profile body. The qualifiers in front of the opening brace are applied to every rule inside when the block is parsed (parser_yacc.y:738-759, block.cc:273-284).
  • The slide's three-rule deny { ... } block is accepted by the parser built from AppArmor 836052d21 (run with -Q -K --skip-kernel-load --warn=all; nothing was loaded into a kernel).
  • That a block and its expanded form compile to the same binary policy is what the tree's equality tests check, for example prompt { /foo r, audit /bar w, owner /baz rw, } against the three separate rules (equality.sh:1445-1447).
  • No comma after the closing brace. deny { /sys/** w, }, is rejected by the same parser: "syntax error, unexpected TOK_END_OF_RULE, expecting TOK_ID or TOK_MODE or TOK_SET_VAR".
  • Full form of a parser error: AppArmor parser error for FILE in profile FILE at line N: MESSAGE. The slides of this deck show MESSAGE only.
  • Line 34 of the map's example profile is deny { /proc/sys/** w, /sys/** w, }. The rule /boot/** w, is added on the slide to make the repetition visible.

Read more

02 Qualifiers, brace, rules, brace

GRAMMAR audit allow|deny|prompt owner|other { RULES } priority=N not on a block audit { ... } deny { ... } owner { ... } audit deny { ... } alone or together { capability setuid, } no qualifier: just grouping owner { } empty: allowed inside: rules of any class, "if" blocks, more qualifier blocks rules inside still end with their commas
Syntax diagram of a qualifier block: the optional qualifiers audit, allow or deny or prompt, and owner or other, then an opening brace, rules that may repeat, and a closing brace. A priority box in front is crossed out. Below, examples of blocks with one qualifier, two qualifiers, none, and an empty block.

[audit] [allow|deny|prompt] [owner|other] { RULES }. No priority. Blocks may be empty, bare and nested.

The grammar is the row of qualifier seats you already know, then braces. One seat is missing: priority can't go on a block. Audit, an access type, and owner or other can stand in front, alone or together, in the usual order. A block with no qualifier at all is legal too, and simply groups rules. So is an empty one. Inside the braces you can write whatever a profile body allows: rules of any class, conditional blocks, and more qualifier blocks. The rules inside still end with their commas.

Details and sources

Details

  • Grammar: [audit] [allow|deny|prompt] [owner|other] '{' RULES '}'. The qualifiers keep the order they have in front of a rule; priority=N is refused on a block with "priority is not allowed on rule blocks" (block.h:46-51).
  • The manual's grammar line is BLOCK = '{' ( RULES )* '}' (apparmor.d.pod:196).
  • A block holds whatever the profile body holds: rules of any class, nested qualifier blocks, if blocks, and by the grammar also hats and child profiles (parser_yacc.y:738-759).
  • Accepted in one profile by the parser built from AppArmor 836052d21 (-Q -K --skip-kernel-load --warn=all): deny { audit /a r, }, audit { deny /b r, }, allow { /c r, }, { /d r, }, owner { } and audit deny { /proc/sys/** w, /sys/** w, }.
  • Test fixtures in the tree: ok_block1.sd (deny, audit and bare blocks), ok_1.sd (owner { ... } and an empty owner { }), entry_mods_audit_ok1.sd (audit { ... }).
  • allow { R } around a rule with no access type is the same as R. The difference between a plain rule and an allow rule shows only in a deny block: the plain rule becomes a deny, the allow rule is an error (see the conflicts scene of this deck).

Read more

03 The qualifier travels to each rule

PUSH DOWN audit { /etc/demo/tls/key.pem r, capability net_bind_service, signal (send) set=(term), } audit /etc/demo/tls/key.pem r, audit capability net_bind_service, audit signal (send) set=(term), the compiled policy has rules, not blocks a rule class that refuses a qualifier refuses it from a block too owner { capability chown, } owner prefix not allowed on capability rules an owner block holds only file rules
An audit block holding a file rule, a capability rule and a signal rule. Each rule leaves the block as a separate rule with audit in front. The compiled policy has rules and no blocks. Below, an owner block with a capability rule and the parser's error.

A block's qualifiers are applied to each contained rule when the block is parsed. Compiled policy contains no blocks.

So what does the parser do with a block? When it reaches the closing brace, it takes the block's qualifiers and hands a copy to each rule inside, whatever the rule's class. Here a file rule, a capability rule and a signal rule all become audited. After that the block is gone: the compiled policy holds rules, not blocks. That has one consequence worth remembering. A qualifier that a rule class refuses on its own is refused through a block as well. So an owner block may contain only file rules, and a capability inside one is an error.

Details and sources

Details

  • When the parser reaches the closing brace it applies the block's qualifiers to the contents, then attaches the contents to the enclosing block or profile (parser_yacc.y:754-757).
  • The qualifiers reach every rule class: file rules, the rule classes with their own keyword, capabilities and rlimits (block_rules.cc:612-640).
  • The slide's audit { } block with a file rule, a capability rule and a signal rule is accepted by the parser built from AppArmor 836052d21 (-Q -K --skip-kernel-load --warn=all).
  • Blocks do not exist in compiled policy. Nothing in the binary profile records that a rule came from a block (from the code: each rule is compiled with its own qualifiers).
  • A rule class that refuses a qualifier refuses it through a block as well. Run with the same parser: owner { capability chown, } gives "owner prefix not allowed on capability rules" (block_rules.h:69, fixture bad_7.sd); deny { set rlimit cpu <= 10, } gives "prefix not allowed on rlimit rules".
  • Run with the same parser (audit { ^hat { /a r, } } compiles to the same binary as ^hat { audit /a r, }, and likewise for a child profile): a hat or child profile defined inside a qualifier block receives the block's qualifiers on its own rules (block.cc:259-268).

for AppArmor developers for security researchers

Internals

  • rules: rules opt_prefix block calls subblock->add_prefix($2, error) and then current->add_subblock(subblock, error). block::add_prefix (block.cc:273-284) visits the block, nested blocks, every conditional branch and hats through for_each_recursive (block.cc:228-271). The next developer scene follows this path.

Read more

04 Block qualifier meets rule qualifier

COMBINING block rule inside result deny { /sys/** w, deny /sys/** w, quiet deny { audit /sys/** w, audit deny /sys/** w, refused and logged audit { deny /sys/** w, audit deny /sys/** w, the same audit { owner /var/lib/demo/** rw, audit owner /var/lib/demo/** rw, from the parser's tests: choose rule by rule deny { capability chown, audit capability kill, } chown: denied quietly kill: denied and logged
A table with the columns block, rule inside and result. A deny block around a plain rule gives a quiet deny. A deny block around an audit rule and an audit block around a deny rule both give audit deny. An audit block around an owner rule gives audit owner. Below, a deny block with two capabilities, one of them audited.

Qualifiers from the block and from the rule combine. deny { audit R } and audit { deny R } both mean audit deny R.

Rules inside a block can bring qualifiers of their own, and the two sets are merged. The pair to understand is audit and deny. A deny block around a plain rule gives a quiet deny. A deny block around an audit rule gives audit deny: a refusal that is logged. An audit block around a deny rule gives the same. Different seats simply add up, so an audit block around an owner rule is audit owner. In a deny block, then, you choose rule by rule which refusals you want to hear about. One of the parser's own tests does that with two capabilities.

Details and sources

Details

BlockRule insideResult
anyno qualifier in that seatthe block's qualifier
denyplaindeny (quiet)
denyauditaudit deny
auditdenyaudit deny
auditowner (file rule)audit owner
allowplain or allowallow
denyallow, prompterror: "conflicting mode prefix"
allow, promptdenyerror: "conflicting mode prefix"
  • Rows 2 and 3 of the slide (deny { audit /sys/** w, }, audit { deny /sys/** w, }) are accepted by the parser built from AppArmor 836052d21 (-Q -K --skip-kernel-load --warn=all). That both compile like audit deny follows from the combination code above and is what the manual states (apparmor.d.pod:2679-2684); the three forms compile to the same binary with the parser built from this commit.
  • A plain deny is quiet: the refusal leaves no log record. audit deny is a refusal that is logged. See syn-allow-deny and syn-audit.
  • Capabilities are kept as four groups (allowed, allowed and audited, denied quietly, denied and audited) and regrouped when a block's qualifiers arrive. A deny block turns all of them into denials and keeps "audited" for those that had it (block_rules.h:76-110). The fixture on the slide is ok_block1.sd.
  • Known discrepancy, not intended behaviour: a deny { } block around a rule that is already audit deny, and deny { deny { audit R } }, lose the audit for rules other than capabilities, so the denial is quiet. The manual says the result is an audited denial. Confirmed with the parser built from this commit, for file, signal and ptrace rules, by comparing binary output and rule dumps; the code is rule.h:428-438, parser_misc.c:1132-1142. Write audit deny on the rule, in an audit block or in no block, and do not rely on this.

for security researchers

Attack surface

  • A deny { } block silently removes an audit trail. deny { audit deny R } and deny { deny { audit R } } compile to a quiet deny for file, signal and ptrace rules: the access is still refused, but the record the author asked for is never written (run with the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel; rule.h:428-438, parser_misc.c:1132-1140). Capability rules keep the audit.
  • A block changes the meaning of text far below it. Wrapping an included file or a long group of rules in deny { }, audit { } or owner { } changes every rule inside, including rules in if branches, hats and child profiles defined in the block (same run).
  • prompt { capability X, } grants the capability: see prompt.
  • owner { change_profile -> x, } is accepted and compiles like the rule without the block, although the direct form is an error.

Read more

05 Blocks inside blocks

NESTING audit { deny { network inet stream, } } deny, then audit deny { audit { network inet stream, } } audit, then deny audit deny network inet stream, one outer qualifier, different inner ones audit { deny { /etc/demo/** w, } owner { /var/lib/demo/** rw, } } = audit deny /etc/demo/** w, audit owner /var/lib/demo/** rw,
Two nested blocks side by side: audit around deny around a network rule, and deny around audit around the same rule. Both lead to one rule, audit deny network inet stream. Below, an audit block that holds a deny block and an owner block, and the two rules it stands for.

Nested blocks apply inner qualifiers first, then outer ones. audit { deny { R } } equals deny { audit { R } } equals audit deny R.

Blocks nest. Put a rule in a deny block, and that inside an audit block, and the rule gets both qualifiers. The inner block is finished first, so the rule receives deny, then audit. Turn the nesting around and it receives audit, then deny. The result is the same either way: audit deny. That's the example the manual uses. Nesting earns its keep when one outer qualifier covers different inner ones: an audit block that holds a deny block for some paths and an owner block for others.

Details and sources

Details

  • Blocks nest to any depth. An inner block is complete before the block around it, so a rule receives the innermost qualifiers first and the outermost last (parser_yacc.y:743-759).
  • The manual states that the order of nesting does not matter and gives the network example of the slide: audit { deny { network inet stream, } } and deny { audit { network inet stream, } } "both resolve to" audit deny network inet stream, (apparmor.d.pod:2600-2624).
  • The line audit { deny { /etc/demo/** w, } owner { /var/lib/demo/** rw, } } is accepted exactly as written by the parser built from AppArmor 836052d21 (-Q -K --skip-kernel-load --warn=all). The two rules under it are what the combination code gives, and the two forms compile to the same binary.
  • Known discrepancy, not intended behaviour: order independence does not hold for deny { deny { audit R } }, which ends as a quiet deny for rules other than capabilities (see the details of the combining scene and the reference below).
  • Nested blocks must still agree: deny { allow { R } } names two access types for R and is refused like deny { allow R } (both forms run with the same parser: conflicting mode prefix).

Read more

06 block::add_prefix for AppArmor developers for security researchers

PARSER: BLOCKS rules: rules opt_prefix block block: TOK_OPEN rules TOK_CLOSE parser_yacc.y:738-759 subblock->add_prefix($2, error) current->add_subblock(subblock, error) block (prefix: audit) block_rules block (deny) if / else hat block::add_prefix block.cc:273 eval_cond=false apply_to_hats=true file, change_profile entries -> entry_add_prefix rule objects -> prefix_rule_t::add_prefix capabilities -> four sets recomputed rlimits -> "prefix not allowed on rlimit rules" prefix_rule_t::add_prefix rule.h:385-440 priority != 0 -> "priority levels not supported" rule_mode differs -> "conflicting mode prefix" owner differs -> "conflicting owner prefix" audit differs -> "conflicting audit prefix" block::valid_prefix block.h:46-51 p.priority != 0 -> "priority is not allowed on rule blocks"
The grammar productions for a block and the action that calls add_prefix on the sub block. A tree: a block with the prefix audit, whose children are its rule set, a nested block, a conditional and a hat. block::add_prefix visits all of them. Four handlers apply the prefix per kind of content, and the conflict checks of prefix_rule_t::add_prefix are listed with their error strings.

block::add_prefix (parser/block.cc:273-284) pushes the prefix through nested blocks, conditionals and hats; conflicts are detected in prefix_rule_t::add_prefix (parser/rule.h:385-440) and generic_add_prefix (parser/parser_misc.c:1111-1142).

The block class derives from prefix_rule_t, so a block can itself receive a prefix from an outer block. The grammar action calls add_prefix on the sub block, then attaches it to the enclosing one. The block's add_prefix walks its own rule set, nested blocks, every branch of each conditional without evaluating it, and hats. Each kind of content takes it differently: file entries through entry_add_prefix, rule objects through their own add_prefix, capabilities by recomputing four sets, and rlimits by refusing. The conflict checks sit in the per rule add_prefix. The first rejects any rule that already has a priority. A priority on the block itself is refused by the block's valid_prefix.

Details and sources

for AppArmor developers for security researchers

Details

  • Grammar: block: TOK_OPEN rules TOK_CLOSE and rules: rules opt_prefix block; the action calls subblock->add_prefix($2, error) and then current->add_subblock(subblock, error) (parser_yacc.y:738-759).
  • class block: public prefix_rule_t with subblocks, conds, rules (a block_rules) and hats; block::valid_prefix returns "priority is not allowed on rule blocks" when p.priority != 0 (block.h:34-52).
  • bool block::add_prefix(const prefixes &p, const char *&error) first runs prefix_rule_t::add_prefix on the block itself, then for_each_recursive(..., false, true): eval_cond=false visits every cond_block of every conditional set, apply_to_hats=true descends into each hat's main_block (block.cc:228-284).
  • bool block_rules::add_prefix(const prefixes &p, const char *&error) sets uses_prompt_rules for a prompt prefix, calls entry_add_prefix on each cod_entry (file and change_profile entries), add_prefix on each rule object, net.apply_compat_prefix(p) for the legacy network table, then caps.add_prefix and rlimits.add_prefix (block_rules.cc:612-640).
  • prefix_rule_t::add_prefix (rule.h:385-440): valid_prefix, then priority != 0 gives "priority levels not supported" (the test looks at the rule's own priority, not at the prefix), then the audit, mode and owner conflict tests, then the audit and deny combination.
  • generic_add_prefix and entry_add_prefix (parser_misc.c:1111-1159): mode conflict, if (p.priority != 0) entry->priority = p.priority;, audit conflict, the audit and deny combination, then the owner or other mask and check_x_qualifier. There is no owner conflict test and no change_profile test here. That is why owner { other /foo r, } and owner { change_profile -> x, } are accepted by the parser built from this commit; both are known discrepancies, see the reference below.
  • Capabilities: the four sets allow, audit, deny, quiet are decomposed into four exclusive groups and rebuilt for the prefix (block_rules.h:62-110). Rlimits: any prefix on a block that sets an rlimit gives "prefix not allowed on rlimit rules" (parser.h:170-180).
  • add_subblock merges capabilities, rlimits, the legacy network table and the uses-prompt flag into the enclosing block, because those are encoded once per profile (block.cc:155-175, block_rules.cc:181-200). Each block later emits its own rules in block::gen_policy_re (block.cc:86-110).

for AppArmor developers for security researchers

Read more

07 Blocks the parser refuses

CONFLICTS deny { allow /etc/demo/** r, } conflicting mode prefix priority=1 { /etc/demo/** r, } priority is not allowed on rule blocks audit { priority=1 signal, } priority levels not supported a file rule with a priority is accepted in a block owner { capability chown, } owner prefix not allowed on capability rules deny { set rlimit cpu <= 10, } prefix not allowed on rlimit rules owner { /var/lib/demo/** rw, } # the profile's own brace the closing brace is missing syntax error, unexpected end of file, expecting TOK_ID or TOK_MODE or TOK_SET_VAR the profile's last brace closed your block, so the error comes at the end of the file
Six rejected blocks with the parser's message: deny around an allow rule, a priority on a block, a signal rule with a priority inside an audit block, a capability in an owner block, an rlimit rule in a deny block, and a block without its closing brace.

"conflicting mode prefix": the block and a rule name different access types. "priority is not allowed on rule blocks". Non-file rules with priority= are rejected inside blocks ("priority levels not supported").

A block and a rule inside it must not contradict each other. Deny around an explicit allow is a conflicting mode prefix. A rule with no access type is fine there: it just becomes a deny. Priority has no place on a block. And at this version a signal rule, or any rule that isn't a file rule, can't carry its own priority inside a block either, while a file rule can. Owner blocks accept only file rules. Rlimit rules take no qualifier at all. And if you forget the closing brace, the profile's last brace is taken for it, and the error arrives at the end of the file.

Details and sources

Details

All six rows were run with the parser built from AppArmor 836052d21 (-Q -K --skip-kernel-load --warn=all), each as the only content of a profile.

InputMessage
deny { allow /etc/demo/** r, }conflicting mode prefix
priority=1 { /etc/demo/** r, }priority is not allowed on rule blocks
audit { priority=1 signal, }priority levels not supported
owner { capability chown, }owner prefix not allowed on capability rules
deny { set rlimit cpu <= 10, }prefix not allowed on rlimit rules
owner { /var/lib/demo/** rw, and no closing bracesyntax error, unexpected end of file, expecting TOK_ID or TOK_MODE or TOK_SET_VAR
  • A rule with no access type inside a deny block is not a conflict; it becomes a deny. Only an explicit allow or prompt contradicts deny.
  • Sources of the messages: rule.h:409-416 and parser_misc.c:1113-1120 (mode), block.h:46-51 (priority on a block), rule.h:391-394 (priority inside a block), block_rules.h:69 (owner on capabilities), parser.h:170-180 (rlimits).
  • Fixtures: bad_8.sd (missing brace), bad_7.sd, bad_rlimit_block_deny.sd.
  • Also run with the same parser: a bare { priority=1 signal, } fails like row 3; audit { priority=5 /etc/demo/override.conf r, } and owner { priority=1 /a r, } are accepted, and the tree tests the second (equality.sh:665-669).
  • Known discrepancy: the different treatment of file rules and all other rule classes for priority= inside a block. The slide states what the parser does at this commit; whether the restriction or the exception is intended is open. A comment above the test reads like an unfinished feature (rule.h:385-394).
  • "conflicting owner prefix" and "conflicting audit prefix" exist in the parser (rule.h:397-426), but no input tried produces them: owner { other /foo r, } and audit { audit /a r, } are accepted. The first is a known discrepancy (the rule ends with no file permission); see the reference below.
  • apparmor_parser 5.0.2 accepts deny { allow R }; the parser built from this commit refuses it.

Read more

08 Where to go from here

ROADS QUALIFIERS { RULES } say the qualifier once · it combines with rule qualifiers · no priority syn-allow-deny deny { ... } syn-owner owner { ... } syn-audit audit { ... } syn-priority the one a block can't take syn-boolean-conditionals if ... { }: braces that choose rules syn-comments commas and braces the code that walks a block, and the whole language fe-grammar fe-rule-classes syntax-map
A chip reading QUALIFIERS, brace, RULES, brace in the centre. Roads lead to syn-allow-deny, syn-audit, syn-owner and syn-priority, then to syn-boolean-conditionals and syn-comments, and to fe-grammar, fe-rule-classes and syntax-map.

Next: syn-allow-deny, syn-audit, syn-owner (the qualifiers a block can carry), syn-boolean-conditionals (the other brace block).

A qualifier block changes nothing that a few more keystrokes couldn't. Use it where it makes a profile easier to read: a deny block for the things a program must not touch, an owner block for per-user files, an audit block around what you want a trail of. Each of those qualifiers has its own deck, and so does priority, the one a block can't take. Don't confuse these braces with the ones after if: a conditional block decides whether its rules exist at all. And if you want to see the code that walks a block, the parser decks are one road further.

Details and sources

Details

  • A qualifier block is notation: the block and its expanded rules compile to the same policy, which the tree's equality tests check for several block forms (equality.sh:1445-1447).
  • Qualifiers a block can carry: audit, one of allow, deny or prompt, and one of owner or other. Not priority (block.h:46-51).
  • The braces after if belong to a conditional block, which decides at compile time whether the rules inside are part of the profile. A conditional takes no qualifiers of its own, but it may stand inside a qualifier block and then its rules receive the block's qualifiers (from the code, block.cc:228-284).

Read more

Basis of the statements on this page: "tree" means the parser built from AppArmor 836052d21 (6.0.0~alpha2) was run on the fragment (-Q -K --skip-kernel-load --warn=all), with nothing loaded into a kernel; "5.0.2" means apparmor_parser 5.0.2 was run the same way; "code" means the statement comes from reading the parser source at that commit and was not run. Blocks exist only in the profile text: compiled policy contains rules, so there is no kernel behaviour specific to blocks.

Grammar

BLOCK = [audit] [allow|deny|prompt] [owner|other] '{' ( RULE | BLOCK | CONDITIONAL | HAT | PROFILE )* '}'
  • No comma after }. deny { /sys/** w, }, gives "syntax error, unexpected TOK_END_OF_RULE, expecting TOK_ID or TOK_MODE or TOK_SET_VAR" (tree).
  • An empty block (owner { }) and a bare block ({ capability setuid, }) are valid (tree).
  • priority=N is not allowed in front of a block (tree).
  • Rules inside keep their own syntax, including the trailing comma.
  • The manual's grammar line is BLOCK = '{' ( RULES )* '}' (apparmor.d.pod:196); the parser's productions are at parser_yacc.y:738-759.

How qualifiers combine

BlockRule insideResultBasis
none (bare)anythe rule's own qualifierstree
auditplainaudittree
denyplaindeny, quiettree
denyauditaudit denyaccepted: tree; result: code
auditdenyaudit denyaccepted: tree; result: code
allowplainallowtree
allowdenyerror: conflicting mode prefixcode
denyallowerror: conflicting mode prefixtree
promptdenyerror: conflicting mode prefixcode
ownerfile ruleownertree
ownerrule of another classerror: owner prefix not allowed on X rulestree for capability; code for the others
audit { deny { R } }, deny { audit { R } }audit deny Raccepted: tree; result: code and the manual

Nested blocks apply inner qualifiers first, then outer ones. For audit and deny the manual states that the order does not matter (apparmor.d.pod:2600-2624); the exception is listed under known discrepancies.

What a block may contain per qualifier

  • owner and other blocks: file rules, the bare file, rule and link rules only. Any other rule class is an error (code; capability: tree).
  • Any block with a qualifier: no rlimit rules ("prefix not allowed on rlimit rules", tree). A bare block may hold them (tree).
  • Capabilities in a deny block all become denied; those written with audit stay audited (code: block_rules.h:76-110; accepted by the tree's fixture ok_block1.sd).
  • A prompt block treats capabilities as allowed: prompt { capability chown, } compiles to the same binary as capability chown, (tree).
  • Rules with their own priority=: file rules only (tree); see known discrepancies.

Errors and warnings

The full form of an error is AppArmor parser error for FILE in profile FILE at line N: MESSAGE.

MessageExample that triggers itBasis
conflicting mode prefixdeny { allow /etc/demo/** r, }tree
priority is not allowed on rule blockspriority=1 { /etc/demo/** r, }tree
priority levels not supportedaudit { priority=1 signal, }, { priority=1 signal, }tree
owner prefix not allowed on capability rulesowner { capability chown, }tree
owner prefix not allowed on X rules (unix, mqueue, ptrace, network, dbus, all, signal, io_uring, mount, userns)an owner or other block around such a rulecode
prefix not allowed on rlimit rulesdeny { set rlimit cpu <= 10, }tree
conflicting audit prefix, conflicting owner prefixpresent in the parser; not produced by audit { audit /a r, } or owner { other /foo r, }, which are acceptedtree
syntax error, unexpected end of file, expecting TOK_ID or TOK_MODE or TOK_SET_VARowner { /var/lib/demo/** rw, without }tree
syntax error, unexpected TOK_END_OF_RULE, expecting TOK_ID or TOK_MODE or TOK_SET_VARdeny { /sys/** w, },tree

No warning is specific to blocks.

Known discrepancies

These are not intended behaviour and should not be relied on. The map's sec-bugs deck collects such findings.

  • deny { audit deny R } and deny { deny { audit R } } lose the audit for rules other than capabilities: the result is a quiet deny. The manual says a deny applied to a rule that carries audit is an audited denial (apparmor.d.pod:2679-2684). Basis: tree, for file, signal and ptrace rules; the code is rule.h:428-438, parser_misc.c:1132-1142.
  • owner { other R } is accepted and R ends with no file permission, with no message (tree; parser_misc.c:1147-1159 has no conflict test). See syn-other.
  • owner { change_profile -> x, } is accepted although owner change_profile -> x, is rejected with "owner conditional not allowed on change_profile rules" (tree). The compiled rule is identical to the one without the block (tree).
  • A rule of a class other than file with priority= is rejected in any block, even a bare one, while a file rule with priority= is accepted (tree; rule.h:385-394 against parser_misc.c:1121-1122). The restriction may be deliberate; the difference between rule classes is the discrepancy. See syn-priority.
  • apparmor_parser 5.0.2 accepts deny { allow R }; the tree refuses it with "conflicting mode prefix".

Hats, child profiles and conditionals inside a block

  • Hats and child profiles defined inside a qualifier block receive its qualifiers on their rules (block.cc:259-268, block.cc:273-284); audit { ^hat { /a r, } } compiles to the same binary as ^hat { audit /a r, }, and the same holds for a child profile (tree).
  • Rules inside an if or else branch that stands in a qualifier block receive the qualifiers whichever branch is later chosen (block.cc:240-257); the rule taken from audit { if $FOO { /a r, } else { /b r, } } is dumped with the audit mask (tree).

for AppArmor developers for security researchers

Code map

StepWhere
productions block and rules: rules opt_prefix blockparser_yacc.y:738-759
class block: public prefix_rule_t, block::valid_prefixblock.h:34-52
block::for_each_recursive(func, eval_cond, apply_to_hats)block.cc:228-271
block::add_prefix (eval_cond=false, apply_to_hats=true)block.cc:273-284
block_rules::add_prefixblock_rules.cc:612-640
prefix_rule_t::add_prefix: priority test, conflict tests, audit and deny combinationrule.h:385-440
generic_add_prefix, entry_add_prefix for cod_entry (file and change_profile entries)parser_misc.c:1111-1159
capability sets recomputed for a prefixblock_rules.h:62-110
rlimits refuse any prefixparser.h:170-180
add_subblock: per-profile data (capabilities, rlimits, legacy network table, uses-prompt flag) merged upwardblock.cc:155-175, block_rules.cc:181-200
block::gen_policy_re: each block emits its rulesblock.cc:86-110

Roads from here

START HERE

PREAMBLE AND REUSE

QUALIFIERS

PROFILE STRUCTURE

INSIDE THE PARSER