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

01 One profile, many users

THE OWNER QUALIFIER profile demo demo (alice, uid 1000) demo (bob, uid 1001) /var/lib/demo/cache/alice.db owner 1000 /var/lib/demo/cache/bob.db owner 1001 /var/lib/demo/cache/** rwk, alice's demo may write bob's file owner /var/lib/demo/cache/** rwk, only files owned by the user demo runs as the Unix permission bits may also stop this. owner makes the profile say it too.
Two instances of demo, one run by alice and one by bob, share the profile demo and each keep a cache file in /var/lib/demo/cache. A plain path rule lets each instance reach both files. With owner in front of the rule, the two crossing accesses are cut.

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

  • owner is 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

for AppArmor developers for security researchers

In the code

02 The fourth seat

GRAMMAR priority=N audit allow|deny|prompt owner other FILE RULE , 1 2 3 4: owner owner /var/lib/demo/cache/** rwk, owner rw /var/lib/demo/state, either spelling of the file rule audit deny owner /var/lib/demo/** w, after the other qualifiers owner file, owner link /var/lib/demo/current -> /var/lib/demo/releases/*, owner { ... } the bare file rule a block of file rules owner comes before the path, not between the path and the letters other shares the fourth seat: one of the two per rule
Syntax diagram of the four qualifier seats: priority=N, audit, the access type, and the fourth seat holding owner or other, followed by a file rule. Below, accepted examples: owner with both spellings of a file rule, audit deny owner, owner file, owner link and an owner block.

[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). owner and other share 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, and owner { ... }.
  • Test fixtures: ok_1.sd (both spellings and blocks), ok_link_owner.sd (owner link subset /alpha/beta -> /tmp/**,).
  • owner after 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 user to the same token as owner (parser_misc.c:95-97). The map does not recommend it.

Read more

03 fsuid against the file's owner

EVERY CHECK owner /var/lib/demo/cache/** rwk, demo fsuid=1000 the kernel, the kernel open("/var/lib/demo/cache/alice.db", O_RDWR) task fsuid 1000 file owner 1000 equal: use the owner permissions: rwk alice.db open("/var/lib/demo/cache/bob.db", O_RDWR) task fsuid 1000 file owner 1001 different: use the permissions for others: none bob.db apparmor="DENIED" operation="open" ... name="/var/lib/demo/cache/bob.db" ... requested_mask="rw" denied_mask="rw" fsuid=1000 ouid=1001 fsuid and ouid are in file records: compare them when an owner rule surprises you
demo with fsuid 1000 opens two files under an owner rule. For alice.db the task fsuid and the file owner are both 1000, so the owner permissions rwk are used. For bob.db the owner is 1001, the permissions for others are used, which are none, and the open is denied. The denial record ends with fsuid=1000 ouid=1001.

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 by aa_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 owner or other contributes to both.
  • Log fields: file records end with fsuid= (the task) and ouid= (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

05 Only file rules have an owner

WHERE OWNER IS ACCEPTED owner /var/lib/demo/** rw, file, link /a -> /b, accepted capability chown, owner conditional not allowed on capability rules signal, owner prefix not allowed on signal rules change_profile -> x, owner conditional not allowed on change_profile rules the same for ptrace, mount, dbus, unix, network, mqueue, io_uring, userns and all: owner prefix not allowed on X rules owner { ... } is for file rules too
The qualifier owner is offered to several rules. A file rule, the bare file rule and a link rule accept it. A capability rule, a signal rule and a change_profile rule reject it, each with its own parser message; the remaining rule classes reject it in the same way.

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, and owner change_profile -> x,. The full form is AppArmor 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).
  • other is 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 form owner change_profile -> x, is rejected. Do not rely on it.

06 Two halves, two table entries for AppArmor developers for security researchers

PARSER AND KERNEL: OWNER owner half: bits 0-13 (AA_USER_SHIFT 0) other half: bits 14-27 (AA_OTHER_SHIFT 14) parse_perms sets both halves: /a r, = 0x10004 entry_add_prefix: perms &= AA_USER_PERMS | AA_SHARED_PERMS owner /a r, = 0x4 parser_misc.c:1147-1159 cleared by owner DFA state perms[index] owner entry perms[index + 1] other entry hfa.cc:1415-1428 accept2 flag ACCEPT_FLAG_OWNER, permsv 3 aa_lookup_condperms (file.c:194-209), the kernel if (uid_eq(subj_uid, cond->uid)) return &(rules->perms[index]); return &(rules->perms[index + 1]); subj_uid = current_fsuid() (file.c:227) cond->uid = inode owner via idmap (lsm.c:248); on create: current_fsuid() (lsm.c:316) older policy without a table: pairs built in the kernel (policy_compat.c:150-171)
A file permission word with an owner half at bits 0 to 13 and an other half at bits 14 to 27. entry_add_prefix masks the word to the owner half. Each file DFA state has two permission entries, owner and other. The kernel function aa_lookup_condperms returns the first when the task fsuid equals the object uid and the second otherwise.

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_SHIFT 0, AA_OTHER_SHIFT 14 (immunix.h:24-25); AA_USER_PERMS, AA_OTHER_PERMS (immunix.h:58-59); AA_SHARED_PERMS is change_hat and change_profile (immunix.h:66).
  • parse_perms sets both halves (parser_misc.c:738-741). entry_add_prefix masks: owner keeps AA_USER_PERMS | AA_SHARED_PERMS, other keeps AA_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 mask 0x10004, owner /a r, 0x4, other /b r, 0x10000; owner /c rw, with other /c r, merge to 0x1000e.
  • 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); permsv 3 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 passes current_fsuid() (file.c:227).
  • struct path_cond is filled from the inode owner through the mount id mapping (lsm.c:248-251) or, on creation, from current_fsuid() (lsm.c:316).
  • Policy without a permission table: compute_fperms builds state * 2 and state * 2 + 1 (policy_compat.c:150-171) and remap_dfa_accept flags every state (policy_compat.c:288-299).
  • Not determined: how a kernel treats a table whose permsv is below 3.

for AppArmor developers for security researchers

Read more

07 owner in the wrong place

COMMON MISTAKES /var/lib/demo/cache/** owner rw, owner goes in front of the path syntax error, unexpected TOK_OWNER, expecting TOK_MODE owner capability chown, a capability has no owner owner conditional not allowed on capability rules owner deny /var/lib/demo/** w, write: deny owner /var/lib/demo/** w, syntax error, unexpected TOK_DENY, expecting TOK_ID or TOK_MODE or TOK_SET_VAR "demo runs as root, so it owns everything" no error no: root's fsuid is 0, and a file owned by uid 1000 is not root's owner is an equality test on user ids, not a permission check the comparison uses numeric uids, as seen through the mount
Three rejected rules with the parser's message: owner after the path, owner on a capability rule, and owner before deny. A fourth row without an error: root does not own a file that belongs to uid 1000, so an owner rule does not cover it.

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), as AppArmor 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

  • owner is 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 with CAP_DAC_OVERRIDE is still not the owner of other users' files, and a task that changes its fsuid changes which files an owner rule 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 owner always 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): an owner exec 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.
  • owner reaching a change_profile rule through a block is accepted and does nothing; on any other rule class it is an error.

Read more

08 Where to go from here

ROADS owner other fsuid = file owner: the owner rules apply syn-other the files owner leaves out syn-qualifier-blocks owner { ... } syn-allow-deny the seat before owner syn-file-rules the rules owner applies to syn-link-rules whose owner for a link syn-access-modes the letters the machinery, and the whole language re-perms two entries per state k-match picking the entry syntax-map every kind of line
Two boxes, owner and other, the two halves of a file permission. Roads lead from other to syn-other, and from owner to syn-qualifier-blocks, syn-allow-deny, syn-file-rules, syn-link-rules and syn-access-modes. Further roads: re-perms, k-match and syntax-map.

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

  • owner and other are the two values of one qualifier seat (parser_yacc.y:696-698); a rule with neither applies in both cases.
  • owner /c rw, with other /c r, gives owners read and write and everyone else read on one path (rule mask 0x1000e in 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=N is not allowed in front of a block: priority is not allowed on rule blocks (tree).
  • owner is 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, and owner rw /path,), on the bare owner file,, on link rules and on blocks (tree).
  • owner and other share the seat: a rule has one of them or neither. other: syn-other.
  • The keyword table also has user as an alias of owner (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).

OperationWhose uid is the object's ownerSource
access to an existing filethe inode's owner, seen through the mount's id mappinglsm.c:248-251
creating a file or directorythe creating task's fsuid, so the rule matcheslsm.c:316-319
hard linkthe existing file's owner, for both namesfile.c:443-448
a check on an open filethe owner of the file's inodefile.c:497-500
execthe owner of the executabledomain.c:995-998
  • A rule without owner or other applies 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, with other /c r, gives owners read and write and everyone else read (tree: one merged rule, mask 0x1000e).

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 classMessageBasis
file rules, file,, linkacceptedtree
capabilityowner conditional not allowed on capability rulestree
capability inside owner { }owner prefix not allowed on capability rulestree
change_profileowner conditional not allowed on change_profile rulestree
signalowner prefix not allowed on signal rulestree
ptrace, mount, dbus, unix, network, mqueue, io_uring, userns, allowner prefix not allowed on X rules, X being the classtree

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).

MessageCause
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_VARowner deny /foo w,: write deny owner (tree)
syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VARowner other /foo r,: one of the two per rule (tree)
owner conditional not allowed on capability rulesowner capability chown, (tree)
owner prefix not allowed on X rulesowner 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.
  • user and other are not documented.
  • The grammar line QUALIFIERS (apparmor.d.pod:200) omits owner and other; '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, while owner 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

StepWhere
grammar: opt_owner_flag is empty, TOK_OWNER or TOK_OTHERparser_yacc.y:696-698
keywords owner, user, otherparser_misc.c:95-97
owner_t { UNSPECIFIED, SPECIFIED, NOT }, field prefixes.ownerrule.h:193, rule.h:245
AA_USER_SHIFT 0, AA_OTHER_SHIFT 14; AA_USER_PERMS, AA_OTHER_PERMS, AA_SHARED_PERMSimmunix.h:24-25, immunix.h:58-66
parse_perms sets both halvesparser_misc.c:738-741
entry_add_prefix masks the word; the only place owner is appliedparser_misc.c:1147-1159
valid_prefix of each rule class rejects itfor example signal.h:51-54
capability and change_profile checksblock_rules.cc:140-141, block_rules.h:68-70, parser_yacc.y:812-813
two permission entries per file statehfa.cc:1415-1428
second accept table flag for file stateschfa.cc:116-122, chfa.cc:157-159
permsv 3parser_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.

RulesRule maskBasis
/a r,0x10004tree
owner /a r,0x4tree
other /b r,0x10000tree
owner /c rw, other /c r,merged 0x1000etree
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 quiettree

Not determined: how a kernel treats a permission table whose permsv is below 3.

Roads from here

START HERE

FILE ACCESS

QUALIFIERS

IN PRACTICE · security-sensitive programs

IN THE KERNEL

THE DFA ENGINE · libapparmor_re