Exec modes

ix px cx ux and fallbacks for application developers for security researchers

An exec mode says which profile a program gets when the confined task executes it. ix keeps the current profile. px and cx switch to another profile or fail. ux removes confinement. pix cix pux and cux add a fallback.

On the map: file access

▶ Watch this deck — 9 scenes, ~6 min

Worth seeing first

Part of journeys

01 demo runs a program. Under which profile?

EXEC MODES profile demo demo execve() /usr/bin/demo-helper ? demo-helper profile demo profile demo-helper a child of demo unconfined /usr/bin/demo-helper Px , the letters before the x pick the profile
The program demo, confined by profile demo, executes /usr/bin/demo-helper; the new program's profile is a question mark with four candidates: profile demo, profile demo-helper, a child of demo, or unconfined. The rule /usr/bin/demo-helper Px, with Px highlighted, makes the choice.

An exec rule is a file rule whose mode ends in x. The letters before the x choose the profile of the new program.

Demo is about to start its helper program. For AppArmor that's two decisions, not one. First: is demo allowed to run that file at all? Second: what confinement does the new program get? It could stay in demo's profile. It could move to a profile of its own, or to a child profile tucked inside demo's. Or it could leave confinement altogether. You choose with the letters in front of the x in the rule. This deck walks through each choice, and what happens when the profile you asked for isn't there.

Details and sources

Details

Kernel facts are from the kernel source, read and not run.

  • The decision is made in the LSM hook bprm_creds_for_exec, implemented by apparmor_bprm_creds_for_exec (domain.c:985, registered at lsm.c:1862). It runs during execve, once per profile of the task's label.
  • First decision: the path of the executable is built (domain.c:684-685) and matched against the profile's file rules; the exec goes on only if the result has MAY_EXEC (domain.c:725-729). Without it the exec fails with EACCES.
  • Second decision: the exec mode stored with the matching rule selects the new confinement: the current profile (ix), a profile found by the executable's path (px), a child (cx), or unconfined (ux).
  • An unconfined task does not consult exec rules: the kernel only searches for a profile that attaches to the executable (domain.c:697-722).
  • The log operation is exec (audit.h:92); a record carries requested_mask="x" and, when a profile was chosen, target=. Example fixture: exec01.in:1.

02 The letters before the x

GRAMMAR x p | P c | C look where? i u | U otherwise? EXEC MODE = [p|P|c|C] [i|u|U] x both parts in front are optional ix px cx ux inherit profile child unconfined pix cix pux cux try p or c first, then fall back to i or u Px Cx Ux Pix Cix PUx CUx uppercase first letter: safe form x alone: only after deny
Syntax diagram of an exec mode: an optional p or c, an optional i or u, then x. Below it the four basic modes ix, px, cx and ux, the four fallback modes pix, cix, pux and cux, the uppercase safe forms, and a note that x alone is only written after deny.

EXEC MODE = [p|P|c|C] [i|u|U] x. Basic: ix px cx ux. With fallback: pix cix pux cux. An uppercase first letter is the safe form.

Read an exec mode as a small recipe. First, where to look for a profile: p for one of the system's profiles, c for a child of the current one, or nothing at all. Then what to do without a lookup, or when the lookup finds nothing: i to inherit the current profile, u to run unconfined. Then the x. So ix, px, cx and ux are the four basic modes, and pix, cix, pux and cux are the fallback modes. The first letter can be uppercase; that's about the environment, and it has its own deck. An x alone is only for deny rules.

Details and sources

Details

  • EXEC MODE = [ 'p' | 'P' | 'c' | 'C' ] [ 'i' | 'u' | 'U' ] 'x'. The scanner's pattern: (([Pp]|[Cc])[Xx])|(([Pp]|[Cc])?([IiUu])[Xx]) (parser_lex.l:257).
  • The complete set: ix, ux Ux, px Px, cx Cx, pix Pix, cix Cix, pux PUx, cux CUx.
  • The case of the first letter is significant (lowercase unsafe, uppercase safe): safe and unsafe. In the fallback modes the case of the second and third letters is not: pIx, PIx and Pux are accepted (parser tests and the released parser 5.0.2).
  • ix has no safe form. Ix is read as ix with the deprecation warning for uppercase letters (parser_misc.c:616-626). There is no uix: it is a syntax error (5.0.2).
  • An exec mode combines with the other letters of the mode: /usr/bin/sort rix,.
  • x alone is written only in deny rules: deny /usr/bin/demo-helper x, (parser_misc.c:1090-1104).
  • Parser tests for the letters are the files of parser/tst/simple_tests/xtrans/, for example simple_ok_pix_1.sd.

