safe and unsafe exec
environment scrubbing for application developers for security researchers
Whether the new program is started in secure-execution mode when an exec changes the profile. Uppercase P C and U request it and lowercase letters do not. The safe and unsafe keywords override the letter case and also apply to change_profile rules.
On the map: file access
▶ Watch this deck — 8 scenes, ~6 min
Worth seeing first
- Exec modes — the exec modes whose letter case this deck explains
Part of journeys
- File access in depth, step 5 of 12 · previous: Exec modes · next: Named exec transitions
- Exec, transitions and labels, step 3 of 13 · previous: Exec modes · next: Named exec transitions
01 The environment crosses the exec
An exec that changes profile can ask for secure-execution mode, in which the C library ignores variables such as LD_PRELOAD. Rules that ask are "safe"; rules that do not are "unsafe". The path /tmp/evil.so is only an illustration.
Demo is tightly confined. Its helper runs under a different profile, and it may do things demo may not. When demo executes the helper, the profile changes, but the environment comes along: every variable demo chose arrives in the new program. Now suppose demo has been taken over. It sets LD_PRELOAD, and the dynamic loader pulls a library of demo's choosing into the helper. That's demo's code, running with the helper's permissions. AppArmor's answer is one flag, raised at exec, that tells the new program not to trust its environment. Whether a rule raises it is what safe and unsafe mean, and the capital P in this rule is one way to ask.
Details and sources
Details
execvepasses the caller's environment to the new program unchanged. AppArmor does not filter it; it can only mark the exec as secure.- A safe rule (
Px,Cx,Ux, or the keywordsafe) asks for that mark when the exec changes profile. An unsafe rule (px,cx,ux, orunsafe) does not. - In the kernel the mark is requested in the exec hook when the rule's unsafe bit is clear (domain.c:776-784). Read from the source, not observed on a running kernel.
- The manual page's wording for
Ux: AppArmor sets "ld.so(8) secure-execution mode" to "clear environment variables such as LD_PRELOAD, similar to setuid programs" (apparmor.d.pod:974-977). - Which variables are ignored is the C library's list (see ld.so(8)); it is in neither source tree.
LD_PRELOADis the usual example. /tmp/evil.soon the slide is an illustration, not a file from either tree.
Read more
- apparmor.d(5) Access Modes Details.
- apparmor.d(5) ux - Unconfined execute mode: the warning about
LD_PRELOAD. - wiki: sanitized_helper.
- Exec modes.
02 Two ways to say it
Uppercase P, C, U = safe; lowercase = unsafe. safe and unsafe before a rule override the case. change_profile [safe|unsafe] EXEC -> TARGET, takes the same keywords.
There are two spellings for the same bit. The short one is the case of the first letter: capital P, C or U is safe, lowercase is unsafe. The long one is a word, safe or unsafe, in front of the rule: after any qualifiers, and after the word file if you write it. Use the keyword and it decides, whatever the case of the letter. The same two keywords appear in change_profile rules, between the rule's name and the program path. And ix has just one form, with no safe version at all, for a reason we'll get to.
Details and sources
Details
- File rule:
[QUALIFIERS] [file] [safe|unsafe] PATH MODE [-> TARGET],or with the mode first:[QUALIFIERS] [file] [safe|unsafe] MODE PATH [-> TARGET],. change_profile [safe|unsafe] [EXEC PATH] [-> TARGET],.- Letter case of the first exec letter: safe
Px Cx Ux Pix Cix PUx CUx; unsafepx cx ux pix cix pux cux.ixhas one form. - The letters as the parser names them:
UNCONFINED = 'U',UNSAFE_UNCONFINED = 'u',PROFILE = 'P',UNSAFE_PROFILE = 'p',LOCAL = 'C',UNSAFE_LOCAL = 'c'(parser.h:198-203). safeandunsafeare keywords of the profile language (parser_misc.c:92-93).- Position, from the parser built from the AppArmor tree at 836052d21:
file unsafe /usr/bin/demo-helper Px,andaudit unsafe /usr/bin/demo-helper Px,are accepted;safe file /x Px,givessyntax error, unexpected TOK_FILE, expecting TOK_ID or TOK_MODE or TOK_SET_VAR;unsafe audit /x Px,givessyntax error, unexpected TOK_AUDIT, expecting TOK_ID or TOK_MODE or TOK_SET_VAR.
for AppArmor developers for security researchers
In the code
opt_exec_modeis empty,TOK_UNSAFEorTOK_SAFE(parser_yacc.y:1065-1067); it is used byfile_rule_tail(parser_yacc.y:1117-1130) and bychange_profile(parser_yacc.y:1648).
03 What "scrubbing" really is
A safe exec sets AT_SECURE for the new program; ld.so then runs in secure-execution mode. Which variables are ignored is decided by the C library, not by AppArmor. Read from the kernel source; not observed on a running kernel.
People say the environment gets scrubbed, but the kernel doesn't touch it. Here's what the code does. Demo executes its helper, and AppArmor's exec hook picks the new profile. The rule was the safe form, so AppArmor marks this exec as secure. The program loader copies that mark into a value called AT_SECURE, which every new program can read. The dynamic linker reads it, switches to secure execution mode, and ignores LD_PRELOAD and its relatives. Which variables those are is the C library's decision, not AppArmor's. With the lowercase form the mark stays off, and the variables are honoured.
Details and sources
Details
All of this is read from the kernel source; none of it was observed on a running kernel.
- The LSM hook is
bprm_creds_for_exec, implemented byapparmor_bprm_creds_for_exec. When the chosen rule is safe,profile_transitionsets*secure_exec = true(domain.c:776-784). - The hook then sets
bprm->secureexec = 1(domain.c:1070-1078). - The ELF loader copies the flag into the auxiliary vector of the new program:
NEW_AUX_ENT(AT_SECURE, bprm->secureexec);(binfmt_elf.c:262). - The dynamic linker of the new program reads the entry and switches to secure-execution mode; see ld.so(8) for the variables it then ignores. The list belongs to the C library and is in neither source tree.
- The kernel does not modify the environment.
- Separately, whenever the exec changes the label, safe or not, AppArmor asks for the
PER_CLEAR_ON_SETIDpersonality bits to be cleared (domain.c:1080-1089). - apparmor.d(5) says the kernel's "unsafe_exec routines" are invoked (apparmor.d.pod:974-977). The kernel has no function of that name; the mechanism is the
secureexecflag.
for security researchers
Attack surface
- The kernel does not remove or change any environment variable. A safe exec sets one flag,
bprm->secureexec, which reaches the new program asAT_SECURE(domain.c:1070-1078, binfmt_elf.c:262; read from the kernel source, not observed on a running kernel). What is ignored afterwards is the C library's decision, and the variables are still in the environment: code that reads the environment itself sees every one. AT_SECUREcovers only what the C library ties to it. Open file descriptors are a separate mechanism: when the exec changes the label to a confined one,aa_inherit_filesrevalidates the inherited descriptors against the new label (file.c:721, called at lsm.c:967), whether the rule was safe or unsafe.- Whenever the exec changes the label, safe or not, AppArmor asks for the
PER_CLEAR_ON_SETIDpersonality bits to be cleared (domain.c:1080-1089). ix, and anixfallback, do not set the flag: the test is skipped when the new label is the profile's own (domain.c:730-739). A learning profile created in complain mode is always unsafe (domain.c:767).- Lowercase
px,cx,pix,cix,puxandcuxare the unsafe forms and print no warning; only lowercaseuxdoes, and only on request. change_profile safe EXEC -> TARGET,compiled without stacking support prints "downgrading change_profile safe rule to unsafe" but the compiled rule is byte-identical to the rule with no keyword (run with the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel; parser_yacc.y:1663-1670). The warning describes what such a kernel does, not what the parser wrote.
for AppArmor developers for security researchers
In the code
- The parser's unsafe bit, 0x100 per half, becomes
AA_X_UNSAFEindfa_map_xindex(policy_compat.c:29-30). The test inprofile_transitionis!(perms.xindex & AA_X_UNSAFE).
04 The keyword overrides the case
unsafe PATH Px, equals PATH px,; safe PATH px, equals PATH Px,. An exec that stays in the same profile (ix, or an ix fallback) does not set AT_SECURE. The table is worked out from the kernel source; it was not measured on a kernel.
The keyword and the letter case drive one bit, and the keyword is applied last. So unsafe in front of capital Px gives you lowercase px. And safe in front of lowercase cx gives you capital Cx. The tree's own tests write the letters first, and that works too. Now, why is there no safe ix? Going by the code of the kernel, the flag is raised only when the exec lands in a different profile. With ix the profile stays, old and new program have the same rights, and there's nothing to protect. The same holds when a fallback mode ends up inheriting.
Details and sources
Details
- The keyword is applied after the mode word is read, so it overrides the letter case:
unsafe /a Px,equals/a px,;safe /a px,equals/a Px,. Each pair merges without a conflict (the parser was run on the fragments). - Mode-first spellings from the parser's tests:
unsafe px /foo6,,unsafe Px /foo7,(front_perms_ok_2.sd);unsafe cx /bin/bar,(simple_ok_cx_1.sd). - When
AT_SECUREis set, worked out from the kernel source and not measured: PxCxUx, a different profile or unconfined: set.pxcxux: not set.ix: not set, with or without a keyword.PixCix: set when a profile was found, not set after theixfallback.PUxCUx: set in both cases.- A learning profile created in complain mode: not set.
- A stacked label: set if the rule of any one profile asks.
- The reason for
ix: when the result is the profile's own label, the kernel jumps past the test (domain.c:730-739); otherwise the test is at domain.c:776-784. unsafe /a ix,is accepted, but together with a plain/a ix,it fails withhas merged rule /a with conflicting x modifiers, although the bit has no effect on anixexec.
Read more
- Exec modes: which exec lands in which profile.
- apparmor.d(5) px - Discrete Profile execute mode.
- Stacking.
for AppArmor developers for security researchers
In the code
unsafesets the bit in each half that has exec,safeclears it (parser_yacc.y:1122-1127).
05 safe and unsafe on change_profile
change_profile [safe|unsafe] EXEC -> TARGET,. Without a keyword the change at exec is safe in the kernel. The keywords require the exec path. The full rule is in syn-change-profile.
There's a second way to change profile at exec: the program asks for it itself. The rule that allows this is change_profile. The program path is the exec condition, and the target comes after the arrow. At run time demo calls aa_change_onexec, names the helper's profile, and then executes the helper. Here the default is the other way round from lowercase px: with no keyword, the exec is safe. Write unsafe to let the environment through. And the keywords need that exec condition, because an immediate change of profile involves no exec, so there's no new program to protect.
Details and sources
Details
- Rule:
change_profile [safe|unsafe] EXEC -> TARGET,. Tests:change_profile safe /usr/bin/bar,(safe_ok_2.sd);change_profile unsafe /usr/bin/bar -> unsafe,, where the word after->is a target calledunsafe(unsafe_ok_3.sd). - "safe is the default":
change_profile safe /onexec -> /bin/foo,andchange_profile /onexec -> /bin/foo,do not conflict (onx_no_conflict_safe1.sd). - The default holds when the feature
domain/stackis in the feature set the profile is compiled for (parser_main.c:1093-1095). Without it the parser only warns about an explicitsafe; the compiled rule is the same as with no keyword (run with the parser built from the tree at 836052d21), and by the comment at parser_yacc.y:1663-1670 kernels without stacking support only the unsafe behaviour. - libapparmor:
int aa_change_onexec(const char *profile);(apparmor.h:81). It sendsexec PROFILEas the task'sexecattribute (kernel.c:1088-1107): through thelsm_set_self_attrsyscall when available, else by writing/proc/<tid>/attr/apparmor/execor the older/proc/<tid>/attr/exec(kernel.c:997-1012, kernel.c:424-426). - Kernel, read and not run: the write reaches
aa_change_profile(args, AA_CHANGE_ONEXEC)(lsm.c:897-899). At the next execprofile_onexecsets the secure flag unless the rule's unsafe bit is set (domain.c:855-863). - An immediate change (
aa_change_profile()) involves no exec, so the keywords do not apply to it.
Read more
- The change_profile rule.
- aa_change_profile(2):
aa_change_onexec. - aa-exec(1).
- libapparmor: changing profile.
for AppArmor developers for security researchers
In the code
- The
change_profileaction: exec bits with an exec condition, the unsafe bits forunsafe, the downgrade warning (parser_yacc.y:1648-1675). - In the lexer
safeandunsafeare keywords in theCHANGE_PROFILE_MODEstate until->(parser_lex.l:593-603).
06 AA_EXEC_UNSAFE to bprm->secureexec for AppArmor developers for security researchers
AA_EXEC_UNSAFE (parser/immunix.h) → AA_X_UNSAFE → *secure_exec in profile_transition (linux:security/apparmor/domain.c:776-784) → bprm->secureexec → AT_SECURE.
In parse_sub_perms the lowercase cases set the unsafe bit and then fall through to the uppercase case. The keywords come afterwards, in file_rule_tail: one sets the bit in every half that has exec, the other clears it. The kernel maps the bit to AA_X_UNSAFE. profile_transition tests it once x_to_label has returned a label, and skips the test when that label is the profile's own, which is the ix case. With a stacked label, any one profile can raise the flag. A learning profile created in complain mode forces unsafe. And mind the caller: its local variable named unsafe actually holds "secure exec requested".
Details and sources
for AppArmor developers for security researchers
Details
AA_EXEC_UNSAFEis1 << 8per half (immunix.h:43);ALL_AA_EXEC_UNSAFEcovers both halves (immunix.h:91-92).parse_sub_perms: the lowercase cases settperms = AA_EXEC_UNSAFEand fall through to the uppercase case (parser_misc.c:628-629, parser_misc.c:649-651).file_rule_tail:unsafesets the bit in each half that has exec,safeclears it; a rule without exec gives "unsafe rule missing exec permissions" (parser_yacc.y:1117-1130).- Kernel:
dfa_map_xindexmaps 0x100 toAA_X_UNSAFE(policy_compat.c:29-30). profile_transition: the own-label case jumps to the audit step (domain.c:730-739); a learning profile forcesAA_X_UNSAFE(domain.c:767);*secure_exec = truewhen the bit is clear (domain.c:776-784).profile_onexechas the same test for a change requested for exec (domain.c:855-863).apparmor_bprm_creds_for_exec: the localbool unsafe(domain.c:994) is passed assecure_execto every profile of the label (domain.c:1032-1035) and becomesbprm->secureexec = 1(domain.c:1070-1078).create_elf_tables:NEW_AUX_ENT(AT_SECURE, bprm->secureexec)(binfmt_elf.c:262).
07 Messages about safe and unsafe
"unsafe rule missing exec permissions"; "Exec condition is required when unsafe or safe keywords are present"; px with Px on one path is "conflicting x modifiers". A downgrade of change_profile safe is a warning. All four were produced with the parser built from the tree.
The keywords only make sense on an exec. Put safe on a read rule and the parser says unsafe rule missing exec permissions, in those words whichever keyword you used. On change_profile the keyword needs the program path. A safe rule and an unsafe rule for the same path are two different exec modes, so the parser reports a conflict. And one warning to take seriously: when the feature set lacks stacking support, the parser warns that a change_profile rule you marked safe will be treated as unsafe by such a kernel. The compiled rule is the same as with no keyword. The tree's parser printed it for a file with no abi line.
Details and sources
Details
Messages of the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel. Errors are printed as AppArmor parser error for FILE in profile FILE at line N: MESSAGE.
safe /etc/demo/demo.conf r,:unsafe rule missing exec permissions. The text is the same for both keywords.change_profile unsafe -> demo-helper,:Exec condition is required when unsafe or safe keywords are present(test unsafe_bad_2.sd).change_profile unsafe a -> b,:Exec condition must begin with '/'.Pxandpxfor one path:profile demo: has merged rule PATH with conflicting x modifiers, with no line number, followed byERROR merging rules for profile demo, failed to load.- Warning
downgrading change_profile safe rule to unsafe due to lack of necessary kernel support: an explicitsafeonchange_profilewhen the featuredomain/stackis missing (parser_main.c:1093-1095). Classrule-downgraded(parser_main.c:282). Printed for a file with noabiline, not printed withabi <abi/5.0>,. - A
change_profilerule with no keyword is compiled the same way on such a feature set and prints nothing. - The
uxwarning is tied to the lowercase letter:unsafe /usr/bin/demo-helper Ux,has the effect ofuxand prints nothing.
for AppArmor developers for security researchers
In the code
- "unsafe rule missing exec permissions": parser_yacc.y:1120-1121.
- The downgrade warning: parser_yacc.y:1662-1665; the two
change_profileerrors: parser_yacc.y:1672-1675.
08 Where to go from here
Next: syn-exec-modes, syn-named-transitions, syn-change-profile, lib-change-profile, k-exec. Rule layout: syn-file-rules, syntax-map.
Here's the rule of thumb. When an exec crosses into a profile with different rights, use the uppercase form, unless you know the new program needs something from its environment. From here, the exec modes deck tells you which exec crosses into which profile, and named transitions adds the arrow. The change_profile decks cover the rule and the library call that asks for a change at the next exec. The kernel's exec deck shows the hook where the flag is set. And if you want to see where the keywords sit among the other parts of a rule, file rules and the syntax map are one step away.
Details and sources
Details
- Safe:
Px Cx Ux Pix Cix PUx CUx, or the keywordsafe. Unsafe: the lowercase forms, orunsafe. The keyword overrides the case. - A safe exec that changes profile sets
AT_SECUREfor the new program;ixand anixfallback never do (source of the kernel, not observed on a running kernel). change_profile EXEC -> TARGET,is safe without a keyword when the featuredomain/stackis available.- Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2), the kernel-rc2 (97d73c825).
Read more
Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the fragment, with the tree's abi/5.0 file as the kernel features and nothing loaded into a kernel; "ran" means the researcher ran a parser on the fragment, as recorded in the findings; "code" means the kernel source of mainline Linux 7.4 (7.4-rc2, 97d73c825) or the parser source was read, not run. Nothing on this page was observed on a running kernel: every statement about AT_SECURE is derived from the kernel source.
Grammar
FILE RULE: [QUALIFIERS] [file] [safe|unsafe] PATH MODE [-> TARGET] ,
[QUALIFIERS] [file] [safe|unsafe] MODE PATH [-> TARGET] ,
CHANGE PROFILE RULE: change_profile [safe|unsafe] [EXEC PATH] [-> TARGET] ,
- On a file rule the keyword needs an exec permission in
MODE. - On
change_profilethe keyword needsEXEC PATH. - Letter case of the first exec letter:
| Safe | Unsafe | Mode |
|---|---|---|
Px | px | profile transition |
Cx | cx | child profile transition |
Ux | ux | unconfined |
Pix Cix | pix cix | transition, falling back to ix |
PUx CUx | pux cux | transition, falling back to ux |
| (none) | ix | inherit: one form only |
The modes themselves: syn-exec-modes. Targets: syn-named-transitions.
Keywords
| Keyword | Position | Effect |
|---|---|---|
safe | after the qualifiers and after file; before the path or the mode | clears the unsafe bit of the rule: same as the uppercase letter |
unsafe | the same | sets the unsafe bit on the owner half and the other half where each has x: same as the lowercase letter |
- The keyword is applied after the mode string is read, so it overrides the letter case.
unsafe /a Px,and/a px,merge without a conflict, and so dosafe /a px,and/a Px,(ran). - Both orders of path and mode take the keyword:
unsafe px /foo6,,unsafe Px /foo7,(parser/tst/simple_tests/file/front_perms_ok_2.sd),unsafe cx /bin/bar,(parser/tst/simple_tests/xtrans/simple_ok_cx_1.sd). file unsafe /usr/bin/demo-helper Px,andaudit unsafe /usr/bin/demo-helper Px,are accepted (tree).- After
->in achange_profilerule the words are ordinary names:change_profile unsafe /usr/bin/bar -> unsafe,names a target calledunsafe(parser/tst/simple_tests/change_profile/unsafe_ok_3.sd).
When AT_SECURE is set
Derived from linux:security/apparmor/domain.c (code); not measured on a kernel.
| Rule | Result of the exec | AT_SECURE |
|---|---|---|
Px Cx Ux | a different profile, or unconfined | set |
px cx ux | a different profile, or unconfined | not set |
ix | the same profile | not set, with or without a keyword |
Pix Cix | a profile was found | set |
Pix Cix | ix fallback | not set |
pix cix | either | not set |
PUx CUx | a profile was found, or ux fallback | set |
pux cux | either | not set |
change_profile EXEC -> TARGET, and a change requested for the next exec | the target | set |
change_profile unsafe EXEC -> TARGET, and the same request | the target | not set |
| no exec rule, profile in complain mode | a learning profile is created | not set |
| a stacked label | each profile decides for itself | set if the rule of any one profile asks |
- An immediate change of profile (
aa_change_profile()) does not exec, and the keywords do not apply to it. See lib-change-profile. - The
change_profiledefault: without a keyword the rule is safe when the featuredomain/stackis in the feature set the profile is compiled for. Without that feature the parser only warns (parser/parser_yacc.y:1663-1670): the compiled rule is unchanged (tree: the-Soutput ofchange_profile safe X -> Y,equals that ofchange_profile X -> Y,and differs fromunsafe). The comment there says kernels without stacking support only the unsafe behaviour.
What the flag does
- AppArmor sets
bprm->secureexec; the ELF loader copies it into theAT_SECUREentry of the new program's auxiliary vector (code). - The kernel does not modify the environment. The C library of the new program reads
AT_SECURE; the manual describes the result as "ld.so(8) secure-execution mode" (parser/apparmor.d.pod:974-977). Which variables are ignored is the C library's list and is in neither tree;LD_PRELOADis the usual example. - Separately, whenever the exec changes the label, safe or not, AppArmor asks for the
PER_CLEAR_ON_SETIDpersonality bits to be cleared (code: linux:security/apparmor/domain.c:1080-1089).
Errors and warnings
Errors are printed as AppArmor parser error for FILE in profile FILE at line N: MESSAGE. The conflict comes from the later compile stage: it has no line number and is followed by ERROR merging rules for profile demo, failed to load.
| Message | Cause | Basis |
|---|---|---|
unsafe rule missing exec permissions | safe or unsafe on a file rule without x, such as safe /etc/demo/demo.conf r,; the text is the same for both keywords | tree |
Exec condition is required when unsafe or safe keywords are present | change_profile unsafe -> demo-helper, | tree |
Exec condition must begin with '/'. | change_profile unsafe a -> b, | tree |
profile demo: has merged rule PATH with conflicting x modifiers | Px and px (or any safe and unsafe pair) for one path | tree |
syntax error, unexpected TOK_FILE, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | safe file /x Px,: the keyword goes after file | tree |
syntax error, unexpected TOK_AUDIT, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | unsafe audit /x Px,: the keyword goes after the qualifiers | tree |
warning downgrading change_profile safe rule to unsafe due to lack of necessary kernel support | an explicit safe on change_profile when the feature domain/stack is missing; class rule-downgraded | tree: printed for a file with no abi line, not printed with abi <abi/5.0>, |
warning Unconfined exec qualifier (ux) allows some dangerous environment variables to be passed to the unconfined process; 'man 5 apparmor.d' for details. | a lowercase ux; class dangerous, shown with --warn=dangerous or --warn=all | tree |
- The downgrade warning is printed only for an explicit
safe. Achange_profilerule with no keyword compiles to the same bytes and prints nothing (tree). - The
uxwarning is tied to the lowercase letter.unsafe /usr/bin/demo-helper Ux,has the same effect asuxand prints nothing (tree);puxandcuxprint nothing either (code).
Known discrepancies
unsafe /a ix,is accepted. By the kernel code the bit has no effect on anixexec, yet the parser treats the rule as a different exec mode: together with a plain/a ix,it fails withhas merged rule /a with conflicting x modifiers(tree).- apparmor.d(5) says the kernel's "unsafe_exec routines" are invoked (parser/apparmor.d.pod:975, 1001, 1022). Mainline Linux 7.4 has no function of that name; the mechanism is the
secureexecflag described above. - The descriptions of parser/tst/simple_tests/xtrans/simple_bad_x_mods_first_35.sd and simple_bad_x_mods_first_36.sd say that in leading permissions "P and p are the same". The parser treats them as different in both spellings.
for AppArmor developers for security researchers
Code map
| Step | Where |
|---|---|
mode letters: cod_t::PROFILE = 'P', UNSAFE_PROFILE = 'p', LOCAL = 'C', UNSAFE_LOCAL = 'c', UNCONFINED = 'U', UNSAFE_UNCONFINED = 'u' | parser/parser.h:198-203 |
AA_EXEC_UNSAFE (0x100 per half), ALL_AA_EXEC_UNSAFE, AA_EXEC_BITS | parser/immunix.h:43, 89-92 |
parse_sub_perms: the lowercase cases set tperms = AA_EXEC_UNSAFE and fall through; the ux warning | parser/parser_misc.c:628-632, 649-651 |
keywords safe, unsafe; opt_exec_mode | parser/parser_misc.c:92-93; parser/parser_yacc.y:1065-1067 |
file_rule_tail: the keyword sets or clears the bit; "missing exec permissions" | parser/parser_yacc.y:1117-1130 |
change_profile action: AA_EXEC_BITS with an exec condition, ALL_AA_EXEC_UNSAFE for unsafe, the downgrade warning, the two errors | parser/parser_yacc.y:1648-1675 |
lexer: safe and unsafe are keywords in CHANGE_PROFILE_MODE until -> | parser/parser_lex.l:593-603 |
features_supports_stacking from domain/stack | parser/parser_main.c:1093-1095 |
process_dfa_entry: the bits go on the pair rule exec condition, NUL, target | parser/parser_regex.c:767-775 |
kernel: dfa_map_xindex maps 0x100 to AA_X_UNSAFE | linux:security/apparmor/policy_compat.c:29-30 |
profile_transition: the own-label case jumps past the test | linux:security/apparmor/domain.c:730-739 |
profile_transition: a learning profile forces AA_X_UNSAFE | linux:security/apparmor/domain.c:767 |
profile_transition: *secure_exec = true when the bit is clear | linux:security/apparmor/domain.c:776-784 |
profile_onexec: the same test for a change requested for exec | linux:security/apparmor/domain.c:837-863 |
apparmor_bprm_creds_for_exec: the local unsafe holds "secure exec requested"; one flag for all profiles of the label; bprm->secureexec = 1; PER_CLEAR_ON_SETID | linux:security/apparmor/domain.c:994, 1032-1035, 1070-1089 |
create_elf_tables: NEW_AUX_ENT(AT_SECURE, bprm->secureexec) | linux:fs/binfmt_elf.c:262 |
- Parser fixtures:
parser/tst/simple_tests/file/front_perms_ok_2.sd,parser/tst/simple_tests/xtrans/,parser/tst/simple_tests/change_profile/(safe_ok_*,unsafe_ok_*,safe_bad_*,unsafe_bad_*,onx_conflict_unsafe*,onx_no_conflict_safe*).
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- Exec modes — the modes whose case this deck explains
- Named exec transitions — exec rules with a target
- File rules — where the keywords sit in a file rule
RULE CLASSES
- change_profile rules — the other rule that takes safe and unsafe
LIBAPPARMOR
- aa_change_profile and onexec (no slides yet) — asking for a profile change at the next exec
IN THE KERNEL
- Exec and domain transitions — the exec hook that sets the flag