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
- File access modes — the plain permission letters; x is the one left over
- Profile attachment — the search by path that px starts
Part of journeys
- Write your first profile, step 6 of 12 · previous: Globbing (AARE) · next: The owner qualifier
- File access in depth, step 4 of 12 · previous: File access modes · next: safe and unsafe exec
- How a rule becomes a permission, step 3 of 12 · previous: File access modes · next: Named exec transitions
- Exec, transitions and labels, step 2 of 13 · previous: Profile attachment · next: safe and unsafe exec
01 demo runs a program. Under which profile?
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 byapparmor_bprm_creds_for_exec(domain.c:985, registered at lsm.c:1862). It runs duringexecve, 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 withEACCES. - 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 carriesrequested_mask="x"and, when a profile was chosen,target=. Example fixture: exec01.in:1.
02 The letters before the x
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,uxUx,pxPx,cxCx,pixPix,cixCix,puxPUx,cuxCUx. - 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,PIxandPuxare accepted (parser tests and the released parser 5.0.2). ixhas no safe form.Ixis read asixwith the deprecation warning for uppercase letters (parser_misc.c:616-626). There is nouix: it is a syntax error (5.0.2).- An exec mode combines with the other letters of the mode:
/usr/bin/sort rix,. xalone 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
- apparmor.d(5) Access Modes: the list of exec modes.
- Access modes: the other letters of the word.
- Named transitions:
-> nameafter the mode.
03 ix and ux: no lookup
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.
ixanduxhave no lookup step (domain.c:588-591). The fallback step then applies: inherit takes the newest version of the current profile's label withinfo="ix fallback"; unconfined takes the unconfined label of the namespace of the profile that holds the rule withinfo="ux fallback"(domain.c:617-637).- Inherit is tested before unconfined.
ixnever requests secure execution: there is no safe form ofix. See safe and unsafe.- Lowercase
uxprints 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=dangerousor--warn=all. Lowercasepuxandcuxdo not print it. - With a stacked label only the member whose profile has the
uxrule becomes unconfined: stacking.
for security researchers
Attack surface
uxandUxremove confinement for the new program and everything it starts.pux,cuxand their uppercase forms do the same whenever no profile attaches: the fallback is taken without an error, and the reason stringux fallbackis 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
uxonly, and only with--warn=dangerousor--warn=all. Lowercasepuxandcux, 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). ixkeeps the profile, so every program reachable through anixrule runs with the caller's permissions. Anixrule 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, andpriority=overrides both (aare_rules.cc:98-105). Braces and plain sets count as exact; see the reference below. - Attachment for
pxandcxis 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).
Read more
- apparmor.d(5) ix - Inherit execute mode.
- apparmor.d(5) ux - Unconfined execute mode.
- Namespaces: which unconfined label.
for AppArmor developers for security researchers
In the code
iximpliesmon the same path:add_implied_ix_mmap(hfa.cc:1497-1524).- After an
ixresultprofile_transitionjumps to the audit step and skips theAA_X_UNSAFEtest (domain.c:730-739).
04 px: the program's own profile
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.
pxruns the attachment searchfind_attachover 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_attachis 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 withEACCES(domain.c:740-754). - Complain mode: a learning profile named
PARENT//null-PATHis created and the exec continues under it (domain.c:749-766). Fixture record withtarget="/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 saysprofile transition not found(domain.c:33-37). - The parser does not check that a profile exists for a
pxrule.
Read more
- apparmor.d(5) px - Discrete Profile execute mode.
- Attachment: how the search scores its candidates.
- Reading denials.
for AppArmor developers for security researchers
In the code
- The parser's type 2 becomes
AA_X_NAMEindfa_map_xindex(policy_compat.c:38-39).
05 cx: a child of this profile
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.
cxruns the same attachment search aspx, 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 needscx -> worker: named transitions. - No matching child: the same result as
px,info="profile transition not found"andEACCES, 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 { ... }.
Read more
for AppArmor developers for security researchers
In the code
- The parser's type 3 becomes
AA_X_NAME | AA_X_CHILDindfa_map_xindex(policy_compat.c:40-41).
06 pix, cix, pux, cux: look, then fall back
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 withinfo="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 fallbackandconflicting 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
PixandCix. Forpuxandcuxthe case of the first letter decides: safe and unsafe. - Parser tests: simple_ok_pix_1.sd, simple_ok_pux_1.sd.
Read more
- apparmor.d(5) Access Modes:
pix,cix,pux,cuxin the list of modes. - Attachment: what "nothing attaches" means.
- The kernel's exec hook.
07 xindex and x_to_label for AppArmor developers for security researchers
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_EXEC0x1,AA_EXEC_PUX0x80,AA_EXEC_UNSAFE0x100,AA_EXEC_INHERIT0x200, type in bits 10 to 13. Types:AA_EXEC_UNCONFINED1,AA_EXEC_PROFILE2,AA_EXEC_LOCAL3 (immunix.h:80-82); values 4 to 15 are table slots,AA_EXEC_COUNTis 16 (immunix.h:70). parse_sub_permssets them:ixat parser_misc.c:616-626,uxandUxat parser_misc.c:628-647,px,cxand the fallback forms at parser_misc.c:649-688.- Kernel:
dfa_map_xindexmaps 0x100 toAA_X_UNSAFE, 0x200 toAA_X_INHERIT, 0x80 and type 1 toAA_X_UNCONFINED, type 2 toAA_X_NAME, type 3 toAA_X_NAME | AA_X_CHILD, a higher type toAA_X_TABLE | (type - 4)(policy_compat.c:24-48). The values of theAA_X_constants: file.h:54-64. apparmor_bprm_creds_for_execcallsprofile_transitionfor each profile of the label, then applies theno_new_privsand ptrace tests and setsbprm->secureexec(domain.c:985-1108).profile_transition:aa_path_name,aa_str_perms, theMAY_EXECtest,x_to_label, "profile transition not found", the learning profile, theAA_X_UNSAFEtest (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_INHERITbeforeAA_X_UNCONFINED(domain.c:574-663).- Plain
ixand plainuxhave typeAA_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
"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, thenERROR processing regexs for profile demo, failed to load. No path and no line number. - The whole exec type is compared, including the unsafe bit:
pxagainstPxon 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,givesInvalid 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).
Read more
- allow and deny, priority.
- apparmor.d(5) deny x - Deny execute.
- Safe and unsafe: why
pxandPxdiffer.
for AppArmor developers for security researchers
In the code
- Within one word the test is
IS_DIFF_QUAL, which comparesAA_EXEC_TYPE(parser_misc.c:563). - Overlapping patterns meet in one DFA state. The conflict is found at hfa.cc:1610-1615 and hfa.cc:1632-1637; the message is printed at hfa.cc:1703-1706.
- An exact match gets a higher internal priority for the exec bits (hfa.cc:1549-1551).
09 Where to go from here
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 withprofile transition not found.- Also in the exec hook of the kernel: a confined task with
no_new_privsset getsEPERMandinfo="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,uxUx,pxPx,cxCx,pixPix,cixCix,puxPUx,cuxCUx. - 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,PIxandPuxare accepted (fixture, tree). ixhas no safe form.Ixis accepted asixwith 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. xalone is written only indenyrules:deny /usr/bin/demo-helper x,. See syn-allow-deny.-> nameafter the mode names the target profile: syn-named-transitions.
What each mode does
| Mode | Search | When nothing is found | Environment |
|---|---|---|---|
ix | none | not applicable: the current profile is kept | not scrubbed |
ux / Ux | none | not applicable: the unconfined label of the profile's namespace | lowercase passes it on; uppercase scrubs |
px / Px | top-level profiles of the current namespace, by the path of the executable | the exec fails | by letter case |
cx / Cx | children of the profile that holds the rule, by the path of the executable | the exec fails | by letter case |
pix / Pix | as px | inherit, as ix | not scrubbed after the fallback |
cix / Cix | as cx | inherit, as ix | not scrubbed after the fallback |
pux / PUx | as px | unconfined, as ux | by the case of the first letter |
cux / CUx | as cx | unconfined, as ux | by 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. pxdoes not consider child profiles or hats.cxconsiders 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 needscx -> name. See syn-child-profiles.- The parser does not check that a profile or child exists for a
pxorcxrule (fixture:xtrans/simple_ok_cx_1.sdhas/bin/foo Cx,and no such child). ixalso grantsmon 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
execveis 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
pxorcxand no result the exec fails withEACCESandinfo="profile transition not found". - Complain mode: where enforce mode would fail the exec, a learning profile named
PARENT//null-PATHis 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 hasno_new_privsset fails withEPERMandinfo="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
uxonly the member whose profile has the rule becomes unconfined. See stacking.
Kernel info strings
info= | When | Result |
|---|---|---|
profile transition not found | px or cx found no profile, or two profiles attached equally well | EACCES; a learning profile in complain mode |
ix fallback | plain ix, or pix/cix after an empty search | the exec continues under the current profile |
ux fallback | plain ux, or pux/cux after an empty search | the exec continues unconfined |
conflicting profile attachments | two profiles attached equally well; under px and cx this text goes only to the kernel log and the record says profile transition not found | see the first row |
conflicting profile attachments - ix fallback | the same tie under pix or cix | the exec continues under the current profile and is audited |
conflicting profile attachments - ux fallback | the same tie under pux or cux | the exec continues unconfined and is audited |
no new privs | the task has no_new_privs and the new label is not a subset | EPERM |
- 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.
| Where | Example | Message |
|---|---|---|
| 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.
pxagainstPxon 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; fixturesxtrans/minimize-x-conflict.sdpasses andxtrans/x-conflict.sdfails). - Not a conflict: a rule with a higher
priority=replaces the mode of the lower one (code). See syn-priority. - Not a conflict: the
ownerhalf 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.
| Message | Cause |
|---|---|
Exec qualifier 'i' invalid, conflicting qualifier already specified | a second exec mode in one mode word, as in pxix |
Exec qualifier '%c' invalid, conflicting qualifier already specified | the same for u, U, p, P, c, C, as in pxPx |
Exec qualifier '%c%c' invalid, conflicting qualifier already specified | the same for a fallback mode |
profile %s: has merged rule %s with conflicting x modifiers | two rules with the same path and different exec modes |
profile has merged rule with conflicting x modifiers | two 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 lowercase | warning for Ix or a capital X; once per run |
| a syntax error | a combination outside the grammar, such as uix |
Known discrepancies
- The two "Invalid perms" messages list the qualifiers
'i', 'p', or 'u'and omitc, althoughcxis equally valid. - A comment in the parser source says a bare
xis 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 forix.
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):
| Name | Value |
|---|---|
AA_MAY_EXEC | 0x1 |
AA_EXEC_PUX | 0x80 |
AA_EXEC_UNSAFE | 0x100 |
AA_EXEC_INHERIT | 0x200 |
| type, bits 10 to 13 | AA_EXEC_UNCONFINED 1, AA_EXEC_PROFILE 2, AA_EXEC_LOCAL 3, table slots 4 to 15 |
AA_EXEC_COUNT | 16 |
| Mode | Bits set (parser/parser_misc.c) | Kernel xindex (linux:security/apparmor/policy_compat.c:24-48) | |
|---|---|---|---|
ix | inherit (616-626) | AA_X_INHERIT | |
ux / Ux | type 1, unsafe for u (628-647) | AA_X_UNCONFINED (+ AA_X_UNSAFE) | |
px / Px | type 2, unsafe for p (649-687) | AA_X_NAME (+ AA_X_UNSAFE) | |
cx / Cx | type 3, unsafe for c (649-687) | `AA_X_NAME \ | AA_X_CHILD (+ AA_X_UNSAFE`) |
pix Pix cix Cix | as px or cx plus inherit (660-667) | as px or cx plus AA_X_INHERIT | |
pux PUx cux CUx | as px or cx plus pux (668-675) | as px or cx plus AA_X_UNCONFINED | |
any mode with -> name | type replaced by a table slot 4 to 15 (parser/block_rules.cc:581-596) | `AA_X_TABLE \ | (slot - 4)` |
| Step | Where |
|---|---|
lexer pattern for exec modes in MODE_CHARS | parser/parser_lex.l:257 |
parse_sub_perms: letters to bits; IS_DIFF_QUAL compares AA_EXEC_TYPE within one word | parser/parser_misc.c:563, 616-701 |
check_x_qualifier: bare x only in deny rules | parser/parser_misc.c:1090-1104 |
merge_file with is_merged_x_consistent: same path text | parser/block_rules.cc:322-327; parser/immunix.h:171-187 |
| conflict between overlapping patterns in one DFA state; exact match and priority | parser/libapparmor_re/hfa.cc:1549-1582, 1604-1637, 1703-1706; parser/libapparmor_re/aare_rules.cc:98-105 |
ix implies m | parser/libapparmor_re/hfa.cc:1497-1524 |
dfa_map_xindex | linux: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 tests | linux: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 test | linux:security/apparmor/domain.c:665-784 |
x_to_label: switch on the type, then the ix and ux fallbacks | linux:security/apparmor/domain.c:574-663 |
find_attach | linux:security/apparmor/domain.c:394-507 |
| the open during exec is skipped | linux:security/apparmor/lsm.c:475-485 |
- Plain
ixand plainuxhave typeAA_X_NONE: no lookup, then the fallback branch.AA_X_INHERITis tested beforeAA_X_UNCONFINED. - After an
ixresultprofile_transitionjumps to the audit step and skips theAA_X_UNSAFEtest, so anixexec does not requestAT_SECURE. - Parser fixtures:
parser/tst/simple_tests/xtrans/,parser/tst/simple_tests/file/front_perms_ok_1.sd.
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
ATTACHMENT, NAMESPACES, STACKING
- Profile attachment — the search that px runs
- Profile stacking — what an exec does to a stacked label
FILE ACCESS
- safe and unsafe exec — what upper and lower case change
- Named exec transitions — naming the profile with an arrow
- File access modes — the other letters of the mode
QUALIFIERS
- allow and deny — the bare x of deny rules
PROFILE STRUCTURE
- Child profiles — the profiles that cx looks for
IN THE KERNEL
- Exec and domain transitions — the exec hook in the kernel