Read more

03 ix and ux: no lookup

ix ux /usr/bin/[a-z]* ix , profile demo demo execve("/usr/bin/sort") profile demo sort same profile, same rules /usr/bin/demo-helper ux , profile demo demo execve("/usr/bin/demo-helper") unconfined demo-helper no rules apply warning for lowercase ux, with --warn=dangerous Unconfined exec qualifier (ux) allows some dangerous environment variables to be passed to the unconfined process; 'man 5 apparmor.d' for details.
Two lanes. Top: with the rule /usr/bin/[a-z]* ix, demo executes /usr/bin/sort and sort runs inside profile demo. Bottom: with the rule /usr/bin/demo-helper ux, demo executes the helper and it runs unconfined, with no rules. Below, the parser's warning about the unconfined exec qualifier ux.

ix runs the program under the current profile and implies m. ux runs it unconfined; lowercase ux draws a warning with --warn=dangerous.

Two modes don't search for anything. ix means inherit: whatever demo runs through this rule keeps running as demo, under demo's rules. It's the right choice for small tools, like sort, and it brings the m permission along for that path. ux is the opposite. The new program runs unconfined, and no profile's rules apply to it. That's a door out of confinement, so use it rarely. The parser can warn you about lowercase ux, because it also lets environment variables such as LD_PRELOAD through. The uppercase form is in the safe and unsafe deck.

Details and sources

Details

Kernel facts are from the kernel source, read and not run.

  • ix and ux have no lookup step (domain.c:588-591). The fallback step then applies: inherit takes the newest version of the current profile's label with info="ix fallback"; unconfined takes the unconfined label of the namespace of the profile that holds the rule with info="ux fallback" (domain.c:617-637).
  • Inherit is tested before unconfined.
  • ix never requests secure execution: there is no safe form of ix. See safe and unsafe.
  • Lowercase ux prints a parser warning: Unconfined exec qualifier (ux) allows some dangerous environment variables to be passed to the unconfined process; 'man 5 apparmor.d' for details. (parser_misc.c:628-632).
  • The warning's class is dangerous (parser_main.c:289), off by default: apparmor_parser --warn=dangerous or --warn=all. Lowercase pux and cux do not print it.
  • With a stacked label only the member whose profile has the ux rule becomes unconfined: stacking.

for security researchers

Attack surface

  • ux and Ux remove confinement for the new program and everything it starts. pux, cux and their uppercase forms do the same whenever no profile attaches: the fallback is taken without an error, and the reason string ux fallback is passed to the audit call of the exec, which for an allowed exec writes a record only when the permission is audited (domain.c:616-638, domain.c:787-790; read from the kernel source, not observed on a running kernel).
  • The parser warns about lowercase ux only, and only with --warn=dangerous or --warn=all. Lowercase pux and cux, which also pass the environment to a possibly unconfined program, print nothing (run with the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel; parser_misc.c:628-632).
  • ix keeps the profile, so every program reachable through an ix rule runs with the caller's permissions. An ix rule on a shell or an interpreter gives every script the task can supply the whole profile.
  • Which rule decides an exec is not the textual order: a path with no *, ? or [^...] overrides patterns that match the same name, and priority= overrides both (aare_rules.cc:98-105). Braces and plain sets count as exact; see the reference below.
  • Attachment for px and cx is by the path of the executable at exec time; a target that is missing fails the exec in enforce mode but creates a learning profile in complain mode (domain.c:740-767).

for AppArmor developers for security researchers

In the code

  • ix implies m on the same path: add_implied_ix_mmap (hfa.cc:1497-1524).
  • After an ix result profile_transition jumps to the audit step and skips the AA_X_UNSAFE test (domain.c:730-739).

04 px: the program's own profile

px profile demo demo /usr/bin/demo-helper Px , execve("/usr/bin/demo-helper") profiles loaded demo /usr/bin/demo demo-helper /usr/bin/demo-helper sshd /usr/sbin/sshd matched by the path of the program, not by the rule's text profile demo-helper demo-helper the same exec, but demo-helper: not loaded exec refused: EACCES ... operation="exec" info="profile transition not found" ... name="/usr/bin/demo-helper" ... child profiles and hats are not candidates for px
demo, with the rule /usr/bin/demo-helper Px, executes the helper. The kernel searches the loaded profiles by the path of the program and finds profile demo-helper, which becomes the new program's profile. In a second case demo-helper is not loaded: the exec is refused with EACCES and the record says profile transition not found.

