The owner qualifier
files you own for application developers
owner limits a file rule to objects whose owner is the user the task is acting as. Mainline Linux 7.4 compares the task's fsuid with the file's owner each time it checks a file. Only file and link rules accept it.
On the map: qualifiers
▶ Watch this deck — 8 scenes, ~6 min
Worth seeing first
- File rules — the file rule owner stands in front of
Part of journeys
- Write your first profile, step 7 of 12 · previous: Exec modes · next: Network rules
- File access in depth, step 8 of 12 · previous: Link rules · next: The other qualifier
- How a rule becomes a permission, step 5 of 12 · previous: Named exec transitions · next: allow and deny
01 One profile, many users
owner RULE, applies a file rule only to files owned by the user the task acts as.
Demo runs for several users, and every instance gets the same profile. Each one keeps a cache file in the same directory: Alice's here, Bob's there. One path rule covers the whole directory. So as far as AppArmor is concerned, Alice's demo may open Bob's cache. You can't fix that with a pattern, because the names are just names. The owner qualifier adds a condition no pattern can express: the rule applies only when the file belongs to the user the program is running as. The permission bits may stop Alice anyway. With owner, the profile says so too. Line twenty-six of the example profile is a rule like this.
Details and sources
Details
owneris a rule qualifier. A rule that carries it grants its permissions only when the file's owner uid equals the uid the task uses for file access (its fsuid).- The rule on the slide is a simplified form of line 26 of the map's example profile:
owner @{APP_DATA}/{cache,state}/** rwk,. The users alice and bob, their uids and the two cache files are illustrations. - A plain
/var/lib/demo/cache/** rwk,holds its permissions for both cases, files the task owns and files it does not (parser_misc.c:738-741). - AppArmor does not replace the file permission bits. Both checks apply to an access, and either can refuse it.
- Kernel statements are for the kernel and come from reading the source; nothing was run against a kernel.
Read more
- apparmor.d(5), owner: the qualifier in the manual page.
- syn-file-rules: the rules
ownerqualifies. - syn-other: the qualifier for files the task does not own.
- why-apparmor: the program
demoand its profile.
for AppArmor developers for security researchers
In the code
- Grammar:
opt_owner_flagis empty,ownerorother(parser_yacc.y:696-698).
02 The fourth seat
[priority=N] [audit] [allow|deny|prompt] owner FILE RULE,. Valid on file rules, file,, link rules and blocks of them.
Owner has the fourth and last seat, right in front of the rule. It works with both spellings of a file rule: path first, or letters first. The other qualifiers come before it, so it's audit deny owner, in that order. Owner also goes in front of the bare file rule, in front of a link rule, and in front of a block of file rules. One thing to remember: owner always comes before the path. Put it between the path and the letters, and you get a syntax error. The word other shares this seat, and it has its own deck.
Details and sources
Details
- Order of the qualifiers:
[priority=N] [audit] [allow|deny|prompt] [owner|other], then the rule (parser_yacc.y:705-711).ownerandothershare the last seat, so a rule has at most one of them. - Accepted by the parser built from AppArmor 836052d21 (run with
-Q -K --skip-kernel-load, nothing loaded into a kernel):owner /path rw,,owner rw /path,,audit deny owner /path w,,owner file,,owner link /a -> /b,,owner /usr/bin/demo-helper Px,andowner { ... }. - Test fixtures: ok_1.sd (both spellings and blocks), ok_link_owner.sd (
owner link subset /alpha/beta -> /tmp/**,). ownerafter the path is rejected:/foo owner rw,gives "syntax error, unexpected TOK_OWNER, expecting TOK_MODE" (bad_3.sd).- The keyword table also maps the undocumented word
userto the same token asowner(parser_misc.c:95-97). The map does not recommend it.
Read more
- apparmor.d(5), Rule Qualifiers and apparmor.d(5), owner.
- syn-allow-deny: the third seat.
- syn-qualifier-blocks:
owner { ... }. - syn-link-rules: link rules.
- syn-other: the other word for this seat.
03 fsuid against the file's owner
owner rules apply when the task's fsuid equals the file's owner uid. Denial records show both as fsuid= and ouid=.
The test is simple, and it happens each time AppArmor checks a file. In the kernel, the kernel takes two numbers. One is the task's filesystem user id, the identity Linux uses for file access. The other is the user id that owns the file. If they're equal, the owner rule applies. If they differ, the rule doesn't apply. Unless some other rule covers Bob's file, the open is refused. The log record carries both numbers, as fsuid and ouid. When an owner rule surprises you, look at those two fields.
Details and sources
Details
- Kernel statements are for the kernel and come from reading the source; nothing was run against a kernel. The record on the slide is the shape the code produces, shortened with
...; it was not captured from a running system. - The task's side of the comparison is
current_fsuid(), passed byaa_str_perms(file.c:227). - The file's side is the inode's owner uid as seen through the id mapping of the mount (lsm.c:248-251).
- When the two are equal the owner permissions of the matched name are used, otherwise the permissions for other files (file.c:194-209). A rule without
ownerorothercontributes to both. - Log fields: file records end with
fsuid=(the task) andouid=(the object's owner), printed as numbers in the initial user namespace (file.c:62-66). - Known discrepancy with the manual: apparmor.d(5) says the task must have "the same euid/fsuid as the object" (apparmor.d.pod:2567-2570). The kernel code compares the fsuid only.
Read more
- apparmor.d(5), owner: "the task must have the same euid/fsuid as the object".
- Kernel documentation: Credentials in Linux: what the fsuid of a task is.
- adm-denials: reading denial records.
- k-match: how the kernel matches a name and picks permissions.
04 Files that do not exist yet, links and programs
Creating a file: the creator counts as owner. Link: the existing file's owner. Exec: the owner of the executable.
Three cases where the owner needs a second look. First, creating a file. It doesn't exist yet, so it has no owner. In the kernel the kernel uses the user who is creating it, so an owner rule with write lets demo create its own files. Second, hard links. The new name doesn't exist either, and here the kernel uses the owner of the existing file. Third, exec. Owner on an exec rule compares against the owner of the program file. Programs in /usr/bin usually belong to root. So for an ordinary user, that rule doesn't apply.
Details and sources
Details
- Kernel statements are for the kernel and come from reading the source; nothing was run against a kernel.
- Creating a file, directory or other object: the condition is built as
{ current_fsuid(), mode }, so the owner compared is the creating task itself (lsm.c:316-319). Anownerrule withwtherefore covers creation. - Hard link:
aa_path_linktakes the owner from the existing inode and uses it for both names (file.c:443-448).ouid=in a link record is the existing file's owner. - Open file descriptors that are checked again take the owner from the file's inode (file.c:497-500).
- Exec: the condition is the owner of the executable being run (domain.c:995-998).
owner /usr/bin/demo-helper Px,applies only when the task's fsuid owns that file. That programs under/usr/binbelong to root is the usual layout of a distribution, not a fact from the source trees. owner /usr/bin/demo-helper Px,is accepted by the parser built from AppArmor 836052d21.
Read more
- apparmor.d(5), owner.
- apparmor.d(5), Link rules.
- Kernel documentation: protected_hardlinks: the kernel's own owner test for hard links, separate from AppArmor.
- syn-link-rules: link rules and the pair of names.
- syn-exec-modes: exec transitions.
- prac-hardlinks: hard links and
ownerin practice.
05 Only file rules have an owner
owner is accepted on file rules, file, and link rules. Other classes fail with "owner prefix not allowed on X rules" (capability and change_profile say "owner conditional not allowed on ...").
Ownership is a property of files, so owner only means something on file rules. That includes the bare file rule and link rules. The grammar lets you type owner in front of anything. Then the rule class says no. A capability has no owner. A signal has no owner. Change profile has no owner either. Each class has its own message, and they all contain the words not allowed on, followed by the kind of rule. The same goes for an owner block: it's meant for file rules only.
Details and sources
Details
- The messages on the slide were printed by the parser built from AppArmor 836052d21 for
owner capability chown,,owner signal,andowner change_profile -> x,. The full form isAppArmor parser error for FILE in profile FILE at line N: MESSAGE. - "owner prefix not allowed on X rules": signal (signal.h:53), ptrace (ptrace.h:52), mount (mount.h:176), dbus (dbus.h:56), unix (af_unix.h:57), network (network.h:275), mqueue (mqueue.h:116), io_uring (io_uring.h:48), userns (userns.h:37), all (all_rule.h:52).
- Capability: "owner conditional not allowed on capability rules" for a rule written directly (block_rules.cc:140-141); "owner prefix not allowed on capability rules" for a capability rule inside an
owner { }block (block_rules.h:68-70). - change_profile: "owner conditional not allowed on change_profile rules" (parser_yacc.y:812-813).
otheris rejected in the same places with the same messages; they say "owner" for both.- Known discrepancy:
owner { change_profile -> x, }is accepted by the parser at this commit although the direct formowner change_profile -> x,is rejected. Do not rely on it.
Read more
- apparmor.d(5), Rule Qualifiers.
- apparmor.d(5), Qualifier Blocks.
- syn-qualifier-blocks: what a block may contain.
- syntax-map: the rule classes.
06 Two halves, two table entries for AppArmor developers for security researchers
owner masks the permission word to the owner half (parser/parser_misc.c:1152-1154). aa_lookup_condperms (linux:security/apparmor/file.c:194-209, the kernel) picks entry index or index + 1 by uid_eq.
Every file rule starts with its permissions in both halves of the word: owner at shift zero, other at shift fourteen. entry_add_prefix handles the qualifier by masking: owner keeps the user half and the shared bits. File rules are still cod_entry structures, so this is the only place owner is applied; every rule class rejects it in valid_prefix. In the file DFA, each state gets two permission entries, owner first, then other. In the kernel, aa_lookup_condperms returns the first when the subject user id equals the object user id, and the second otherwise. The subject is current_fsuid. Policy from an older parser has no table, and the kernel builds the pairs itself.
Details and sources
for AppArmor developers for security researchers
Details
- Permission word:
AA_USER_SHIFT0,AA_OTHER_SHIFT14 (immunix.h:24-25);AA_USER_PERMS,AA_OTHER_PERMS(immunix.h:58-59);AA_SHARED_PERMSis change_hat and change_profile (immunix.h:66). parse_permssets both halves (parser_misc.c:738-741).entry_add_prefixmasks:ownerkeepsAA_USER_PERMS | AA_SHARED_PERMS,otherkeepsAA_OTHER_PERMS | AA_SHARED_PERMS(parser_misc.c:1147-1159).- Dumps from the parser built from AppArmor 836052d21 (
-D rule-exprs):/a r,has rule mask0x10004,owner /a r,0x4,other /b r,0x10000;owner /c rw,withother /c r,merge to0x1000e. - Two entries per file DFA state, owner then other (hfa.cc:1415-1428). The second accept table carries the owner flag for every file state (chfa.cc:116-122, chfa.cc:157-159);
permsv3 is written when the kernel feature set supports it (parser_interface.c:376-380). - The kernel:
aa_lookup_condperms(kuid_t subj_uid, struct aa_policydb *rules, aa_state_t state, struct path_cond *cond)(file.c:194-209);ACCEPT_FLAG_OWNER = 1(policy.h:62); caller passescurrent_fsuid()(file.c:227). struct path_condis filled from the inode owner through the mount id mapping (lsm.c:248-251) or, on creation, fromcurrent_fsuid()(lsm.c:316).- Policy without a permission table:
compute_fpermsbuildsstate * 2andstate * 2 + 1(policy_compat.c:150-171) andremap_dfa_acceptflags every state (policy_compat.c:288-299). - Not determined: how a kernel treats a table whose
permsvis below 3.
for AppArmor developers for security researchers
Read more
- AppArmor wiki: TechnicalDoc_HFA_permissions: how permissions are encoded on accept states.
- apparmor.d(5), owner.
- re-perms: building the permission table.
- k-match: the kernel's matching and lookup.
07 owner in the wrong place
owner goes before the path. It is an equality test between the task's fsuid and the file's owner uid; root is not the owner of other users' files. (The kernel, read from the source.)
Three mistakes the parser catches, and one it can't. Owner between the path and the letters is a syntax error: the parser expected the letters. Owner on a rule that isn't a file rule is refused by that rule class. Owner before deny is the wrong order; write deny owner. The fourth one produces no error at all. Owner doesn't mean has permission by Unix rules. It's an equality test on user ids. A demo running as root doesn't own a file that belongs to user one thousand, so an owner rule doesn't cover that file.
Details and sources
Details
- Rows 1 to 3 were printed by the parser built from AppArmor 836052d21 (
-Q -K --skip-kernel-load), asAppArmor parser error for FILE in profile FILE at line N: MESSAGE. /foo owner rw,: "syntax error, unexpected TOK_OWNER, expecting TOK_MODE" (fixture bad_3.sd).owner capability chown,: "owner conditional not allowed on capability rules" (fixture bad_1.sd; block_rules.cc:140-141).owner deny /foo w,: "syntax error, unexpected TOK_DENY, expecting TOK_ID or TOK_MODE or TOK_SET_VAR". The order is fixed by parser_yacc.y:705-711.- Row 4 is derived from the kernel code of the kernel, not observed: the test is
uid_eq(subj_uid, cond->uid)(file.c:202-205), an equality of two uids. No capability and no uid, 0 included, makes it true for a file owned by someone else. - The file's uid is taken through the id mapping of the mount (lsm.c:248-251), so on an id-mapped mount it is the mapped owner that is compared.
for security researchers
Attack surface
owneris one equality test, the task's fsuid against the file's owner uid (file.c:202-205, file.c:227; read from the kernel source, not observed on a running kernel). It does not look at groups, the mode bits, ACLs or capabilities: root withCAP_DAC_OVERRIDEis still not the owner of other users' files, and a task that changes its fsuid changes which files anownerrule covers.- The owner uid is read through the id mapping of the mount (lsm.c:248-251), so on an id-mapped mount the comparison uses the mapped owner.
- A file the task creates is compared with the task's own fsuid, so
owneralways holds at creation (lsm.c:316-319). For a hard link the owner is that of the existing file (file.c:443-448); for an exec it is the owner of the executable (domain.c:995-998): anownerexec rule therefore admits any matching program the user owns, including one the user has just written. - The comparison is made when a name is checked (open, create, link, exec, and rechecks), not on each read or write of an open descriptor: by reading file.c:648-661, a descriptor is not rechecked while the task's label is unchanged, so a chown after the open does not revoke access.
ownerreaching achange_profilerule through a block is accepted and does nothing; on any other rule class it is an error.
Read more
- apparmor.d(5), owner and apparmor.d(5), Rule Qualifiers.
- syn-allow-deny:
denyand its seat. - syn-other: rules for files the task does not own.
08 Where to go from here
Next: syn-other (the complement), syn-qualifier-blocks (owner { }), syn-file-rules.
Owner narrows a file rule to the user's own files. Its twin, other, covers exactly the files owner leaves out. Together they let you give owners one set of permissions and everyone else another. That's the next deck. If you have many owner rules, a qualifier block saves typing, and the allow and deny deck covers the seat just before this one. The file rules and link rules decks cover the rules owner applies to. And if you want the machinery, there are decks on the permission entries and on matching in the kernel.
Details and sources
Details
ownerandotherare the two values of one qualifier seat (parser_yacc.y:696-698); a rule with neither applies in both cases.owner /c rw,withother /c r,gives owners read and write and everyone else read on one path (rule mask0x1000ein the dump of the parser built from AppArmor 836052d21).
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), with nothing loaded into a kernel; "code" means the parser or kernel source was read, not run. Nothing here was observed on a running kernel. Kernel statements are for mainline Linux 7.4.
Grammar
[priority=N] [audit] [allow|deny|prompt] ( owner | other ) FILE RULE ,
[audit] [allow|deny|prompt] ( owner | other ) { FILE RULES }
priority=Nis not allowed in front of a block:priority is not allowed on rule blocks(tree).owneris the last qualifier, directly in front of the rule (code; parser_yacc.y:705-711).- Accepted on file rules in both spellings (
owner /path rw,andowner rw /path,), on the bareowner file,, onlinkrules and on blocks (tree). ownerandothershare the seat: a rule has one of them or neither.other: syn-other.- The keyword table also has
useras an alias ofowner(tree; parser_misc.c:95-96). It is not documented in apparmor.d(5).
The test
In mainline Linux 7.4 an owner rule applies when the task's fsuid (current_fsuid()) equals the owner uid of the object (code).
| Operation | Whose uid is the object's owner | Source |
|---|---|---|
| access to an existing file | the inode's owner, seen through the mount's id mapping | lsm.c:248-251 |
| creating a file or directory | the creating task's fsuid, so the rule matches | lsm.c:316-319 |
| hard link | the existing file's owner, for both names | file.c:443-448 |
| a check on an open file | the owner of the file's inode | file.c:497-500 |
| exec | the owner of the executable | domain.c:995-998 |
- A rule without
ownerorotherapplies in both cases. - The test is an equality of uids. Being root, or holding a capability, does not make a task the owner of another user's file.
owner /c rw,withother /c r,gives owners read and write and everyone else read (tree: one merged rule, mask0x1000e).
Log fields
File records carry fsuid= (the task) and ouid= (the object's owner) after requested_mask= and denied_mask= (code; file.c:62-66). The shape of a denial under an owner rule, shortened, not captured from a running system:
apparmor="DENIED" operation="open" ... name="/var/lib/demo/cache/bob.db" ... requested_mask="rw" denied_mask="rw" fsuid=1000 ouid=1001
In a link record ouid= is the existing file's owner. Reading records: adm-denials.
Rule classes
| Rule class | Message | Basis |
|---|---|---|
file rules, file,, link | accepted | tree |
| capability | owner conditional not allowed on capability rules | tree |
capability inside owner { } | owner prefix not allowed on capability rules | tree |
| change_profile | owner conditional not allowed on change_profile rules | tree |
| signal | owner prefix not allowed on signal rules | tree |
| ptrace, mount, dbus, unix, network, mqueue, io_uring, userns, all | owner prefix not allowed on X rules, X being the class | tree |
other is rejected by the same checks with the same messages.
Errors and warnings
A parse error is printed as AppArmor parser error for FILE in profile FILE at line N: MESSAGE (tree).
| Message | Cause |
|---|---|
syntax error, unexpected TOK_OWNER, expecting TOK_MODE | /foo owner rw,: owner goes before the path (tree) |
syntax error, unexpected TOK_DENY, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | owner deny /foo w,: write deny owner (tree) |
syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | owner other /foo r,: one of the two per rule (tree) |
owner conditional not allowed on capability rules | owner capability chown, (tree) |
owner prefix not allowed on X rules | owner or other on another rule class, directly or through a block (code) |
An owner { block without its closing brace is a syntax error as well.
Differences from the man page
Known discrepancies between apparmor.d(5) at the commit above and the code:
- The manual says the task must have "the same euid/fsuid as the object" (apparmor.d.pod:2567-2570). The kernel code of mainline Linux 7.4 compares the fsuid only.
userandotherare not documented.- The grammar line
QUALIFIERS(apparmor.d.pod:200) omitsownerandother;'owner'appears only in the file and link rule lines.
Known discrepancies
These are not intended behaviour and should not be relied on.
owner { change_profile -> x, }is accepted, whileowner change_profile -> x,is rejected (tree).owner { other /foo r, }is accepted and yields a rule with no file permissions, without a diagnostic (tree; code: parser_misc.c:1147-1159 has no conflict check). See syn-other.- apparmor_parser 5.0.2 prints "owner conditional not allowed on unix rules" for
owner change_profile -> foo,; the tree names change_profile.
for AppArmor developers for security researchers
Code map
| Step | Where |
|---|---|
grammar: opt_owner_flag is empty, TOK_OWNER or TOK_OTHER | parser_yacc.y:696-698 |
keywords owner, user, other | parser_misc.c:95-97 |
owner_t { UNSPECIFIED, SPECIFIED, NOT }, field prefixes.owner | rule.h:193, rule.h:245 |
AA_USER_SHIFT 0, AA_OTHER_SHIFT 14; AA_USER_PERMS, AA_OTHER_PERMS, AA_SHARED_PERMS | immunix.h:24-25, immunix.h:58-66 |
parse_perms sets both halves | parser_misc.c:738-741 |
entry_add_prefix masks the word; the only place owner is applied | parser_misc.c:1147-1159 |
valid_prefix of each rule class rejects it | for example signal.h:51-54 |
| capability and change_profile checks | block_rules.cc:140-141, block_rules.h:68-70, parser_yacc.y:812-813 |
| two permission entries per file state | hfa.cc:1415-1428 |
| second accept table flag for file states | chfa.cc:116-122, chfa.cc:157-159 |
permsv 3 | parser_interface.c:376-380 |
aa_lookup_condperms, ACCEPT_FLAG_OWNER (Linux 7.4) | file.c:194-209, policy.h:62 |
current_fsuid() as subject uid (Linux 7.4) | file.c:227 |
struct path_cond construction (Linux 7.4) | lsm.c:248-251, lsm.c:316, file.c:443-448, file.c:497-500, domain.c:995-998 |
policy without a table: compute_fperms, remap_dfa_accept (Linux 7.4) | policy_compat.c:150-171, policy_compat.c:288-299 |
Dump format (-D rule-exprs -D dfa-states-initial): bits per half x 0x1, w 0x2, r 0x4, a 0x8; the other half is shifted left by 14.
| Rules | Rule mask | Basis |
|---|---|---|
/a r, | 0x10004 | tree |
owner /a r, | 0x4 | tree |
other /b r, | 0x10000 | tree |
owner /c rw, other /c r, | merged 0x1000e | tree |
owner /a rw, other /a r, deny owner /a w, | state (0x 10004/a//0/0/a): both get read; only the owner's write denial is quiet | tree |
Not determined: how a kernel treats a permission table whose permsv is below 3.
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- File rules — the rules owner applies to
- Link rules — which file's owner counts for a link
- File access modes — the letters each half holds
QUALIFIERS
- The other qualifier — the complement for files the task does not own
- allow and deny — the qualifier seat before owner
- Qualifier blocks — owner in front of a block of file rules
IN PRACTICE · security-sensitive programs
- Writing rules for /sys and /proc — what owner means on /proc files
IN THE KERNEL
- Matching at run time — where the kernel picks the entry
THE DFA ENGINE · libapparmor_re
- Permissions in the DFA — the two permission entries per state