change_profile rules

switching profiles for application developers for administrators for security researchers

A change_profile rule lets a confined task ask the kernel to move it to another profile either immediately or at its next exec. The rule names the target after an arrow and may name the executable the change is tied to. With an exec condition the change is safe by default which means the new program starts in secure execution mode. The rule only gives permission. The task asks through libapparmor.

On the map: rule classes

▶ Watch this deck — 9 scenes, ~5 min

Worth seeing first

Part of journeys

01 demo becomes the worker

CHANGE_PROFILE RULES demo (child) demo aa_change_profile("demo//worker") kernel = -1 EACCESwithout a rule change_profile -> demo//worker, line 23, in profile demo demo (child) demo//worker the rule permits; the program has to ask

change_profile -> TARGET, lets a task under this profile ask to continue under TARGET.

Demo has prepared everything with its broad profile, and the child process that will do the risky work should give those rights up. It asks the kernel: move me to the worker profile. The kernel checks demo's own profile first, because a profile that could be left at will wouldn't confine anything. Line twenty-three is the permission: change_profile, arrow, the target. Note what the rule doesn't do: it doesn't switch anything by itself. The program has to make the call.

Details and sources

Details

  • The calls are int aa_change_profile(const char *profile) and int aa_change_onexec(const char *profile) (apparmor.h:80-81). They write changeprofile NAME to /proc/self/attr/apparmor/current (or /proc/self/attr/current) and exec NAME to the exec file next to it.
  • The kernel reads the commands at lsm.c:882-904 and calls aa_change_profile (domain.c:1484-1660). aa-exec -p PROFILE -- CMD uses the same interface.
  • Feature files: /sys/kernel/security/apparmor/features/domain/change_profile, change_onexec and stack (apparmorfs.c:2604-2606).
  • An unconfined task needs no rule (domain.c:295-299).
  • change_profile -> demo//worker, is line 23 of demo's profile; it compiles with no warning (run with the tree's parser). The program demo and its profile are invented for the map.
  • Kernel statements are read from the kernel source and were not run.

02 An exec condition, an arrow, a target

GRAMMAR QUALIFIERSchange_profilesafe | unsafeEXEC-> TARGET, change_profile -> demo//worker, line 23 of demo's profile change_profile /usr/lib/demo/worker -> demo//worker, EXEC: a path; starts with / or a variable change_profile -> demo//*, the target is a pattern change_profile, any target -> &demo//worker a stack: see Stacking -> :ns:demo another namespace: see Namespaces owner is refused; allow, deny, prompt and priority= are accepted
The syntax diagram of a change_profile rule: optional qualifiers, the word change_profile, optional safe or unsafe, an optional exec condition, an optional arrow and target, a comma. Examples: demo's line; a rule with the exec condition /usr/lib/demo/worker; a rule whose target is a pattern; change_profile alone for any target. A target starting with an ampersand asks for a stack and a target with colons names another namespace. owner is refused.

[QUALIFIERS] change_profile [[safe|unsafe] EXEC] [-> TARGET],. No target means any profile.

Three optional parts follow the keyword. First an exec condition: the path of a program, with safe or unsafe in front if you like. Then the arrow and the target, which is a profile name and may be a pattern. Leave the target out and it means any profile. Leave the exec condition out and the change isn't tied to a program. The target can also start with an ampersand, which asks for a stack, or name a profile in another namespace. Those two have their own decks.

Details and sources

