File access modes
r w a l k m for application developers for security researchers
What each file permission letter allows in the kernel. w covers create and delete and attribute changes. a covers only opens for append. k is locking and m is mapping a file as executable.
On the map: file access
▶ Watch this deck — 9 scenes, ~7 min
Worth seeing first
- File rules — the rule whose letters this deck explains
Part of journeys
- New to AppArmor, step 7 of 10 · previous: File rules · next: allow and deny
- File access in depth, step 3 of 12 · previous: Globbing (AARE) · next: Exec modes
- How a rule becomes a permission, step 2 of 12 · previous: How the kernel checks an access · next: Exec modes
01 Seven letters
The file letters are r w a l k m and x with a transition type. They may appear in any order.
The rule for demo's state directory ends in three letters: rwk. There are seven such letters, and this rule uses three of them: read, write and lock. They look obvious, and mostly they are. But a few things surprise people. The letter w is also what lets a program create and delete files. The letter a is narrower than you'd guess. And the log sometimes shows a letter, c or d, that you can't write in a profile at all. This deck takes the letters one at a time and tells you which system calls ask for each in the kernel. Two of them, x and l, have decks of their own.
Details and sources
Details
- The letters a profile may use in a file rule:
r w a l k mandxwith a transition type. The scanner's set is[RrWwaLlMmkXx]plus the exec forms (parser_lex.l:257-258). - The letters the kernel prints in
requested_maskanddenied_maskcome from its own string,x w r a c d k m l, in the kernel (lib.c:253).c(create) andd(delete) exist only there; both are granted byw. - A record with
cfrom the log fixtures in the AppArmor tree:apparmor="ALLOWED" operation="mkdir" profile="/usr/sbin/sshd" name="/run/user/1000/kakoune/" ... requested_mask="c" denied_mask="c"(testcase_socklogd_mkdir.in:1). - The statements about what the kernel asks for in this deck were read from the kernel source; they were not observed on a running kernel.
- The manual page describes the letters under "Access Modes" (apparmor.d.pod:1 is its source).
Read more
- apparmor.d(5) Access Modes and Access Modes Details.
- apparmor.net: Profiles quick reference, file permissions.
- File rules: the rule the letters sit in.
02 The mode word
MODE = ( r | w | a | l | k | m | EXEC MODE )+. w with a is an error. Bare x is valid only after deny.
The mode is a single word. You build it from six plain letters: r, w, a, l, k and m. If the rule is about running the file, you add an exec mode such as ix or px. Order doesn't matter: rw and wr mean the same. Two combinations are refused. The letters w and a can't share a word, and an x with nothing in front of it is valid only in a deny rule. Capital R, W, L and M still parse as old spellings, with a deprecation warning, but capital P, C and U are real exec modes. And keep it one word: white space or the comma ends it.
Details and sources
Details
MODE = ( 'r' | 'w' | 'a' | 'l' | 'k' | 'm' | EXEC MODE )+. One word; letters in any order, repeats allowed; white space or a comma ends it.- The scanner's definition:
MODE_CHARS ([RrWwaLlMmkXx])|(([Pp]|[Cc])[Xx])|(([Pp]|[Cc])?([IiUu])[Xx])andMODES {MODE_CHARS}+(parser_lex.l:257-258). wwithain one word:Conflict 'a' and 'w' perms are mutually exclusive.(parser_misc.c:595, parser_misc.c:602; test bad_append_1.sd).- A bare
xin a rule that is not a deny rule:Invalid perms, 'x' must be preceded by exec qualifier 'i', 'p', or 'u'. An exec mode in a deny rule:Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u'(parser_misc.c:1090-1104). - Uppercase
R W L M X Iare lowered with a warning (parser_misc.c:704-718). UppercaseP,CandUare exec modes: see exec modes and safe and unsafe.AandKare not accepted. - The full form of an error is
AppArmor parser error for FILE in profile FILE at line N: MESSAGE.
Read more
- apparmor.d(5) Access Modes.
- File rules: where the mode sits in a rule.
- Exec modes.
03 r: read
r allows open for reading, read, directory listing and PROT_READ mappings. A rename needs r and w on the source name.
The letter r is what you'd expect, and a little more. Demo's configuration rule gives r on everything under its configuration directory. That covers opening a file for reading and the reads that follow. Listing the directory needs r on the directory's own name. Mapping a file readable asks for r. A file descriptor received from another process is checked again for whatever it was opened for. The less obvious one is rename: moving a file asks for read as well as write on the old name, so a profile that can write a file but not read it can't rename it. And the program you execute is checked for x, not for r.
Details and sources
Details
All kernel facts are from the kernel source, read and not run.
open: the LSM hookapparmor_file_openasks for the permissions computed from the open flags byaa_map_file_to_perms;FMODE_READgivesMAY_READ(lsm.c:498-500, file.h:119-120). A directory opened for listing is an open of the directory's own name.read: hookapparmor_file_permissionpasses the mask from the VFS (lsm.c:547-550).- Receiving a descriptor from another process: hook
apparmor_file_receive, with the permissions of the open mode (lsm.c:542-545). mmapormprotectwithPROT_READasks forMAY_READ(lsm.c:570-571).- Rename: hook
apparmor_path_renameasks on the old name forMAY_READ | AA_MAY_GETATTR | MAY_WRITE | AA_MAY_SETATTR | AA_MAY_DELETE(lsm.c:433-437). - The file named in an exec: its open is not checked for
r; the kernel recordsMAY_EXEC | MAY_READ | AA_EXEC_MMAPfor it (lsm.c:482-485). rin a profile also grants reading attributes and open: the old read bit maps toAA_MAY_GETATTR | AA_MAY_OPEN(policy_compat.c:82-83).
Read more
- apparmor.d(5) r - Read mode.
- Reading denials.
- Exec modes: the check for the executed file.
04 w: write, create, delete
w allows write, create, delete, rename, truncate, chmod and chown. Logs show create as c and delete as d; both are granted by w.
The letter w is the big one. Besides writing to an open file, and opening one for writing, it's the letter that lets demo create a file or a directory, delete it, rename it, truncate it, and change its mode or owner. There are no separate letters for those. The kernel does keep them apart internally, and that shows in the log: a refused mkdir says requested mask c, and a refused unlink says d. When you see c or d, the fix is a w rule. And the rule has to match the new file's own path. Write permission on the directory isn't what the kernel asks for.
Details and sources
Details
All kernel facts are from the kernel source, read and not run.
- What
wgrants: the old write bit maps toAA_MAY_SETATTR | AA_MAY_CREATE | AA_MAY_DELETE | AA_MAY_CHMOD | AA_MAY_CHOWN | AA_MAY_OPEN, next toMAY_WRITEandMAY_APPENDthemselves (policy_compat.c:80, policy_compat.c:84-86). - LSM hooks and what they ask for (lsm.c:327-365):
apparmor_path_unlink,apparmor_path_rmdir:AA_MAY_DELETE.apparmor_path_mkdir,apparmor_path_mknod,apparmor_path_symlink:AA_MAY_CREATE.apparmor_path_truncate,apparmor_file_truncate:MAY_WRITE | AA_MAY_SETATTR.apparmor_path_renameasks forMAY_WRITE | AA_MAY_SETATTR | AA_MAY_CREATEon the new name (lsm.c:439-443);apparmor_path_chmodandapparmor_path_chownask forAA_MAY_CHMODandAA_MAY_CHOWN(lsm.c:450-458).- Open flags:
FMODE_WRITEgivesMAY_WRITE,O_TRUNCaddsMAY_WRITE,O_CREATaddsAA_MAY_CREATE(file.h:117-128). - The path checked for create and delete is built from the directory's mount and the entry itself, so a rule must match the object's own name (lsm.c:271-278).
- Log letters:
aa_file_perm_chrsis"xwracd km l "(lib.c:253); setattr, chmod and chown are printed asw, getattr asr(file.c:28-38). - Fixture record:
operation="mkdir" ... requested_mask="c" denied_mask="c"(testcase_socklogd_mkdir.in:1).
for security researchers
Attack surface
wis wider than "write": by the old-format mapping it also grants create, delete, setattr, chmod and chown on every name the rule matches (policy_compat.c:78-98; read from the kernel source, not observed on a running kernel). The only narrower letter isa.- Reading attributes is granted on every name that any file rule matches, with or without
r:compute_fperms_allowaddsAA_MAY_GETATTRunconditionally (policy_compat.c:100-103). By that code a profile cannot hide the existence, size or owner of a file it names for another purpose. anarrows the open, not necessarily the descriptor: whether a laterwrite(2)on a descriptor opened withO_APPENDunder an a-only rule is refused was not determined (see "Not determined" in the reference below).- The log letters
canddcannot be written in a profile, so a policy cannot allow create without delete, or the reverse.
Read more
- apparmor.d(5) w - Write mode.
- Reading denials:
requested_maskanddenied_mask. - Link rules: a hard link is not a create.
05 a: append only
a grants the append permission only: an open with O_APPEND of an existing file. O_TRUNC, O_CREAT, delete and chmod need w.
Demo should add lines to its log and not be able to rewrite history. That's what the letter a is for. When a file is opened for writing with O_APPEND, the kernel asks for the append permission instead of write, and the append letter grants exactly that. Open without O_APPEND and the request is for w. Add O_TRUNC and it's w again. Add O_CREAT and the open also asks for create, which the append letter doesn't give, so demo can't create the log this way. Deleting, truncating and chmod stay out of reach too. And since w already contains the append permission, you write one letter or the other, not both.
Details and sources
Details
- Parser:
asetsAA_MAY_APPEND;wsetsAA_MAY_WRITE | AA_MAY_APPEND; the two letters in one word are an error (parser_misc.c:599-604). Tests: ok_append_1.sd, bad_append_1.sd. - Two separate rules,
/a a,and/a w,, are merged without error (observed with the released parser 5.0.2). - Kernel, read and not run.
aa_map_file_to_permsturns the open flags into the request (file.h:117-128): O_WRONLY | O_APPEND:MAY_APPENDreplacesMAY_WRITE.O_TRUNCaddsMAY_WRITE;O_CREATaddsAA_MAY_CREATE, whether or not the file exists.O_RDWR | O_APPEND:MAY_READandMAY_APPEND, so the rule needsras well.- The append bit is kept as it is; create, delete, chmod and chown are added only for the write bit (policy_compat.c:80-86).
- Not determined: whether a later
write(2)on a descriptor opened under an a-only rule is allowed by a running kernel. The open records the granted request (lsm.c:502) and each write arrives asMAY_WRITE(lsm.c:547-550, file.c:655-669). The AppArmor regression tests have no append test.
Read more
06 k and m: lock and map
k allows flock and fcntl locks (a write lock also needs w). m allows mmap or mprotect with PROT_EXEC; libraries need mr.
Two smaller letters. The letter k is locking: flock and fcntl locks both ask for it, and a write lock asks for w as well. If demo's database complains that it can't lock its file, look in the log for requested mask k. The letter m is for mapping a file into memory as executable code. That's how shared libraries get loaded, which is why library rules read mr. An ix rule adds m for the same path, so a program that stays in demo's profile can map itself. But every library, and the loader too, needs mr in the profile the program runs under.
Details and sources
Details
Kernel facts are from the kernel source, read and not run.
- Locks: LSM hook
apparmor_file_lockasks forAA_MAY_LOCK, plusMAY_WRITEwhen the command isF_WRLCK(lsm.c:552-560). The log operation isfile_lock(audit.h:66). - Fixture record:
operation="file_lock" requested_mask="k" denied_mask="k" name="/var/run/samba/unexpected.tdb" ... profile="/usr/sbin/nmbd"(testcase14.in:1). - Mapping:
common_mmap, called from the hooksapparmor_mmap_fileandapparmor_file_mprotect, asks forMAY_READforPROT_READ,MAY_WRITEfor aPROT_WRITEmapping that is notMAP_PRIVATE, andAA_EXEC_MMAPforPROT_EXEC(lsm.c:562-595). - The file named in an exec is recorded with
MAY_EXEC | MAY_READ | AA_EXEC_MMAPwithout a rule lookup at open (lsm.c:482-485). Shared libraries and the ELF loader are opened and mapped later, under the profile the program runs in. apparmor_parser -X(--readimpliesX, "Map profile read permissions to mr") makesrimplym(parser_main.c:243).
Read more
- apparmor.d(5) k - lock mode and m - Allow executable mapping.
- Exec modes:
ix. - Abstractions: where the library rules usually come from.
for AppArmor developers for security researchers
In the code
iximpliesm:add_implied_ix_mmapadds the mapping bit for the owner and the other half when the priority of the mapping bit is not higher than that of the exec bit (hfa.cc:1497-1524).
07 Fourteen bits, twice for AppArmor developers for security researchers
parse_sub_perms (parser/parser_misc.c:560) sets bits from parser/immunix.h:35-48; map_old_perms (linux:security/apparmor/policy_compat.c:78-98) expands them.
parse_sub_perms walks the letters and sets bits in a fourteen bit field. parse_perms then copies that field into both halves of one word: owner at shift zero, other at shift fourteen. The owner and other qualifiers just clear a half. Each plain letter is one bit, except w, which sets write and append; that's why rw comes out as 0x3800e. On the kernel side, map_old_perms spreads those few bits over the real permission set, and that's where w picks up create, delete, chmod and chown. The parser calls the same mapping when it builds a permission table itself, so the letter table holds for either format.
Details and sources
for AppArmor developers for security researchers
Details
- Bits of one half (immunix.h:35-48):
AA_MAY_EXEC0x1,AA_MAY_WRITE0x2,AA_MAY_READ0x4,AA_MAY_APPEND0x8,AA_OLD_MAY_LINK0x10,AA_OLD_MAY_LOCK0x20,AA_OLD_EXEC_MMAP0x40,AA_EXEC_PUX0x80,AA_EXEC_UNSAFE0x100,AA_EXEC_INHERIT0x200, transition type 0x3c00. parse_sub_permswalks the letters (parser_misc.c:560-734);perm32_t parse_perms(const char *str_perms)stores the field atAA_USER_SHIFT0 andAA_OTHER_SHIFT14 (parser_misc.c:736-745, immunix.h:24-25).- Bit 30 is
AA_ONEXECandAA_CHANGE_HAT, bit 31 isAA_CHANGE_PROFILE(immunix.h:63-65). - Dumps from the parser built from the AppArmor tree at 836052d21:
/a r,is0x10004,/a rw,is0x3800e;ownerleaves only the low half. - Kernel:
map_old_permskeeps the low four bits and addsAA_MAY_GETATTR | AA_MAY_OPENfor read,AA_MAY_SETATTR | AA_MAY_CREATE | AA_MAY_DELETE | AA_MAY_CHMOD | AA_MAY_CHOWN | AA_MAY_OPENfor write,AA_MAY_LINKfor 0x10,AA_MAY_LOCK | AA_LINK_SUBSETfor 0x20 andAA_EXEC_MMAPfor 0x40 (policy_compat.c:78-98). The owner and other halves are read withdfa_user_allowanddfa_other_allow(policy_compat.c:53-70); the exec bits of a half become an index throughdfa_map_xindex(policy_compat.c:24-48). compute_fperms_allowaddsAA_MAY_GETATTRto every allow set (policy_compat.c:100-103).- The parser has the same mapping for the permission tables it writes itself (
map_old_permsat policy_compat.cc:127-147,dfa_map_xindexat policy_compat.cc:41-65).
08 Letters the parser refuses
"Conflict 'a' and 'w' perms are mutually exclusive." "Invalid perms, 'x' must be preceded by exec qualifier 'i', 'p', or 'u'". Uppercase R W L M X I are deprecated spellings of lowercase.
Four ways the parser says no. Put w and the append letter in one word and it reports a conflict: pick one. Write an x with nothing before it in an allow rule and it's refused, because the kernel needs to know which profile the new program gets. A letter that isn't on the list, capital K for instance, isn't a mode, so you get a syntax error that asks for one. Capital R and W are accepted as lowercase, with a deprecation warning you see only on request. One more trap: a word made only of mode letters is always read as a mode, so a name like mark confuses the parser.
Details and sources
Details
Messages of the parser built from the AppArmor tree at 836052d21. The full form is AppArmor parser error for FILE in profile FILE at line N: MESSAGE.
/a wa,:Conflict 'a' and 'w' perms are mutually exclusive.(parser_misc.c:595, parser_misc.c:602; bad_append_1.sd)./bin/ls rx,:Invalid perms, 'x' must be preceded by exec qualifier 'i', 'p', or 'u'(parser_misc.c:1097-1100; simple_bad_no_bare_x.sd). The message omitsc, althoughcxis an exec mode./bin/ls K,:syntax error, unexpected TOK_ID, expecting TOK_MODE(bad_lock_1.sd).Kis not in the scanner's letter set (parser_lex.l:257-258).mark r,:syntax error, unexpected TOK_MODE, expecting TOK_ID or TOK_SET_VAR(observed with the released parser 5.0.2).- Uppercase
R W L M X I: warningUppercase qualifiers "RWLIMX" are deprecated, please convert to lowercase, thenSee the apparmor.d(5) manpage for details.(parser_misc.c:549-558, parser_misc.c:704-718). Printed once per run. - The warning's class is
deprecated(parser_main.c:284), off by default.apparmor_parser --warn=deprecatedor--warn=allturns it on.
Read more
- apparmor.d(5) Access Modes.
- apparmor_parser(8) OPTIONS:
--warn. - Exec modes: the letters that go before
x.
09 Where to go from here
Next: syn-exec-modes for x, syn-link-rules for l, adm-denials for the letters in log records.
You now know what each plain letter buys. The letter x is a subject of its own, because executing a program also decides which profile it runs under, so exec modes is the deck to take next. The letter l needs more than a letter; that's in link rules. The rule these letters sit in, the path patterns they apply to and the owner qualifier each have a deck too. When a denial shows up in the log, its masks use these same letters, and the denials deck shows how to read them. And if you want to watch the bits become tables, there's the permissions deck in the compiler district.
Details and sources
Details
r: open for reading, read, directory listing,PROT_READmappings, the old name of a rename.w: write, create, delete, rename, truncate, chmod, chown; the log shows create ascand delete asd.a: an open withO_APPENDof an existing file, nothing else.k:flockandfcntllocks.m:PROT_EXECmappings.xneeds a transition type andlneeds a link target; each has its own deck.- Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2), the kernel-rc2 (97d73c825). Kernel behaviour was read from the source and not run.
Read more
Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the fragment, with nothing loaded into a kernel; "code" means the kernel source of mainline Linux 7.4 (7.4-rc2, 97d73c825) or the parser source was read, not run. Nothing on this page was run against a kernel: every statement about what the kernel asks for or grants is "code".
Grammar
MODE = ( 'r' | 'w' | 'a' | 'l' | 'k' | 'm' | EXEC MODE )+
- The scanner's letter set is
[RrWwaLlMmkXx]plus the exec forms (ix,px,Px,cx,Cx,ux,Uxand the fallback forms such aspix); exec modes are in syn-exec-modes. - A mode is one word. Letters may be in any order and may repeat:
wrisrw. - White space or a comma ends the word. There are no spaces inside it.
- A word made only of mode letters is always read as a mode, also where a path or a name is expected.
- Where the mode sits in a rule: syn-file-rules.
Letters
| Letter | Allows | Requests that ask for it | Also needs |
|---|---|---|---|
r | read | open for reading; read; listing a directory; mmap or mprotect with PROT_READ; receiving a descriptor from another process; the source name of a rename | a rename source also needs w |
w | write, create, delete, attribute changes | open for writing; O_TRUNC; write; create through O_CREAT, mkdir, mknod, symlink; unlink; rmdir; truncate; chmod; chown; both names of a rename; a shared writable mapping; a write lock | a rename source also needs r; a write lock also needs k |
a | append | open for writing with O_APPEND | nothing else is granted: see the next section |
l | a hard link with this name | link on the new name | a link rule or a matching target: syn-link-rules |
k | file locks | flock; fcntl locks | a write lock (F_WRLCK) also needs w |
m | mapping the file as executable | mmap or mprotect with PROT_EXEC | libraries are normally given mr |
x | execute | execve | a transition type in allow rules: syn-exec-modes |
- Create, delete and rename are checked on the path of the object itself, built from the directory and the entry name. To create
/var/lib/demo/xa rule must givewon/var/lib/demo/x;won/var/lib/demo/is not what is asked (code). - A symbolic link is a create and asks for
won the new name. It is not a link request and does not needl(code). - A private writable mapping does not ask for
w; a shared one does (code).
a compared with w
What an open asks for, from the kernel's translation of the open flags (code):
| Open flags | The open asks for | Under a rule with only a |
|---|---|---|
O_WRONLY, O_APPEND | append | granted |
O_WRONLY | write | not granted |
O_WRONLY, O_APPEND, O_TRUNC | append and write | not granted |
O_WRONLY, O_APPEND, O_CREAT | append and create | not granted |
O_RDWR, O_APPEND | read and append | needs r as well |
agrants the append permission and nothing else: no create, delete, truncate, chmod or chown.wsets both the write and the append bit, so every request thatasatisfies is also satisfied byw.wandain one mode word are an error. Two separate rules,/a a,and/a w,, are merged without error (tree).- Whether later write calls on a descriptor opened under an a-only rule are allowed was not determined from the code alone and was not tested.
Letters in log records
The kernel prints requested_mask and denied_mask with its own letter string, x w r a c d k m l (code).
| Letter in the log | Meaning | Profile letter that grants it |
|---|---|---|
c | create | w |
d | delete | w |
w | write; also chmod, chown and other attribute changes | w |
r | read; also reading attributes | r |
a | append | a or w |
k | lock | k |
m | executable mapping | m |
l | link | l |
x | execute | an exec mode |
Sample records, shortened, from the log fixtures in the AppArmor tree:
apparmor="ALLOWED" operation="mkdir" profile="/usr/sbin/sshd" name="/run/user/1000/kakoune/" ... requested_mask="c" denied_mask="c" ... operation="file_lock" requested_mask="k" denied_mask="k" name="/var/run/samba/unexpected.tdb" ... profile="/usr/sbin/nmbd"
Reading denial records: adm-denials.
Things that are implied
wincludesa.ixaddsmon the same path, unless a rule of higher priority decided that bit (code).- Reading attributes (getattr) is granted wherever a rule matches the name, with or without
r(code). - The open that the kernel does for the file named in an exec is not checked for
r; the kernel records read and executable mapping for it under the label that ran the exec. Derived from the code of mainline Linux 7.4 and not run on a kernel: a profile reached throughpxorcxis asked again and needsmron its own executable, because the recorded permissions count only while the task's label is the one that opened the file (linux:security/apparmor/lsm.c:482-485, linux:security/apparmor/file.c:506-520, 655-669). Withixthe label stays, and the parser addsmto anixrule (parser/libapparmor_re/hfa.cc:1497-1524). Shared libraries and the ELF loader are mapped by the new program and needmrin the profile it runs under (code). apparmor_parser -Xmakesrimplym: the dumped permission of/a r,changes from0x10004to0x110044(tree). A parser built withFORCE_READ_IMPLIES_EXECdoes the same (code).
Errors and warnings
The parser prints an error as AppArmor parser error for FILE in profile FILE at line N: MESSAGE (tree). The table gives MESSAGE.
| Message | Cause |
|---|---|
Conflict 'a' and 'w' perms are mutually exclusive. | wa or aw in one mode word (tree) |
Invalid perms, 'x' must be preceded by exec qualifier 'i', 'p', or 'u' | an allow rule with a bare x, such as rx (tree); also /a x -> b, (tree) |
Invalid perms, in deny rules 'x' must not be preceded by exec qualifier 'i', 'p', or 'u' | deny /a px, (tree); deny /a x, is accepted |
syntax error, unexpected TOK_ID, expecting TOK_MODE | a word that is not a mode where one is expected, such as K (tree) |
syntax error, unexpected TOK_MODE, expecting TOK_ID or TOK_SET_VAR | a word of mode letters where a path is expected, such as mark r, (tree) |
Uppercase qualifiers "RWLIMX" are deprecated, please convert to lowercase followed by See the apparmor.d(5) manpage for details. | a warning, for uppercase R W L M X I (tree, with --warn=all). Its class is deprecated, which is off by default; --warn=deprecated turns it on. Printed once per run |
Internal: unexpected perms character 'C' in input | internal; needs a mismatch between the scanner and the mode parser (code) |
Internal error generated invalid perm 0xN | internal (code) |
- Uppercase
P,CandUare not deprecated spellings: they are exec modes.AandKare not accepted at all.
Known discrepancies
- Both "Invalid perms" messages name the qualifiers
'i', 'p', or 'u'and omitc, althoughcxis an exec mode. - The deprecation text lists
RWLIMX, and the code that lowers the letter also names append, but the scanner does not accept an uppercaseA. - A comment in the parser says a bare
xis valid for named transitions; the parser rejects/a x -> b,(tree).
for AppArmor developers for security researchers
Bit layout and mapping
Bits of one half, set by parse_sub_perms (parser/parser_misc.c:560-734) from parser/immunix.h:35-48:
| Bit | Name | Letter |
|---|---|---|
0x1 | AA_MAY_EXEC | x |
0x2 | AA_MAY_WRITE | w (with 0x8) |
0x4 | AA_MAY_READ | r |
0x8 | AA_MAY_APPEND | a, w |
0x10 | AA_OLD_MAY_LINK | l |
0x20 | AA_OLD_MAY_LOCK | k |
0x40 | AA_OLD_EXEC_MMAP | m |
0x80 | AA_EXEC_PUX | exec fallback |
0x100 | AA_EXEC_UNSAFE | exec |
0x200 | AA_EXEC_INHERIT | exec |
0x3c00 | transition type | exec |
parse_perms(parser/parser_misc.c:736-745) stores the field twice:AA_USER_SHIFT0 andAA_OTHER_SHIFT14 (parser/immunix.h:24-25)./a r,dumps as0x10004,/a rw,as0x3800e(tree);ownerleaves only the low half.- Bit 30 is
AA_ONEXECandAA_CHANGE_HAT; bit 31 isAA_CHANGE_PROFILE(parser/immunix.h:63-65). - Dump tuples read
(allow/deny//prompt/audit/quiet)in this layout.
map_old_perms (linux:security/apparmor/policy_compat.c:78-98; the parser's copy is parser/libapparmor_re/policy_compat.cc:127-147):
| Old bit | Kernel permissions |
|---|---|
0x1 0x2 0x4 0x8 | kept: MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND |
| read | adds AA_MAY_GETATTR, AA_MAY_OPEN |
| write | adds AA_MAY_SETATTR, AA_MAY_CREATE, AA_MAY_DELETE, AA_MAY_CHMOD, AA_MAY_CHOWN, AA_MAY_OPEN |
0x10 | AA_MAY_LINK |
0x20 | AA_MAY_LOCK, AA_LINK_SUBSET (the same value, linux:security/apparmor/include/perms.h:34,49) |
0x40 | AA_EXEC_MMAP |
AA_MAY_GETATTRis also added to the allow set bycompute_fperms_allow(linux:security/apparmor/policy_compat.c:103).aa_map_file_to_perms(linux:security/apparmor/include/file.h:112-131) turns open flags into the request:FMODE_WRITEtoMAY_WRITE,FMODE_READtoMAY_READ,O_APPENDreplacesMAY_WRITEbyMAY_APPEND,O_TRUNCaddsMAY_WRITE,O_CREATaddsAA_MAY_CREATE.- Log letters:
aa_file_perm_chrs(linux:security/apparmor/lib.c:253); the folding of chmod, chown and setattr intowand getattr intoris in linux:security/apparmor/file.c:28-38. - The
iximpliesmstep: parser/libapparmor_re/hfa.cc:1497-1524.
Hooks in linux:security/apparmor/lsm.c:
| Operation | Hook | Request |
|---|---|---|
| unlink, rmdir | apparmor_path_unlink, apparmor_path_rmdir (327-330, 339-342) | AA_MAY_DELETE |
| mkdir, mknod, symlink | apparmor_path_mkdir, apparmor_path_mknod, apparmor_path_symlink (332-348, 360-365) | AA_MAY_CREATE |
| truncate | apparmor_path_truncate, apparmor_file_truncate (350-358) | MAY_WRITE, AA_MAY_SETATTR |
| link | apparmor_path_link (367-384) | see syn-link-rules |
| rename | apparmor_path_rename (386-448) | source: MAY_READ, AA_MAY_GETATTR, MAY_WRITE, AA_MAY_SETATTR, AA_MAY_DELETE; destination: MAY_WRITE, AA_MAY_SETATTR, AA_MAY_CREATE |
| chmod, chown | apparmor_path_chmod, apparmor_path_chown (450-458) | AA_MAY_CHMOD, AA_MAY_CHOWN |
| open | apparmor_file_open (465-507) | from aa_map_file_to_perms; an exec open is preset to MAY_EXEC, MAY_READ, AA_EXEC_MMAP (482-485) |
| receive a descriptor | apparmor_file_receive (542-545) | from the open mode |
| read, write | apparmor_file_permission (547-550) | the mask from the VFS |
| lock | apparmor_file_lock (552-560) | AA_MAY_LOCK, plus MAY_WRITE for F_WRLCK |
| mmap, mprotect | common_mmap (562-595) | MAY_READ for PROT_READ; MAY_WRITE for a shared PROT_WRITE mapping; AA_EXEC_MMAP for PROT_EXEC |
How the bits become tables: re-perms. Where the kernel looks them up: k-match.
for AppArmor developers for security researchers
Not determined
- Whether
write(2)on a descriptor opened withO_APPENDunder an a-only rule is allowed by a running kernel. The open recordsMAY_APPENDin the file context (linux:security/apparmor/lsm.c:502) and each write arrives asMAY_WRITE(linux:security/apparmor/lsm.c:547-550; linux:security/apparmor/file.c:655-669). No kernel was available and tests/regression/apparmor has no append test. - Whether
openwithO_APPEND|O_CREATon a file that already exists is refused under an a-only rule.O_CREATaddsAA_MAY_CREATEto the request whether or not the file exists (linux:security/apparmor/include/file.h:127-128), so by reading it is refused. Not run. - Whether the non-accepting state of the file DFA also carries
AA_MAY_GETATTRin every policy format, that is, whetherstatof a path that no rule matches is ever refused.
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- File rules — the rule the letters sit in
- Exec modes — the letters that end in x
- Link rules — what l needs besides the letter
- Globbing (AARE) — the path the letters apply to
QUALIFIERS
- The owner qualifier — one set of letters for the owner and one for everyone else
RUNNING THE PARSER
- Reading a denial — the same letters in a denial record
IN THE KERNEL
- Matching at run time — where the kernel reads the permissions
THE DFA ENGINE · libapparmor_re
- Permissions in the DFA — how the letters become permission tables