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

01 A profile that starts from everything

THE ALL RULE profile worker { all, } worker demo//worker files network signals mounts capabilities deny network, deny capability sys_admin, all but sys_admin the profile is still loaded, named and enforced: this is not unconfined
The profile worker contains the single rule all. The worker process, under profile demo//worker, reaches files, network, signals, mounts and capabilities. Adding deny network cuts the network; adding deny capability sys_admin leaves all capabilities but sys_admin. The profile is still loaded, named and enforced: this is not unconfined.

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

  • all has 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 program demo and its profiles are invented for the map.
  • An example in the tree: ok_01.sd.

for AppArmor developers for security researchers

In the code

02 One word and two seats

GRAMMAR auditallow | deny | promptall, all, the worker profile of demo allow all, the same audit deny all, refuse everything and log it 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
The syntax diagram of the all rule: optional audit, optional allow, deny or prompt, the word all, a comma. all and allow all are the same. audit deny all refuses everything and logs it. priority=1 all and owner all are refused. A path after the word is a syntax error.

[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, and prompt all, are accepted (run with the tree's parser). What prompt does in the kernel is in prompt.
  • priority=1 all, gives priority prefix not allowed on all rules; owner all, gives owner prefix not allowed on all rules; all /srv/** r, gives syntax 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 allow and names beginning with all are unaffected.
  • capability all, gives syntax 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, } 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). 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

03 One line becomes a rule of every class

THE EXPANSION all, apparmor_parser unix, dbus, signal, ptrace, mqueue, userns, io_uring, network, mount, remount, umount, pivot_root, /{**,}every file: all permissions but exec /{**,} ix,execute anything, staying here capability,every capability audit all, puts audit on every one of these lines
apparmor_parser turns the line all into ordinary rules: unix, dbus, signal, ptrace, mqueue, userns, io_uring, network, mount, remount, umount and pivot_root, each as a bare rule; a file rule for every path with all file permissions but exec; a file rule that executes anything with ix, staying in this profile; and every capability. audit all puts audit on every one of these lines.

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 all rule: 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.

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 IN THE EXPANSION worker demo//worker all, aa_change_profile("other") = -1 EACCES no change_profile rule execve("/usr/bin/sudo") sudo demo//worker ix: no transition to sudo's own profile setrlimit(...) no limit is set by all; set rlimit is separate aa_change_hat("admin") refused hats and children must be declared all, change_profile -> other, add what is missing as ordinary rules
The worker runs under profile demo//worker, which has the rule all. Four attempts: aa_change_profile to another profile is refused with EACCES because there is no change_profile rule; execve of /usr/bin/sudo runs sudo under demo//worker because ix makes no transition to sudo's own profile; no limit is set by all, set rlimit is separate; aa_change_hat is refused because hats and children must be declared. What is missing can be added as ordinary rules next to all.

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 rlimit rule AppArmor sets no limit, and whether the call succeeds is the kernel's ordinary rule; see rlimit rules.
  • all, next to change_profile -> other, compiles (run with the tree's parser).
  • With deny all, the exec entry has no ix.
  • 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 why all refuses a priority= of its own.

for AppArmor developers for security researchers

In the code

05 all is not unconfined

TWO DIFFERENT THINGS profile worker { all, } profile worker flags=(unconfined) { } the rules are asked on every operation deny rules enforced exec stays in worker (ix) seen by others peer=demo//worker signal, ptrace and unix rules can name it no: the mode is tested first no rules to subtract from as for an unconfined task see Profile modes default_allow is a third thing: a flag that the manual calls similar to allow all,
Two columns. A profile with the rule all: the kernel asks the rules on every operation; deny rules are enforced; an exec stays in the worker profile through ix; other profiles' signal, ptrace and unix rules can name the peer demo//worker. A profile with flags=(unconfined): the mode is tested first and the rules are not asked; there are no rules to subtract from; exec is as for an unconfined task. default_allow is a third thing, a flag the manual calls similar to allow all.

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 unconfined and default_allow are 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, and change_profile is 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.

for AppArmor developers for security researchers

In the code

  • The parser adds no class markers to unconfined and default_allow profiles, except the one for user namespaces (parser_regex.c:1392-1397).

06 Everything except

ALL, MINUS profile worker { all, deny /etc/shadow r, deny capability sys_admin, deny mount, } worker open("/etc/hostname") allowed by all open("/etc/shadow") denied mount(...) denied quietly: add audit to log it audit all, the other use: log everything a program does, refuse nothing
The profile worker has all, deny /etc/shadow r, deny capability sys_admin and deny mount. Opening /etc/hostname is allowed by all. Opening /etc/shadow is denied, quietly unless audit is added. A mount call is denied. The other use is audit all: log everything a program does and refuse nothing.

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. A deny at the default priority therefore wins, and an allow rule with a higher priority than a deny would win over that deny; see priority. all itself 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 is audit all,. The manual's deny-list example itself does not compile: deny file, is refused with Invalid 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.

07 What deny all, compiles to for files for AppArmor developers for security researchers

DENY ALL all, owner other 0x1f807e deny /** rwlk, owner other deny 0xb802e a hand-written deny deny all, owner other deny 0x6e the owner half only /etc/hostname r,deny all, demo open("/etc/hostname") demo is uid 1000; the file is root's the deny does not cover this file; the allow rule decides (confirmed on a kernel) exec, capabilities and every other class of deny all, are denied in full a known discrepancy, confirmed on a kernel
Compiled file permissions as two halves, owner and other. all fills both halves, 0x1f807e. A hand-written deny /** rwlk fills both halves, deny 0xb802e. deny all fills the owner half only, deny 0x6e. In a profile with /etc/hostname r and deny all, demo with uid 1000 opens /etc/hostname, which root owns: the deny does not cover this file and the allow rule decides, and the read succeeds. Exec, capabilities and every other class of deny all are denied in full. A known discrepancy, confirmed on a kernel.

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, with deny all, compiles, with the rule for /etc/hostname beside the deny. deny /** rwlk, gives 0xb802e and deny owner /** rw, gives 0xe.
  • The code: if (rule_mode != rule_mode_t::DENY) { perms |= perms << AA_OTHER_SHIFT; } with the comment duplicate 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, equals deny 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).

for AppArmor developers for security researchers

Read more

08 A rule that only adds other rules for AppArmor developers for security researchers

IN THE PARSER parse add_implied_rules expand variables merge compile all_rule unix_rule dbus_rule io_uring_rule mqueue_rule ptrace_rule signal_rule userns_rule mnt_rule x4 network_rule cod_entry /{**,} cod_entry /{**,} ix add_capabilities(all bits) priority - 1 mount + umount + pivot_root mnt_rule perms 0x7 remount stays apart: 0x2 all_rule: gen_policy_re: nothing rules are always added to the main block, whatever block the all rule was in, with the block's qualifiers
The parser's stages: parse, add_implied_rules, expand variables, merge, compile. all_rule exists after parsing. In add_implied_rules it adds a unix_rule, dbus_rule, io_uring_rule, mqueue_rule, ptrace_rule, signal_rule, userns_rule, four mnt_rule objects and a network_rule, two file entries for every path, the second with ix at priority minus one, and all capabilities. In the merge the mount, umount and pivot_root objects become one mnt_rule with permissions 0x7 while remount stays apart with 0x2. At compile time all_rule itself generates nothing.

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_re returns 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, \x16 0x18, \x15 0x8, 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_conditionals that 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

ROADS all, shorthand for a lot of rules syn-allow-deny subtracting syn-flags-modes unconfined, default_allow syn-change-profile not in all syn-rlimit not in all syn-exec-modes ix syn-audit audit all,
The all rule in the centre with roads to syn-allow-deny, to syn-flags-modes, to syn-change-profile and syn-rlimit, and to syn-exec-modes and syn-audit.

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 than ix, 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).
  • all is a keyword only when followed by a blank or a character that cannot be part of a word; allow is unaffected (code).
SeatOn an all rule
priority=refused: priority prefix not allowed on all rules (tree)
audittaken: copied onto every implied rule
allow, deny, prompttaken: copied onto every implied rule; prompt is in syn-prompt
owner, otherrefused: owner prefix not allowed on all rules (tree)

The expansion

Implied rule, as a profile lineDeckUnder deny all,
unix,syn-unixdenied
dbus,syn-dbusdenied
io_uring,syn-io-uringdenied
mqueue,syn-mqueuedenied
ptrace,syn-ptracedenied
signal,syn-signaldenied
userns,syn-usernsdenied
mount, remount, umount, pivot_root,syn-mountdenied
network,syn-networkdenied
/{**,} with every file permission except execsyn-file-rulesthe owner half only (known discrepancy)
/{**,} ix, at the rule's priority minus onesyn-exec-modesexec denied, without ix
capability, (every capability)syn-capabilitydenied

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

MissingEffectDeck
change_profilea task under all, cannot ask to change profilesyn-change-profile
set rlimitno limit is setsyn-rlimit
exec transitions other than ixevery program runs under the same profilesyn-exec-modes
hats and child profilesthey must be declaredsyn-hats, syn-child-profiles

all, unconfined, default_allow

all,flags=(unconfined)flags=(default_allow)
What it isa rule, expanded by the parsera profile modea profile mode
Rules evaluated by the kernelyes, on every operationno: the mode is tested firstsee syn-flags-modes
Deny rules beside itenforcednothing to subtract fromsee syn-flags-modes
Execstays in the profile (ix)as for an unconfined tasksee 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

RuleMessage
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_rule is a prefix_rule_t whose gen_policy_re returns 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 the all rule, two file entries, and calls add_capabilities with every bit set.
  • Priorities: the implied rules have the priority of the all rule, 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_rule with 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, \x16 0x18, \x15 0x8, 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, where all, 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, undefined move_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

FILE ACCESS

  • Exec modes — ix which is how all executes everything

PROFILE HEAD

QUALIFIERS

RULE CLASSES

PROFILE STRUCTURE

SECURITY · threat model and limits