Details

  • EXEC begins with / or @{. safe and unsafe are allowed only with EXEC.
  • TARGET may be a variable, a glob or an alternation (-> {new_profile1,new_profile2},). A rule without a target means any profile. A target literally named safe or unsafe is read as a name after the arrow: change_profile -> safe, is accepted.
  • change_profile -> b, and change_profile -> &b, are different permissions: the & stays in the compiled target. What a stack target means is in stacking; a target in another namespace is in namespaces.
  • Seats: allow, deny, prompt and priority= are accepted, and audit is accepted by the grammar (run with the tree's parser). owner and other are refused: owner change_profile -> demo//worker, gives owner conditional not allowed on change_profile rules.
  • Known discrepancy, on the bug list as "audit change_profile is never audited, and the warning blames the kernel": audit change_profile ... is accepted and the audit flag is not compiled; see the details of "What demo and the log see".
  • Known discrepancy, on the bug list as "owner { change_profile -> x, } is accepted although owner change_profile is an error".
  • Known discrepancy, on the bug list as "change_profile -> :ns://name, compiles to a pattern the kernel never walks".
  • Known discrepancy, on the bug list as "Without an abi rule, xattrs= is dropped silently and change_profile -> &x is refused "by the kernel"": in a profile with no abi rule, change_profile -> &x, is refused with The current kernel does not support stacking of named transitions: &x, whatever the kernel supports (run with the tree's parser).
  • Known discrepancy, on the bug list as "Stack targets (&name) are validated and feature-gated only for change_profile, and only without stacking support". See Known bugs.
  • Examples in the tree: a_ok_3.sd, stacking_ok_3.sd; apparmor.d(5): apparmor.d.pod:2216, apparmor.d.pod:2235.

for AppArmor developers for security researchers

In the code

03 Two ways to ask: now, or at the next exec

TWO REQUESTS demo under demo aa_change_profile("demo//worker") under demo//worker change now demo under demo aa_change_onexec("demo//worker") still under demo execve("/usr/lib/demo/worker") under demo//worker change at exec change_profile -> demo//worker, one rule permits both change at exec replaces whatever the profile's exec rules would have chosen for that program

aa_change_profile() changes now; aa_change_onexec() changes at the next exec. Every change_profile rule grants both.

There are two ways for a program to use this permission. Change now: the calling task continues under the new profile from the next instruction on. Or change at exec: the task says which profile it wants, keeps running as it is, and the switch happens when it executes its next program. The second is the cleaner one, because the new program starts fresh under the new profile, and nothing of the old one's memory comes along. One rule in the profile permits both forms.

Details and sources

Details

  • Commands on the current attribute file: changeprofile NAME (change now), permprofile NAME (test only) and stack NAME. On the exec attribute file: exec NAME and stack NAME (lsm.c:882-904).
  • The kernel's requests are AA_MAY_CHANGE_PROFILE and AA_MAY_ONEXEC. A change now replaces the label (domain.c:1622-1628); a change at exec stores the target for the next exec (domain.c:1629-1636). At exec the stored target is checked again against the executable (domain.c:837-862).
  • Every change_profile rule grants both requests.
  • Known discrepancy, on the bug list as "Kernel: the unprivileged-unconfined restriction is decided at exec time for change_onexec, so a task that drops CAP_MAC_OVERRIDE after asking is stacked with unconfined". It applies where kernel.apparmor_restrict_unprivileged_unconfined is on; see Known bugs.
  • "Nothing of the old one's memory comes along" is the general meaning of exec, said as motivation; it is not a finding from the source trees.
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

In the code

  • The parser's note that a change_profile rule also implies the on-exec permission: block_rules.cc:598.

04 Tying the change to one program

EXEC CONDITION change_profile -> demo//worker, after aa_change_onexec("demo//worker"): execve("/usr/lib/demo/worker")allowed execve("/bin/sh")allowed a shell under the worker profile change_profile /usr/lib/demo/worker -> demo//worker, with an exec condition execve("/usr/lib/demo/worker")allowed execve("/bin/sh")refused change_profile /usr/lib/demo/worker, one word after the keyword is the exec condition: any target, for this program

change_profile EXEC -> TARGET, permits the change at exec only for executables matching EXEC.

A rule with only a target says: you may become the worker, whatever you execute next. The worker profile then confines a shell just as well as the worker binary, which may not be what you meant. Put the program's path before the arrow and the change at exec is tied to it: executing the worker binary is fine, executing anything else is refused. And watch the short form: one word after the keyword is the exec condition, not the target.

Details and sources

Details

  • "Allowed" and "refused" on the slide are derived from the compiled rules and the kernel's check at exec (domain.c:837-862); they were not run. At exec the kernel matches the name of the executable, requires the on-exec permission, and then matches the target. When the executable does not match, the refusal's info is no change_onexec valid for executable (domain.c:840).
  • The exec condition does not limit a change now: a rule with a condition still permits aa_change_profile() to the target.
  • change_profile /usr/lib/demo/worker, compiles with any profile as the target (run with the tree's parser).
  • Kernel statements are read from the kernel source and were not run.

for security researchers

Attack surface

  • change_profile -> T, lets the task enter T with any executable. change_profile, lets it enter any profile visible to it, less restrictive ones included, subject to the kernel's other checks: the target must exist, a tracer must be allowed to trace the new label (domain.c:1581-1585), and under no_new_privs the change must not reduce confinement (domain.c:1612-1619).
  • A glob target (-> demo//*) grows with every profile loaded later that matches.

for AppArmor developers for security researchers

In the code

  • The three compiled entries (parser_regex.c:764-784): TARGET with change-now and on-exec; EXEC, or any absolute path when there is none, with on-exec; EXEC NUL TARGET with on-exec plus the exec bits. With the condition of the slide they are demo//worker, /usr/lib/demo/worker and /usr/lib/demo/worker\x00demo//worker (run with the tree's parser).

05 safe is the default

SAFE AND UNSAFE change_profile /usr/lib/demo/worker-> demo//worker, the same as writing safe before the path worker LD_PRELOAD LD_LIBRARY_PATH AT_SECURE = 1 the loader ignores them change_profile unsafe /usr/lib/demo/worker-> demo//worker, worker LD_PRELOAD LD_LIBRARY_PATH AT_SECURE = 0 they pass through safe and unsafe need an exec condition change_profile safe /usr/lib/demo/worker -> demo//worker,change_profile unsafe /usr/lib/demo/worker -> demo//worker, profile demo: has merged rule demo//worker with conflicting x modifiers

With an exec condition the exec sets AT_SECURE unless the rule says unsafe. safe and unsafe need an exec condition.

When a change happens at exec, the new program inherits its environment from a process that was under another profile. Safe, which is what you get when you write nothing, tells the kernel to start the program in secure execution mode: the dynamic loader then ignores variables like LD_PRELOAD, exactly as it does for a setuid program. Unsafe turns that off, for programs that need their environment. Both words only make sense with an exec condition. And you can't have a safe and an unsafe rule for the same program and target.

Details and sources

Details

  • At exec the kernel sets secure execution when the permissions it matched lack the unsafe bit (domain.c:855-862). Secure execution is what sets AT_SECURE for the new program; what the loader then ignores is in safe and unsafe exec.
  • Run with the tree's parser, a rule with an exec condition compiles as safe unless it says unsafe; a rule without an exec condition carries no exec bits at all.
  • The two rules at the bottom of the slide, in one profile, give profile demo: has merged rule demo//worker with conflicting x modifiers, followed by ERROR merging rules for profile demo, failed to load (run with the tree's parser). Examples in the tree: the onx_conflict_unsafe_*.sd files in parser/tst/simple_tests/change_profile.
  • Known discrepancy, on the bug list as ""downgrading change_profile safe rule to unsafe" does not describe what is compiled": when the feature set lacks domain/stack (a profile with no abi rule), a safe rule prints the warning downgrading change_profile safe rule to unsafe due to lack of necessary kernel support (class rule-downgraded, off by default) and is compiled exactly like a rule with no mode, without the unsafe bits.
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

In the code

  • The compiled permissions of the exec pair: 0x40004001 for safe, 0x40404101 for unsafe (run with the tree's parser). The conflict check: block_rules.cc:325. The warning, with no change to the rule: parser_yacc.y:1663-1665.

06 What demo and the log see

THE DENIAL demo aa_change_profile("demo//worker") = -1 EACCES apparmor="DENIED" operation="change_profile" class="file" profile="demo"name="demo//worker" pid=825 comm="demo" target="demo//worker" change_profile -> demo//worker, the target goes after the arrow aa_change_onexec("demo//wrker") = -1 ENOENT apparmor="DENIED" operation="change_onexec" class="file" info="label not found" error=-2profile="demo" name="demo//wrker" pid=825 comm="demo" the profile must be loaded: no rule fixes a name that does not exist under no_new_privs a request that would loosen confinement fails with EPERM and is not logged

Missing rule: EACCES, operation="change_profile" / "change_onexec" with target=. Missing profile: ENOENT, info="label not found".

If the rule is missing, the call fails with EACCES, and the record says operation="change_profile", or change_onexec, with the target. Put that target after the arrow. A different failure looks similar: the target profile isn't loaded, or is misspelt. Then the error is no such entry, and info says label not found. A rule won't help: the profile has to exist. And one silent case: a task that has set no_new_privs can only move to tighter confinement. That refusal isn't logged at all.

Details and sources

Details

  • Both records on the slide are assembled from fixtures, with demo's values, which are illustrative. The first follows testcase_changeprofile_02.in (apparmor="DENIED" operation="change_profile" profile="php-fpm" name="php-fpm//webapp" pid=825 comm="php-fpm" target="php-fpm//webapp") with class="file" after operation as in the newer testcase_changeprofile_03.in. The second follows change_onexec_gl636.in (operation="change_onexec" class="file" info="label not found" error=-2 profile=... name="snap.firefox.firefox" pid=6209 comm="snap-confine").
  • The operations are change_profile, change_onexec, stack and stack_onexec. error=-2 is ENOENT.
  • In complain mode a missing target is replaced by a learning profile (domain.c:1536-1558).
  • The no_new_privs refusal of the request returns EPERM, next to the comment not an apparmor denial per se, so don't log it (domain.c:1612-1619). A change that is refused for the same reason at exec time is logged with info="no new privs" (domain.c:1050-1056); an older record of that kind is change_onexec_lp1648143.in.
  • A tracer must be allowed to trace the new label (domain.c:1581-1585).
  • Known discrepancy, on the bug list as "audit change_profile is never audited, and the warning blames the kernel": audit change_profile ... is accepted and the audit flag is not compiled; the only notice is Warning kernel does not support audit modifier for change_profile rule., shown with --warn=rule-downgraded or --warn=all (run with the tree's parser; a deny change_profile rule prints the same warning).
  • Known discrepancy, on the bug list as "Kernel: changeprofile &name is audited as operation="change_profile"": a changeprofile &name request is logged as operation="change_profile". See Known bugs.
  • Kernel statements are read from the kernel source and were not run.

07 Three strings in the file rules for AppArmor developers for security researchers

IN THE PARSER change_profile /usr/lib/demo/worker -> demo//worker, demo//worker 0xc0000000change now + on exec /usr/lib/demo/worker 0x40000000on exec /usr/lib/demo/worker \x00 demo//worker 0x40004001on exec + exec bits (safe) /proc/*/attr/apparmor/ r /proc/*/attr/{apparmor/,}{current,exec} w /sys/module/apparmor/parameters/enabled r added to any profile with a change_profile rule change now: match the target from the file start state, AA_MAY_CHANGE_PROFILE at exec: match the exec name, AA_MAY_ONEXEC, NUL, match the target the audit argument of all three entries is 0

parser_regex.c:764-784 adds target, exec and exec NUL target to the file DFA; block_rules.cc:602-608 adds the /proc/*/attr/ rules; domain.c:837-862, 1448-1469 match them.

A change_profile rule isn't a rule_t. The grammar builds a file style entry whose name is the target and whose extra field is the exec condition. Then process_dfa_entry turns that into three entries of the file rules: the target with both permissions; the exec pattern with on exec; and exec pattern, NUL, target, with on exec and the exec bits, where safe and unsafe live. The profile also gets write access to its own attribute files in proc, which is how the request is made. The kernel matches the target for a change now, and the exec name, a NUL, and the target at exec.

Details and sources

for AppArmor developers for security researchers

Details

  • The grammar action: parser_yacc.y:1650-1691. The three entries: parser_regex.c:717-785. The implied file rules: block_rules.cc:527-570, block_rules.cc:602-608.
  • Dumps from the tree's parser (-D rule-exprs): demo's line 23 gives demo//worker 0xc0000000, /[^/\x00][^\x00]* 0x40000000 and /[^/\x00][^\x00]*\x00demo//worker 0x40000000; with the exec condition of the slide, demo//worker 0xc0000000, /usr/lib/demo/worker 0x40000000 and /usr/lib/demo/worker\x00demo//worker 0x40004001; with unsafe the last entry is 0x40404101; change_profile, gives [^\x00]*, /[^/\x00][^\x00]* and /[^/\x00][^\x00]*\x00[^\x00]*. A target &demo//worker keeps the & in the string.
  • The implied rules are /proc/*/attr/apparmor/ and /sys/module/apparmor/parameters/enabled with read, and /proc/*/attr/{apparmor/,}{current,exec} with write (run with the tree's parser).
  • Only domain/stack is consulted for feature gating (parser_main.c:1093-1095); without it the target is split into namespace and name (parser_regex.c:742-759).
  • Kernel: the check at exec (domain.c:837-862); the check of a request (domain.c:1448-1469).
  • Kernel statements are read from the kernel source and were not run.

for security researchers

Attack surface

  • The implied file rules give every profile with a change_profile rule write access to /proc/*/attr/{apparmor/,}{current,exec} for any pid in the path pattern. What a write there can do is decided by the kernel's own checks on the attribute interface; see who can change policy.
  • The audit flag is dropped (known discrepancy, on the bug list as "audit change_profile is never audited, and the warning blames the kernel"; see "What demo and the log see"), so allowed profile changes cannot be audited per rule.

for AppArmor developers for security researchers

Read more

08 Mistakes and their messages

MISTAKES change_profile demo//worker, Exec condition must begin with '/'. the target needs the arrow change_profile safe -> demo//worker, Exec condition is required when unsafe or safe keywords are present owner change_profile -> demo//worker, owner conditional not allowed on change_profile rules safe and unsafe rules for one program and target profile demo: has merged rule demo//worker with conflicting x modifiers change_profile -> demo//wrker, accepted: the parser does not check that the target exists
Five change_profile rules. A target without the arrow is read as an exec condition and refused. safe without a program is refused. owner is refused. A safe and an unsafe rule for the same program and target conflict. A misspelt target is accepted because the parser does not check that the target exists.

The target goes after ->. safe/unsafe need an exec condition. Target names are not checked at compile time.

Forget the arrow and the parser reads your target as an exec condition, and complains that it doesn't start with a slash. Safe or unsafe without a program is an error. Owner isn't allowed. Safe and unsafe for the same pair conflict. And a misspelt target is accepted, because profiles can be loaded later. You'll find out at run time, with label not found.

Details and sources

Details

  • The parser prints an error as AppArmor parser error for FILE in profile FILE at line N: MESSAGE; the slide shows MESSAGE. Rows 1 to 4 were run with the tree's parser. The conflict of row 4 is printed without a line number and is followed by ERROR merging rules for profile demo, failed to load.
  • Row 5, change_profile -> demo//wrker,, is accepted (run with the tree's parser). That it fails at run time with label not found is derived from the kernel source.
  • In a profile with no abi rule a & target gives The current kernel does not support stacking of named transitions: &x. Known discrepancy, on the bug list as "Without an abi rule, xattrs= is dropped silently and change_profile -> &x is refused "by the kernel""; the check itself is on the bug list as "Stack targets (&name) are validated and feature-gated only for change_profile, and only without stacking support".
  • Two warnings are in the class rule-downgraded, which is off by default: the warning that says a safe rule was downgraded (see "safe is the default"), and Warning kernel does not support audit modifier for change_profile rule.
  • The tree has 512 example files under parser/tst/simple_tests/change_profile.

09 Asking, stacking, namespaces

ROADS change_profile -> demo//worker, the worker runs under its own profile lib-change-profile the calls stacking -> &name namespaces -> :ns:name syn-exec-modes changes without asking syn-safe-unsafe secure execution syn-hats change_hat
change_profile rules in the centre with roads to lib-change-profile, to stacking and namespaces, and to syn-exec-modes, syn-safe-unsafe and syn-hats.

change_profile permits; libapparmor asks. & targets: Stacking. :ns: targets: Namespaces.

The worker is now running under its own profile. How a program makes the call is in the libapparmor deck. A target with an ampersand adds a profile on top of the current one, which is stacking. A target with colons crosses into another namespace. And if you'd rather not change the program at all, exec rules can switch profiles without it asking.

Details and sources

Details

  • [QUALIFIERS] change_profile [[safe|unsafe] EXEC] [-> TARGET],: no target means any profile; no exec condition means any program.
  • The rule permits; the task asks with aa_change_profile() or aa_change_onexec().
  • Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2) and the kernel tree named on the page. The kernel behaviour was read from the source, not observed on a running kernel.

Read more

Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the line (-Q -K --skip-kernel-load --warn=all, -D rule-exprs for compiled forms), with nothing loaded into a kernel; "code" means the parser source or the kernel source was read, not run. Nothing here was observed on a running kernel.

Grammar

CHANGE_PROFILE RULE:  [QUALIFIERS] change_profile [ [safe|unsafe] EXEC ] [ -> TARGET ] ,
QUALIFIERS:           [priority=N] [audit] [allow|deny|prompt]
  • EXEC is a path pattern; it begins with / or @{ (tree).
  • safe and unsafe need EXEC; with EXEC and neither word the rule is safe (tree).
  • TARGET is a profile name; it may be a glob, an alternation or a variable. No TARGET means any profile (tree).
  • One word after the keyword is EXEC, not TARGET: change_profile /usr/lib/demo/worker, (tree).
SeatOn a change_profile rule
priority=taken
audittaken by the grammar: the audit flag is not compiled (known discrepancy)
allow, deny, prompttaken; prompt is in syn-prompt
owner, otherrefused: owner conditional not allowed on change_profile rules (tree)

Rule and what it permits

RuleChange nowChange at execSecure execution at that exec
change_profile,to any profileto any profile, with any executablethe rule carries no exec bits
change_profile -> T,to Tto T, with any executablethe rule carries no exec bits
change_profile EXEC -> T,to Tto T, only when executing EXECyes (safe is the default)
change_profile EXEC,to any profileto any profile, only when executing EXECyes
change_profile unsafe EXEC -> T,to Tto T, only when executing EXECno

The first three columns follow from the compiled entries (tree) and the kernel's checks (linux:security/apparmor/domain.c:837-862, 1448-1469, code); nothing was run on a kernel. The kernel sets secure execution when the matched permissions lack the unsafe bit (linux:security/apparmor/domain.c:855-862). By that test a change at exec under the first two rows would also get secure execution, because an entry without EXEC cannot carry the unsafe bit; this is derived from the code and was not run.

Target forms

FormExampleMeaning
name-> demo//workerthat profile
glob or alternation-> demo//*, -> {a,b}every profile whose name matches, also ones loaded later
variable-> @{profile_name}//workerexpanded by the parser
&name-> &demo//workera stack: see stacking
:ns:name-> :ns:demoa profile in another namespace: see namespaces

Requests and interfaces

libapparmor callAttribute file and commandKernel requestOperation in the log
aa_change_profile(name)/proc/self/attr/apparmor/current: changeprofile NAMEAA_MAY_CHANGE_PROFILEchange_profile
aa_change_onexec(name)/proc/self/attr/apparmor/exec: exec NAMEAA_MAY_ONEXECchange_onexec
aa_stack_profile(name)current: stack NAMEstack
aa_stack_onexec(name)exec: stack NAMEstack_onexec

The commands are read at linux:security/apparmor/lsm.c:882-904 (code). The calls are in lib-change-profile.

The log records and the caller's errors

The caller getsWhenThe record
EACCESno rule permits the changeoperation="change_profile" or "change_onexec", name= and target= the target
ENOENTthe target profile is not loadedinfo="label not found" error=-2, name= the target
EPERMunder no_new_privs, a request that would reduce confinementnone

A tracer that may not trace the new label also refuses the change, with info="ptrace prevents transition" (linux:security/apparmor/domain.c:50-82, 1581-1585, code); see stacking.

Records from the tree (libraries/libapparmor/testsuite/test_multi/testcase_changeprofile_02.in and change_onexec_gl636.in):

apparmor="DENIED" operation="change_profile" profile="php-fpm" name="php-fpm//webapp" pid=825 comm="php-fpm" target="php-fpm//webapp"
apparmor="DENIED" operation="change_onexec" class="file" info="label not found" error=-2 profile="/usr/lib/snapd/snap-confine" name="snap.firefox.firefox" pid=6209 comm="snap-confine"

Errors and warnings

RuleMessage
change_profile demo//worker,Exec condition must begin with '/'.
change_profile safe -> demo//worker,Exec condition is required when unsafe or safe keywords are present
owner change_profile -> demo//worker,owner conditional not allowed on change_profile rules
a safe and an unsafe rule for the same EXEC and TARGETprofile demo: has merged rule demo//worker with conflicting x modifiers, then ERROR merging rules for profile demo, failed to load
change_profile -> demo//wrker,none; the target is not checked
audit change_profile -> demo//worker, with --warn=rule-downgradedWarning kernel does not support audit modifier for change_profile rule.
a safe rule in a profile with no abi rule, --warn=rule-downgradedwarning downgrading change_profile safe rule to unsafe due to lack of necessary kernel support
change_profile -> &x, in a profile with no abi ruleThe current kernel does not support stacking of named transitions: &x

All rows are from the tree's parser.

for AppArmor developers for security researchers

In the parser and the kernel

  • No rule class of its own: the grammar builds a file-style entry with the target as name and EXEC as the extra field (parser/parser_yacc.y:1650-1691).
  • Three entries in the file rules (parser/parser_regex.c:764-784): TARGET with change-now and on-exec (0xc0000000); EXEC, or /[^/\x00][^\x00]* when absent, with on-exec (0x40000000); EXEC NUL TARGET with on-exec and the exec bits (0x40004001 safe, 0x40404101 unsafe, 0x40000000 without EXEC) (tree).
  • Implied file rules for /proc/*/attr/apparmor/, /proc/*/attr/{apparmor/,}{current,exec} and /sys/module/apparmor/parameters/enabled (parser/block_rules.cc:602-608).
  • Kernel: aa_change_profile (linux:security/apparmor/domain.c:1484-1660); a change now replaces the label, a change at exec stores the target; at exec the kernel matches the exec name, requires AA_MAY_ONEXEC, steps over a NUL and matches the target (linux:security/apparmor/domain.c:837-862).

for AppArmor developers for security researchers

Known discrepancies

None of these is taught as intended behaviour. All are on the bug list as confirmed; see Known bugs.

  • audit change_profile ... is accepted and the audit flag is not compiled; the only notice is a warning that is off by default (tree).
  • Without an abi rule, change_profile -> &x is refused with a message that names the kernel (code).
  • change_profile -> :ns://name, compiles to a pattern the kernel never walks (code).
  • Stack targets (&name) are validated and feature-gated only for change_profile, and only without stacking support (code).
  • owner { change_profile -> x, } is accepted although owner change_profile is an error (tree).
  • A changeprofile &name request is audited as operation="change_profile" (code).
  • "downgrading change_profile safe rule to unsafe" does not describe what is compiled: the warning is printed and the rule is compiled like one with no mode (tree).
  • Kernel: the unprivileged-unconfined restriction is decided at exec time for change_onexec, so a task that drops CAP_MAC_OVERRIDE after asking is stacked with unconfined (kernel; on the bug list).

Roads from here

START HERE

ATTACHMENT, NAMESPACES, STACKING

FILE ACCESS

RULE CLASSES

  • The all rule — the rule that does not include change_profile

PROFILE STRUCTURE

  • Hats — change_hat which is the lighter relative
  • Child profiles — the child profile demo changes to

SECURITY · threat model and limits

LIBAPPARMOR

IN THE KERNEL