px switches to the profile that attaches to the executable's path and fails with "profile transition not found" when none does.

px means: give the new program its own profile. The kernel takes the path of the file being executed and runs the search it runs at any program start, over the profiles of the current namespace. The best match becomes the new confinement. Notice that the rule's pattern doesn't pick the profile; the program's path does. So one rule with a star can send ten programs to ten profiles. And if nothing attaches, the exec fails. That's the point of px: no profile, no run. The reason the kernel records is profile transition not found.

Details and sources

Details

Kernel facts are from the kernel source, read and not run.

  • px runs the attachment search find_attach over the top-level profiles of the namespace of the profile that holds the rule, with the path of the executable (domain.c:603-612; find_attach is domain.c:394-507).
  • The best path match wins, then the number of matched extended attributes: attachment. Child profiles and hats are not considered.
  • The path pattern of the rule only grants the exec. /usr/bin/* Px, resolves each program separately.
  • No result: info="profile transition not found", the exec permission is removed from the result and the exec fails with EACCES (domain.c:740-754).
  • Complain mode: a learning profile named PARENT//null-PATH is created and the exec continues under it (domain.c:749-766). Fixture record with target="/home/cb/bin/hello.sh//null-/usr/bin/rm": exec01.in:1.
  • Two profiles that attach equally well: the kernel log gets conflicting profile attachments, the record says profile transition not found (domain.c:33-37).
  • The parser does not check that a profile exists for a px rule.

Read more

for AppArmor developers for security researchers

In the code

05 cx: a child of this profile

cx profile demo /usr/bin/demo { /usr/lib/demo/worker Cx , profile /usr/lib/demo/worker { /var/lib/demo/jobs/** rw, } } the child is named after the program demo execve() demo///usr/lib/demo/worker worker full name: parent // child profile worker { ... } a plain name attaches to nothing /usr/lib/demo/worker Cx -> worker, write it with an arrow no matching child: the exec fails, as with px. The parser does not check.
Profile demo with the rule /usr/lib/demo/worker Cx, and a child profile named /usr/lib/demo/worker. demo executes the worker, which runs under the child, full name demo///usr/lib/demo/worker. A child with the plain name worker attaches to nothing and needs the rule written with an arrow. With no matching child the exec fails, and the parser does not check.

cx searches only the children of the current profile. A child named after the executable matches; a child with a plain name needs cx -> name.

cx keeps the helper's rules inside demo's own profile. The kernel runs the search again, but only over demo's children. So the child has to attach to the program, and the simple way is to name the child after the path; the parser's own tests do exactly that. A child with a short name, like worker, doesn't attach to any path. For that you name it with an arrow, which is the named transitions deck. And be careful: the parser doesn't check that a matching child exists. If there's none, the exec fails at run time, just like px.

Details and sources

Details

Kernel facts are from the kernel source, read and not run.

  • cx runs the same attachment search as px, over the children of the profile that holds the rule instead of the namespace's profiles (domain.c:604-607).
  • A child matches when its name is the executable's path or its attachment matches it. A child with a plain name, such as worker, attaches to nothing and needs cx -> worker: named transitions.
  • No matching child: the same result as px, info="profile transition not found" and EACCES, or a learning profile in complain mode.
  • The parser does not check that a child exists: the test simple_ok_cx_1.sd has /bin/foo Cx, with no such child and is expected to pass. The same file names its children after paths: profile /bin/cat { ... }.

for AppArmor developers for security researchers

In the code

06 pix, cix, pux, cux: look, then fall back

FALLBACK MODES /usr/bin/* Pix , demo execve("/usr/bin/sort") a profile attaches to /usr/bin/sort? yes profile sort sort as px no profile demo sort as ix /usr/bin/* PUx , no profile attaches unconfined sort as ux info="ix fallback" info="ux fallback" cix and cux: the same, searching children
With the rule /usr/bin/* Pix, demo executes /usr/bin/sort. If a profile attaches to sort, sort runs under profile sort, as with px. If none does, sort runs under profile demo, as with ix, and the info string is ix fallback. With PUx the no branch ends unconfined with the info string ux fallback. cix and cux do the same, searching children.

pix/cix: use the attaching profile or child, else inherit. pux/cux: else run unconfined. Without a fallback letter a failed search refuses the exec.

px is strict, and sometimes too strict. Say one rule covers everything in /usr/bin. You'd like programs that have a profile to use it, and the rest to stay under demo's. That's pix: search first, and inherit if the search comes back empty. cix does the same with children. pux and cux fall back to unconfined instead, so keep the same caution as for ux. A fallback isn't an error. The exec goes ahead, and the reason string in the kernel says ix fallback or ux fallback.

Details and sources

Details

Kernel facts are from the kernel source, read and not run.

  • After an empty search the fallback letters apply: inherit gives the current profile with info="ix fallback", unconfined gives the namespace's unconfined label with info="ux fallback" (domain.c:616-638). Inherit is tested first.
  • A fallback is not an error: the exec continues. Whether a record is written follows the usual audit rules.
  • Exception: when two profiles attached equally well, the strings are conflicting profile attachments - ix fallback and conflicting profile attachments - ux fallback (domain.c:33-37), and a record is forced (domain.c:730-739).
  • Without a fallback letter an empty search refuses the exec: profile transition not found, EACCES.
  • Environment: after an inherit fallback secure execution is not requested, also for Pix and Cix. For pux and cux the case of the first letter decides: safe and unsafe.
  • Parser tests: simple_ok_pix_1.sd, simple_ok_pux_1.sd.

Read more

07 xindex and x_to_label for AppArmor developers for security researchers

THE KERNEL: profile_transition -> x_to_label parser bits, per half (immunix.h) AA_MAY_EXEC 0x1 type, bits 10-13: 1 unconfined, 2 profile, 3 local, 4-15 table AA_EXEC_INHERIT 0x200 AA_EXEC_PUX 0x80 AA_EXEC_UNSAFE 0x100 dfa_map_xindex (policy_compat.c:24) ix AA_X_INHERIT ux AA_X_UNCONFINED px AA_X_NAME cx AA_X_NAME | AA_X_CHILD -> name AA_X_TABLE | slot-4 lowercase | AA_X_UNSAFE profile_transition (domain.c:665) aa_str_perms(rules->file, ...) perms.allow & MAY_EXEC x_to_label (domain.c:574): switch (xtype) AA_X_NONE: no lookup AA_X_NAME: find_attach(ns profiles, or children) AA_X_TABLE: x_table_lookup if (!new) AA_X_INHERIT: "ix fallback" else AA_X_UNCONFINED: "ux fallback" still !new: "profile transition not found" -EACCES complain mode: a //null- learning profile instead of the error
The parser's exec bits per half, AA_MAY_EXEC, a type in bits 10 to 13 and the flags AA_EXEC_PUX, AA_EXEC_UNSAFE and AA_EXEC_INHERIT, are remapped by dfa_map_xindex to the kernel's xindex. In the kernel profile_transition checks MAY_EXEC and calls x_to_label, which switches on the type for the lookup, then applies the ix or ux fallback when no label was found; with no label profile_transition reports profile transition not found.

dfa_map_xindex (linux:security/apparmor/policy_compat.c:24-48) maps the parser's bits; x_to_label (linux:security/apparmor/domain.c:574-663) does lookup then fallback.

In the parser the mode is the exec bit, a four bit type and three flags: inherit, pux and unsafe. dfa_map_xindex turns that into the kernel's xindex. In the exec hook of the kernel, profile_transition matches the executable's name and checks the exec permission, then x_to_label does the work. Its switch does the lookup: none, by name, or by table. Only if that produced nothing do the inherit and unconfined flags apply, inherit first. So plain ix and plain ux are literally a lookup of nothing followed by a fallback. No label at the end means profile transition not found.

Details and sources

for AppArmor developers for security researchers

Details

  • Parser bits per half (immunix.h:35-48): AA_MAY_EXEC 0x1, AA_EXEC_PUX 0x80, AA_EXEC_UNSAFE 0x100, AA_EXEC_INHERIT 0x200, type in bits 10 to 13. Types: AA_EXEC_UNCONFINED 1, AA_EXEC_PROFILE 2, AA_EXEC_LOCAL 3 (immunix.h:80-82); values 4 to 15 are table slots, AA_EXEC_COUNT is 16 (immunix.h:70).
  • parse_sub_perms sets them: ix at parser_misc.c:616-626, ux and Ux at parser_misc.c:628-647, px, cx and the fallback forms at parser_misc.c:649-688.
  • Kernel: dfa_map_xindex maps 0x100 to AA_X_UNSAFE, 0x200 to AA_X_INHERIT, 0x80 and type 1 to AA_X_UNCONFINED, type 2 to AA_X_NAME, type 3 to AA_X_NAME | AA_X_CHILD, a higher type to AA_X_TABLE | (type - 4) (policy_compat.c:24-48). The values of the AA_X_ constants: file.h:54-64.
  • apparmor_bprm_creds_for_exec calls profile_transition for each profile of the label, then applies the no_new_privs and ptrace tests and sets bprm->secureexec (domain.c:985-1108).
  • profile_transition: aa_path_name, aa_str_perms, the MAY_EXEC test, x_to_label, "profile transition not found", the learning profile, the AA_X_UNSAFE test (domain.c:665-796).
  • x_to_label: a switch on the type (AA_X_NONE, AA_X_TABLE, AA_X_NAME), then the fallback, AA_X_INHERIT before AA_X_UNCONFINED (domain.c:574-663).
  • Plain ix and plain ux have type AA_X_NONE: no lookup, then the fallback branch.
  • The open of the executable during exec is not checked (lsm.c:475-485).

08 Conflicting x modifiers

COMMON MISTAKES /usr/bin/demo-helper pxix, Exec qualifier 'i' invalid, conflicting qualifier already specified /usr/bin/demo-helper Px, /usr/bin/demo-helper px, profile demo: has merged rule /usr/bin/demo-helper with conflicting x modifiers /usr/bin/demo-* Px, /usr/bin/* ix, profile has merged rule with conflicting x modifiers overlapping patterns: no path in the message /usr/bin/demo-helper Px, /usr/bin/* ix, accepted no conflict: an exact path wins over a pattern deny /usr/bin/demo-helper Px, Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u' deny /usr/bin/demo-helper x, write a bare x after deny
Five cases with the parser's answer: pxix in one mode word is a conflicting qualifier; Px and px for the same path, and Px and ix on overlapping patterns, are merged rules with conflicting x modifiers; an exact path with Px next to a pattern with ix is accepted; and deny with Px is rejected because deny rules take a bare x.

"has merged rule ... with conflicting x modifiers" means two rules give one path two exec modes. A path with no *, ? or [^...] overrides one that has them. In deny rules write a bare x.

An exec of one file can have only one outcome, so the parser refuses a profile where two rules disagree. Inside one mode word it complains at once. Two rules with the same path and different modes are caught when rules are merged, and the message names the path. Two overlapping patterns are caught later; that message names nothing, so you find the pair yourself. Uppercase and lowercase count as different modes. One useful exception: a rule with no star, question mark or negated set beats one that has them, so an exact px next to a broad ix is fine. And a deny rule takes a bare x, with no letters in front.

Details and sources

Details

Messages of the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel.

  • Inside one mode word, /usr/bin/demo-helper pxix,: Exec qualifier 'i' invalid, conflicting qualifier already specified (parser_misc.c:619). For the other letters the message names the letter or the pair.
  • Two rules with the same path text, /usr/bin/demo-helper Px, and /usr/bin/demo-helper px,: profile demo: has merged rule /usr/bin/demo-helper with conflicting x modifiers (block_rules.cc:322-327).
  • Two overlapping patterns, /usr/bin/demo-* Px, and /usr/bin/* ix,: profile has merged rule with conflicting x modifiers, then ERROR processing regexs for profile demo, failed to load. No path and no line number.
  • The whole exec type is compared, including the unsafe bit: px against Px on one path is a conflict (immunix.h:171-186). The owner half and the other half are compared separately.
  • Not a conflict: a rule whose path has no *, **, ? or [^...] overrides patterns that match the same path. Braces and plain sets still count as exact: /usr/bin/{demo-helper,x} Px, with /usr/bin/* ix, is accepted, /usr/bin/demo-? Px, conflicts (run with the parser built from the tree at 836052d21). Tests: minimize-x-conflict.sd passes, x-conflict.sd fails.
  • Not a conflict: a rule with a higher priority=: priority.
  • Deny rules: deny /a px, gives Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u'; deny /a x, is accepted (parser_misc.c:1090-1104).

for AppArmor developers for security researchers

In the code

09 Where to go from here

ROADS exec modes i stay · p own profile · c child · u unconfined syn-safe-unsafe Px or px? syn-named-transitions Px -> name attachment what px searches syn-child-profiles what cx searches k-exec the hook, no_new_privs, ptrace also nearby syn-access-modes syn-allow-deny stacking syntax-map the other letters the bare x of deny a stacked label the whole profile
Exec modes in the centre with roads to syn-safe-unsafe for letter case, syn-named-transitions for the arrow, attachment and syn-child-profiles for what px and cx search, k-exec for the kernel hook, and syn-access-modes, syn-allow-deny, stacking and syntax-map.

Next: syn-safe-unsafe (letter case), syn-named-transitions (-> name), attachment (the search behind px), k-exec (the kernel hook).

Four choices and their fallbacks: that's the exec mode. The natural next step is the case of the letter, which decides whether the new program's environment is trusted. Then the arrow, for when the profile you want isn't the one that attaches by path. The attachment deck explains how the px search scores its candidates, and the child profiles deck covers what cx looks through. The kernel exec deck has what else can stop an exec, such as no new privs. The other letters of the mode, deny rules and stacking have decks too.

Details and sources

Details

  • ix: keep the current profile. ux: unconfined. px: the profile that attaches to the executable's path. cx: the same search over the children of the current profile.
  • pix, cix, pux, cux: search, then fall back to inherit or unconfined. Without a fallback letter an empty search fails the exec with profile transition not found.
  • Also in the exec hook of the kernel: a confined task with no_new_privs set gets EPERM and info="no new privs" unless the new label is a subset of the label held when the flag was set (domain.c:1050-1056).
  • Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2), the kernel-rc2 (97d73c825). Kernel behaviour was read from the source and not run.

Read more

Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the fragment, with the tree's abi/5.0 file as the kernel features and nothing loaded into a kernel; "code" means the kernel source of mainline Linux 7.4 (7.4-rc2, 97d73c825) or the parser source was read, not run; "fixture" means a parser test in parser/tst/simple_tests/ asserts it. Nothing here was run against a kernel: every statement about what happens at exec is from the kernel source.

Grammar

EXEC MODE:  [ 'p' | 'P' | 'c' | 'C' ] [ 'i' | 'u' | 'U' ] 'x'
lexer:      (([Pp]|[Cc])[Xx])|(([Pp]|[Cc])?([IiUu])[Xx])
  • The complete set: ix, ux Ux, px Px, cx Cx, pix Pix, cix Cix, pux PUx, cux CUx.
  • The case of the first letter is significant: lowercase is the unsafe form, uppercase the safe form. See syn-safe-unsafe.
  • The case of the second and third letters is not significant in the fallback modes: pIx, PIx and Pux are accepted (fixture, tree).
  • ix has no safe form. Ix is accepted as ix with the deprecation warning for uppercase letters (code).
  • There is no uix: it is a syntax error (tree).
  • An exec mode is part of the mode of a file rule and combines with the other letters, as in /usr/bin/sort rix,. See syn-access-modes.
  • x alone is written only in deny rules: deny /usr/bin/demo-helper x,. See syn-allow-deny.
  • -> name after the mode names the target profile: syn-named-transitions.

What each mode does

ModeSearchWhen nothing is foundEnvironment
ixnonenot applicable: the current profile is keptnot scrubbed
ux / Uxnonenot applicable: the unconfined label of the profile's namespacelowercase passes it on; uppercase scrubs
px / Pxtop-level profiles of the current namespace, by the path of the executablethe exec failsby letter case
cx / Cxchildren of the profile that holds the rule, by the path of the executablethe exec failsby letter case
pix / Pixas pxinherit, as ixnot scrubbed after the fallback
cix / Cixas cxinherit, as ixnot scrubbed after the fallback
pux / PUxas pxunconfined, as uxby the case of the first letter
cux / CUxas cxunconfined, as uxby the case of the first letter
  • All rows are from the kernel source (code). The environment column is the subject of syn-safe-unsafe.
  • The search is the attachment search that an unconfined task's exec runs: the best path match wins, then the number of matched extended attributes. See attachment.
  • The profile is chosen by the path of the executable, not by the path pattern in the rule. /usr/bin/* Px, resolves each program separately.
  • px does not consider child profiles or hats. cx considers only the children of the profile holding the rule; a child matches when its name is the executable's path or its attachment matches it. A child with a plain name needs cx -> name. See syn-child-profiles.
  • The parser does not check that a profile or child exists for a px or cx rule (fixture: xtrans/simple_ok_cx_1.sd has /bin/foo Cx, and no such child).
  • ix also grants m on the same path (code).
  • "Unconfined" is the unconfined label of the namespace of the profile that holds the rule. See namespaces.

At exec time

  • The exec permission is tested only by the exec hook. The open of the executable during execve is not tested against the profile (code).
  • An unconfined task does not consult exec rules; the kernel only searches for an attaching profile (code).
  • With no exec permission for the path the exec fails with EACCES.
  • With px or cx and no result the exec fails with EACCES and info="profile transition not found".
  • Complain mode: where enforce mode would fail the exec, a learning profile named PARENT//null-PATH is created and the exec continues under it (code).
  • When the path of the executable cannot be built the exec fails, unless the profile is unconfined or was loaded with the flag that turns such errors into ix (code).
  • no_new_privs: after the new label is chosen, an exec from a confined task that has no_new_privs set fails with EPERM and info="no new privs" unless the new label is a subset of the label held when the flag was set (code). See k-exec.
  • A traced task: the tracer must be allowed to trace the new label (code).
  • A stacked label: each profile in the label makes its own decision and the results are combined. With ux only the member whose profile has the rule becomes unconfined. See stacking.

Kernel info strings

info=WhenResult
profile transition not foundpx or cx found no profile, or two profiles attached equally wellEACCES; a learning profile in complain mode
ix fallbackplain ix, or pix/cix after an empty searchthe exec continues under the current profile
ux fallbackplain ux, or pux/cux after an empty searchthe exec continues unconfined
conflicting profile attachmentstwo profiles attached equally well; under px and cx this text goes only to the kernel log and the record says profile transition not foundsee the first row
conflicting profile attachments - ix fallbackthe same tie under pix or cixthe exec continues under the current profile and is audited
conflicting profile attachments - ux fallbackthe same tie under pux or cuxthe exec continues unconfined and is audited
no new privsthe task has no_new_privs and the new label is not a subsetEPERM
  • The strings are from linux:security/apparmor/domain.c (code). A fallback is not an error; whether a record is written for it follows the usual audit rules, except for the two tie rows, which force one.
  • A recorded exec without permission in complain mode, from libraries/libapparmor/testsuite/test_multi/exec01.in:
apparmor="ALLOWED" operation="exec" profile="/home/cb/bin/hello.sh" name="/usr/bin/rm"
  pid=13108 comm="hello.sh" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0
  target="/home/cb/bin/hello.sh//null-/usr/bin/rm"

Conflicts

One path may have one exec mode. The parser tests this in three places.

WhereExampleMessage
inside one mode word/usr/bin/demo-helper pxix,Exec qualifier 'i' invalid, conflicting qualifier already specified
two rules with the same path text/usr/bin/demo-helper Px, and /usr/bin/demo-helper px,profile demo: has merged rule /usr/bin/demo-helper with conflicting x modifiers
two overlapping patterns/usr/bin/demo-* Px, and /usr/bin/* ix,profile has merged rule with conflicting x modifiers, then ERROR processing regexs for profile demo, failed to load
  • All three rows: tree.
  • What is compared: the whole exec type, which includes the safe or unsafe bit. px against Px on one path is a conflict.
  • Not a conflict: a rule whose path has no *, **, ? or [^...] overrides patterns that also match that path. Braces and plain sets still count as exact: /usr/bin/{demo-helper,x} Px, and /usr/bin/demo-[ab] Px, with /usr/bin/* ix, are accepted, /usr/bin/demo-? Px, conflicts (tree; parser/libapparmor_re/aare_rules.cc:98-105). /usr/bin/demo-helper Px, with /usr/bin/* ix, is accepted (tree; fixtures xtrans/minimize-x-conflict.sd passes and xtrans/x-conflict.sd fails).
  • Not a conflict: a rule with a higher priority= replaces the mode of the lower one (code). See syn-priority.
  • Not a conflict: the owner half and the other half of a rule are compared separately (code).
  • Not a conflict: the same mode twice, also in one word (/a pixpix, is accepted, tree), and two rules naming the same target profile.
  • Two different named targets on overlapping paths conflict.

Errors and warnings

The full form of a parser error is AppArmor parser error for FILE in profile FILE at line N: MESSAGE. Errors from the later compile stage carry no line number.

MessageCause
Exec qualifier 'i' invalid, conflicting qualifier already specifieda second exec mode in one mode word, as in pxix
Exec qualifier '%c' invalid, conflicting qualifier already specifiedthe same for u, U, p, P, c, C, as in pxPx
Exec qualifier '%c%c' invalid, conflicting qualifier already specifiedthe same for a fallback mode
profile %s: has merged rule %s with conflicting x modifierstwo rules with the same path and different exec modes
profile has merged rule with conflicting x modifierstwo overlapping patterns with different exec modes; the message names neither
Invalid perms, 'x' must be preceded by exec qualifier 'i', 'p', or 'u'a bare x in a rule that is not a deny rule, as in /bin/ls rx,
Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u'an exec mode in a deny rule, as in deny /a px,
Unconfined exec qualifier (ux) allows some dangerous environment variables to be passed to the unconfined process; 'man 5 apparmor.d' for details.warning for a lowercase ux; class dangerous, off by default (--warn=dangerous or --warn=all). Lowercase pux and cux do not print it
Uppercase qualifiers "RWLIMX" are deprecated, please convert to lowercasewarning for Ix or a capital X; once per run
a syntax errora combination outside the grammar, such as uix

Known discrepancies

  • The two "Invalid perms" messages list the qualifiers 'i', 'p', or 'u' and omit c, although cx is equally valid.
  • A comment in the parser source says a bare x is valid with a named target. The parser rejects /a x -> b, with the first "Invalid perms" message (tree).
  • unsafe /a ix, together with /a ix, fails with "has merged rule /a with conflicting x modifiers" (tree), although the kernel does not look at the unsafe bit for ix.

for AppArmor developers for security researchers

Encoding

Parser bits per half, the other half shifted left by 14 (parser/immunix.h:35-48, 70, 80-82):

NameValue
AA_MAY_EXEC0x1
AA_EXEC_PUX0x80
AA_EXEC_UNSAFE0x100
AA_EXEC_INHERIT0x200
type, bits 10 to 13AA_EXEC_UNCONFINED 1, AA_EXEC_PROFILE 2, AA_EXEC_LOCAL 3, table slots 4 to 15
AA_EXEC_COUNT16
ModeBits set (parser/parser_misc.c)Kernel xindex (linux:security/apparmor/policy_compat.c:24-48)
ixinherit (616-626)AA_X_INHERIT
ux / Uxtype 1, unsafe for u (628-647)AA_X_UNCONFINED (+ AA_X_UNSAFE)
px / Pxtype 2, unsafe for p (649-687)AA_X_NAME (+ AA_X_UNSAFE)
cx / Cxtype 3, unsafe for c (649-687)`AA_X_NAME \AA_X_CHILD (+ AA_X_UNSAFE`)
pix Pix cix Cixas px or cx plus inherit (660-667)as px or cx plus AA_X_INHERIT
pux PUx cux CUxas px or cx plus pux (668-675)as px or cx plus AA_X_UNCONFINED
any mode with -> nametype replaced by a table slot 4 to 15 (parser/block_rules.cc:581-596)`AA_X_TABLE \(slot - 4)`
StepWhere
lexer pattern for exec modes in MODE_CHARSparser/parser_lex.l:257
parse_sub_perms: letters to bits; IS_DIFF_QUAL compares AA_EXEC_TYPE within one wordparser/parser_misc.c:563, 616-701
check_x_qualifier: bare x only in deny rulesparser/parser_misc.c:1090-1104
merge_file with is_merged_x_consistent: same path textparser/block_rules.cc:322-327; parser/immunix.h:171-187
conflict between overlapping patterns in one DFA state; exact match and priorityparser/libapparmor_re/hfa.cc:1549-1582, 1604-1637, 1703-1706; parser/libapparmor_re/aare_rules.cc:98-105
ix implies mparser/libapparmor_re/hfa.cc:1497-1524
dfa_map_xindexlinux:security/apparmor/policy_compat.c:24-48
apparmor_bprm_creds_for_exec: one profile_transition per profile of the label, then no_new_privs and ptrace testslinux:security/apparmor/domain.c:985-1108
profile_transition: name, aa_str_perms, MAY_EXEC, x_to_label, "profile transition not found", learning profile, AA_X_UNSAFE testlinux:security/apparmor/domain.c:665-784
x_to_label: switch on the type, then the ix and ux fallbackslinux:security/apparmor/domain.c:574-663
find_attachlinux:security/apparmor/domain.c:394-507
the open during exec is skippedlinux:security/apparmor/lsm.c:475-485
  • Plain ix and plain ux have type AA_X_NONE: no lookup, then the fallback branch. AA_X_INHERIT is tested before AA_X_UNCONFINED.
  • After an ix result profile_transition jumps to the audit step and skips the AA_X_UNSAFE test, so an ix exec does not request AT_SECURE.
  • Parser fixtures: parser/tst/simple_tests/xtrans/, parser/tst/simple_tests/file/front_perms_ok_1.sd.

Roads from here

START HERE

ATTACHMENT, NAMESPACES, STACKING

FILE ACCESS

QUALIFIERS

PROFILE STRUCTURE

IN THE KERNEL