Profiles for general-purpose apps
broad rules, apps keep working for application developers for administrators for security researchers
Ordinary programs get short profiles built from abstractions with rules wider than the program needs. The program keeps working across versions and the profile still removes capabilities and raw sockets and writes outside the user's own files. Shown on the shipped curl profile.
On the map: general-purpose apps
▶ Watch this deck — 11 scenes, ~8 min
Worth seeing first
- Abstractions and tunables — the abstractions this profile style starts from
- The owner qualifier — the owner qualifier that bounds broad user-file rules
- Globbing (AARE) — the wide patterns these profiles accept
Part of journeys
- Write your first profile, step 9 of 12 · previous: Network rules · next: Choosing abstractions
01 A profile that keeps the app working
The shipped curl profile grants owner file rw @{HOME}/**, because the files are chosen on the command line. Broad rules keep the program working; what the profile leaves out is the protection.
You're writing a profile for curl, and here's the trouble: the user decides where the download goes. Today it's a PDF in Downloads, tomorrow it's a file in some work directory, and the config file can be anywhere too. You can't list those paths. So the profile that ships says: read and write anything this user owns under home. That's more than any single run needs. The bet is that curl keeps working, and that the profile still stops what curl has no business doing. This deck walks through that profile and the tools that produce profiles like it. It's for people who write profiles and people who deploy them.
Details and sources
Details
- The rule and its reason, as shipped (curl:30-33):
# allow reading other configuration files/certs from $HOME
# (see --config, --cacert options)
# allow writing output to $HOME, /tmp (see -o option)
owner file rw @{HOME}/**,
- Size of the profile (curl): 23 non-comment lines, 6
include <abstractions/...>lines, nocapabilityrule of its own. - The style in four marks: several
include <abstractions/...>lines;ownerrules under@{HOME}with**;networkrules by family and type, without addresses; nocapabilityrule. ownerbounds the breadth: the rule gives nothing on files of other users. See the scene "Your files"./etc/passwdandsys_adminon the slide are examples of what has no rule. The scene "What the broad profile still blocks" goes through the list.- Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2), the kernel-rc2 (97d73c825). Nothing in the deck was run on a live kernel; kernel behaviour is read from the source.
02 curl next to ping: two styles in one tree
curl: 6 abstractions, no capability rules of its own, owner file rw @{HOME}/**,. ping: capability net_raw, capability setuid, two raw socket rules and two exact file paths.
Open the profiles directory in the AppArmor tree and you find two styles side by side. curl has six includes, one big owner rule and sockets by family. ping has two capabilities, two raw sockets and two exact file names, and not one double star. Why the difference? curl runs as you. It can already do what you can do, so the profile's job is to keep a compromised curl inside your files. ping starts with privileges, so each line is a privilege somebody decided to hand over. This deck is the left side. The security-sensitive programs deck is the right side.
Details and sources
Details
- The two files: curl:14-41 and bin.ping:15-27.
- The tallies are grep counts over each file:
capabilitylines, lines containing**,ownerlines. curl's threeownerlines are 27, 28 and 33. - ping's other rules, left off the slide:
@{exec_path} mixr,and@{PROC}/sys/net/ipv6/conf/all/disable_ipv6 r,(bin.ping:25-27). - Both profiles include
abstractions/baseandabstractions/nameservice, so both get the rules shown in the scene "What the includes brought along". - The 198 profile files directly in
profiles/apparmor.d/, by style (grep counts):
| Group | Files |
|---|---|
flags=(unconfined): a name only, nothing confined | 76 |
allow all, (sbuild and 13 sbuild-*) and plasmashell | 15 |
| all others | 107, of which 68 have a capability NAME, rule |
- A
flags=(unconfined)profile is not a broad profile. Its file says so: "This profile allows everything and only exists to give the application a name instead of having the label "unconfined"" (firefox:1-2, profile line at firefox:7). - "Starts with privileges" is deliberate wording: how ping gets its privileges (setuid bit, file capabilities) differs between systems and is not in either tree.
Read more
- apparmor.d(5): Capabilities, apparmor.d(5): Network Rules.
- Profiles for security-sensitive programs: the same pair seen from the other side.
- Capability rules, Network rules.
03 Start from abstractions
Each include <abstractions/NAME> pulls in a shared block of rules. apparmor_parser -p prints the profile with every include expanded: curl's 23 lines become 397.
You don't list the C library's files yourself. You include base, which names libraries by pattern, so an upgrade doesn't break your profile. You don't work out what a name lookup touches. You include nameservice. One line for each thing the program uses: the terminal, certificates, temporary files. That's why the curl profile fits on one screen. But the parser pastes every included file in. Ask it to print the result with -p, count the lines that aren't comments, and twenty-three lines of your own have become about four hundred. That's the trade in numbers: a short text you read, and a much longer one that gets compiled.
Details and sources
Details
- The six lines: curl:15-22.
- Why the profile survives upgrades:
basenames shared libraries by pattern, for example/{usr/,}lib/@{multiarch}/**.so* mr,(base:74-77), so a new library version or file name is still covered. A profile that listed exact library files would need an edit after such an upgrade. apparmor_parser -p(--preprocess) prints the profile with every include pasted in. Each pasted file is announced by a##included <...>line (parser_lex.l:176); a repeated include is replaced by##skipped duplicate include <...>(parser_lex.l:223).- The numbers 23 and 397 are non-comment lines. They come from running the parser built from the AppArmor tree at 836052d21 with
-I profiles/apparmor.d -ponprofiles/apparmor.d/curl. The pipeline on the slide is a reading aid for an installed system; that exact command line was not run. - The variables used by abstractions (
@{HOME},@{PROC},@{run}) come frominclude <tunables/global>in the profile's preamble (curl:12). - A profile created by
aa-genproforaa-autodepalways starts withabstractions/base(aa.py:391-392). - Other shipped profiles of this style: mbsync has four includes, five
networkrules and 11ownerrules (mbsync:17-40); znc hasbase,nameservice,ssl_certs,perl,python(znc:6-37).
04 What the includes brought along
After expansion curl has capability net_bind_service, (from abstractions/nis), network netlink raw, (from nameservice) and ptrace, signal and unix rules (from base). Check with apparmor_parser -p.
The curl profile has no capability line. The profile the parser compiles has one: net_bind_service. It arrives through nameservice, which includes the NIS abstraction. Nameservice also brings a netlink raw socket. Base brings ptrace, signal and unix socket rules, and a rule for an encrypted home directory that includes execute. None of that is a defect. It's what these abstractions are for. But if you're judging what a takeover of curl is worth, this is the list that counts, not the file you opened. So print the expanded profile, and grep for the rule classes you care about before you say what a profile grants.
Details and sources
Details
- All rules on the slide were found in the output of the parser built from the AppArmor tree at 836052d21, run with
-ponprofiles/apparmor.d/curl. capability net_bind_service,:nameserviceincludesnis(nameservice:62), andnishas the rule with the comment "portmapper may ask root processes to do nis/ldap at low ports" (nis:15-16).network inet stream,network inet6 stream,network inet dgram,network inet6 dgram,andnetwork netlink raw,("Netlink raw needed for nscd"): nameservice:92-99.- From
base(base:134-163):ptrace (readby),ptrace (tracedby),ptrace (read) peer=@{profile_name},signal (receive) peer=unconfined,signal peer=@{profile_name},signal (receive, send) set=("exists"),unix peer=(label=@{profile_name}),unix (receive) peer=(label=unconfined),unix (create),unix (getattr, getopt, setopt, shutdown),. - The eCryptfs rules, with
ix:owner @{HOME}/.Private/** mrixwlk,andowner @{HOMEDIRS}/.ecryptfs/*/.Private/** mrixwlk,(base:176-180). - The precise profile has them too:
pingincludesnameservice(bin.ping:18) and its expanded text contains the same rules. - The narrower choice is
nameservice-strict: 30 non-comment lines after expansion against 142 fornameservice.
Read more
- apparmor_parser(8), apparmor.d(5): abstractions/base, apparmor.d(5): abstractions/nameservice.
- Choosing abstractions: what each abstraction grants.
- Capability rules, Ptrace rules, Signal rules, Unix socket rules.
for security researchers
Attack surface
- Review the output of
apparmor_parser -p, not the profile file. The six include lines of curl stand for about 370 lines the author of the profile did not write. - Rules that arrive in every profile with
baseand matter for lateral movement:ptrace (readby),andptrace (tracedby),carry no peer condition, so any task whose own policy lets it read or trace may do so to this one;signal (receive) peer=unconfined,andunix (receive) peer=(label=unconfined),open the profile to unconfined peers. owner @{HOME}/.Private/** mrixwlk,givesixon files the user owns under~/.Private/: a place where a confined program that can write may also execute, inheriting the same profile.nameservicereaches further than name lookup: throughkerberosclientandldapclientit grants read access to/etc/krb5.keytaband/etc/ldap.secret(kerberosclient:30, ldapclient:15). The files' own permissions still apply.- Abstractions are extended on the installed system by files in
abstractions/NAME.d/(for exampleinclude if exists <abstractions/base.d>), so the expanded text of a machine can differ from the tree.
05 Your files: owner, @{HOME} and user-tmp
owner limits a rule to files whose owner is the process's fsuid. abstractions/user-tmp grants owner /tmp/** rwkl, and owner /var/tmp/** rwkl,.
The shipped profiles grant user data at three widths. curl takes the whole home directory. qpdf takes one kind of file anywhere in home, and skips dot directories. znc takes its own directory. Pick the narrowest your program can live with. All three start with owner. In the kernel, an owner rule only counts when the process's user is the file's owner, so even curl's rule gives nothing on a file somebody else owns. For temporary files there's user-tmp: the same idea for the temp directories. Notice it includes the link letter. The hard links deck comes back to that.
Details and sources
Details
- The three widths:
owner file rw @{HOME}/**,(curl:33);owner @{HOME}/[^.]**.@{qpdf_ext} rw,with@{qpdf_ext} = [qQpP][dD][fF] [jJ][sS][oO][nN](qpdf:6, qpdf:17);owner @{HOME}/.znc/moddata/** rw,(znc:32). @{HOME}is defined bytunables/globalthroughtunables/home:@{HOME}=@{HOMEDIRS}/*/ /root/with@{HOMEDIRS}=/home/(home:15-21)./home/annon the slide is an illustration.- The owner test in the kernel, read from the code: an
ownerrule is used when the uid the task accesses files with (its fsuid) equals the file's owner; otherwise the rules withoutownerdecide. The log fieldsfsuid=andouid=are the two values compared. abstractions/user-tmpin full (user-tmp:15-22):
owner @{HOME}/tmp/** rwkl,
owner @{HOME}/tmp/ rw,
owner /var/tmp/** rwkl,
/var/tmp/ rw,
owner /tmp/** rwkl,
/tmp/ rw,
- The narrower alternative is one named pattern:
owner /tmp/tr_session_id_* rwk,(transmission:31). - The widest rules in the app profiles are
mon files the user can write, which allows mapping them executable:owner file mrw @{HOME}/orcexec.*,(rygel:62-64, generated code) andowner @{HOME}/.znc/modules/* mrw,(znc:30, loadable modules). They are deliberate.
Read more
for AppArmor developers
Code
- The owner test: the state's accept entry carries an owner flag; if
uid_eq(subj_uid, cond->uid)the first permission set is used, else the next one (file.c:202-205).
06 What the broad profile still blocks
The expanded curl profile has no write rule for system directories (its write rules outside owner paths name devices, service sockets, the snapd socket and the temp directories themselves), no raw socket rule, no exec rule of its own, one capability, and audit deny @{HOME}/.ssh/{,**} mrwkl, from private-files-strict. A missing rule is a denial. The outcomes are read from the kernel code, not run.
Say an attacker takes over curl through a bad download. What can they do with it? Write a cron job: no, there's no write rule for system directories. Open a raw socket to sniff the network: no raw rule. Start a shell: no execute rule for it. If root ran curl, use root's power to walk past file permissions: no, the profile lists one capability and that isn't it. Read your SSH key, which you do own: no, private-files-strict denies it, and deny wins over the big owner rule. What's left is your own files that aren't on that list. That's real damage, and far less than everything.
Details and sources
Details
- The rule lists are from the expanded curl profile (parser built from the AppArmor tree at 836052d21,
-p). The outcomes are what the kernel code does; none was run on a kernel. - Write to
/etc/cron.d/x: the write rules areowner file rw @{HOME}/**,(curl:33),abstractions/user-tmpandfile rw @{run}/snapd.socket,(curl:45). Nothing covers/etc,/usr,/var/libor/boot. The open fails withEACCES. - Raw socket: the
networkrules areunix stream,unix dgram,inet stream,inet dgram,inet6 stream,inet6 dgram(curl:36-41) plusnetlink rawfromnameservice. There is nonetwork inet raw,and nonetwork packet,. - Exec: curl's own line is
@{exec_path} mr,(curl:24), withoutx. The expanded profile has exec permission in three places only:@{run}/nscd/db* mix,(fromnameservice) and the two eCryptfs rules ofbase. Any other exec fails withEACCES. - Capability: the only capability rule is
capability net_bind_service,. Every other capability is refused withEPERM, also for a process started by root. - SSH key:
audit deny @{HOME}/.ssh/{,**} mrwkl,(private-files-strict:12). A deny rule wins over an allow rule of the same priority, andauditputs the refusal in the log. - curl re-allows its own configuration with
priority=1 owner file r @{HOME}/.curlrc,andpriority=1 owner file r @{HOME}/.config/curlrc,(curl:27-28).private-fileshasdeny @{HOME}/.*rc mrk,, which matches the name.curlrc; which deny each of the two lines was written against was not traced. - The log record is assembled on the field layout of
testcase_dmesg_capability.in(operation="capable" ... capability=23 capname="sys_nice", two spaces beforecapname) with illustrative values (testcase_dmesg_capability.in).dac_overrideis capability 1 (capability.h:121). - Also without any rule:
mount,umount,pivot_root,userns,change_profile, and ptrace or signals towards other profiles. - A missing rule denies only what the kernel mediates. Which classes are mediated depends on the feature set the profile was compiled for (
abi <abi/5.0>,) and on the kernel:mqueuehas no hook in the kernel, so no profile restricts it there. - The profile does not stop curl from reading or changing the user's own files in the granted area.
Read more
for AppArmor developers
Code
- Capabilities:
apparmor_capablecallsaa_capablefor a confined task (lsm.c:199-211);profile_capablereturns-EPERMunless the capability is in the allow set (capability.c:128-154). - Sockets:
aa_profile_af_permmatches family, type and protocol against the profile's rules (net.c:254-270). - Exec without a matching rule:
error = -EACCES(domain.c:740-770). - The parser adds a "mediates" entry per supported class, so that a class without rules is denied instead of unmediated; it skips this for
unconfinedanddefault_allowprofiles (parser_regex.c:1385-1450).
for security researchers
Attack surface
- The five refusals are properties of names and rule classes. The protection stands on the path the kernel computes for the object; see Hard links and name-based rules and What is not mediated for where that breaks.
- "Even as root" covers capabilities only. Root's ownership still counts: a root-run curl satisfies
owneron root's files under/root/(@{HOME}includes/root/). file rw @{run}/snapd.socket,(curl:43-45) lets the profile talk to the snapd socket; the comment says it is kept "until we can revisit it with delegation or profile refactoring". What snapd grants to that peer is outside both trees.- The scene "What a hijacked curl keeps" lists what is left inside the granted area.
07 When broad is acceptable
Broad fits when the program has no capabilities, writes only owner paths and keeps its children confined. tar (capability dac_override, with file rwl /**,) shows what happens otherwise.
How do you know broad is good enough? Look at what the shipped broad profiles have in common. They hold no capabilities of their own. They write only files the user owns. And when they start another program, it stays confined. curl, mbsync, qpdf and znc pass all three. tnftp runs commands you type, so it sends them into a child profile that can't use the network. tar is the warning: four capabilities, including dac_override, next to a rule for the whole filesystem. That combination is what the precise style exists to avoid.
Details and sources
Details
- The three properties are what the shipped broad profiles have in common. They are derived from the profiles; no document in the tree states them as a rule.
- No capabilities of their own: curl, mbsync, qpdf, znc, john, tnftp, rygel and the four transmission profiles have no
capabilityline in their files. - Writes through
ownerrules only: under@{HOME},/tmp,/var/tmp,@{run}/user/*, or for the daemon variant under its own state directory:owner /var/lib/transmission{-daemon,}/downloads/** rw,(transmission:39). - Exec stays inside: no exec rule (curl, mbsync, qpdf),
ixof an interpreter (/{usr/,}bin/python{3,3.[0-9],3.[1-9][0-9]} rix,, znc:41) or a child profile (file Cx /usr/bin/dash,, tnftp:34;file Cx /usr/libexec/rygel/mx-extract -> mx-extract,, rygel:37). None usesux,Uxorpux. - tnftp:
priority=1 file Cx @{tnftp_rx}/* -> cmds,(tnftp:66); thecmdschild hasdeny network,(tnftp:77) andaudit deny file w @{tnftp_rx}/*,(tnftp:80). - tar:
capability chown,capability fowner,capability dac_override,capability dac_read_search,andfile rwl /**,(tar:18-25).usr.sbin.apache2has the same combination. - A tolerated exception in the extras profiles, which their README calls "not as mature": the firefox profile there uses
Uxrfor three helpers and says "Ideally these would use a child profile. They are all ELF executables so running with 'Ux', while not ideal, is ok because we will at least benefit from glibc's secure execute" (firefox:480-485). - A profile with
flags=(unconfined)is not a broad profile: it gives the program a profile name and confines nothing. 76 of the 198 files inprofiles/apparmor.dcarry the flag (grep). aa-enforceandaa-complainskip a profile withflags=(unconfined)unless--forceis given (tools.py:198-206).aa-enforce --forceon one of the 76 stubs would leave a profile whose only rules areuserns,and@{exec_path} mr,(firefox:7-11).
08 The profiling loop: complain, run, scan, enforce
aa-genprof PROGRAM creates the profile with flags=(complain) and abstractions/base, then loops: run the program, (S)can, answer. (F)inish sets enforce mode. Missing permissions in complain mode are logged as apparmor="ALLOWED" (read from the kernel code).
You rarely write a profile from a blank page. For a program without a profile, aa-genprof makes a tiny one, base plus the binary, puts it in complain mode and loads it. In complain mode the kernel lets a missing permission through and logs it as allowed. So you run curl in another window and really use it. Press S, and the tool reads the new log records and asks one question for each. Answer, run more, scan again. When the questions stop, press F and the profile goes to enforce. One catch: a feature you didn't exercise left no record, so it gets no rule.
Details and sources
Details
aa-genprof [-d DIR] [-f LOGFILE] [-j] [--no-abstraction] [-o OUTDIR] program(aa-genprof:67-74). Related:aa-autodep [--force] [-d DIR] [--no-reload] program...,aa-logprof [-d DIR] [-f LOGFILE] [-m MARK] [-j] [-a] [--no-abstraction] [-o OUTDIR],aa-complain,aa-enforce.- What it does, in order (aa-genprof:122-192): create the profile if no profile file for the program exists; set it to complain mode and reload it; set
/proc/sys/kernel/printk_ratelimitto 0 so that records are not dropped, restoring it at exit; print "Please start the application to be profiled in another window and exercise its functionality now."; offer(S)can system log for AppArmor eventsand(F)inish. On Finish every profile it put into complain mode is set to enforce and reloaded: "Reloaded AppArmor profiles in enforce mode." - The slide shows a program that has no profile yet. Where a profile file already exists, as it does for curl on a system that installs the shipped profile,
aa-genprofuses that file and puts it in complain mode. - The new profile:
flags=(complain),include <abstractions/base>, and for a binaryPATH mr,(aa.py:386-410); a script with a#!line getsron the script,ixon the interpreter and the interpreter's abstraction. The file also getsabi <abi/5.0>,andinclude <tunables/global>when those files exist (aa.py:516-519); they are left off the slide. - The profile is named after the full path, which is also its attachment, so the head reads
/usr/bin/curl flags=(complain) {(read from the tool's code, not from a run). - Log file:
-f, or the first existing of/var/log/audit/audit.log /var/log/syslog /var/log/messages(logprof.conf:15). - Complain mode in the kernel, read from the code: a permission that no rule allows and no rule denies is let through and logged as
apparmor="ALLOWED". An exec with no matching rule runs under a learning profile named intarget=with//null-in its name. - Complain mode is not the same as unconfined: plain
denyrules still refuse, and silently. A complain-mode profile that includesprivate-files-strictstill blocks~/.ssh. - A running program keeps the confinement it started with. Start it after the profile is loaded; that is why the tool asks for "another window".
- Errors: "It seems AppArmor was not started. Please enable AppArmor and try again." (aa-genprof:90-92). Programs listed under
[qualifiers]inlogprof.conf(shells, core utilities) are refused a profile of their own (aa.py:2501-2510). - The same loop by hand, from the extras README: copy the profile,
aa-complain, restart the service, use it,aa-logprof, answer,aa-enforce(README:11-34).
Read more
- aa-genprof(8), aa-logprof(8), aa-autodep(8), aa-complain(8), aa-enforce(8), logprof.conf(5).
- apparmor(7): Complain mode, apparmor.net: Generate profiles with aa-genprof, wiki: Profiling_with_tools (dated).
- Generating a profile, Switching profile modes, Profile mode flags, Reading a denial, Profile attachment.
for AppArmor developers
Code
create_new_profile(aa.py:386-428),autodep(aa.py:484-520), the profile head inget_header(profile_storage.py:136-176),do_logprof_pass(aa.py:1501-1516),set_logfile(aa.py:1478-1490).- Kernel:
perms->complain |= ~(perms->allow | perms->deny)(lib.c:369-370); the error is cleared for an ALLOWED record (lib.c:460-461,complain_errorat audit.h:206-211); the learning profile on exec (domain.c:749-767).
09 One log record, one question, and how profiles get broad
aa-logprof offers include <abstractions/...> lines whose rules cover the event, then the exact path and globs. Keys: (A)llow, (D)eny, (I)gnore, (G)lob, Glob with (E)xtension, (N)ew, Audi(t). Glob widens one step per press, ending at /**. The menu is rendered from the tool's code, not captured from a session.
Here's one record: curl opened the system's certificate bundle. aa-logprof turns it into a question. First it offers every abstraction that has a rule covering this path, then the exact path. Two abstractions qualify here: ssl_certs, which is what a client needs, and ssl_keys, which reads everything in that directory tree, private keys included. The tool doesn't rank them. Then there's Glob: each press widens the path one step, until it covers the whole filesystem. So a broad profile isn't an accident of the tool. It's the sum of your answers. For curl, an include is usually the right answer. Just read what you're including.
Details and sources
Details
- The record is assembled on the field layout of an
operation="open"record insyslog_datetime_01.in(syslog_datetime_01.in), with illustrative values;pid=andcomm=are behind the.... The profile name is the oneaa-genprofgave the new profile in the previous scene. - The menu is rendered from the tool's code and was not captured from a session; the bracket on
(D)enyfollows the sessions recorded for aa-logprof. HeadersProfile,Path,New Mode,Severity(aa.py:1167-1173, file.py:353-399); options are printed asN - textwith the selected one in brackets (ui.py:500-507). The severity number comes fromutils/severity.db, is left out on the slide and blocks nothing. - Order of the options:
include <abstractions/NAME>for every abstraction with a rule that covers the event, sorted by name (aa.py:1152-1156); then, for a file, paths of existing rules that match, globs from the[globs]table oflogprof.conf, and the exact path last (aa.py:2378-2408). The first option is the preselected one. - Why these two:
ssl_certshas/etc/{,libre}ssl/certs/{,**} r,(ssl_certs:17) andssl_keyshas/etc/ssl/** r,under the comment "Just include the whole /etc/ssl directory if we should have access to private keys too" (ssl_keys:16-19). Nothing ranks proposals by breadth. That these are the only two for this path is read from the abstraction files, not from a run. - An event already covered by the profile or by one of its includes, followed recursively, produces no question (aa.py:2341-2351).
basealready covers/etc/ssl/openssl.cnfthroughcryptoandopenssl. - Keys (aa.py:1331-1361): (A)llow, (D)eny, (I)gnore, (G)lob, Glob with (E)xtension, (N)ew (edit the path), Audi(t), Abo(r)t, (F)inish.
(O)wner permissions offappears only when the record'sfsuidequals itsouidand the proposed rule therefore starts withowner. - The bracketed default is
(D)eny, as the slide shows, also for a record logged in complain mode (ALLOWED): Return writes adenyrule, so pressAto allow. Known discrepancy, "the default answer of every rule question is Deny": the code means Allow to be the default for complain-mode records and Deny for enforce-mode records, but the test that should select Allow never matches (aa.py:1177-1182). Observed in the recorded sessions of aa-logprof: every rule question underComplain-mode changes:showed(A)llow / [(D)eny]. - Glob replaces the last path component with
*; when the path already ends in/*or/**it removes one more directory and ends in/**(aare.py:97-123). --no-abstractionon either tool suppresses the include offers (aa-genprof:72, aa-logprof:32);baseis still added to a new profile.aa-logprof -aaccepts every rule and answers exec questions withpxwhen a profile for the target exists, otherwiseix(ui.py:518-526).- Exec records get their own menu: inherit, profile, child, named, unconfined, deny (aa.py:622-661). Choosing unconfined prints "Launching processes in an unconfined state is a very dangerous operation and can cause serious security holes." (aa.py:890-895).
- Known discrepancy: the tool's matcher does not expand variables (aare.py:49), so a rule written with
@{etc_ro}or@{HOME}may not be recognised as covering a logged path, and the question is asked again. A full session was not run. See Choosing abstractions.
Read more
for security researchers
Attack surface
- The loop learns from whatever the program did while it was in complain mode. Activity triggered by hostile input during that window is logged like any other and is offered as a rule; with
aa-logprof -ait is accepted without a question. - The preselected option is the first abstraction in name order, and one keypress accepts it.
ssl_keyson a client is the example on the slide.
10 What a hijacked curl keeps for security researchers
owner file rw @{HOME}/**, minus the deny rules of private-files-strict is what a compromised curl can read and write; network inet stream, has no address condition. This is derived from the profile text and the kernel code; it was not run.
What does a hijacked curl keep? The secrets list in private-files-strict is a list of names. Your SSH and GPG directories are on it. A Git credentials file or a Kubernetes config isn't, so the big owner rule hands them over. Writing works the same way. The autostart directory is denied, but nothing denies a new unit file in the user's systemd directory, and on a system where your session reads that directory, the code runs later, outside this profile. And the network rules name no address, so whatever was read can be sent anywhere. In a broad profile the deny list is the wall. Read it.
Details and sources
Details
- Everything on this slide is derived from the text of the expanded curl profile and the kernel code. None of it was run.
- Read and write:
owner file rw @{HOME}/**,(curl:33) covers every file the user owns under the home directory, less the deny rules below. - The deny list is two files.
private-files(private-files:9-49) denies shell history and editor backup files, reading and writing~/.*rc,~/.bash*,~/.profile*and login files, and writing under~/bin/,~/.config/autostart/,~/.config/upstart/,~/.init/, the KDE autostart and env directories and~/.local/share/thumbnailers/.private-files-strict(private-files-strict:10-27) adds~/.aws,~/.gnupg,~/.ssh, GNOME keyrings,~/.mozilla, Chromium, Evolution, Thunderbird, KMail and KWallet data. - Not named by either file, so granted:
~/.git-credentials,~/.kube/config, documents and source trees. These names are examples chosen for the slide; the claim is only that no deny rule in the two files matches them. audit deny @{HOME}/.config/ w,is a rule for the directory itself. It does not match~/.config/systemd/user/x.service, and no other deny does. Whether a file there is ever run depends on the system: on a system where the user's systemd instance reads that directory, the unit runs as a new process that the curl profile does not confine, unless a profile attaches to it.- Network:
network inet stream,network inet dgram,and the inet6 pair (curl:36-41) have no address or port condition. file rw @{run}/snapd.socket,(curl:43-45) is the one grant in the profile that is neither the user's own files nor a network family: the profile may open the snapd socket for reading and writing. The comment above the rule says it stays "until we can revisit it with delegation or profile refactoring". What snapd lets that peer do is outside both trees.- This scene is the other half of "What the broad profile still blocks".
Read more
- apparmor.d(5): deny, apparmor.d(5): Mediation of inet/inet6 family.
- Choosing abstractions: the private-files pair. allow and deny. What is not mediated.
11 Where to go from here
Next: prac-abstractions, prac-privileged, syn-owner, syn-globbing, ut-genprof, ut-logprof, adm-denials.
So: start from abstractions, bound your own rules with owner, let the profiling loop find the rest, and check the expanded result. If you want to know what each include line really grants, go to the choosing abstractions deck. If your program holds privileges, the security-sensitive programs deck shows the opposite style, on ping and dnsmasq. And owner, globbing, the two tools and reading denials each have a deck of their own.
Details and sources
Details
- Choosing abstractions: what each abstraction grants, which ones carry side grants, how the tools propose them.
- Profiles for security-sensitive programs: the precise style on ping, dnsmasq and other privileged programs.
- The owner qualifier: what
ownercompares and where it can be written. - Globbing (AARE): what
*,**and[^.]match. - Generating a profile and aa-logprof: every option and key of the two tools.
- Reading a denial: the fields of the records the loop reads.
- include and Profile mode flags: include lines and the complain flag.
- 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 with -p on a shipped profile, with nothing loaded into a kernel; "code" means the source of the tools or of mainline Linux 7.4 was read, not run; "derived" means the result was reasoned from that code and from the profile text. Counts are grep counts over the tree. Nothing here was observed on a running kernel.
The curl profile, annotated
profiles/apparmor.d/curl, 23 non-comment lines.
| Line | Text | Remark |
|---|---|---|
| 10 | abi <abi/5.0>, | the feature set the profile is compiled for |
| 12 | include <tunables/global> | defines @{HOME}, @{PROC}, @{run} |
| 14 | profile curl /usr/bin/curl { | name and attachment |
| 15 | include <abstractions/base> | libc, locale, loader, logging; also ptrace, signal and unix rules |
| 16 | include <abstractions/consoles> | /dev/tty, /dev/pts/*, /dev/console |
| 17 | include <abstractions/nameservice> | users, hosts, DNS; also sockets and one capability |
| 18 | include <abstractions/private-files-strict> | deny rules for key stores and start-up files |
| 19 | include <abstractions/ssl_certs> | CA certificates, read-only |
| 22 | include <abstractions/user-tmp> | owner rules for /tmp, /var/tmp, ~/tmp |
| 24 | @{exec_path} mr, | map and read the binary; no x |
| 27-28 | priority=1 owner file r @{HOME}/.curlrc, and .config/curlrc | curl's own configuration, above the deny rules |
| 33 | owner file rw @{HOME}/**, | the broad rule: --config, --cacert, -o |
| 36-41 | network unix stream, unix dgram, inet stream, inet dgram, inet6 stream, inet6 dgram, | by family and type, no addresses |
| 45 | file rw @{run}/snapd.socket, | the snap socket |
| 48 | /etc/rpmdevtools/curlrc r, | rpmdev-spectool's curlrc |
| 51 | include if exists <local/curl> | site additions |
Rules of other classes after expansion (tree):
| Rule | Comes from | File and line |
|---|---|---|
capability net_bind_service, | nameservice includes nis | abstractions/nis:16 (include at abstractions/nameservice:62) |
network netlink raw, | nameservice | abstractions/nameservice:99 |
network inet stream, and three more | nameservice (and curl itself) | abstractions/nameservice:92-95 |
ptrace (readby), ptrace (tracedby), ptrace (read) peer=@{profile_name}, | base | abstractions/base:134-142 |
signal (receive) peer=unconfined, signal peer=@{profile_name}, signal (receive, send) set=("exists"), | base | abstractions/base:145-151 |
unix peer=(label=@{profile_name}), unix (receive) peer=(label=unconfined), unix (create), unix (getattr, getopt, setopt, shutdown), | base | abstractions/base:154-163 |
owner @{HOME}/.Private/** mrixwlk, owner @{HOMEDIRS}/.ecryptfs/*/.Private/** mrixwlk, | base | abstractions/base:177,180 |
@{run}/nscd/db* mix, | nameservice | abstractions/nameservice:40 |
- 23 non-comment lines become 397 after expansion (tree).
nameservicealone expands to 142 non-comment lines,nameservice-strictto 30 (tree).
Shipped profiles by style
The 198 regular files directly in profiles/apparmor.d/ (not abstractions/, tunables/, abi/, local/, apache2.d/).
| Group | Files | Evidence |
|---|---|---|
| Name only, nothing confined | 76 with flags=(unconfined) (1password, brave, chrome, chromium, code, firefox, flatpak, steam, thunderbird, ...) | body is userns, and @{exec_path} mr, |
| Everything allowed by rule | sbuild and 13 sbuild-*; plasmashell | allow all,; bare capability, network, mount, ... |
| Broad, abstraction-based, no capability rules of their own | curl, tnftp, mbsync, qpdf, znc, john, gs, rygel, transmission, lsb_release | 3 to 11 abstractions per profile, owner @{HOME}/... rules, recursive globs |
| Precise, privileged | bin.ping, usr.sbin.traceroute, sbin.klogd, unix-chkpwd, who, iotop-c, nvidia_modprobe, usr.sbin.ntpd, usr.sbin.dnsmasq, the dovecot files, ... | 1 to 12 named capabilities, exact paths, Px/Cx, peer conditions |
| Privileged and broad | tar, usr.sbin.apache2, zgrep's helper child | capabilities next to a whole-filesystem glob |
Numbers per file (non-comment lines; include <abstractions/ lines; capability lines; lines with **; owner lines):
| File | Lines | Abstractions | Capabilities | ** | owner |
|---|---|---|---|---|---|
| curl | 23 | 6 | 0 | 1 | 3 |
| mbsync | 27 | 4 | 0 | 9 | 11 |
| qpdf | 25 | 1 | 0 | 16 | 12 |
| znc | 27 | 5 | 0 | 4 | 13 |
| tnftp (4 profiles) | 49 | 16 | 0 | 2 | 5 |
| transmission (4 profiles) | 70 | 23 | 0 | 6 | 9 |
| bin.ping | 15 | 3 | 2 | 0 | 0 |
| usr.sbin.dnsmasq | 88 | 4 | 7 | 1 | 5 |
profiles/apparmor/profiles/extras/holds 111 more profile files. Its README says they "are not turned on by default because they are not as mature as the profiles in /etc/apparmor.d/".
What a broad profile leaves out
The expanded curl profile (tree) and the result in the kernel (code, derived).
| Rule class | In the expanded curl profile | Request without a rule |
|---|---|---|
| capability | net_bind_service only | refused with EPERM |
| file write | owner rules under @{HOME}, /tmp, /var/tmp; @{run}/snapd.socket | refused with EACCES |
| network | unix and inet/inet6 stream and dgram; netlink raw | socket creation refused |
| exec | @{run}/nscd/db* mix, and the two eCryptfs ix rules | refused with EACCES |
| ptrace | be read or traced by others; read itself | refused |
| signal | receive from unconfined; itself; the exists check | refused |
| mount, umount, pivot_root, userns, change_profile | none | refused |
| named secrets | audit deny on ~/.ssh, ~/.gnupg, ~/.aws and others | refused and logged |
- A class is denied by a missing rule only if the kernel mediates it and the profile was compiled for a feature set that has it.
mqueuehas no hook in the mainline kernel. - A broad profile does not protect the user's own files in the granted area from the program.
Widths of home directory rules
| Width | Shipped example | File |
|---|---|---|
| The whole home directory | owner file rw @{HOME}/**, | curl:33 |
| One file type, outside dot directories | owner @{HOME}/[^.]**.@{qpdf_ext} rw, | qpdf:17 |
| The program's own directory | owner @{HOME}/.znc/moddata/** rw, | znc:32 |
| A directory tree kept in a tunable | owner file r @{rygel_media_dirs}/{,**}, | rygel:56 |
abstractions/user-tmp:
owner @{HOME}/tmp/** rwkl,
owner @{HOME}/tmp/ rw,
owner /var/tmp/** rwkl,
/var/tmp/ rw,
owner /tmp/** rwkl,
/tmp/ rw,
ownerin the kernel (code): the rule is used when the task's fsuid equals the file's owner.- A narrower temp rule:
owner /tmp/tr_session_id_* rwk,(transmission:31).
The tools
aa-autodep [--force] [-d DIR] [--no-reload] program... aa-genprof [-d DIR] [-f LOGFILE] [-j] [--no-abstraction] [-o OUTDIR] program aa-logprof [-d DIR] [-f LOGFILE] [-m MARK] [-j] [-a] [--no-abstraction] [-o OUTDIR] aa-complain [-d DIR] [--no-reload] [--force] program... aa-enforce [-d DIR] [--no-reload] [--force] program...
A new profile contains (code):
| Program | Contents |
|---|---|
| any | flags=(complain), include <abstractions/base>; in the file also abi <abi/5.0>, and include <tunables/global> when present |
| a binary | PATH mr, |
a #! script | SCRIPT r,, INTERPRETER ix, and abstractions/bash, perl, python or ruby when the interpreter is one of those |
Question keys for a file record:
| Key | Effect |
|---|---|
| (A)llow | add the selected option to the profile |
| (D)eny | add a deny rule |
| (I)gnore | skip this record |
| (G)lob | widen the path one step and add it to the options |
| Glob with (E)xtension | widen the path and keep the file extension |
| (N)ew | edit the path by hand |
| Audi(t) | toggle audit on the proposed rule |
| (O)wner permissions on / off | toggle owner; offered when the record's fsuid equals its ouid |
| Abo(r)t, (F)inish | abandon the session (after a confirmation), or stop asking |
- Options are listed in this order: matching abstractions by name, paths of existing rules,
[globs]entries oflogprof.conf, the exact path. The first is preselected. - Glob ladder:
/usr/share/foo/a.txt,/usr/share/foo/*,/usr/share/**,/usr/**,/**. - Default key: Allow for
ALLOWEDrecords, Deny forDENIEDrecords. aa-logprof -a: every rule accepted, exec questions answered withpxif a profile for the target exists, elseix.- Log files searched when
-fis not given:/var/log/audit/audit.log,/var/log/syslog,/var/log/messages, first existing.
| Message | When |
|---|---|
It seems AppArmor was not started. Please enable AppArmor and try again. | aa-genprof when AppArmor is not available |
... is currently marked as a program that should not have its own profile. ... | the program is listed under [qualifiers] in logprof.conf (shells, core utilities) |
Profile ... is in unconfined mode. Use --force to switch it to enforce mode. | aa-enforce on a flags=(unconfined) profile |
WARNING: Can't find abstractions/base, therefore not adding it to the new profile. | the abstraction file is missing |
Complain mode in the kernel
- Let through and logged as
apparmor="ALLOWED": any permission that no rule allows and no rule denies (code). - Not let through: what a plain
denyrule covers. It is refused without a record (code). - An exec with no matching rule runs under a learning profile instead of failing (code). A record from the library's test suite (
libraries/libapparmor/testsuite/test_multi/exec01.in, shortened) names it intarget=:
apparmor="ALLOWED" operation="exec" profile="/home/cb/bin/hello.sh" name="/usr/bin/rm" ... requested_mask="x" denied_mask="x" fsuid=1000 ouid=0 target="/home/cb/bin/hello.sh//null-/usr/bin/rm"
- A denied capability in enforce mode, from
testcase_dmesg_capability.in(shortened):
apparmor="DENIED" operation="capable" ... pid=7292 comm="syscall_setprio" capability=23 capname="sys_nice"
aa-logprofturns that record intocapability sys_nice,.
for AppArmor developers
Where the defaults are decided
| What | Where |
|---|---|
new profile: complain flag, base, mr on the binary | utils/apparmor/aa.py:386-428 |
| interpreter to abstraction mapping | utils/apparmor/aa.py:347-383 |
abi and tunables/global added to the file | utils/apparmor/aa.py:516-519 |
| genprof loop, printk ratelimit, Scan and Finish | utils/aa-genprof:122-192 |
| one pass over the log | utils/apparmor/aa.py:1501-1516 |
include proposals (match_includes) | utils/apparmor/aa.py:1419-1459 |
known-rule check (is_known_rule) | utils/apparmor/aa.py:2341-2351 |
file options (propose_file_rules), option order (order_globs) | utils/apparmor/aa.py:2378-2408, utils/apparmor/aa.py:1022-1034 |
keys (available_buttons), default key | utils/apparmor/aa.py:1331-1361, utils/apparmor/aa.py:1177-1182 |
Glob (glob_path) | utils/apparmor/aare.py:97-123 |
-a answers | utils/apparmor/ui.py:518-526 |
| exec menu and its defaults | utils/apparmor/aa.py:622-661, utils/apparmor/aa.py:785-789 |
[qualifiers] refusal | utils/apparmor/aa.py:2501-2510 |
--force guard for unconfined profiles | utils/apparmor/tools.py:198-206 |
| owner test | linux:security/apparmor/file.c:202-205 |
| capability check | linux:security/apparmor/lsm.c:199-211, linux:security/apparmor/capability.c:128-154 |
| socket check | linux:security/apparmor/net.c:254-270 |
| exec without a rule; learning profile in complain mode | linux:security/apparmor/domain.c:749-770 |
| complain set and cleared error | linux:security/apparmor/lib.c:369-370, linux:security/apparmor/lib.c:460-461, linux:security/apparmor/include/audit.h:206-211 |
| "mediates" entry per class | parser/parser_regex.c:1385-1450 |
Roads from here
FILE ACCESS
- Globbing (AARE) — what one star and two stars match
PREAMBLE AND REUSE
- include — how include lines are read
PROFILE HEAD
- Profile mode flags — complain and enforce on the profile line
QUALIFIERS
- The owner qualifier — the owner qualifier that bounds a home directory rule
IN PRACTICE · general-purpose apps
- Choosing abstractions — what each include line grants and which ones to pick
IN PRACTICE · security-sensitive programs
- Profiles for security-sensitive programs — the opposite style for programs that hold privileges
RUNNING THE PARSER
- Reading a denial — reading the log records the loop feeds on
TOOLS · utils/
- Generating a profile — the tool that runs the profiling loop
- aa-logprof — every key of the question menu