Child profiles
profiles inside profiles for application developers for security researchers
A profile declared inside another profile. It is loaded as parent//child and entered when the parent runs a program through a cx rule. A child has its own rules and may have its own attachment which only its parent's cx rules consult.
On the map: profile structure
▶ Watch this deck — 9 scenes, ~7 min
Worth seeing first
- Exec modes — cx, the exec mode that reaches a child profile
- The profile name — the profile keyword and name, reused inside a body
Part of journeys
- Hardening a privileged program, step 5 of 11 · previous: Writing rules for /sys and /proc · next: Capability rules
- Exec, transitions and labels, step 5 of 13 · previous: Named exec transitions · next: Hats
01 A helper that should get less
A child profile is a profile declared inside another profile. It is used when the parent starts a program through an exec rule with a c mode such as Cx.
Demo starts a helper, the worker. What should confine it? It could inherit demo's rules, but the worker needs less, and different things. It could have a profile of its own at the top level, but then that profile applies to the worker whoever starts it, and it fills the namespace with something only demo cares about. No profile at all is not an answer. The fourth option is a child profile: a profile written inside demo, named after it, and used only when demo is the one starting the program. The rule that starts the helper and the rules for the helper live in one file, inside one pair of braces.
Details and sources
Details
- Syntax:
profile NAME { RULES }written inside the body of another profile, and an exec rule in the parent with acmode, as in/usr/lib/demo/worker Cx -> worker,. - apparmor.d(5) calls it a subprofile or child profile: "subprofiles (aka child profiles) in a profile, limited only by kernel memory" (apparmor.d.pod:433-434). Its example profile has both the rule and the child:
/usr/bin/baz Cx -> baz,(apparmor.d.pod:2880) andprofile baz { ... }(apparmor.d.pod:2889-2896). - The exec modes that send the started program into a child are
cx,Cx,cix,Cix,cuxandCUx(apparmor.d.pod:865-905). - The child is loaded under the name
demo//worker, next to its parent, not as a top-level profile of its own. - Kernel, read and not run: the decision is made in the LSM hook
bprm_creds_for_exec, implemented byapparmor_bprm_creds_for_exec(lsm.c:1862, domain.c:985). For acmode the search is over the current profile's own children; for apmode over the namespace's top-level profiles (domain.c:603-611). - The program
demo, its worker and the profile are invented for the map. Nothing on this slide was observed on a running kernel.
Read more
- Profiles quick reference: child profiles on apparmor.net.
- apparmor.d(5), FORMAT: the grammar, where a child is a SUBPROFILE.
- Exec modes, hats.
for AppArmor developers for security researchers
In the code
- The grammar rule is
local_profile: TOK_PROFILE profile_base(parser_yacc.y:480-488). - The mode letters
candCsetAA_EXEC_LOCAL | AA_MAY_EXEC(parser_misc.c:649-687; the constant is at immunix.h:82).
02 The profile keyword, inside a profile
profile NAME [ATTACHMENT] [xattrs=( )] [+ identities=( )] [flags=( )] { rules } inside a profile body. The keyword is required. A child does not inherit its parent's rules.
The syntax is the one you already know. Inside the body of demo, write the keyword profile, a name, optionally an attachment and flags, and a body in braces. It's the same head as at the top level, with one difference. At the top level you may leave the keyword out when the name is a path. Inside a profile you may not, because a path at the start of a line there is the start of a file rule. Here is demo with its worker. Like a hat, a child inherits nothing: its body is all it has. And a child's body takes any rules, so children can contain children.
Details and sources
Details
- Form:
profile NAME [ATTACHMENT] [xattrs=( )] [+ identities=( )] [flags=( )] { RULES }, inside a profile body. There is no comma after the closing brace. - The keyword
profileis required inside a body. Without it,/usr/lib/demo/worker {is read as the start of a file rule and the parser built from the AppArmor tree at 836052d21 answerssyntax error, unexpected TOK_OPEN, expecting TOK_MODE(-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel). - The name is on the same line as the keyword. A new line between them gives
Lexer found unexpected character: '\n' (0xa) in state: SUB_ID(same parser, same options). - The attachment must begin with
/or a variable:Profile attachment must begin with a '/' or variable. - A child may have
xattrs; a hat may not (hat profiles can't use xattrs matches). - Nothing is inherited from the parent. The body is an ordinary profile body, so it may hold children and hats of its own.
- Fixtures in the parser's tests: local_profiles_ok1.sd has a child named by a path,
profile /bin/grep { }; local_named_profile_ok1.sd hasprofile true /bin/true { }, a name plus an attachment, next to a hat.
Read more
for AppArmor developers for security researchers
In the code
profile_base: TOK_ID opt_id_or_var opt_cond_list identities flags TOK_OPEN rules TOK_CLOSEis shared by top-level profiles, children and hats (parser_yacc.y:391-399);local_profileis at parser_yacc.y:480-488 and is added to a body byrules: rules local_profile(parser_yacc.y:836-843).- The attachment check is at parser_yacc.y:431-433; the hat rule with its xattrs check at parser_yacc.y:490-504.
- The scanner returns
TOK_PROFILEfor the keyword and enters theSUB_IDstate for the name (parser_lex.l:850, parser_lex.l:456-461). A bare path at the start of a rule isTOK_ID(parser_lex.l:838-841), which is why the keyword cannot be left out.
03 parent, two slashes, child
A child named worker in profile demo is demo//worker in listings, labels and logs. apparmor_parser -N prints the full names alphabetically. Inside the child, @{profile_name} expands to the full name.
What is the child called? In the file, just worker. Ask the parser for the names it would load, and you get demo//worker: the parent's name, two slashes, the child's. If you name a child with a path, the result has three slashes in a row, two for the separator and one from the path. It's legal, and a good reason to give children short names. The long form is the name the kernel knows: a running worker carries it as its label, and denials are filed under it, so that's what to search your logs for. One more thing about the listing: it's alphabetical, not in the order of your file.
Details and sources
Details
apparmor_parser -N(--names, "Dump names of profiles in input.") prints the full names without compiling or loading anything (parser_main.c:231, apparmor_parser.pod:102).- Run with the parser built from the AppArmor tree at 836052d21:
profile worker { }inprofile demo /usr/bin/demo { }is listed asdemo//worker;profile /usr/lib/demo/helper { }asdemo///usr/lib/demo/helper. - The listing and the load order are alphabetical, not file order: children and hats of one profile are kept in a sorted set (profilelist.h:28).
- With the parent in a namespace
nsthe fully qualified name is:ns://demo//worker(profile.h:462-470, read from the source). - Inside the child
@{profile_name}is the full name without the namespace (parser_variable.c:154-155; asserted by the tests at equality.sh:919-923). - Kernel, read and not run: the hierarchical name is built as
prefix//nameinaa_policy_init(lib.c:478-497). - Where the name shows up: the
profile=field of log records;/proc/<pid>/attr/apparmor/current(and the older/proc/<pid>/attr/current); andint aa_getcon(char **label, char **mode)orint aa_gettaskcon(pid_t target, char **label, char **mode)from libapparmor (apparmor.h:110-111). - apparmor.d(5) says "Subprofile names are limited to 974 characters" (apparmor.d.pod:434). No such limit was found in the parser source.
Read more
for AppArmor developers for security researchers
In the code
Profile::hname()returnsparent->hname() + "//" + name;fqname()adds:ns://(profile.h:454-470).- The name written into a child's binary profile is
get_name(false)(parser_interface.c:488-490).
04 Cx with an arrow: go to the child by name
/usr/lib/demo/worker Cx -> worker, runs the helper in demo//worker. The child is found by name, so it needs no attachment. A missing child is found out only at exec: "profile transition not found" (read from the kernel source, for a profile in enforce mode).
How does the worker end up in the child? Through an exec rule in demo: the path of the helper, the mode Cx, an arrow, and the child's name. The C says child, the x says execute. You write the short name. The parser stores the full one, demo//worker, and at exec time the kernel looks that profile up and starts the program in it. The child doesn't need an attachment for this, because the rule names it. And if no child of that name is loaded when the exec happens? The kernel refuses the exec and reports that the profile transition was not found.
Details and sources
Details
- Rule:
/usr/lib/demo/worker Cx -> worker,. The target is the child's short name; the man page example is/usr/bin/baz Cx -> baz,(apparmor.d.pod:2880). - The parser stores the string
demo//workerin the parent's exec table. Checked with the parser built from the AppArmor tree at 836052d21: the string is in the binary profile. - The parser does not check that the child exists:
Cx -> missing,compiles without a message (same parser,-Q -K --skip-kernel-load --warn=all). - The exec table has 16 slots, of which the first 4 are reserved, so a profile can name 12 different targets. One more gives
Profile NAME has too many specified profile transitions.(immunix.h:70, read from the source). - Kernel, read and not run:
x_table_lookupwalks the table entry and, for a child transition, callsaa_find_child(profile, name)(domain.c:523-559). - No child found, enforce mode: the exec is refused and the record carries
info="profile transition not found"(domain.c:740-751). In complain mode a learning profile is created instead and the exec goes on (the same lines). - With a fallback in the mode the exec is not refused:
cixcontinues in the parent (info="ix fallback"),cuxunconfined (info="ux fallback") (domain.c:616-637).
Read more
for AppArmor developers for security researchers
In the code
add_named_transitionbuilds the entry withsprintf(name, "%s//%s", prof->name, entry->nt_name)when the mode is acmode and the target has no namespace (block_rules.cc:474-520);add_entry_to_x_tablestarts at index(AA_EXEC_LOCAL >> 10) + 1and reuses an equal string (block_rules.cc:458-472).post_parse_profile_filecalls it for every entry with a target and prints the table-full error (block_rules.cc:576-611).prof->nameis the local name of the profile holding the rule, so a namedcx ->inside a child storeschild//target, not the full name; see "Known discrepancies" in the reference below.
05 Cx without an arrow: the child's attachment decides
A bare Cx searches the parent's children by attachment (or by a name equal to the path). A child's attachment is used only for such execs from its parent. Started from elsewhere, the program is matched against top-level profiles only, and runs unconfined if none of those attaches to it.
There's a second way in. Write Cx with no arrow, and the kernel does for the children of demo what it normally does for all profiles: it compares the program's path with each child's attachment and picks the match. So one rule with a glob can spread several helpers over several children. For that, each child needs an attachment, or a name that is itself the path. Keep in mind who looks at that attachment: only an exec from demo through a Cx rule. Start the same logger from a shell and the kernel searches the top-level profiles only. The child stays out of it, and the logger runs unconfined.
Details and sources
Details
- Rule:
/usr/lib/demo/* Cx,with no arrow. Each child that should be found needs an attachment (profile logger /usr/lib/demo/logger { }) or a name that is the path (profile /usr/lib/demo/helper { }). - Kernel, read and not run: for a
cmodex_to_labelcallsfind_attachover the current profile's children,profile->base.profiles; for apmode over the namespace's top-level profiles,ns->base.profiles(domain.c:603-611). find_attachcompares the program's path with each candidate's attachment and keeps the best match; a profile whose name equals the path also matches (domain.c:394-520, the name comparison at domain.c:485). Two equally good matches giveinfo="conflicting profile attachments"(domain.c:33).- An exec by an unconfined task searches
ns->base.profilesonly (domain.c:697-699). A child is not on that list, so its attachment is never consulted there. - No child matches:
cxrefuses the exec,cixcontinues in the parent,cuxruns unconfined (see the previous slide). - Fixture: local_named_profile_ok1.sd declares children with attachments,
profile true /bin/true { }.
Read more
- apparmor.d(5), Attachment Conditionals.
- Attachment: how the best match is chosen.
- Exec modes, exec in the kernel.
for AppArmor developers for security researchers
In the code
- The attachment, or a path-like name, is compiled into the child's
xmatchDFA byprocess_profile_name_xmatch(parser_regex.c:478-520); an invalid pattern givesInvalid profile name 'NAME' - bad regular expression. - The attachment is the optional second word of
profile_base(parser_yacc.y:388-391); its check is at parser_yacc.y:431-433. - In the kernel the packed exec index 3 becomes
AA_X_NAME | AA_X_CHILD(policy_compat.c:40-41); the flags are defined at file.h:58-62.
06 Child profile or hat?
Child profile: entered at exec through a cx rule, for a program you start. Hat: entered and left with aa_change_hat(), for part of your own program's work. change_hat on a child fails with "target not hat".
Children and hats look alike in the file, so here they are side by side. Both are nested rule sets named after the parent, and neither inherits anything. The difference is the door. A child is entered at exec: demo starts another program, and a rule in demo's profile sends it into the child. A hat is entered by the running program itself, with a library call, and left again with a token. So a child is for a helper program, and a hat is for a phase of your own program. The kernel keeps the doors apart: ask change_hat for a child declared with the profile keyword and the answer is "target not hat".
Details and sources
Details
- A hat is written
^NAME { }orhat NAME { }; a childprofile NAME { }. Both are loaded asparent//NAME, and the two share one set of names within a profile. - The hat's door is libapparmor:
int aa_change_hat(const char *subprofile, unsigned long magic_token)andint aa_change_hatv(const char *subprofiles[], unsigned long token)(apparmor.h:79-83).aa_change_hat(NULL, token)returns to the parent. - The call writes
changehat TOKEN^NAMEto the task's/proc/<tid>/attr/apparmor/current(or/proc/<tid>/attr/current) (kernel.c:1033, path formats at kernel.c:424-426). - Kernel, read and not run: the write arrives in
apparmor_setprocattr(lsm.c:943);change_hatlooks the name up among the profile's children and, when the profile found is not a hat, fails withinfo="target not hat"and EPERM (domain.c:1232-1243). - The child's door is exec: the
bprm_creds_for_exechook and acmode in the parent (domain.c:603-611). There is no way back: the started program keeps the child's label and its own execs follow the child's rules. - A profile that declares a child or a hat receives the implied rules that
change_hatneeds:/proc/*/attr/apparmor/ r,,/sys/module/apparmor/parameters/enabled r,and/proc/[0-9]*/attr/{apparmor/,}current w,(profile.cc:78-89, block_rules.h:27; rule dump made with the released parser 5.0.2). - Whether an exec rule
cx -> NAMEcan enter a hat was not determined.
Read more
for AppArmor developers for security researchers
In the code
- The hat rule is
hat: hat_start profile_baseand setsprofile_flag_t::HAT;local_profileis the same without the flag (parser_yacc.y:480-504).
07 Local profiles and the exec table for AppArmor developers for security researchers
local_profile: TOK_PROFILE profile_base; storage in defined_hats; add_named_transition() stores name//target in the exec table; kernel x_to_label() uses find_attach() over the profile's children or x_table_lookup().
For developers. The grammar calls a child a local profile: the profile token and then profile_base, the same rule a hat uses, minus the hat bit. Children and hats are stored together in defined_hats, which is where the duplicate check lives. For an exec rule with a target and no namespace, add_named_transition glues the profile's name and the target together with two slashes and puts the result in the exec table, which has sixteen slots with four reserved. Each child is serialized as its own blob. In the kernel, x_to_label handles both doors: the child search goes through find_attach over the profile's own children, and table entries are parsed as labels.
Details and sources
for AppArmor developers for security researchers
Details
- Grammar:
local_profile: TOK_PROFILE profile_base(parser_yacc.y:480-488);rules: rules local_profilecallsadd_hat, with the messageAssert: 'local_profile rule' returned NULL.(parser_yacc.y:836-843). - Storage:
block::add_hatsetshat->parentand callsadd_to_known_hats, which inserts intodefined_hatsand exits withMultiple definitions for profile NAME exist,bailing out.on a duplicate (block.cc:137-155). - Exec table:
add_entry_to_x_tableandadd_named_transition(block_rules.cc:458-520), driven bypost_parse_profile_file(block_rules.cc:576-611).AA_EXEC_COUNTis 16 (immunix.h:70);AA_EXEC_LOCALisAA_EXEC_MOD_0 | AA_EXEC_MOD_1, index 3 (immunix.h:82), and the loop starts at index 4. - If the target of a
cx ->rule equals the rule's own path the rule is turned back into the unnamed form (block_rules.cc:492-496). - Serialization:
load_flattened_hatsloadsdefined_hatsas a policy list after the parent (parser_policy.c:84-89, called from parser_interface.c:783-785); each child's blob carries its full name (parser_interface.c:488-490). - Kernel, read and not run: packed exec index 3 is mapped to
AA_X_NAME | AA_X_CHILD(policy_compat.c:40-41). x_to_label(domain.c:574-650):AA_X_TABLEgoes tox_table_lookup, which usesaa_find_childwhenAA_X_CHILDis set andaa_label_parseotherwise (domain.c:523-559);AA_X_NAMEgoes tofind_attachoverprofile->base.profilesorns->base.profiles.- A table entry that begins with
&is a stack: the entry is looked up and then theAA_X_NAMEsearch runs as well (domain.c:597-600).
Read more
08 Missing keyword, missing child
Inside a profile the keyword profile is required. Children and hats of one profile share one set of names. The parser does not verify Cx -> targets; a wrong name shows up at exec as "profile transition not found".
Four mistakes. Leave out the keyword and write a path and a brace, as you could at the top level, and the parser expects permissions after the path: syntax error at the brace. An attachment that doesn't start with a slash is refused in so many words. Two children with one name, or a child and a hat with one name, stop the parser. The fourth is the one that reaches production: a typo in the target of a Cx rule. The parser doesn't check that the child exists. Everything loads, and the first exec of the helper is refused with profile transition not found.
Details and sources
Details
- Messages from the parser built from the AppArmor tree at 836052d21 (
-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel). The full form isAppArmor parser error for FILE in profile FILE at line N: MESSAGE. - A path and a brace without the keyword:
syntax error, unexpected TOK_OPEN, expecting TOK_MODE. profile worker bin { }:Profile attachment must begin with a '/' or variable.- Two children, or a child and a hat, with one name:
Multiple definitions for profile NAME exist,bailing out.(block.cc:137-146). The released parser 5.0.2 words itMultiple definitions for hat NAME in profile (null) exist,bailing out. Cx -> missing,compiles without a message; the parser does not verify that the target exists.- Kernel, read and not run: with no child of that name loaded the exec fails with
info="profile transition not found"when the parent is in enforce mode (domain.c:740-751). The record'sprofile=is the parent andname=the program's path. - With the parent in complain mode the same exec is allowed and runs in a learning profile created for it (the same lines).
- Reloading a parent with
apparmor_parser -rafter deleting a child from the file leaves the old child loaded (read from the kernel source, policy.c:1066-1091:__replace_profilemoves children that the new version does not replace over to it).
Read more
for AppArmor developers for security researchers
In the code
- The attachment check: parser_yacc.y:431-433. The place where a child is added to its parent's body: parser_yacc.y:836-843.
- Targets are entered into the exec table without a lookup (block_rules.cc:576-611).
09 Around child profiles
The mode letters: syn-exec-modes. The arrow: syn-named-transitions. The sibling: syn-hats. The kernel's side: k-exec.
Two parts of that exec rule have decks of their own. The exec modes deck explains Cx and its relatives, including what happens when no child is found and the rule has a fallback. The named transitions deck covers the arrow and everything a target can be. Hats are next door, and the profile name deck shows how the long names are built. And if you want to watch the kernel pick the child, the attachment deck explains the matching, and the exec deck in the kernel district follows the same call from the inside.
Details and sources
Details
- A child profile is
profile NAME { }inside a profile, loaded asparent//NAME. - It is entered at exec through
cx,Cx,cix,Cix,cuxorCUx: by name with-> NAME, by attachment without the arrow. - A missing child is reported only at exec, as
info="profile transition not found"(the kernel, domain.c:746). - 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 (-Q -K --skip-kernel-load --warn=all, nothing loaded into a kernel); "5.0.2" means the released parser 5.0.2 was run; "code" means the kernel or parser source was read, not run. Everything said here about what happens at exec is "code".
Grammar
CHILD: 'profile' NAME [ATTACHMENT] [xattrs=( ... )] { '+' identities=( ... ) } [flags=( ... )] '{' rules '}'
- Written inside the body of another profile. The head is the one a top-level profile has.
- The keyword
profileis required. At the top level a path may stand alone as a profile head; inside a body a path at the start of a line begins a file rule. - The name is on the same line as the keyword.
ATTACHMENTmust begin with/or a variable.rulesis an ordinary profile body, so children may contain children and hats, to any depth.- No comma after the closing brace.
- Nothing is inherited from the parent: the child's body is its whole rule set.
- Other names for the same thing: "subprofile" in apparmor.d(5), "local profile" in the grammar.
Keywords
| Token | Meaning |
|---|---|
profile | inside a body: starts a child profile |
// | the separator in loaded names: parent//child. Not written in the child's head |
cx Cx cix Cix cux CUx | the exec modes that send the started program into a child of the current profile: syn-exec-modes |
-> | names the child in an exec rule: syn-named-transitions |
Names
For children of profile demo /usr/bin/demo { }:
| In the file | Loaded name | Basis |
|---|---|---|
profile worker { } | demo//worker | tree |
profile logger /usr/lib/demo/logger { } | demo//logger | tree |
profile /usr/lib/demo/helper { } | demo///usr/lib/demo/helper | tree |
profile inner { } inside worker | demo//worker//inner | tree |
any of these when demo is in namespace ns | :ns://demo//worker | code |
apparmor_parser -Nprints the full names. Children and hats of one profile are listed and loaded in alphabetical order, not file order (tree).- The full name is what the kernel is given, what a task confined by the child carries as its label, and the
profile=field of its log lines (code). - Inside a child
@{profile_name}expands to the full name without the namespace (asserted byparser/tst/equality.sh). - A child named by a path does not get the "file paths as profile names" deprecation warning that a top-level profile gets (code).
Two ways in
| Rule in the parent | How the child is found | The child needs |
|---|---|---|
/usr/lib/demo/worker Cx -> worker, | by name: the parser stores demo//worker in the profile's exec table (tree: the string is in the binary profile) and the kernel looks that name up at exec (code) | nothing more |
/usr/lib/demo/* Cx, | by search: the kernel matches the program's path against the attachments of the parent's children (code) | an attachment, or a name that is the path |
- A child's attachment is consulted only for this search. An exec through
px, or by an unconfined task, searches the namespace's top-level profiles (code). - Among several matching children the choice follows the rules for top-level profiles: attachment.
- The parser does not check that the target of
Cx ->exists:Cx -> missing,compiles without a message (tree). - No child found at exec (code):
| Mode | Result |
|---|---|
cx, Cx | the exec is refused; the log line carries info="profile transition not found" |
cix, Cix | the program runs in the parent profile |
cux, CUx | the program runs unconfined |
cx, Cx with the parent in complain mode | a learning profile is created and the exec goes on |
The modes and their fallbacks: syn-exec-modes.
Child or hat
| Child profile | Hat | |
|---|---|---|
| Written as | profile NAME { } | ^NAME { } or hat NAME { } |
| Loaded as | parent//NAME | parent//NAME |
| Entered | at exec, by a cx rule of the parent | at any time, by the program calling aa_change_hat() |
| Left | not at all: the started program keeps the child's label; its own execs follow the child's rules | aa_change_hat(NULL, token) |
| May have an attachment | yes | yes (what it is for was not determined) |
May have xattrs=( ) | yes | no |
change_hatto a child declared withprofilefails withinfo="target not hat"(code).- Whether an exec rule
cx -> NAMEcan enter a hat was not determined. - Hats: syn-hats.
What a parent with children gets
A profile that declares a child or a hat receives three implied file rules (tree, rule dump):
/proc/*/attr/apparmor/ r,
/sys/module/apparmor/parameters/enabled r,
/proc/[0-9]*/attr/{apparmor/,}current w,
They exist for change_hat. A parent that has only child profiles gets them too, although change_hat cannot enter such a child. A child without hats or children of its own does not get them. Details: syn-hats.
Loading and reloading
As for hats, see syn-hats:
- Each child leaves the parser as a binary profile of its own, written after its parent under the full name.
- Reloading a parent with
-rafter deleting a child from the file leaves the old child loaded (code). apparmor_parser -Rremoves the parent, and the kernel removes its children with it (code).
Errors and warnings
| Message | Cause |
|---|---|
syntax error, unexpected TOK_OPEN, expecting TOK_MODE | a path and a brace inside a profile, without the keyword profile (tree) |
Profile attachment must begin with a '/' or variable. | profile worker bin { } (tree) |
Multiple definitions for profile NAME exist,bailing out. | two children, or a child and a hat, with one name in the same profile (tree). 5.0.2 words it Multiple definitions for hat NAME in profile (null) exist,bailing out. |
Lexer found unexpected character: '\n' (0xa) in state: SUB_ID | a new line between profile and the name; the character is printed raw (tree) |
Profile NAME has too many specified profile transitions. | more named exec targets than the exec table holds: 16 slots of which 4 are reserved (code) |
FILE: Invalid profile name 'NAME' - bad regular expression | the attachment, or a path-like name, is not a valid pattern (code) |
Assert: 'local_profile rule' returned NULL. | internal check in the grammar (code) |
kernel: info="profile transition not found" | plain cx or Cx and no child found at exec, enforce mode (code) |
kernel: info="target not hat" | change_hat to a child that is not a hat (code) |
Known discrepancies
- Named
cx ->inside a child. The prefix the parser puts before the target is the local name of the profile that holds the rule, not its full name. Forprofile a { profile b { /z cx -> c, profile c { } } }the exec table ofa//bholdsb//c, while the grandchild is loaded asa//b//c(tree, strings of the binary profile). By the code of mainline Linux 7.4 the entry is resolved from the namespace root, whereb//cdoes not exist unless a top-level profilebhas a childc, so the rule does not reach the grandchild. Not run on a kernel. One level of nesting, as in this deck, is not affected. - A top-level profile written as
a//band a childbnested inaget the same loaded name. The parser keeps them in different lists and its duplicate check does not see the clash (code). What a running kernel does with the two was not determined. - apparmor.d(5) says "Subprofile names are limited to 974 characters". No such limit was found in the parser.
- A named transition to another profile's child,
Cx -> other//name, can be rewritten by the parser into a transition to a child of the current profile whennameequals the rule's path (code; listed in the project's bug notes as a suspected parser bug).
for AppArmor developers for security researchers
Code map
| Step | Where | |
|---|---|---|
local_profile: TOK_PROFILE profile_base; rules: rules local_profile | parser/parser_yacc.y:480-488, 836-843 | |
profile_base: name, attachment, xattrs, identities, flags, body | parser/parser_yacc.y:391-399 | |
| attachment check | parser/parser_yacc.y:431-433 | |
hat rule: the same profile_base plus the HAT flag | parser/parser_yacc.y:490-504 | |
profile keyword pushes SUB_ID; the name token | parser/parser_lex.l:278, 456-461, 850 | |
a bare path inside a body is TOK_ID | parser/parser_lex.l:838-841 | |
block::add_to_known_hats, block::add_hat: defined_hats, duplicate check | parser/block.cc:137-155 | |
| ordered set of children and hats | parser/profilelist.h:28 | |
hname(), fqname() | parser/profile.h:454-470 | |
c modes set AA_EXEC_LOCAL | parser/parser_misc.c:649-687; parser/immunix.h:82 | |
add_entry_to_x_table, add_named_transition: sprintf("%s//%s", prof->name, nt_name) | parser/block_rules.cc:458-520 | |
post_parse_profile_file: every entry with a target; the table-full error | parser/block_rules.cc:576-611 | |
AA_EXEC_COUNT 16 | parser/immunix.h:70 | |
| attachment or path-like name compiled to the child's xmatch | parser/parser_regex.c:478-520 | |
@{profile_name} | parser/parser_variable.c:154-155 | |
implied rules for a profile with defined_hats | parser/profile.cc:78-89 | |
serialization: name written is hname(); load_flattened_hats | parser/parser_interface.c:488-490, 783-785; parser/parser_policy.c:84-89 | |
| kernel: packed exec index 3 becomes `AA_X_NAME \ | AA_X_CHILD` | linux:security/apparmor/policy_compat.c:40-41 |
kernel: x_table_lookup(), aa_label_parse() | linux:security/apparmor/domain.c:523-559 | |
kernel: x_to_label(); find_attach() over profile->base.profiles for cx, ns->base.profiles for px | linux:security/apparmor/domain.c:574-650, 603-611 | |
kernel: find_attach(); a name equal to the path matches | linux:security/apparmor/domain.c:394-520, 485 | |
| kernel: "profile transition not found"; learning profile in complain mode | linux:security/apparmor/domain.c:740-751 | |
| kernel: "target not hat" | linux:security/apparmor/domain.c:1232-1243 | |
kernel: hname built as prefix//name | linux:security/apparmor/lib.c:478-497 | |
| kernel: parent lookup on load; children kept on replacement | linux:security/apparmor/policy.c:523-544, 1071-1091, 1293-1323 |
post_parse_profileruns when the innerprofile_baseis reduced (parser/parser_yacc.y:450), beforeadd_hatsetsparent(parser/parser_yacc.y:836-843), sohname()is not yet usable inadd_named_transition: the origin of the first known discrepancy above.- If the target of a
cx ->rule equals the rule's own path, the rule is turned back into the unnamed form (parser/block_rules.cc:492-496). - Fixtures:
parser/tst/simple_tests/profile/local/local_profiles_ok1.sd,local_named_profile_ok1.sd;parser/tst/simple_tests/xtrans/x-conflict.sd. Man page example: parser/apparmor.d.pod:2880, 2889-2896.
Roads from here
START HERE
- The profile language at a glance — back to the whole profile on one page
ATTACHMENT, NAMESPACES, STACKING
- Profile attachment — how a path picks a profile at exec
FILE ACCESS
- Exec modes — cx and its fallbacks ix and ux
- Named exec transitions — the arrow and what a target may be
PROFILE HEAD
- The profile name — how parent//child names are built
PROFILE STRUCTURE
- Hats — the nested profile entered without exec
- Comments and line structure — braces and bodies
IN THE KERNEL
- Exec and domain transitions — the exec path in the kernel
INSIDE THE PARSER
- The grammar — the grammar rule shared by profiles and children