The other qualifier
files you do not own for application developers
other limits a file rule to objects whose owner differs from the user the task is acting as. It is the complement of owner. A rule with neither keyword covers both cases.
On the map: qualifiers
▶ Watch this deck — 7 scenes, ~5 min
Worth seeing first
- The owner qualifier — the owner qualifier and its user id comparison
Part of journeys
- File access in depth, step 9 of 12 · previous: The owner qualifier · next: allow and deny
01 Read everyone's, write only your own
other RULE, applies a file rule only to files whose owner uid differs from the task's fsuid. It is the complement of owner. (The kernel, read from the source.)
Demo runs as user one thousand, and in its shared directory there are two databases: its own, and one that belongs to somebody else. In the owner deck you saw the rule for the first: owner, read and write. But often you also want to read everyone else's files, just not change them. Owner can't say that. Other can. It's the exact complement: an owner rule applies when the file's owner is the user the program is acting as, and an other rule applies when it isn't. Put both on the same path and you get two sets of letters for one pattern.
Details and sources
Details
otheris a rule qualifier for file rules. Anotherrule applies when the owner uid of the file differs from the task's fsuid; anownerrule applies when they are equal; a rule with neither keyword applies in both cases.- The pair on the slide:
owner /var/lib/demo/shared/** rw,andother /var/lib/demo/shared/** r,. The directory and the two file names are invented for this deck;demois the map's example program. - The comparison is made by the kernel each time a file is checked (at open, create, link and exec). In the kernel (commit 97d73c825) the subject id is
current_fsuid()(file.c:227) and the choice between the two cases is inaa_lookup_condperms(file.c:194-209). This was read from the kernel source; nothing in this deck was observed on a running kernel. - Which uid counts as the file's owner (existing files, files being created, links, executables) is the subject of syn-owner.
for AppArmor developers for security researchers
Code
- Grammar:
TOK_OTHERinopt_owner_flag, parser_yacc.y:696-698; keyword table parser_misc.c:97. - The mask applied for
other: parser_misc.c:1155-1156.
Read more
- The qualifier list of the manual page, which has
ownerand no entry forother: apparmor.d(5), Rule Qualifiers - The qualifiers on the wiki: AppArmor wiki: rule prefixes and modes
- The other half of the pair: syn-owner
- The rules it applies to: syn-file-rules
02 The same seat as owner
[priority=N] [audit] [allow|deny|prompt] other FILE RULE,. owner and other share a seat; a rule with neither applies to all files.
Other sits in the same seat as owner: the last one before the rule. This line is from the parser's own tests. Audit and deny go in front of it, as with any qualifier. What you can't do is write both words on one rule; the parser stops at the second one with a syntax error. And you don't need to. For any file rule there are three possibilities: owner, for the user's own files; other, for files of other users; or neither word, which covers both. Leaving them out is how you say both.
Details and sources
Details
- Form:
[priority=N] [audit] [allow|deny|prompt] other FILE RULE,. The order of the qualifiers is fixed;ownerandotherare alternatives for the last seat. - Fixtures in the tree, all expected to pass:
other /tmp/** rw,(ok_other_1.sd),deny other /tmp/** rw,(ok_other_2.sd),audit other /tmp/** rw,(ok_other_3.sd). owner other /foo r,is rejected withsyntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR(run with the tree's parser at 836052d21,-Q -K --skip-kernel-load --warn=all). The slide shows the same rule with the path/tmp/**.- Full form of a parse error:
AppArmor parser error for FILE in profile FILE at line N: MESSAGE. - The three cases for a file rule X:
owner X(files the task's user owns),other X(files it does not own),X(both). - Known discrepancy with the manual: apparmor.d(5) at this commit has no
'other'in its grammar;FILE RULEandLINK RULEshow only[ 'owner' ](apparmor.d.pod:397, apparmor.d.pod:416).
for AppArmor developers for security researchers
Code
opt_owner_flag: empty,TOK_OWNERorTOK_OTHER, parser_yacc.y:696-698. One production, so one keyword per rule.- Keywords
owner,user(bothTOK_OWNER) andother: parser_misc.c:95-97.
Read more
- The manual page on qualifiers: apparmor.d(5), Rule Qualifiers
- The four qualifier seats: syn-allow-deny
owner, and its undocumented aliasuser: syn-ownerauditin front: syn-audit
03 Two rules, one path
owner P rw, with other P r, gives owners read-write and everyone else read-only on P. The kernel uses one half per access, chosen by comparing the task's fsuid with the file's owner.
Here's what the pair builds. Think of the permissions for a path as a box with two compartments: one for the owner case, one for everybody else. An owner rule fills the left one, an other rule fills the right one, and a plain rule fills both. At each access, the kernel compares the user ids and opens one compartment. Demo writing its own file finds read and write. Demo writing someone else's file looks in the other compartment, finds only read, and is refused. Reading that file is fine.
Details and sources
Details
owner /c rw,withother /c r,compile to one rule whose permission mask is0x1000e:rwin the owner half,rin the other half (dump from the tree's parser at 836052d21 with-D rule-exprs -D dfa-states-initial; nothing was loaded into a kernel).- Reading the mask: per half
x 0x1, w 0x2, r 0x4, a 0x8; the other half is shifted left by 14 bits, sorfor others is0x10000.wimpliesa, so the owner halfrwis0xe. - The three outcomes on the slide are derived from the kernel code and were not run. In the kernel
aa_lookup_condpermsreturns the first permission entry of a file state whenuid_eq(subj_uid, cond->uid)and the second otherwise (file.c:194-209); the subject uid iscurrent_fsuid()(file.c:227). - A refused request is logged with both ids:
fsuid=... ouid=...(file.c:63-66, the kernel). - A rule with neither keyword puts its letters in both halves.
for AppArmor developers for security researchers
Code
ownerkeepsAA_USER_PERMS | AA_SHARED_PERMS,otherkeepsAA_OTHER_PERMS | AA_SHARED_PERMS: parser_misc.c:1152-1156.- File entries that compare equal (same name, link name, access type, audit and priority) are merged with
cur->perms |= next->permsinblock_rules::merge_file: block_rules.cc:285-338.
Read more
ownerin the manual page: apparmor.d(5), owner- The qualifiers on the wiki: AppArmor wiki: rule prefixes and modes
- Which uid is the file's owner in each kind of access: syn-owner
- The two permission entries per state: re-perms
04 deny other: protect files that are not yours
deny other P rw, denies access to files under P that the task does not own; the task's own files are unaffected. Like any deny it is quiet unless you write audit deny other. (The kernel, read from the source.)
Other is most useful with deny. A shared temporary directory is full of other people's files. So allow read and write there, then deny other for the same pattern. The deny strikes out only the compartment for files the user doesn't own. Demo keeps full access to its own temporary files, and has none to anybody else's, even if some included abstraction tried to allow it. And like every plain deny it's silent, so add audit if you want to hear about attempts.
Details and sources
Details
deny other /tmp/** rw,is a fixture in the tree: ok_other_2.sd./d rw,withdeny other /d rw,compiles to the state(0x e/38000//0/0/38000)(dump from the tree's parser at 836052d21; format(allow/deny//prompt/audit/quiet)): the owner half allowsrw; the other half is denied and quiet.- The two requests on the slide are derived from that state and the kernel's two-entry lookup in the kernel (file.c:194-209); they were not run.
/tmp/demo-1000.sockand/tmp/other-user.txtare illustrations. - Compared with
owner /tmp/** rw,alone: both leave the other half without permissions. Withdeny otherthe refusals are quiet, and an allow rule from elsewhere (an included abstraction, for example) cannot add permissions for those files at the same priority. Rules with a higherpriority=Ncan: syn-priority. audit deny other /tmp/** rw,keeps the refusal and makes it logged: syn-audit.
for AppArmor developers for security researchers
Code
- The qualifier masks the rule's permission word before the rule is compiled; the deny then covers only the other half: parser_misc.c:1155-1156.
Read more
denyandownerin the manual page: apparmor.d(5), deny, apparmor.d(5), owner- How deny overrides allow, and why it is quiet: syn-allow-deny
- Making a deny audible: syn-audit
05 owner_t::NOT and entry index + 1 for AppArmor developers for security researchers
other → owner_t::NOT → perms &= AA_OTHER_PERMS | AA_SHARED_PERMS (parser/parser_misc.c:1155-1156) → entry index + 1 in aa_lookup_condperms (linux:security/apparmor/file.c:203-205, the kernel).
In the grammar, other is the second alternative of opt_owner_flag and becomes owner_t::NOT; the debug dump prints it as !owner. For file rules, entry_add_prefix masks the permission word with the other permissions and the shared bits: the mirror image of owner. An owner rule and an other rule with the same path are merged by OR in merge_file, giving one word with different halves. In the kernel, the other half is the second entry of the pair, the one aa_lookup_condperms returns when the user ids differ. And the rule classes that refuse owner test for anything but unspecified, so other gets the same messages.
Details and sources
for AppArmor developers for security researchers
Details
- Grammar action:
TOK_OTHER { $$ = owner_t::NOT; }, parser_yacc.y:698;enum class owner_t { UNSPECIFIED, SPECIFIED, NOT }, rule.h:193. The prefix dump prints!owner: rule.h:297-301. - File permission word: owner half at shift 0, other half at shift 14 (immunix.h:24-25, immunix.h:58-59); the shared bits are change_hat and change_profile (immunix.h:66).
entry_add_prefix:entry->perms &= (AA_OTHER_PERMS | AA_SHARED_PERMS)forowner_t::NOT, parser_misc.c:1155-1156. It is the only place the qualifier is applied to file rules.- Rule masks (dumps from the tree's parser at 836052d21,
-D rule-exprs):other /b r,is0x10000;owner /c rw,withother /c r,is one rule with0x1000e. - Merge:
block_rules::merge_filesorts the file entries and ORs the permission words of entries that compare equal, block_rules.cc:285-338 (the OR is at line 329). - Kernel: for a state flagged
ACCEPT_FLAG_OWNER,aa_lookup_condpermsreturnsperms[index + 1]when the uids differ, file.c:203-205. - Other rule classes test
p.owner != owner_t::UNSPECIFIEDinvalid_prefix, for example signal.h:52, sootherandownerget the same message.
Read more
- How permissions are encoded on accept states: AppArmor wiki: TechnicalDoc_HFA_permissions
- The same drawing for the owner half, and how the two entries are written: syn-owner
- The permission table: re-perms
- Where the kernel walks the file DFA: k-match
06 other in the wrong place
other is rejected wherever owner is, with messages that say "owner". An other rule alone does not cover the task's own files.
Other follows owner's rules. You can't combine the two on one line. It's refused on anything that isn't a file rule, and here's a small trap when you read the error: the message says owner prefix not allowed, even though you wrote other. Capability rules have their own wording, and it says owner too. Then the usual logic slip: an other rule on its own gives nothing for the user's own files, so a program that may read everybody else's file can be refused its own. Finally, don't look for other in the manual page. At this version it isn't there.
Details and sources
Details
owner other /tmp/** r,:syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR.other signal,:owner prefix not allowed on signal rules.other capability chown,:owner conditional not allowed on capability rules.- These three were run with exactly these lines on the tree's parser at 836052d21 (
-Q -K --skip-kernel-load --warn=all). Full form:AppArmor parser error for FILE in profile FILE at line N: MESSAGE. - The same "owner prefix not allowed on X rules" string exists for ptrace, mount, dbus, unix, network, mqueue, io_uring, userns and all rules (read from the code; the table is in the reference below).
other P r,alone is accepted. It putsrin the other half only, so a file the task's user owns gets no permission from it (derived from the code and from the rule mask0x10000; not run against a kernel).- Not in the manual: apparmor.d(5) at this commit lists
ownerunder "Rule Qualifiers" and has no item forother(apparmor.d.pod:2531-2572). - Known discrepancy:
owner { other /foo r, }is accepted with exit status 0 and no message (run with the tree's parser), and yields a rule that grants no file permission. It is a suspected bug, not a feature to rely on. See the reference below.
for AppArmor developers for security researchers
Code
- Rule classes: signal.h:52-53; capability rules: block_rules.cc:140-141; change_profile: parser_yacc.y:812-813.
- No conflict check for file rules in
entry_add_prefix: parser_misc.c:1147-1159; the "conflicting owner prefix" check for rule objects: rule.h:419-424.
for security researchers
Attack surface
owner { other RULE }andother { owner RULE }are accepted without a message and leave a rule with the mask0x0: the author believes a rule is in force and nothing is granted (run with the parser built from the AppArmor tree at 836052d21, nothing loaded into a kernel,-D rule-exprs; parser_misc.c:1147-1159). The failure is closed, but it is silent.other P r,alone grants nothing on files the task's user owns. A profile that means "everyone's files" needs the plain rule, or bothownerandother.deny other P rw,protects other users' files only at equal or higher priority than the allow rules it meets, and it is quiet: addauditto see attempts.- "Other" is decided by fsuid against the file's owner uid at the time a name is checked, like
owner(file.c:202-205; read from the kernel source, not observed on a running kernel). A task that can change its fsuid moves files between the two halves.
Read more
- The manual page on qualifiers and blocks: apparmor.d(5), Rule Qualifiers, apparmor.d(5), Qualifier Blocks
- The same restrictions for
owner: syn-owner - Qualifiers in front of a block: syn-qualifier-blocks
07 Where to go from here
Next: syn-owner (the comparison in detail), syn-qualifier-blocks, syn-allow-deny, syn-audit. Internals: re-perms.
That completes the four seats: priority, audit, the access type, and owner or other. If you skipped the owner deck, go there for the details of the comparison: which user id is used, and what counts as the owner of a file that's being created. Deny other and audit other have their own decks behind them. Qualifier blocks let you write other once for a group of rules. And the permissions deck shows the two table entries behind the two compartments.
Details and sources
Details
- The four qualifier seats, in order:
priority=N,audit, the access type (allow,denyorprompt), andownerorother. otheris compiled by the parser at AppArmor 836052d21 into the second permission entry of each file state; the kernel selects that entry when the task's fsuid differs from the file's owner (read from source, not run).
Read more
- apparmor.d(5), Rule Qualifiers: the manual page; it lists
ownerand has no entry forother - AppArmor wiki: rule prefixes and modes: the qualifiers on the wiki
- syn-owner: the comparison in detail, and the owner of a file being created
- syn-allow-deny:
deny other - syn-audit:
audit other - syn-qualifier-blocks:
other { ... } - syn-file-rules: the rules
otherapplies to - re-perms: the two permission entries of a state
- syntax-map: every kind of line on one page
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, plus -D rule-exprs -D dfa-states-initial for dumps), with nothing loaded into a kernel; "code" means the parser or kernel source was read, not run; "derived" means reasoned from the code and the dumps. Nothing here was observed on a running kernel. Kernel statements are for mainline Linux 7.4.
Grammar
RULE LINE: [priority=N] [audit] [allow|deny|prompt] other FILE RULE ,
BLOCK: [audit] [allow|deny|prompt] other { RULES }
priority=Nis not allowed in front of a block:priority is not allowed on rule blocks(tree).- Keyword:
other. It has no alias (ownerhas one,user). - It takes the same seat as
owner, the last one before the rule. A rule hasowner,otheror neither; both on one rule is a syntax error (tree). - Accepted on file rules, the bare
file,rule,linkrules and blocks of them (tree). Other rule classes reject it: see "Errors and warnings". - Fixtures:
parser/tst/simple_tests/file/ok_other_1.sd(other /tmp/** rw,),ok_other_2.sd(deny other /tmp/** rw,),ok_other_3.sd(audit other /tmp/** rw,).
Meaning
The test is the one described in syn-owner: the task's fsuid against the owner uid of the object, with the cases for creating a file, linking and exec explained there. other applies when the two differ.
| Rules | Task owns the file | Task does not own the file | Basis |
|---|---|---|---|
owner P rw, | rw | nothing | derived |
other P r, | nothing | r | derived; rule mask 0x10000 (tree) |
P r, | r | r | derived; rule mask 0x10004 (tree) |
owner P rw, and other P r, | rw | r | derived; merged rule mask 0x1000e (tree) |
P rw, and deny other P rw, | rw | denied, quiet | derived; state (0x e/38000//0/0/38000) (tree) |
owner P rw, and other P r, and deny owner P w, | r; write denied, quiet | r | derived; state (0x 10004/a//0/0/a) (tree) |
"Nothing" means the rule contributes no permission for that case: in enforce mode the request is refused and logged unless another rule allows it. In mainline Linux 7.4 the log record of a file request carries both ids as fsuid= and ouid= (code, linux:security/apparmor/file.c:63-66).
Errors and warnings
A parse error is printed as AppArmor parser error for FILE in profile FILE at line N: MESSAGE (tree). The messages say "owner" when the rule says other.
| Message | Cause | Basis |
|---|---|---|
syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR | owner other /foo r, | tree |
owner prefix not allowed on signal rules | other signal, | tree |
owner prefix not allowed on X rules, X one of ptrace, mount, dbus, unix, network, mqueue, io_uring, userns, all | other on a rule of that class | code |
owner conditional not allowed on capability rules | other capability chown, | tree |
owner prefix not allowed on capability rules | other reaching a capability rule through a block | tree |
owner conditional not allowed on change_profile rules | other change_profile ... | tree |
There is no warning for an other rule that leaves the task's own files uncovered.
Not in the man page
Known discrepancy with the manual: apparmor.d(5) at this commit has no 'other' in its grammar (FILE RULE and LINK RULE show [ 'owner' ] only, parser/apparmor.d.pod:397 and 416) and no item for it under "Rule Qualifiers" (parser/apparmor.d.pod:2531-2572). The parser's keyword table and the three fixtures above define its use.
Known discrepancies
owner { other RULE }, and the reverse, is accepted with exit status 0 and no diagnostic (tree) and produces a file rule that grants no file permission: the two masks are applied in turn and only the shared bits remain (code, parser/parser_misc.c:1147-1159).-D rule-exprsshows the rule with mask0x0(tree). Suspected bug; do not rely on it.- The message
conflicting owner prefixexists for rule objects (parser/rule.h:419-424) and cannot be reached for file rules, which are the only rules that accept the qualifier (code).
for AppArmor developers for security researchers
Code map
| Step | Where |
|---|---|
token TOK_OTHER, keyword other | parser/parser_yacc.y:117; parser/parser_misc.c:97 |
opt_owner_flag: TOK_OTHER gives owner_t::NOT | parser/parser_yacc.y:696-698; enum at parser/rule.h:193 |
prefix dump prints !owner | parser/rule.h:297-301 |
entry_add_prefix: perms &= AA_OTHER_PERMS or AA_SHARED_PERMS | parser/parser_misc.c:1155-1156 |
halves: AA_USER_SHIFT 0, AA_OTHER_SHIFT 14; AA_OTHER_PERMS; AA_SHARED_PERMS | parser/immunix.h:24-25, 59, 66 |
block_rules::merge_file: equal entries are ORed | parser/block_rules.cc:285-338 |
| two permission entries per file state, owner then other | parser/libapparmor_re/hfa.cc:1415-1417, 1427-1428 |
valid_prefix tests p.owner != owner_t::UNSPECIFIED | parser/signal.h:52 and the other rule class headers |
| capability and change_profile checks | parser/block_rules.cc:140-141; parser/block_rules.h:68-70; parser/parser_yacc.y:812-813 |
aa_lookup_condperms: perms[index + 1] when the uids differ (Linux 7.4) | linux:security/apparmor/file.c:203-205 |
subject uid current_fsuid() (Linux 7.4) | linux:security/apparmor/file.c:227 |
Dump format (-D dfa-states-initial): (allow/deny//prompt/audit/quiet) in hex; the doubled / is a known defect of the dump. Bits per half: x 0x1, w 0x2, r 0x4, a 0x8; the other half is shifted left by 14; w implies a.
| Rules | Dump | Basis |
|---|---|---|
other /b r, | rule mask 0x10000 | tree |
owner /c rw, other /c r, | one rule, mask 0x1000e | tree |
/d rw, deny other /d rw, | state (0x e/38000//0/0/38000) | tree |
owner /a rw, other /a r, deny owner /a w, | state (0x 10004/a//0/0/a) | tree |
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- File rules — the rules other applies to
QUALIFIERS
- The owner qualifier — the comparison and the other half of the pair
- allow and deny — deny other
- The audit qualifier — audit other
- Qualifier blocks — other in front of a block
THE DFA ENGINE · libapparmor_re
- Permissions in the DFA — the second permission entry of a state