allow and deny
which rule wins for application developers
allow is the default access type of a rule. deny removes permissions that other rules of the same or lower priority grant and by default leaves no log record. The decision is made per permission.
On the map: qualifiers
▶ Watch this deck — 8 scenes, ~6 min
Worth seeing first
- File rules — the allow rules you have been writing so far
- File access modes — the letters a deny takes away one at a time
Part of journeys
- New to AppArmor, step 8 of 10 · previous: File access modes · next: How the kernel checks an access
- File access in depth, step 10 of 12 · previous: The other qualifier · next: Rule priority
- How a rule becomes a permission, step 6 of 12 · previous: The owner qualifier · next: The audit qualifier
01 Everything in the directory, except one file
deny removes permissions that other rules grant. Rule order in the file has no effect.
Demo reads its configuration from one directory, and a single rule covers all of it. Then someone drops a secret key into that directory. Now what? You could rewrite the pattern so it no longer matches the key, and that gets ugly fast. It's easier to say it directly: allow the directory, deny the key. A deny rule doesn't grant anything. It takes away what other rules grant, so the key is cut off while the other files stay readable. And it doesn't matter which of the two lines comes first in the file.
Details and sources
Details
- Syntax: the word
denyin front of a rule, as indeny /etc/demo/secret.key r,. - A deny rule grants nothing. It removes the permissions it names from what allow rules of the same or lower priority grant for the names it matches.
- The order of the rules in the file has no effect: all rules of a profile are compiled together and the decision is made per name and per permission.
- The manual page: deny "specifies that permissions requests that match the rule should be denied without logging" (apparmor.d.pod:2561-2565).
- The same shape in the parser's tests:
/usr/bin/** r,withdeny /usr/bin/foo r,(ok_deny_3.sd). - What the program sees: the
open(2)of the key fails with EACCES. In the kernel a file request is refused when it asks for a permission that is not in the allow set of the matched name (file.c:246-247). - The program
demo, its files and its profile are invented for the map. Nothing on this slide was observed on a running kernel; the kernel behaviour is stated from the kernel source.
Read more
- apparmor.d(5), deny and Rule Qualifiers.
- AppArmor wiki: rule prefixes and modes.
- Globbing: the pattern in the first rule.
for AppArmor developers for security researchers
In the code
- Compiled with the tree's parser and
-D dfa-states-initial, the state for the key is(0x 0/10004//0/0/10004)in the format(allow/deny//prompt/audit/quiet): nothing allowed, read denied and quiet for both the owner and the other half. - In the grammar
denyis one of the alternatives ofopt_rule_mode(parser_yacc.y:700-703).
02 Four seats in front of a rule
[priority=N] [audit] [allow|deny|prompt] [owner|other] RULE,. No access type means allow.
Every rule can start with up to four qualifiers, and they have fixed seats. Priority comes first, then audit, then the access type, then owner or other. This deck is about the third seat. It holds one word: allow, deny or prompt. Here are three rules that use the seats in order. Because the seats are fixed, audit deny is right and deny audit is a syntax error. And one seat holds one word, so you can't write deny allow. Leave the seat empty and the rule is an allow rule. The same four seats stand in front of every kind of rule, with a few exceptions.
Details and sources
Details
- Order of the qualifiers:
[priority=N] [audit] [allow|deny|prompt] [owner|other] RULE,. The order is fixed. - The third seat holds at most one word. With nothing written the rule is an allow rule.
- The qualifiers come before the optional word
fileand before the keyword of any other rule class:deny file /a w,,deny capability chown,. - Run with the parser built from the AppArmor tree at 836052d21 (
-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel):deny audit /etc/demo/** w,is rejected:syntax error, unexpected TOK_AUDIT, expecting TOK_ID or TOK_MODE or TOK_SET_VAR;deny allow /foo r,is rejected:syntax error, unexpected TOK_ALLOW, expecting TOK_ID or TOK_MODE or TOK_SET_VAR. - The full form of the message is
AppArmor parser error for FILE in profile FILE at line N: MESSAGE. - "With a few exceptions":
set rlimitrules take no qualifier at all, also not through a block; the message isprefix not allowed on rlimit rules(parser.h:171-178, bad_rlimit_block_deny.sd). This is from the parser source and its test file. - The grammar line of the manual page,
ACCESS TYPE = ( 'allow' | 'deny' ), omitsprompt(apparmor.d.pod:198); the parser accepts three words.
Read more
- apparmor.d(5), Rule Qualifiers.
- priority, audit, prompt, owner, other: the other seats and the third word.
- Qualifier blocks.
for AppArmor developers for security researchers
In the code
- The order comes from the
opt_prefixproduction,opt_priority opt_audit_flag opt_rule_mode opt_owner_flag(parser_yacc.y:705-711); the third seat isopt_rule_mode: empty,TOK_ALLOW,TOK_DENYorTOK_PROMPT(parser_yacc.y:700-703). - The keyword table:
deny,allow,prompt(parser_misc.c:100-102). - The parsed value is the field
prefixes.rule_mode(rule.h:244).
03 allow is what you already write
allow RULE, equals RULE,. Permissions of allow rules matching the same name are combined.
You've been writing allow rules all along. Putting the word allow in front changes nothing about what the rule grants. Allow rules that match the same file simply add up: read from one, write from another, lock from a third, and demo's state file ends up with all three. Anything no rule mentions is refused, so there's no need to deny it. Why does the keyword exist, then? Partly for symmetry. And inside a qualifier block the explicit word counts as a statement: it conflicts with a deny around it, where a rule with nothing in front just takes the block's deny.
Details and sources
Details
allow RULE,grants exactly whatRULE,grants. The manual page: "This is the default value for rules and does not need to be specified" (apparmor.d.pod:2550-2554).- Allow rules of the same priority that match the same name add up their permissions. Compiled with the parser built from the AppArmor tree at 836052d21 (
-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel),/var/lib/demo/state rw,together withallow /var/lib/demo/state k,gives one name with read, write, append and lock. - Anything no rule mentions is refused. In the kernel a file request is denied when it asks for a bit outside the allow set (file.c:246-247); for the other rule classes the test is
request & (~perms->allow | perms->deny)(lib.c:430). Read from the source, not run. - The explicit word matters in one place, a qualifier block.
deny { allow /etc/demo/** r, }is rejected withconflicting mode prefix;deny { /etc/demo/** r, }is accepted and the rule becomes a deny rule. - A block that replaces the default access type, from the parser's tests:
deny { capability chown, audit capability kill, }(ok_block1.sd).
Read more
- apparmor.d(5), allow.
- Qualifier blocks: where the explicit word conflicts.
- Access modes: the letters that add up.
for AppArmor developers for security researchers
In the code
- A rule with
allowand a rule with no access type both become aMatchFlagnode, or anExactMatchFlagfor a pattern without globs (aare_rules.h:85-92). - Accumulation per permission bit:
perms.allow |= match->perms & amask; perms.audit |= match->audit & amask;(hfa.cc:1638-1639). - The conflict check: an explicit rule mode that differs from the block's is
conflicting mode prefix; an unspecified one takes the block's (rule.h:409-416 for rule classes, parser_misc.c:1111-1118 for file rules). - The state for the example,
-D dfa-states-initial:(0x b802e/0//0/0/0).
04 deny wins, one permission at a time
At equal priority a deny overrides an allow for the permissions the deny names; other permissions of the allow remain. The refusal is what the file check of the kernel does with a missing allow bit.
How exactly does a deny win? Not rule against rule, but permission by permission. Demo may read and write its state, and a second rule denies write under archive. For a file in the archive both rules match. The first grants read and write. The deny names write, so write is gone. It doesn't name read, so read stays. Open that file for reading and it works; open it for writing and you get EACCES. The result is a read-only archive. That's the normal case, where both rules have the same priority. Give the allow rule a higher priority and it wins instead; that's the priority deck.
Details and sources
Details
- The decision is made for one permission of one name at a time, not rule against rule.
- At equal priority a deny overrides an allow for the permissions the deny names. With
/a rw,anddeny /a w,, read stays allowed; write and append are refused.wincludes append, so a deniedwalso removesa. - A higher priority on the allow rule reverses it: with
priority=1 /a rw,anddeny /a w,, read and write are allowed. Withpriority=1on both, the deny wins again. - A lower priority on the deny makes it a default that more specific rules override: with
/a* rw,andpriority=-1 deny /** w,, names matching/a*keep read and write. - The manual page on priority: rules with a higher priority "completely override permissions of lower priority rules where they overlap" (apparmor.d.pod:2539-2548).
- The refusal: in the kernel the file check computes the permissions of the name and returns EACCES when the request has a bit that is not allowed (file.c:233-251). Read from the source, not run.
- The check is made when the file is opened, for the access mode of that open. Opening an archive file read-only succeeds; opening it for writing fails.
Read more
- apparmor.d(5), deny and priority.
- priority: the scores.
- Access modes.
for AppArmor developers for security researchers
In the code
pri_update_permscores each matching node per bit:priority << 2, plus 3 for a deny node, 2 for an exact match on an exec bit, 1 for an allow node, 0 for prompt (hfa.cc:1529-1554). The highest score keeps the bit.- A winning deny node:
perms.deny |= match->perms & amask; perms.quiet |= match->audit & amask;and the bit is cleared from allow, audit and prompt (hfa.cc:1585-1594). - State dumps (
-D dfa-states-initial,rfor both halves is0x10004,wwith append0x2800a):/a rw,withdeny /a w,gives(0x 10004/2800a//0/0/2800a);priority=1 /a rw,withdeny /a w,gives(0x 3800e/0//0/0/0).
05 A deny leaves no trace
deny refuses without a log record. Reading the kernel code of the kernel, this holds in complain mode as well; it was not tested on a running kernel. audit deny logs the refusal.
There are two ways for an access to be refused: no rule allows it, or a rule denies it. To the program they feel the same: permission denied. To you they don't. A refusal for lack of a rule is logged. A refusal by a deny rule is not. Deny means: I know about this, don't tell me. That's handy for silencing noise, and confusing when you forget the rule is there. One more consequence, read from the code of the kernel: in complain mode, where missing rules are only logged, a plain deny still refuses, silently. To get a log record, write audit in front.
Details and sources
Details
- Kernel side, read from the kernel source and not observed on a running kernel.
- No rule allows the request: in enforce mode EACCES and a record with
apparmor="DENIED"; in complain mode the request is allowed and the record saysapparmor="ALLOWED"(audit.c:200-236). - A
denyrule: EACCES and no record, in enforce and in complain mode. The denied permissions are marked quiet; the kernel removes quiet bits from the request before logging and returns the error when nothing is left (file.c:142-149 for files, lib.c:440-447 for the other rule classes, capability.c:87-92 for capabilities). - A request that mixes a quieted permission with one that is merely not granted is judged on what remains after the quiet bits are removed; in complain mode the whole request is then permitted. Derived by reading.
audit denydoes not mark the permissions quiet, so the refusal is logged.- The kernel's audit mode overrides the quieting for every profile:
echo -n noquiet > /sys/module/apparmor/parameters/audit, orapparmor.audit=noquieton the kernel command line (apparmor.pod:222-235). The modes arenormal,quiet_denied,quiet.allowed,quiet,noquietandall(audit.c:20-27);noquietandallignore the quiet marks (file.c:143-146). - The manual page describes explicit denials in complain mode in other terms (apparmor.d.pod:609-616): it speaks of denial information carried by the kernel. By the code read here, what keeps a plain
denyin force in complain mode is the quiet mark.
for security researchers
Attack surface
- A plain
denyhides probing. The refused request returns EACCES and leaves no record, so a confined program that probes a denied path is not visible in the log (file.c:143-149; read from the kernel source, not observed on a running kernel). Shipped profiles use plaindenyto silence noise; the absence of DENIED records is not evidence that nothing was attempted.audit deny, or the kernel audit modenoquiet, brings the records back. - In complain mode a plain
denystill refuses, silently, because the quiet bits are removed from the request before the complain decision; anaudit denyin complain mode is permitted and logged as ALLOWED (derived from the same code, not run; see audit). - The compiled policy carries no deny set: with and without
-O filter-denythedenyfield written for the kernel is 0, and a denial is a bit missing from allow plus a bit in quiet (run with the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel,-D compressed-dfa; hfa.h:132-138). The kernel's test ofperms->denyfor the other rule classes (lib.c:430) therefore has nothing to match in policy built by this parser. - A deny wins only at equal or higher priority. An included file with
priority=on an allow rule overrides a deny written without one: priority.
Read more
- apparmor(7), Debugging: "Turn off deny audit quieting".
- apparmor.d(5), deny and audit.
- audit:
audit deny. - Reading a denial, profile mode flags.
for AppArmor developers for security researchers
In the code
- A plain
denygetsaudit_t::IMPLIED,audit denygetsUNSPECIFIED(rule.h:426-440);IMPLIEDcompares equal toFORCE(rule.h:207-211), so the emitters pass the permissions as the fourth argument, which on a deny node is the quiet mask. - Complain mode in the file path:
complain |= ~(perms->allow | perms->deny)(file.c:117-118);aa_auditturns anAUDIT_APPARMOR_ALLOWEDrecord into success withcomplain_error, but a fully quieted request has already returned. - The module parameter
audit(lsm.c:1974-1976).
06 Deny never reaches the kernel as deny for AppArmor developers for security researchers
Scores: priority*4 + 3 deny, +1 allow (parser/libapparmor_re/hfa.cc:1536-1554). apply_and_clear_deny and map_perms_to_accept leave allow and quiet; the packed deny field is 0.
A deny rule becomes a DenyMatchFlag node carrying its permissions and a quiet mask. When a state is built, each bit keeps the highest-scoring node: priority times four, plus three for deny, one for allow. Deny takes the write bit: it clears allow, audit and prompt there and sets deny and quiet. Then apply_and_clear_deny, the filter-deny optimization, zeroes the deny word so states differing only there can merge. map_perms_to_accept emits allow, audit or quiet, and prompt. The kernel has a deny field and would honour it, but this parser always writes zero. What survives is a missing allow bit and a quiet bit.
Details and sources
for AppArmor developers for security researchers
Details
- A deny rule becomes a
DenyMatchFlag(priority, perms, quiet)node (expr-tree.h:1191-1197), created by the node cache next toPromptMatchFlag,ExactMatchFlagandMatchFlag(aare_rules.h:85-92). pri_update_perm(hfa.cc:1529-1554): scorepriority << 2,+3deny,+2exact match on an exec bit,+1allow,+0prompt. The comment notes that this is the last use of priority; it is not passed to the back end.- A winning deny bit sets
perms.denyandperms.quietand clears allow, audit and prompt (hfa.cc:1585-1594). DFA::apply_and_clear_deny(hfa.cc:685-693) calls the per-state function:allow &= ~deny; prompt &= ~deny; deny = 0;, with audit and quiet left as computed (hfa.h:106-130).- It runs when the target has no extended permissions or
-O filter-denyis set (aare_rules.cc:273-278). The option is on by default:{ 1, "filter-deny", "filter out deny information from final dfa", CONTROL_DFA_FILTER_DENY }(common_optarg.c:104-105), default flags at parser_common.c:123-129. map_perms_to_acceptemitsaccept1 = allow,accept2 = PACK_AUDIT_CTL(audit, quiet),accept3 = prompt(hfa.h:132-138);compute_perms_table_entbuilds the permission table entries from those three words (hfa.cc:1406-1421, builders at policy_compat.cc:160-244). None of them setsdeny.- The packed entry has a
denyfield, written bysd_serialize_perm(parser_interface.c:346-350); with this parser its value is 0. - The kernel has the field and would honour it:
u32 deny; /* explicit deny, or conflict if allow also set */(perms.h:69-71),denied = request & (~perms->allow | perms->deny)(lib.c:430), and complain mode excludes it (lib.c:369-370). - Dumps, parser built from the AppArmor tree at 836052d21:
-D dfa-states-initialfor/a rw,withdeny /a w,prints(0x 10004/2800a//0/0/2800a);-D dfa-states-post-filterprints(0x 10004/0//0/0/2800a). The header line of the dump reads(allow/deny/prompt/audit/quiet). - Capabilities are bit sets, not pattern rules: allowed is
caps.allow & ~caps.deny, quiet iscaps.deny & caps.quiet(parser_interface.c:549-558).
Read more
- Permissions in the DFA.
- priority: the scores from the profile writer's side.
- apparmor_parser(8), -O and -D.
07 Deny rules the parser refuses, and one surprise
audit deny, not deny audit. In deny rules write a bare x. A higher-priority allow overrides a deny.
The mistakes here are mostly about seats. Audit goes before deny, not after. A deny rule for exec takes a plain x, because a denied exec has no profile to choose. An explicit allow inside a deny block contradicts the block, and the parser refuses it. Then the surprise: deny doesn't always win. A rule with a higher priority beats it, so this allow with priority ten makes the override file readable in spite of the deny. And when a program fails with no log record at all, suspect a deny rule somewhere in the profile, or in a file it includes.
Details and sources
Details
- Messages are from the parser built from the AppArmor tree at 836052d21 (
-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel). The full form isAppArmor parser error for FILE in profile FILE at line N: MESSAGE. deny audit /etc/demo/** w,:syntax error, unexpected TOK_AUDIT, expecting TOK_ID or TOK_MODE or TOK_SET_VAR. Writeaudit deny.deny /usr/bin/demo-helper Px,:Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u'. Writedeny /usr/bin/demo-helper x,.deny { allow /etc/demo/** r, }:conflicting mode prefix.priority=10 allow /etc/demo/override.conf r,withdeny /etc/demo/** r,:override.confis readable, the other names are refused and quiet.- Finding a silent deny:
echo -n noquiet > /sys/module/apparmor/parameters/auditmakes the kernel log refusals that deny rules keep quiet (apparmor.pod:222-235). Deny rules also arrive throughincludelines, for example from abstractions. - A deny rule on files does not carry the link and change_profile permissions;
priority=has no effect on capability rules, so adeny capabilityrule cannot be overridden that way.
Read more
for AppArmor developers for security researchers
In the code
- The seat order is the
opt_prefixproduction (parser_yacc.y:705-711), which is whydeny auditfails in the grammar. check_x_qualifierholds the exec message (parser_misc.c:1090-1102).conflicting mode prefix: rule.h:409-416 and parser_misc.c:1111-1118.- The state for
override.conf,-D dfa-states-initial:(0x 10004/0//0/0/0); the priority 10 allow scores 41 against 3 for the deny (hfa.cc:1536-1554). - File deny rules mask out
AA_LINK_BITSandAA_CHANGE_PROFILE(parser_regex.c:674-683).
08 Where to go from here
Next: syn-audit (log a denial), syn-priority (override a deny), syn-qualifier-blocks (deny a group of rules).
Allow adds. Deny removes, and keeps quiet about it. The other seats refine that. Priority decides between an allow and a deny when you don't want the deny to win. Audit in front of deny brings the log record back. Prompt is the third word that fits in this seat. Owner and other limit a rule to some files. And a qualifier block puts one deny in front of a whole group of rules. From there, the denials deck shows how to read what does get logged.
Details and sources
Details
allowis the default access type; allow rules that match the same name add up.denyremoves the permissions it names from allow rules of the same or lower priority, and the refusal is not logged.audit denylogs the refusal; a higherpriority=on an allow rule overrides a deny.- In the kernel, read from the source, a plain
denyalso refuses silently in complain mode. - Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2), the kernel-rc2 (97d73c825).
Read more
Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the fragment (-Q -K --skip-kernel-load --warn=all), with nothing loaded into a kernel; "code" means the parser or kernel source was read, not run. Nothing here was observed on a running kernel. Kernel statements are for mainline Linux 7.4.
Grammar
QUALIFIERS: [priority=N] [audit] [allow|deny|prompt] [owner|other] RULE LINE: [QUALIFIERS] RULE ,
- The order is fixed. Any other order is a syntax error (tree).
- The access type seat holds at most one of
allow,deny,prompt. With nothing written the rule is an allow rule (code). - The qualifiers come before the optional word
fileand before the keyword of any other rule class:deny file /a w,,deny capability chown,. audit denyis the only way to combine the two words;deny auditis rejected (tree).
Keywords
| Keyword | Meaning |
|---|---|
allow | The default access type, spelled out. allow RULE, grants what RULE, grants. The explicit word conflicts with a surrounding deny { } or prompt { } block; a rule with no access type takes the block's. |
deny | Removes the named permissions from what allow rules of the same or lower priority grant. Grants nothing. Without audit it also marks the permissions quiet, so the refusal is not logged. audit deny logs it: syn-audit. |
prompt | The third access type: syn-prompt. |
Allow rules of the same priority that match the same name add up their permissions (code).
Which rule wins
The decision is made for one permission of one name at a time, not rule against rule. The order of the rules in the file has no effect. Scoring: syn-priority.
| Rules | Result | Basis |
|---|---|---|
/a rw, and deny /a w, | read allowed; write and append refused and quiet | tree |
/etc/demo/** r, and deny /etc/demo/secret.key r, | the key is refused and quiet; other names readable | tree |
priority=1 /a rw, and deny /a w, | read and write allowed; nothing quiet | tree |
priority=10 allow /etc/demo/override.conf r, and deny /etc/demo/** r, | override.conf readable; other names refused and quiet | tree |
priority=1 /a rw, and priority=1 deny /a w, | as the first row: at equal priority the deny wins | tree |
/a* rw, and priority=-1 deny /** w, | names matching /a* keep read and write; elsewhere write is refused and quiet | tree |
What a refusal looks like
Kernel side, from the source of mainline Linux 7.4 (code); none of it was run.
| Cause | Enforce mode | Complain mode |
|---|---|---|
| no rule allows the request | EACCES and a DENIED record | allowed, with an ALLOWED record |
deny rule | EACCES, no record | EACCES, no record |
audit deny rule | see syn-audit | see syn-audit |
- The complain-mode row for
denyfollows from the quiet bit: the kernel removes quieted bits from the request before logging, and returns the error when nothing is left (linux:security/apparmor/file.c:143-149 for files, lib.c:440-447 for other classes, capability.c:87-92 for capabilities). - A request that mixes a quieted bit with a bit that is merely not granted is judged on the remaining bits after the quiet bits are removed; in complain mode the whole request is then permitted. Derived by reading; not run.
- The audit modes
noquietandallignore the quiet masks, so quieted denials are logged (/sys/module/apparmor/parameters/audit; linux:security/apparmor/file.c:144-145). Reading the records: adm-denials.
Other rule classes
denyis accepted on every rule class except rlimit rules, which take no qualifier (code).- Capabilities and the legacy network table are bitmasks, not pattern rules: allowed is
allow & ~deny, quiet isdeny & quiet(code).priority=has no effect on capability rules. - A deny rule on files does not carry the link and change_profile bits (code).
- In a deny rule an exec permission is a bare
x; there is no transition to choose (tree).
Compiler option
| Option | Default | Effect |
|---|---|---|
-O filter-deny | on | removes the denied bits from allow and prompt and clears the deny word of each state before minimization, so states that differ only in deny can merge |
-O no-filter-deny | keeps the deny word during minimization |
With either setting the deny field written to the kernel is 0 (tree: -D compressed-dfa prints every table entry with deny 0x0; code: parser/libapparmor_re/hfa.h:132-138). A deny rule reaches the kernel as a bit missing from allow and a bit set in quiet.
Errors and warnings
A parse error is printed as AppArmor parser error for FILE in profile FILE at line N: MESSAGE (tree).
| Message | Cause |
|---|---|
syntax error, unexpected TOK_AUDIT, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | deny audit /etc/demo/** w,: write audit deny (tree) |
syntax error, unexpected TOK_ALLOW, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | deny allow /foo r,: one access type per rule (tree) |
Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u' | deny /usr/bin/demo-helper Px,: write a bare x (tree) |
conflicting mode prefix | a rule's explicit access type against its block's, as in deny { allow /etc/demo/** r, } (tree) |
prefix not allowed on rlimit rules | an rlimit rule inside a deny { } block (tree; parser/tst/simple_tests/rlimits/bad_rlimit_block_deny.sd) |
Differences from the man page
Known discrepancies between apparmor.d(5) at the commit above and the code:
- The grammar line
ACCESS TYPE = ( 'allow' | 'deny' )(parser/apparmor.d.pod:198) omitsprompt; the parser accepts three words. - The complain-mode paragraph on explicit denials (parser/apparmor.d.pod:608-616) speaks of explicit denial information carried by the kernel and stripped by
-O filter-deny. By the code read here the parser does not emit that information with or without the option; what keeps a plaindenyin force in complain mode is the quiet mask.
for AppArmor developers for security researchers
Code map
| Step | Where |
|---|---|
grammar: opt_rule_mode is empty, TOK_ALLOW, TOK_DENY or TOK_PROMPT | parser/parser_yacc.y:700-703; seat order 705-711 |
| keywords | parser/parser_misc.c:100-101 |
field prefixes.rule_mode | parser/rule.h:244 |
prefix_rule_t::add_prefix (rule classes): conflict check, IMPLIED for deny, UNSPECIFIED for audit deny | parser/rule.h:409-440 |
generic_add_prefix (file and change_profile entries) | parser/parser_misc.c:1111-1142 |
audit_t::IMPLIED compares equal to FORCE | parser/rule.h:207-211 |
MatchFlag, ExactMatchFlag, DenyMatchFlag | parser/libapparmor_re/aare_rules.h:85-92, expr-tree.h:1191-1197 |
pri_update_perm: score priority*4 + 3 deny, 2 exact exec, 1 allow, 0 prompt | parser/libapparmor_re/hfa.cc:1529-1653 |
apply_and_clear_deny | parser/libapparmor_re/hfa.cc:685-693, hfa.h:106-127; called from aare_rules.cc:273-278 |
map_perms_to_accept | parser/libapparmor_re/hfa.h:132-138 |
permission table builders, which do not set deny | parser/libapparmor_re/policy_compat.cc:160-246 |
packed deny field | parser/parser_interface.c:350 |
aa_check_perms (Linux 7.4) | linux:security/apparmor/lib.c:430-447 |
aa_audit_file (Linux 7.4) | linux:security/apparmor/file.c:143-153 |
Dump format (-D dfa-states-initial): (allow/deny//prompt/audit/quiet) in hex. The doubled / is a known defect of the dump. Bits per half: x 0x1, w 0x2, r 0x4, a 0x8; the other half is shifted left by 14, so r for both halves is 0x10004, w (which implies a) is 0x2800a and rw is 0x3800e.
| Rules | State | Basis |
|---|---|---|
/a rw, deny /a w, | (0x 10004/2800a//0/0/2800a), after filter-deny (0x 10004/0//0/0/2800a) | tree |
/etc/demo/** r, deny /etc/demo/secret.key r,, state for the key | (0x 0/10004//0/0/10004) | tree |
priority=1 /a rw, deny /a w, | (0x 3800e/0//0/0/0) | tree |
priority=10 allow /etc/demo/override.conf r, deny /etc/demo/** r,, state for override.conf | (0x 10004/0//0/0/0) | tree |
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- File rules — the rules these examples qualify
PROFILE HEAD
- Profile mode flags — complain mode and explicit denials
QUALIFIERS
- The audit qualifier — making a denial show up in the log
- Rule priority — letting an allow win over a deny
- The prompt qualifier — the third access type
- Qualifier blocks — one deny for a group of rules
- The owner qualifier — the qualifier that follows the access type
RUNNING THE PARSER
- Reading a denial — reading the denials that are logged
THE DFA ENGINE · libapparmor_re
- Permissions in the DFA — how allow and deny are merged per state