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

Part of journeys

01 Read everyone's, write only your own

THE OTHER QUALIFIER demo (uid 1000) /var/lib/demo/shared/mine.db owner 1000 /var/lib/demo/shared/theirs.db owner 1001 owner /var/lib/demo/shared/** rw, rw other /var/lib/demo/shared/** r, r owner: fsuid = file owner other: fsuid ≠ file owner two rules, one path, two sets of letters
The program demo, running as uid 1000, and two files in one directory: mine.db owned by uid 1000 and theirs.db owned by uid 1001. An owner rule gives read and write on the first, an other rule gives read on the second. Owner applies when the fsuid equals the file owner, other when it differs.

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

  • other is a rule qualifier for file rules. An other rule applies when the owner uid of the file differs from the task's fsuid; an owner rule 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, and other /var/lib/demo/shared/** r,. The directory and the two file names are invented for this deck; demo is 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 in aa_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

Read more

02 The same seat as owner

GRAMMAR priority=N audit allow | deny | prompt owner other FILE RULE , one of the two, or neither other /tmp/** rw, from the tree's tests deny other /tmp/** rw, audit other /tmp/** rw, audit and the access type go before it owner other /tmp/** r, syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR owner X own files other X other users' files X both
Syntax diagram of the four qualifier seats: priority=N, audit, the access type, and a fourth seat holding owner or other with other highlighted, followed by the file rule. Below it an other rule from the tree's tests, deny other and audit other, the syntax error for owner other on one rule, and three chips: owner for own files, other for other users' files, neither for both.

[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; owner and other are 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 with syntax 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 RULE and LINK RULE show only [ 'owner' ] (apparmor.d.pod:397, apparmor.d.pod:416).

for AppArmor developers for security researchers

Code

Read more

03 Two rules, one path

OWNER + OTHER owner /var/lib/demo/shared/** rw, other /var/lib/demo/shared/** r, owner: r w other: r one permission set for the path, two compartments demo, fsuid 1000 ids compared write mine.db owner 1000 = fsuid allowed write theirs.db owner 1001 ≠ fsuid refused: no w for others read theirs.db owner 1001 ≠ fsuid allowed
An owner rule with rw and an other rule with r on the same path fill the two compartments of one box: owner r w, other r. Demo with fsuid 1000 writes mine.db, owned by 1000: the owner compartment allows it. It writes theirs.db, owned by 1001: the other compartment has no w and the write is refused. It reads theirs.db: allowed.

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, with other /c r, compile to one rule whose permission mask is 0x1000e: rw in the owner half, r in 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, so r for others is 0x10000. w implies a, so the owner half rw is 0xe.
  • The three outcomes on the slide are derived from the kernel code and were not run. In the kernel aa_lookup_condperms returns the first permission entry of a file state when uid_eq(subj_uid, cond->uid) and the second otherwise (file.c:194-209); the subject uid is current_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

  • owner keeps AA_USER_PERMS | AA_SHARED_PERMS, other keeps AA_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->perms in block_rules::merge_file: block_rules.cc:285-338.

Read more

04 deny other: protect files that are not yours

DENY + OTHER /tmp/** rw, owner: r w other: r w a plain rule fills both deny other /tmp/** rw, the second line is the tree's test file/ok_other_2.sd demo (uid 1000) /tmp/demo-1000.sock (owner 1000) read, write demo (uid 1000) /tmp/other-user.txt (owner 1001) refused, silently like "owner /tmp/** rw," alone, except that the refusals are quiet and other allow rules for those files are overridden too
A plain rule gives rw on /tmp/** to both compartments. deny other on the same pattern strikes out the other compartment only. Demo with uid 1000 keeps read and write on its own socket file, and is refused silently on a file owned by uid 1001.

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, with deny 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 allows rw; 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.sock and /tmp/other-user.txt are illustrations.
  • Compared with owner /tmp/** rw, alone: both leave the other half without permissions. With deny other the 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 higher priority=N can: 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

05 owner_t::NOT and entry index + 1 for AppArmor developers for security researchers

PARSER AND KERNEL: OTHER opt_owner_flag: TOK_OTHER -> owner_t::NOT parser_yacc.y:698, rule.h:193 debug dump prints "!owner" owner half: bits 0-13, cleared by other other half: bits 14-27 (AA_OTHER_SHIFT 14) entry_add_prefix: perms &= AA_OTHER_PERMS | AA_SHARED_PERMS other /b r, = 0x10000 parser_misc.c:1155-1156 owner /c rw, (0xe) + other /c r, (0x10000) merge_file: 0x1000e block_rules.cc:329, perms |= perms DFA state perms[index] owner entry perms[index + 1] other entry aa_lookup_condperms (file.c:203-205), the kernel !uid_eq(subj_uid, cond->uid) -> return &(rules->perms[index + 1]); non-file rule classes test p.owner != owner_t::UNSPECIFIED (signal.h:52), so "other" gets the "owner prefix not allowed" messages
The grammar turns TOK_OTHER into owner_t::NOT. entry_add_prefix masks the file permission word to the other half, bits 14 to 27, so other /b r, is 0x10000. An owner rule 0xe and an other rule 0x10000 on one path merge to 0x1000e. Each file state has two permission entries, and aa_lookup_condperms returns perms[index + 1] when the uids differ. Other rule classes reject other with the owner messages.

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) for owner_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, is 0x10000; owner /c rw, with other /c r, is one rule with 0x1000e.
  • Merge: block_rules::merge_file sorts 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_condperms returns perms[index + 1] when the uids differ, file.c:203-205.
  • Other rule classes test p.owner != owner_t::UNSPECIFIED in valid_prefix, for example signal.h:52, so other and owner get the same message.

Read more

06 other in the wrong place

COMMON MISTAKES owner other /tmp/** r, leave both out to mean "any owner" syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VAR other signal, the message says "owner" for other too owner prefix not allowed on signal rules other capability chown, owner conditional not allowed on capability rules other /var/lib/demo/shared/** r, accepted, no message the user's own files are not covered: add an owner rule or drop the keyword other is not in the apparmor.d man page; the parser and its tests define it
Four rows. owner other on one rule is a syntax error. other signal is rejected with owner prefix not allowed on signal rules. other capability chown is rejected with owner conditional not allowed on capability rules. An other rule alone is accepted and does not cover the user's own files. A foot note says other is not in the apparmor.d man page.

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 puts r in 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 mask 0x10000; not run against a kernel).
  • Not in the manual: apparmor.d(5) at this commit lists owner under "Rule Qualifiers" and has no item for other (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

for security researchers

Attack surface

  • owner { other RULE } and other { owner RULE } are accepted without a message and leave a rule with the mask 0x0: 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 both owner and other.
  • deny other P rw, protects other users' files only at equal or higher priority than the allow rules it meets, and it is quiet: add audit to 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

07 Where to go from here

ROADS owner other owner: mine · other: not mine neither: both syn-owner the comparison in detail syn-allow-deny deny other syn-audit audit other syn-qualifier-blocks other { ... } re-perms the two entries per state syn-file-rules · syntax-map
The two-compartment box, owner and other, with other highlighted, and roads: syn-owner from the owner half, syn-allow-deny and syn-audit for deny other and audit other, syn-qualifier-blocks for other in front of a block, and a row naming syn-file-rules, re-perms and syntax-map.

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, deny or prompt), and owner or other.
  • other is 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

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=N is not allowed in front of a block: priority is not allowed on rule blocks (tree).
  • Keyword: other. It has no alias (owner has one, user).
  • It takes the same seat as owner, the last one before the rule. A rule has owner, other or neither; both on one rule is a syntax error (tree).
  • Accepted on file rules, the bare file, rule, link rules 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.

RulesTask owns the fileTask does not own the fileBasis
owner P rw,rwnothingderived
other P r,nothingrderived; rule mask 0x10000 (tree)
P r,rrderived; rule mask 0x10004 (tree)
owner P rw, and other P r,rwrderived; merged rule mask 0x1000e (tree)
P rw, and deny other P rw,rwdenied, quietderived; state (0x e/38000//0/0/38000) (tree)
owner P rw, and other P r, and deny owner P w,r; write denied, quietrderived; 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.

MessageCauseBasis
syntax error, unexpected TOK_OTHER, expecting TOK_ID or TOK_MODE or TOK_SET_VARowner other /foo r,tree
owner prefix not allowed on signal rulesother signal,tree
owner prefix not allowed on X rules, X one of ptrace, mount, dbus, unix, network, mqueue, io_uring, userns, allother on a rule of that classcode
owner conditional not allowed on capability rulesother capability chown,tree
owner prefix not allowed on capability rulesother reaching a capability rule through a blocktree
owner conditional not allowed on change_profile rulesother 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-exprs shows the rule with mask 0x0 (tree). Suspected bug; do not rely on it.
  • The message conflicting owner prefix exists 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

StepWhere
token TOK_OTHER, keyword otherparser/parser_yacc.y:117; parser/parser_misc.c:97
opt_owner_flag: TOK_OTHER gives owner_t::NOTparser/parser_yacc.y:696-698; enum at parser/rule.h:193
prefix dump prints !ownerparser/rule.h:297-301
entry_add_prefix: perms &= AA_OTHER_PERMS or AA_SHARED_PERMSparser/parser_misc.c:1155-1156
halves: AA_USER_SHIFT 0, AA_OTHER_SHIFT 14; AA_OTHER_PERMS; AA_SHARED_PERMSparser/immunix.h:24-25, 59, 66
block_rules::merge_file: equal entries are ORedparser/block_rules.cc:285-338
two permission entries per file state, owner then otherparser/libapparmor_re/hfa.cc:1415-1417, 1427-1428
valid_prefix tests p.owner != owner_t::UNSPECIFIEDparser/signal.h:52 and the other rule class headers
capability and change_profile checksparser/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.

RulesDumpBasis
other /b r,rule mask 0x10000tree
owner /c rw, other /c r,one rule, mask 0x1000etree
/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

FILE ACCESS

QUALIFIERS

THE DFA ENGINE · libapparmor_re