The all rule
allow everything for application developers for administrators for security researchers
all stands for a bare rule of every rule class plus access to every file with inherit execution and every capability. It is expanded by the parser and the kernel sees ordinary rules. It leaves out change_profile and rlimits. A profile with all is still a confined profile and differs from the unconfined flag.
On the map: rule classes
▶ Watch this deck — 9 scenes, ~5 min
Worth seeing first
- allow and deny — why subtracting with deny from a broad allow works
01 A profile that starts from everything
all, allows everything the rule classes can express. Add deny rules to subtract.
Most profiles are lists of what's allowed. Sometimes you want the opposite: allow everything, and take a few things away. That's what all is for. In demo's profile, the worker child profile is just that one line. With all in place the worker can do whatever it could do unconfined, almost. Then you add deny rules for what it must not do. And it remains a real profile: it has a name, it shows up in the process list, and its deny rules are enforced.
Details and sources
Details
allhas no kernel object: the parser replaces it with ordinary rules before compiling, and the kernel sees those.- apparmor.d(5) describes it as "a generic rule for all supported rule types", for a deny-list style of policy or to add a qualifier to everything (apparmor.d.pod:2259-2280).
profile worker { all, }is line 36 of demo's profile. The profile on the slide, with the two deny rules, compiles with no warning (run with the tree's parser). The programdemoand its profiles are invented for the map.- An example in the tree: ok_01.sd.
Read more
for AppArmor developers for security researchers
In the code
- The expansion: all_rule.cc:33-148. The rule itself compiles to nothing (all_rule.h:77).
02 One word and two seats
[audit] [allow|deny|prompt] all,. No priority=, no owner, nothing after the word.
The grammar is a single word. In front of it you may put audit, and allow, deny or prompt. Priority and owner are refused, each with its own message. And nothing can come after the word: all isn't a permission you can attach to a path. It's a rule on its own.
Details and sources
Details
all,,allow all,,audit all,,audit deny all,andprompt all,are accepted (run with the tree's parser). Whatpromptdoes in the kernel is in prompt.priority=1 all,givespriority prefix not allowed on all rules;owner all,givesowner prefix not allowed on all rules;all /srv/** r,givessyntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE(run with the tree's parser).- The word is a keyword only when it is followed by a blank or a character that cannot be part of a word, so
allowand names beginning withallare unaffected. capability all,givessyntax error, unexpected TOK_ALL, expecting TOK_ID or TOK_END_OF_RULE; see capability rules.- Inside a qualifier block the block's qualifiers apply:
audit { all, }isaudit all,anddeny { all, }isdeny all,;owner { all, }is refused with the owner message. Inside a trueifblock it works as outside (run with the tree's parser). The expansion is always added to the profile's main block. - Examples in the tree: ok_05.sd, bad_02.sd.
for AppArmor developers for security researchers
In the code
- The production: parser_yacc.y:1629-1635. The scanner rule for the word: parser_lex.l:811-813. The refused seats: all_rule.h:46-56. The main block: all_rule.cc:40.
03 One line becomes a rule of every class
all, = a bare rule of every class + /{**,} with all file permissions + /{**,} ix + all capabilities, each with the qualifiers of the all rule.
All never reaches the kernel. The parser swaps it for a set of ordinary rules. A bare rule of each class: unix, dbus, signal, ptrace, mqueue, userns, io_uring, network, and the four mount rules. Then two file rules covering every path: one with all the file permissions, and one that allows executing anything with ix, so programs it starts stay in this profile. And finally every capability. Whatever you put in front of all, audit or deny, is copied onto each of them.
Details and sources
Details
- The panel shows profile lines that are equivalent to the expansion; the parser creates the rules internally and does not write such lines anywhere.
- The file rule covers every path with every file permission except exec. The exec rule covers every path with
ix(inherit): a program the task starts runs under the same profile. - Each implied rule carries the qualifiers of the
allrule:audit all,audits every one of them,deny all,denies them, with one exception: its file entry covers only files the task owns. - Known discrepancy, on the bug list as "
deny all,denies only the owner half of the file permissions": for a file the task does not own,deny all,denies nothing and an allow rule elsewhere in the profile still applies. See Known bugs. - The classes the feature set lacks are dropped from the expansion one by one, silently by default; the "not enforced" warnings appear with
--warn=rule-not-enforced, as for hand-written rules. - Capabilities do not appear in a dump of the compiled rules: they are masks, see capability rules.
Read more
- apparmor.d(5), all rule.
- The class decks: file rules, exec modes, capability, network, unix, D-Bus, signal, ptrace, message queues, user namespaces, io_uring, mount.
for AppArmor developers for security researchers
In the code
all_rule::add_implied_rules(all_rule.cc:33-148), called from parser_policy.c:131, before variable expansion. By source line: unix 38-40, dbus 42-44, io_uring 46-48, mqueue 50-52, ptrace 54-56, signal 58-60, userns 62-64, mount, remount, umount and pivot_root 66-80, network 82-85, the file entry 89-110, the exec entry 111-141, capabilities 142-145.- The file permissions are
AA_BASE_PERMS & ~(AA_EXEC_TYPE | AA_MAY_EXEC)(all_rule.cc:97); compiled,all,gives/([^\x00]*|)with 0x1f807e at priority 0 and the exec entry 0x804201 at priority -1 (run with the tree's parser).
04 What all does not include
Not included: change_profile, set rlimit, exec transitions other than ix, hats and child profiles.
All is a little less than its name. Four things aren't in it. First, change_profile: a task under all can't ask to move to another profile. Exec transitions: everything is executed with ix, so a program that has a profile of its own doesn't get it. It runs under this one. Rlimits: all sets none. And hats and child profiles, which you have to declare. Any of these can be added next to all as an ordinary rule.
Details and sources
Details
- The first, second and fourth result on the slide are derived from the expansion, which has no such entry, and from the decks of those rules; they were not run on a kernel.
- The third attempt shows no result on purpose: without a
set rlimitrule AppArmor sets no limit, and whether the call succeeds is the kernel's ordinary rule; see rlimit rules. all,next tochange_profile -> other,compiles (run with the tree's parser).- With
deny all,the exec entry has noix. - A more specific exec rule written next to
all,, for example/usr/bin/sudo Px,, is an ordinary rule at priority 0 against the implied exec entry at priority -1, so it wins. That is whyallrefuses apriority=of its own.
Read more
for AppArmor developers for security researchers
In the code
- The exec entry and its priority: all_rule.cc:111-141,
priority - 1at all_rule.cc:124, noixunder deny at all_rule.cc:129-130. The comment// TODO: rlimit: all_rule.cc:147.
05 all is not unconfined
all, gives a confined profile with broad rules. flags=(unconfined) is a mode tested before any rule.
It's tempting to think of all as a way to write unconfined. It isn't. Under all, the kernel still evaluates the profile's rules on every operation. That's why a deny next to it works. A program the task executes stays in the profile. And other profiles see a confined peer with a name they can match. The unconfined flag is a mode: the kernel checks the mode first and never looks at rules. If you want everything, minus these, all is the tool.
Details and sources
Details
- The kernel tests whether a profile is in unconfined mode at the top of its per-profile checks, before any rule is read (ipc.c:87, task.c:384). A profile with
all,is not in that mode, so its rules are evaluated. - apparmor.d(5) on
default_allow: "similar and for many profiles will be equivalent to specifying an allow all, rule", without the same options (apparmor.d.pod:742-745). - The flags
unconfinedanddefault_alloware taught in profile modes; this slide states only what distinguishes them from the rule. - Kernel statements are read from the kernel source and were not run.
for security researchers
Attack surface
all,is broader than most hand-written profiles (every capability, every mount, every file) and narrower than unconfined in two ways only: exec stays in the profile, andchange_profileis absent.- A profile that is
all,plus a short deny list confines exactly as much as that list. Anything the list forgot, and anything a rule class cannot express (see what is not mediated), is allowed.
Read more
for AppArmor developers for security researchers
In the code
- The parser adds no class markers to
unconfinedanddefault_allowprofiles, except the one for user namespaces (parser_regex.c:1392-1397).
06 Everything except
all, plus deny rules is a deny-list profile. audit all, logs everything and refuses nothing.
Here's the pattern the manual shows: all, then the exceptions as deny rules. Reading most files is allowed by all. Reading the shadow file hits the deny, and deny beats allow. The same goes for a capability, or a whole class like mount. Remember that a plain deny is quiet, so add audit if you want to see the attempts. The manual's second use is audit all: nothing is refused and every access is logged.
Details and sources
Details
- The profile on the slide compiles with no warning, and so does
audit all,(run with the tree's parser). The results "allowed" and "denied" are derived from the rule that a deny wins over an allow of the same priority (see allow and deny); they were not run on a kernel. - The implied rules of
all,sit at priority 0, the exec entry at -1. Adenyat the default priority therefore wins, and an allow rule with a higher priority than a deny would win over that deny; see priority.allitself cannot be given a priority. - apparmor.d(5) shows the deny-list pattern (apparmor.d.pod:2268-2271). It writes its audit example as
audit access all,; the form the grammar accepts isaudit all,. The manual's deny-list example itself does not compile:deny file,is refused withInvalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u'(run with the tree's parser). Write the denies per path or per class, as on the slide.
Read more
07 What deny all, compiles to for files for AppArmor developers for security researchers
deny all, gives /{**,} deny 0x6e: the owner half only (all_rule.cc:97-101). all, gives both halves. Checked with the tree's parser and on a kernel.
One more for reviewers. A file rule has two halves: what the task may do to files it owns, and to files it doesn't. All fills both. An ordinary deny on a path fills both. But the file entry that deny all generates fills only the owner half. So for files the task doesn't own, deny all denies nothing, and an allow rule elsewhere in the profile still applies. Everything else in deny all is complete. If you rely on deny all to close a profile, check the file half with a dump.
Details and sources
for AppArmor developers for security researchers
Details
- Run with the tree's parser (
-D rule-exprs):all,gives/([^\x00]*|)with 0x1f807e;deny all,gives/([^\x00]*|)deny 0x6e and the exec entry deny 0x4001;/etc/hostname r,withdeny all,compiles, with the rule for/etc/hostnamebeside the deny.deny /** rwlk,gives 0xb802e anddeny owner /** rw,gives 0xe. - The code:
if (rule_mode != rule_mode_t::DENY) { perms |= perms << AA_OTHER_SHIFT; }with the commentduplicate to other permission set(all_rule.cc:97-101). The exec entry is duplicated to the other half in both modes (all_rule.cc:131-132). - Known discrepancy, on the bug list as "
deny all,denies only the owner half of the file permissions". Confirmed on a kernel: under/** r, deny all,a file owned by root is read and a file the task owns is refused (see Known bugs).
for AppArmor developers for security researchers
Attack surface
- The file part of
deny all,equalsdeny owner /{**,}with the non-exec permissions. - Consequences as compiled: an allow rule for a file the task does not own is not overridden; accesses to such files without an allow rule are refused by the default and logged, not quieted.
- Whether this is intended is not stated in the code or in apparmor.d(5).
08 A rule that only adds other rules for AppArmor developers for security researchers
all_rule::add_implied_rules (all_rule.cc:33-148), called from parser_policy.c:131; all_rule.h:77 compiles to nothing.
The class all_rule is a rule_t that produces no output of its own. Its work happens in add_implied_rules, which runs first in post processing, before variables are expanded. It creates one object of each class with no conditionals and copies its prefixes onto them, adds two file entries, and calls add_capabilities with every bit set. The exec entry gets the rule's priority minus one, so any exec rule you write yourself wins. Later, in the merge, the mount, umount and pivot_root objects compare equal and become one rule with all three permission bits.
Details and sources
for AppArmor developers for security researchers
Details
all_rule::add_implied_rules: all_rule.cc:33-148, called from parser_policy.c:131. The refused seats: all_rule.h:46-56.gen_policy_rereturns without output (all_rule.h:77).- The merge of the mount-class objects: the comparison leaves the permission out and the permissions are ORed (rule.h:540-554, mount.cc:688-714).
- The dump of
all,from the tree's parser (-D rule-exprs), summarised: the file entry 0x1f807e at priority 0, the link pair 0x40030, the exec entry 0x804201 at priority -1,\x160x18,\x150x8, the ptrace rule(\x10|)\x09[^\000]+0x1e, the signal rule(\x10\xa|\x0a.)[^\000]+0x6, three dbus rules, mqueue rules for classes 17 and 18, the mount-class rules with 0x7 and the remount rule with 0x2. prompt all,marks each implied rule as prompt (run with the tree's parser).- Known discrepancy, on the bug list as "Leftovers in all_rule.h": leftovers in the header: copies of the io_uring permission macros and a
move_conditionalsthat is declared and not defined (all_rule.h:33-40).
for security researchers
Attack surface
- The merged 0x7 puts the umount and pivot_root bits on the strings of the mount rule. The kernel reads each permission at a different state, and no cross-grant was found by reading. Not run on a kernel.
for AppArmor developers for security researchers
Read more
09 Around all
all, expands to rules. Deny subtracts; flags are something else.
All is shorthand for a lot of rules. The deny deck explains why subtracting works. The profile modes deck has the flags people mix it up with. And change_profile and rlimit are the two rules you'll most often write next to it.
Details and sources
Details
[audit] [allow|deny|prompt] all,is replaced by the parser with a bare rule of every class, two file rules for every path and every capability.- Not included:
change_profile,set rlimit, exec transitions other thanix, hats and child profiles. - Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2) and the kernel tree named on the page. The kernel behaviour was read from the source, not observed on a running kernel.
Read more
Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the line (-Q -K --skip-kernel-load --warn=all, -D rule-exprs for compiled forms), with nothing loaded into a kernel; "code" means the parser source or the kernel source was read, not run. Nothing here was observed on a running kernel.
Grammar
ALL RULE: [audit] [allow|deny|prompt] all ,
- Nothing may follow the word (tree).
allis a keyword only when followed by a blank or a character that cannot be part of a word;allowis unaffected (code).
| Seat | On an all rule |
|---|---|
priority= | refused: priority prefix not allowed on all rules (tree) |
audit | taken: copied onto every implied rule |
allow, deny, prompt | taken: copied onto every implied rule; prompt is in syn-prompt |
owner, other | refused: owner prefix not allowed on all rules (tree) |
The expansion
| Implied rule, as a profile line | Deck | Under deny all, |
|---|---|---|
unix, | syn-unix | denied |
dbus, | syn-dbus | denied |
io_uring, | syn-io-uring | denied |
mqueue, | syn-mqueue | denied |
ptrace, | syn-ptrace | denied |
signal, | syn-signal | denied |
userns, | syn-userns | denied |
mount, remount, umount, pivot_root, | syn-mount | denied |
network, | syn-network | denied |
/{**,} with every file permission except exec | syn-file-rules | the owner half only (known discrepancy) |
/{**,} ix, at the rule's priority minus one | syn-exec-modes | exec denied, without ix |
capability, (every capability) | syn-capability | denied |
The classes the feature set lacks are dropped from the expansion, silently by default (code). Read from the parser source and confirmed with a dump of all, and of deny all, (tree).
Not in the expansion
| Missing | Effect | Deck |
|---|---|---|
change_profile | a task under all, cannot ask to change profile | syn-change-profile |
set rlimit | no limit is set | syn-rlimit |
exec transitions other than ix | every program runs under the same profile | syn-exec-modes |
| hats and child profiles | they must be declared | syn-hats, syn-child-profiles |
all, unconfined, default_allow
all, | flags=(unconfined) | flags=(default_allow) | |
|---|---|---|---|
| What it is | a rule, expanded by the parser | a profile mode | a profile mode |
| Rules evaluated by the kernel | yes, on every operation | no: the mode is tested first | see syn-flags-modes |
| Deny rules beside it | enforced | nothing to subtract from | see syn-flags-modes |
| Exec | stays in the profile (ix) | as for an unconfined task | see syn-flags-modes |
| apparmor.d(5) | "a generic rule for all supported rule types" | "similar and for many profiles will be equivalent to specifying an allow all, rule" |
Errors and warnings
| Rule | Message |
|---|---|
priority=1 all, | priority prefix not allowed on all rules |
owner all, | owner prefix not allowed on all rules |
all /srv/** r, | syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE |
capability all, | syntax error, unexpected TOK_ALL, expecting TOK_ID or TOK_END_OF_RULE |
All rows are from the tree's parser.
for AppArmor developers for security researchers
In the parser
all_ruleis aprefix_rule_twhosegen_policy_rereturns without output (parser/all_rule.h:77).add_implied_rules(parser/all_rule.cc:33-148) runs first in post-processing (parser/parser_policy.c:131), before variable expansion. It adds one object of each rule class with no conditionals and the prefixes of theallrule, two file entries, and callsadd_capabilitieswith every bit set.- Priorities: the implied rules have the priority of the
allrule, which is always 0; the exec entry has that priority minus one (parser/all_rule.cc:124). - The mount, umount and pivot_root objects are merged into one
mnt_rulewith the permissions 0x7; the remount rule stays apart with 0x2 (tree). - The dump of
all,(tree): the file entry/([^\x00]*|)0x1f807e, the link pair 0x40030, the exec entry 0x804201 at priority -1,\x160x18,\x150x8, and the rules of the other classes.
for AppArmor developers for security researchers
Known discrepancies
None of these is taught as intended behaviour. All are on the bug list as confirmed; see Known bugs.
- The file entry of
deny all,carries the owner half of the permissions only:deny all,compiles to/([^\x00]*|)deny 0x6e, whereall,has 0x1f807e; reproduce with-D rule-exprs(tree). Confirmed on a kernel. - Leftovers in
parser/all_rule.h: copies of the io_uring permission macros and a declared, undefinedmove_conditionals(code).
Inside a qualifier block the block's qualifiers apply: audit { all, } is audit all, and deny { all, } is deny all,; owner { all, } is refused with the owner message. Inside a true if block it works as outside (run with the tree's parser).
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- Exec modes — ix which is how all executes everything
PROFILE HEAD
- Profile mode flags — the unconfined and default_allow flags
QUALIFIERS
- allow and deny — deny rules that subtract from all
- The audit qualifier — audit all logs every allowed operation
- The owner qualifier — the owner and other halves of a file rule
- Rule priority — why all refuses a priority
RULE CLASSES
- change_profile rules — the permission all does not include
- rlimit rules — limits which all does not set
- Capability rules — every capability is included
PROFILE STRUCTURE
- Child profiles — the worker profile of the example
SECURITY · threat model and limits
- AppArmor's threat model (no slides yet) — what a profile with all still confines