From AARE to regular expressions

globs become patterns for AppArmor developers for security researchers for application developers

The last step of the front end rewrites each AppArmor glob as the regular expression string the backend receives. By then quotes and numeric escapes are decoded and variables are expanded and repeated slashes are removed. One loop with three flags does the rewriting. Its errors come after parsing and have no line number.

On the map: inside the parser

▶ Watch this deck — 8 scenes, ~6 min

Worth seeing first

Part of journeys

01 After parsing, the name is still a glob

FROM AARE TO REGULAR EXPRESSIONS scanparsepost-processconvertbackend entry name /etc/demo/** convert the string for the backend /etc/demo/[^/\x00][^\x00]* what reaches it · how it walks a pattern · what it escapes · what it reports the meaning of each wildcard is in the globbing deck one scene here is for anyone who has met a "Regex grouping error"
Five stages in a row: scan, parse, post-process, convert and backend, with convert highlighted; below, an entry whose name is /etc/demo/** goes through the conversion and comes out as the string /etc/demo/[^/\x00][^\x00]*, which the backend receives

convert_aaregex_to_pcre() (parser/parser_regex.c:118) rewrites one AppArmor glob as a regular expression string. It runs last in the front end, once per pattern.

After parsing, demo's first rule is an entry in memory, and its name is still what you typed: a path that ends in two stars. The backend can't use that. It builds state machines from regular expressions, and a glob isn't one. So the last thing the front end does is translate. One function does it, and its output is the exact string the backend receives. What each wildcard means is in the globbing deck. This deck is the function itself: what reaches it, how it walks a pattern, what it escapes, and what it reports. One scene is for anyone who has met a regex grouping error.

Details and sources

Details

  • pattern_t convert_aaregex_to_pcre(const char *aare, int anchor, int glob, std::string& pcre, int *first_re_pos) (parser_regex.c:118-119). "AARE" is the AppArmor regular expression syntax of profiles: the globs *, **, ?, [ ] and { }. The name says PCRE; the output is the smaller regular expression syntax that the backend's own parser reads.
  • Order of work for one profile: post_process_profile adds implied rules, expands variables, applies aliases, merges rules and then calls process_profile_rules (parser_policy.c:127-165), which converts the attachment and every rule and hands the strings to the backend (parser_regex.c:1215-1283).
  • For a file rule the call is in process_dfa_entry (parser_regex.c:648-688).
  • The profile followed in this deck (file demo3.sd):
abi <abi/5.0>,
include <tunables/global>
profile demo /usr/bin/demo {
  /etc/demo/** r,
  audit deny @{HOME}/.ssh/** rw,
  /usr/bin/[a-z]* ix,
}
  • Dumps are from the parser built from the AppArmor tree at 836052d21, run with -Q -K -D rule-exprs (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set. Each aare: line is printed by the conversion itself.

Read more

02 Three things are already done for AppArmor developers for security researchers

WHAT REACHES THE FUNCTION before after the scanner"/etc/demo/my file"->/etc/demo/my file quotes stripped, escapes decoded post-processing@{HOME}/.ssh/**->{/home//*,/root}/.ssh/** a variable is now braces with alternatives filter_slashes{/home//*,/root}/.ssh/**->{/home/*,/root}/.ssh/** /etc//demo///conf->/etc/demo/conf //etc/x->//etc/x exactly two leading slashes are kept convert_aaregex_to_pcre(entry->name, 0, glob_default, tbuf, &pos)
Three earlier steps and what each did to a pattern: the scanner removed quotes; post-processing turned @{HOME}/.ssh/** into {/home//*,/root}/.ssh/**; filter_slashes turned that into {/home/*,/root}/.ssh/** and /etc//demo///conf into /etc/demo/conf, but kept //etc/x

Before the conversion: processunquoted (scanner), process_variables (post-processing) and filter_slashes (parser/parser_regex.c:61-96). A leading // survives.

The function doesn't see your profile text. Three things have already happened to a pattern. The scanner stripped quotes and decoded escapes, keeping a backslash only in front of glob characters. Post-processing expanded variables: the @{HOME} variable is no longer a variable, it's a pair of braces with two alternatives inside, so the conversion needs no idea what a variable is. And just before the call, filter_slashes squeezes every run of slashes into one. Expansion often leaves doubles behind, like the one after home here. One exception: exactly two slashes at the very start are kept; the code comment calls that a namespace of its own.

Details and sources

Details

  • The scanner: processunquoted decodes escapes and keeps a backslash before a decoded * ? [ ] { } ^ , \ (parser_misc.c:468-509); see The lexer.
  • Variables: block_rules::process_variables expands the name and the link name of every entry and calls expand_variables of every rule object (block_rules.cc:393-416). A variable with several values becomes {a,b}. The -d dump shows the entry at that point: ({/home//*,/root}/.ssh/**); tunables/home defines @{HOME} as @{HOMEDIRS}/*/ /root/ and @{HOMEDIRS} as /home/.
  • filter_slashes (parser_regex.c:61-96) rewrites the string in place: a / that follows a / is dropped; when the string starts with exactly two slashes they are both kept ("special case for linux // namespace", lines 70-74). A single trailing slash is kept, although the comment above the function says trailing slashes are filtered.
  • For a file rule: filter_slashes(entry->name) unless the entry is a change_profile rule, then the conversion (parser_regex.c:658-660); the same for the link target (parser_regex.c:699-701).
  • filter_slashes is also applied to the attachment (parser_variable.c:76), mount points and devices (mount.cc:649-653), D-Bus paths (dbus.cc:190) and unix socket addresses (af_unix.cc:174-178).
  • The right-hand column of the slide is what -D rule-exprs prints after aare:; //etc/x and /etc//demo///conf are from a profile written for this deck.
  • Dumps are from the parser built from the AppArmor tree at 836052d21, run with -Q -K -D rule-exprs (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set. Each aare: line is printed by the conversion itself.
  • Known discrepancy, by title: "A variable after a prefix of only slashes keeps its leading /, so the rule starts with // and never matches".

03 One loop and three flags for AppArmor developers for security researchers

ONE LOOP, THREE FLAGS {/home/*,/root}/.ssh/** bEscape ingrouping incharclass reads writes {(ingrouping = 1 *[^/\x00]*a comma follows, not a slash: no mandatory character ,|inside braces: an alternative })ingrouping = 0 .\.a regex character: always escaped **[^/\x00][^\x00]*a whole component: one mandatory character first (/home/[^/\x00]*|/root)/\.ssh/[^/\x00][^\x00]*
The pattern {/home/*,/root}/.ssh/** converted character by character: open brace to parenthesis, star to a run without slash, comma to bar, close brace to parenthesis, dot to backslash dot, two stars to one mandatory character and a run of anything; three flag boxes bEscape, ingrouping and incharclass

bEscape, ingrouping and incharclass (parser/parser_regex.c:132-134) are all the state there is. {/home/*,/root}/.ssh/** becomes (/home/[^/\x00]*|/root)/\.ssh/[^/\x00][^\x00]*.

The function is a single loop over the characters with three pieces of memory: was the last character a backslash, how deep are we in braces, are we inside brackets. Watch the deny rule go through. The open brace becomes a parenthesis and the depth goes to one. The star becomes any run without a slash; it gets no mandatory first character, because a comma follows it, not a slash. The comma, being inside braces, becomes a bar. The close brace closes the group. The dot is a regex character, so it's escaped. And the final two stars, a whole path component, get the mandatory character and then anything.

Details and sources

Details

  • State: bool bEscape, int ingrouping, int incharclass and int grouping_count[MAX_ALT_DEPTH] (parser_regex.c:132-135). The loop is while (error == error_type::no_error && *sptr) with one switch (*sptr) (parser_regex.c:149-405); bEscape is cleared at the end of every pass except the one that reads the backslash.
  • The cases: \ (parser_regex.c:152-168), * (parser_regex.c:169-229), ? (parser_regex.c:231-254), [ and ] (parser_regex.c:256-280), { and } (parser_regex.c:282-330), , (parser_regex.c:332-355), ^ and $ (parser_regex.c:358-366), ., +, |, (, ) and every other character (parser_regex.c:374-402).
  • The mandatory character: when the output so far ends in / and the run of stars is followed by / or the end of the pattern, [^/\x00] is written first (parser_regex.c:178-205). The test looks only for / or the end. A star that is followed by , or } inside a group does not get it, so {/home/*,/root}/.ssh/** also describes /home//.ssh/...; a path with an empty component does not reach the matcher from the kernel, so nothing more is matched in practice (derived).
  • The first line of the dump for this rule: aare: {/home/*,/root}/.ssh/** -> (/home/[^/\x00]*|/root)/\.ssh/[^/\x00][^\x00]*.
  • The output string is appended to the caller's buffer; the function never clears it.
  • Dumps are from the parser built from the AppArmor tree at 836052d21, run with -Q -K -D rule-exprs (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set. Each aare: line is printed by the conversion itself.

Read more

04 Escaping runs in two directions for AppArmor developers for security researchers

ESCAPING aare: /etc/demo/a+b(c)|$^ -> /etc/demo/a\+b\(c\)\|\$\^ regex characters that are not globs: always escaped aare: /etc/demo/a\*b -> /etc/demo/a\*baare: /etc/demo/a\{b\} -> /etc/demo/a\{b\} an escaped glob character stays escaped for the next parser aare: /etc/demo/a\?b -> /etc/demo/a?baare: /etc/demo/c\,d -> /etc/demo/c,d these two mean nothing to the regex parser: the backslash goes any other backslash: a valid escape such as \x00 is kept, the rest is dropped with a warning
Dump lines of the conversion: a+b(c)|$^ gets a backslash before each of its regex characters; backslash star and escaped braces stay escaped; backslash question mark and backslash comma lose the backslash

. + | ( ) are always escaped, ^ $ outside a class. \* \[ \] \{ \} stay escaped; \? and \, become ? and ,.

Escaping runs in two directions. Some characters mean nothing in a profile but a lot in a regular expression: dot, plus, bar, parentheses, and outside brackets, caret and dollar. The function always escapes those, so a dot in a file name stays a dot. Then the reverse case: you escaped a glob character. A \* must still be a literal star for the next parser, so it stays escaped; so do escaped brackets and braces. An escaped question mark or comma can drop its backslash, because the regex parser gives those no meaning. Any other backslash that isn't a valid escape is dropped too, with a warning.

Details and sources

Details

  • Always escaped: ., +, |, (, ) (parser_regex.c:374-380). Escaped outside a character class and copied inside one: ^ and $ (parser_regex.c:358-366).
  • An escaped glob character is written with its backslash: \* (parser_regex.c:170-177), \[ and \] (parser_regex.c:257-260, parser_regex.c:269-272), \{ and \} (parser_regex.c:283-286, parser_regex.c:307-310). \\ is written as \\ (parser_regex.c:152-168).
  • \? is written as ? (parser_regex.c:232-238); \, as , outside a class and as \, inside one (parser_regex.c:333-345).
  • A backslash before any other character (parser_regex.c:382-402): when str_escseq accepts what follows as an escape sequence (\x00, \000, \d000 and the letter escapes), the sequence is copied with its backslash for the backend to decode; otherwise the backslash is dropped and, with warnings of class format enabled, the parser prints Character q was quotedunnecessarily, dropped preceding quote ('\') character.
  • The scanner has already decoded most escapes, so what reaches this function with a backslash is mainly the set * ? [ ] { } ^ , \ (see The lexer).
  • The unit tests of the function list the expected output for each of these inputs (parser_regex.c:1566-1699).
  • Dumps are from the parser built from the AppArmor tree at 836052d21, run with -Q -K -D rule-exprs (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set. Each aare: line is printed by the conversion itself.
  • Known discrepancies, by title: "Parser messages with wrong text or wrong line" (the missing blank in "quotedunnecessarily", and the line number of that warning, which is the last line of the file); "Character classes: \^ loses its escape, and * or ? inside [...] are expanded".

Read more

05 Braces are counted, brackets are copied for AppArmor developers for security researchers

{ } AND [ ] aare: /etc/demo/{a,b}/** -> /etc/demo/(a|b)/[^/\x00][^\x00]*aare: /etc/demo/{c,} -> /etc/demo/(c|) ingrouping: the depth, below 50 · grouping_count[depth]: the commas seen no comma: an error · a comma and nothing: an empty alternative aare: /etc/demo/file[0-9].conf -> /etc/demo/file[0-9]\.confaare: /etc/demo/[^a]x -> /etc/demo/[^a]x incharclass: characters are copied; { } and , are literal inside [^a] is copied as written: it can match a slash known discrepancy: * and ? inside [ ] are still expanded
Dump lines: {a,b} becomes (a|b); {c,} becomes (c|) with an empty alternative; the class [0-9] is copied and the dot after it escaped; the negated class [^a] is copied unchanged

{a,b} becomes (a|b), nested fewer than 50 deep, with at least one comma per group. [...] is copied; a negated class written in a profile can match /.

Braces and brackets are where the function must remember its place. For braces it keeps a depth, which must stay below fifty, and for each level a count of commas. A group with no comma is refused, so braces around a single word are an error. But a comma with nothing after it is fine: an empty alternative, which means optional. Brackets are simpler. The function marks that it's inside a class and copies the characters through, leaving it to the backend's regex parser. Inside, braces and commas are just characters. And a negated class is copied as written, so unlike a question mark it can match a slash.

Details and sources

Details

  • {: ingrouping++; at 50 (MAX_ALT_DEPTH, parser_regex.c:122) the error Regex grouping error: Exceeded maximum nesting of {}; otherwise the comma count of the new level is cleared and ( is written. So 49 levels are the most that convert: a pattern nested 49 deep compiles and one nested 50 deep is refused (both run with the tree's parser) (parser_regex.c:282-304).
  • , inside a group and outside a class: the count of the current level goes up and | is written; elsewhere the comma is copied (parser_regex.c:346-353).
  • }: a count of zero is the error Regex grouping error: Invalid number of items between {}; then ingrouping-- and ) (parser_regex.c:306-330). So {conf} is refused and {c,} gives (c|).
  • At the end of the pattern an open group or class is the error Regex grouping error: Unclosed grouping or character class, expecting close } (parser_regex.c:411-416).
  • [: incharclass = 1 and the character is copied; ] clears it (parser_regex.c:256-280). Inside a class {, } and , are copied (parser_regex.c:288-290, parser_regex.c:312-314). The class is parsed later by the regular expression grammar of the backend (parse.y:109-150).
  • The globs *, ** and ? are written as classes that exclude / (and NUL); a class written by the author has no such exclusion, so [^a] matches / as well.
  • Dumps are from the parser built from the AppArmor tree at 836052d21, run with -Q -K -D rule-exprs (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set. Each aare: line is printed by the conversion itself.
  • Known discrepancy, by title: "Character classes: \^ loses its escape, and * or ? inside [...] are expanded". With the tree's parser /etc/demo/[a*]z is converted to /etc/demo/[a[^/\x00]*]z.
  • Known discrepancy: a } without an opening { prints two messages, "Invalid number of items between {}" and then "Invalid close }, no matching open { detected", because the comma count is tested before the depth (parser_regex.c:316-324). Run with the tree's parser.
  • Known discrepancy, by title: "@{u16} has an unbalanced bracket and also matches [ and 65536 to 69999".

Read more

06 The function returns more than a string for AppArmor developers for security researchers

pattern_t AND first_re_pos Basic/usr/bin/demono globTailGlob/etc/demo/**one final **Regex/usr/bin/[a-z]*anything elseInvalid/etc/demo/{conf}an error was printed most callers: if (ptype == pattern_t::Invalid) return false; the attachment Basic name, nothing else: no xmatch DFAthe kernel compares the name otherwise: an xmatch DFAxmatch_len starts from the first glob position the same function, through convert_entry and direct calls: dbus · signal · ptrace · unix · network · mount · mqueue · io_uring xattr values and abstract socket names use a second glob set that allows NUL
Four pattern types with an example each: Basic /usr/bin/demo, TailGlob /etc/demo/**, Regex /usr/bin/[a-z]*, Invalid /etc/demo/{conf}; below, the attachment either needs no xmatch DFA or gets one with a match length from the first glob position; a last line lists other callers

pattern_t is Basic, TailGlob, Regex or Invalid; *first_re_pos is the offset of the first glob. process_profile_name_xmatch uses both.

The function returns more than a string: it also classifies the pattern. Basic, with no glob; tail glob, plain text that ends in two stars; regex, for everything else; and invalid. And it reports where the first glob was. Most callers only ask: invalid or not? The interesting user is the attachment. If a profile's name is basic, and there's no separate attachment, no alias name and no xattr condition, the parser builds no attachment machine; the kernel compares names. Otherwise the position of the first glob seeds the match length that ranks competing profiles. The other rule classes use the same function: D-Bus names, signal peers, mount points.

Details and sources

Details

  • enum class pattern_t { Basic, TailGlob, Regex, Invalid } (immunix.h:139-144). The function starts with Basic; a ** that ends the pattern while the type is still Basic makes it TailGlob; every other glob, class or group makes it Regex (parser_regex.c:206-221); an error makes it Invalid (parser_regex.c:437-438).
  • *first_re_pos is set once, to the offset of the first glob in the input, and stays 0 when there is none (update_re_pos, parser_regex.c:121).
  • The attachment, in process_profile_name_xmatch (parser_regex.c:478-518): the attachment, or the profile name when there is none, is converted with &prof->xmatch_len as the position; for a Basic pattern the length is strlen(name). A Basic pattern in a profile without alias names, separate attachment or xattrs gets prof->xmatch = NULL; anything else goes to the backend as a small DFA.
  • Kernel statements are read from the kernel source and were not run: without an xmatch DFA the kernel attaches by comparing the executable's name with the profile name (domain.c:485).
  • File rules store the type in entry->pattern_type (parser_regex.c:664); no other code in parser/ reads it, and nothing outside the unit tests distinguishes TailGlob from Regex.
  • Other callers: convert_entry appends the conversion of a value, or the default "match anything" pattern when the value is absent (parser_regex.c:1316-1336); build_list_val_expr joins a list of values with | (parser_regex.c:1286-1314). Direct calls: dbus.cc:229-281, signal.cc:330, ptrace.cc:141, af_unix.cc:275-299, network.cc:434, mount.cc:769.
  • The glob argument: glob_default writes [^/\x00]*, [^\x00]* and [^/\x00]; glob_null writes [^/]*, .* and [^/], which also match a NUL byte (parser_regex.c:98-114). glob_null is used for xattr values (parser_regex.c:582-584) and abstract unix socket addresses (af_unix.cc:275).
  • Known discrepancy, by title: "NotCharSetNode::contains_oob() is inverted, so xmatch_len stops at the first wildcard".

Read more

07 A pattern error has no line number

REGEX GROUPING ERROR /etc/demo/{conf} r, /src/apparmor/parser/apparmor_parser: Regex grouping error: Invalid number of items between {}/src/apparmor/parser/apparmor_parser: Unable to parse input line '/etc/demo/{conf}'ERROR processing regexs for profile demo, failed to loadERROR generating policy re for profile demo, failed to load/src/apparmor/parser/apparmor_parser: Errors found in file. Aborting. no file name, no line number: the pattern is converted after the whole file was parsed line 1 what is wrong: braces need at least one comma line 2 the pattern, with variables already expanded: search for it the path in front the parser program, not your file lines 3 to 5 each caller giving up; lines 3 and 4 name the profile
The rule /etc/demo/{conf} r, and the five lines the parser prints for it: Regex grouping error: Invalid number of items between {}, Unable to parse input line with the pattern quoted, two ERROR lines naming the profile demo, and Errors found in file. Aborting.

Regex grouping error: ... says what is wrong; Unable to parse input line 'PATTERN' quotes the pattern with variables expanded. Neither has a file name or a line number.

A pattern mistake looks like this, and it's unlike a syntax error. No file name, no line number. That's because the conversion runs after the whole file has been parsed, when the parser no longer knows which line a pattern came from. So read it like this. The first line says what's wrong: here, braces with nothing to choose between. The second quotes the pattern after variables were expanded; search your profile for it, and remember the problem may hide in a variable's value. The name in front is the parser program, not your file. The remaining three lines are each caller giving up; two of them name the profile.

Details and sources

Details

  • The complete output for the profile demo with the rule /etc/demo/{conf} r,. The path at the start of three of the lines is where the parser program was when it ran:
/src/apparmor/parser/apparmor_parser: Regex grouping error: Invalid number of items between {}
/src/apparmor/parser/apparmor_parser: Unable to parse input line '/etc/demo/{conf}'
ERROR processing regexs for profile demo, failed to load
ERROR generating policy re for profile demo, failed to load
/src/apparmor/parser/apparmor_parser: Errors found in file. Aborting.
  • The first lines for other mistakes:
PatternFirst line
/etc/demo/{conf}Regex grouping error: Invalid number of items between {}
/etc/demo/{a,bRegex grouping error: Unclosed grouping or character class, expecting close }
/etc/demo/[abthe same text, also with "expecting close }"
/etc/demo/a]Regex grouping error: Invalid close ], no matching open [ detected
/etc/demo/a}Regex grouping error: Invalid number of items between {} and then Regex grouping error: Invalid close }, no matching open { detected
  • A mistake in the attachment or in a pattern used as the profile name ends differently: after the first two lines come Invalid profile name 'PATTERN' - bad regular expression and ERROR processing xmatch for profile NAME, failed to load.
  • The quoted pattern is the one the conversion received. A rule written as @{CONF}/x is quoted with the value of the variable in place of @{CONF}: the value itself for one value, {a,b} for several.
  • With --warn=all the conversion can also print a warning, Character C was quotedunnecessarily, dropped preceding quote ('\') character. It does carry a file and a line, but the line is the last line of the file.
  • The exit status of these runs was 255; a syntax error gives 1.
  • Output shown here is from the parser built from the AppArmor tree at 836052d21, run with -Q -K (nothing loaded into a kernel, no cache) and the tree's abi/5.0 feature set.
  • Known discrepancies, by title: "Parser messages with wrong text or wrong line"; "An undefined variable is reported without file name or line".

Read more

for AppArmor developers for security researchers

In the code

08 Where to go from here

ROADS From AARE to regex The backend pipeline the strings arrive here The expression tree the next parser Profile attachment what the match length is for Globbing (AARE) the author's side Quoting and escaping the author's side The grammar where the entry was built
Roads from the conversion: the backend pipeline, the expression tree, globbing, quoting and escaping, profile attachment and the grammar

Next: the backend pipeline, then the expression tree. Related: globbing, quoting and escaping, profile attachment, the grammar.

So that's the bridge: decoded text in, one loop over it, backslashes added and removed, braces counted, classes copied, and out comes a string with a type and a position. That string is passed to the backend's add_rule function together with the permissions, and with that the front end's work is done. The backend pipeline deck picks up from exactly this point, with the same three rules. The tree deck shows the next parser, the one that reads these strings. For what the wildcards mean when you write a profile, go to globbing and to quoting. And the attachment deck explains what the match length is for.

Details and sources

Details

  • The stage in four lines: the pattern arrives decoded, expanded and with single slashes; one loop rewrites it; regex-only characters are escaped and glob characters translated; the result is a string plus a pattern type and the position of the first glob.
  • The hand-off: dfarules->add_rule(tbuf.c_str(), entry->priority, entry->rule_mode, entry->perms, audit, parseopts) (parser_regex.c:685-688); aare_rules::add_rule is at aare_rules.cc:46. -D rule-exprs prints both sides, the aare: line of the front end and the rule: line of the backend:
aare: /etc/demo/**   ->   /etc/demo/[^/\x00][^\x00]*
rule: /etc/demo/[^/\x00][^\x00]*  ->  /etc/demo/[^\x0/]([^\x0])* priority=0 (0x10004/0)< 0x10004>

Read more

Basis of the statements on this page: "tree" means the parser built from the AppArmor commit 836052d21 (6.0.0~alpha2) was run (-Q -K -D rule-exprs, with the tree's abi/5.0 feature set), with nothing loaded into a kernel. "code" means the parser source was read and not run; "derived" means the result was reasoned from that code.

Character by character

ReadWrittenNotesBasis
*[^/\x00]*after / and before / or the end, [^/\x00] firsttree
**[^\x00]*the same mandatory charactertree
?[^/\x00]tree
[ ... ]copied{, }, ,, ^, $ are copied insidetree
{ , }(, a bar, )at least one comma; at most 49 levelstree
. + ( ) and the barwith a backslashalwaystree
^ $\^ \$outside a classtree
\* \[ \] \{ \} \\unchangedtree (\*, \{, \}), code
\? \,? ,\, stays inside a classtree
\x00 \000 \d000 and letter escapesunchangeddecoded by the backendcode
\ + any other characterthe characterwarning of class formattree
anything elsecopiedtree

With glob_null (xattr values, abstract unix socket addresses) the three globs are [^/]*, .* and [^/] (code).

What was done to the pattern earlier

StepWhereEffect
quotes and escapesscanner, processidquotes removed; escapes decoded; a decoded * ? [ ] { } ^ , \ keeps a backslash
variablespost-processing, process_variables@{VAR} replaced by its value, or by {a,b} for several values
aliasespost-processingan entry whose name starts with an alias source is duplicated with the target
slashesfilter_slashes, just before the conversionruns of / collapsed; exactly two leading slashes kept

Return value

pattern_tMeaningExample
Basicno glob/usr/bin/demo
TailGlobplain text and one final **/etc/demo/**
Regexany other glob, class or group/usr/bin/[a-z]*
Invalidan error was printed/etc/demo/{conf}

*first_re_pos: offset of the first glob in the input; 0 without one (code).

Messages

MessageCauseBasis
Regex grouping error: Invalid number of items between {}a group without a commatree
Regex grouping error: Unclosed grouping or character class, expecting close }{ or [ not closedtree
Regex grouping error: Invalid close ], no matching open [ detected] without [tree
Regex grouping error: Invalid close }, no matching open { detected} without {tree
Regex grouping error: Exceeded maximum nesting of {}50 or more levelstree
Regex error: trailing '\' escape characterpattern ends in a backslashcode
Unable to parse input line 'PATTERN'follows each of the abovetree
Invalid profile name 'PATTERN' - bad regular expressionthe pattern is an attachment or profile nametree
Character C was quotedunnecessarily, dropped preceding quote ('\') characterwarning, class formattree

for AppArmor developers for security researchers

Functions and callers

FunctionWhereWhat
convert_aaregex_to_pcreparser_regex.c:118-445the conversion
filter_slashesparser_regex.c:61-96collapse repeated slashes in place
process_profile_name_xmatchparser_regex.c:478-628attachment, alias names, xattr values
process_dfa_entryparser_regex.c:648-787file, link and change_profile entries
convert_entry, clear_and_convert_entry, build_list_val_exprparser_regex.c:1286-1336helpers for the other rule classes
aare_rules::add_ruleaare_rules.cc:46where the string enters the backend

Roads from here

ATTACHMENT, NAMESPACES, STACKING

FILE ACCESS

PREAMBLE AND REUSE

  • Variables — where the braces of an expanded variable come from

PROFILE STRUCTURE

INSIDE THE PARSER

THE DFA ENGINE · libapparmor_re