Mount rules
mounting filesystems for application developers for administrators for security researchers
A mount rule allows mount calls that match a source a mount point a filesystem type and a set of mount flags. options=( ) is an exact set of flags and options in ( ) is a set of optional ones. The kernel sorts each call into remount bind propagation change move or new mount and compares only the fields that kind has. A refusal is logged as operation mount with the field that failed.
On the map: rule classes
▶ Watch this deck — 9 scenes, ~6 min
Worth seeing first
- Rule conditionals — conditionals and the in operator that options uses
- Capability rules — the sys_admin capability every mount call needs
- Globbing (AARE) — the patterns for source and mount point
Part of journeys
- Network, IPC and privileges, step 11 of 14 · previous: User namespace rules · next: D-Bus mediation
01 demo mounts a scratch area
A mount rule describes the mount(2) calls a profile allows: type, flags, source and mount point. The program also needs capability sys_admin,.
Demo wants a private scratch area for its worker, so at start-up it mounts a tmpfs on /run/demo. Under a profile, that call fails with EACCES unless a mount rule matches it. This is line fourteen of demo's profile. The rule describes the call in four parts: the filesystem type, the mount flags, the source and, after the arrow, the mount point. The rule doesn't make demo privileged: it still needs the sys_admin capability. And changing a mount, unmounting and pivot_root are separate rules with their own decks.
Details and sources
Details
- The LSM hook is
sb_mountfor mount(2) (lsm.c:707-742, registered at lsm.c:1792) andmove_mountfor move_mount(2) (lsm.c:744-758). An unconfined task is not checked. - A confined profile is checked only if it mediates the mount class (mount.c:254-255, mount.c:313-314). It does when it was compiled for a feature set that has
mount: the feature file/sys/kernel/security/apparmor/features/mount/maskreadsmount umount pivot_root(apparmorfs.c:2650). Then a mount call without a matching rule is refused withEACCES. mount fstype=tmpfs options=(rw, nosuid) tmpfs -> /run/demo/,is line 14 of demo's profile. It and the three lines after it (remount,umount,pivot_root) compile together with no warning (run with the tree's parser). The programdemoand its profile are invented for the map.- The rule does not replace the capability: mount(2) needs
CAP_SYS_ADMIN, which a confined task has only withcapability sys_admin,. Without it the call fails withEPERM. mount(2) asks AppArmor first, so a call with no matching rule is refused withEACCESand logged whether or not the task has the capability (namespace.c:4279-4283). - Kernel statements are read from the kernel source and were not run.
02 Conditionals, source, arrow, mount point
mount [fstype=...] [options=... | options in ...] [SOURCE] [-> MOUNTPOINT],. Everything after the keyword is optional.
After the keyword come the conditionals, and a mount rule knows two: fstype, for the filesystem type, and options, for the mount flags. Options takes either an equals sign or the word in, and that difference matters enough to get its own slide. Then comes the source, then an arrow and the mount point. Everything is optional. The bare keyword allows any mount. One path on its own is the source. An arrow with one path names only the mount point. Just remember that the conditionals have to come before the paths.
Details and sources
Details
- The conditional names are
fstype,vfstype,optionsandoption. The operators are=andin.options:=rois a scanner error:Lexer found unexpected character: ':' (0x3a) in state: MOUNT_MODE. fstypevalues are patterns (fstype=ext*,fstype={procfs,sysfs}). Severalfstypeconditionals in one rule are collected into one list of alternatives, and forfstypethe operators=andinmean the same (run with the tree's parser).- Source, mount point and fstype take variables.
- A conditional after the arrow is refused. The mount point is not checked to be an absolute path:
mount options=(rw) /a -> b,is accepted. - Known discrepancy, on the bug list as "A source-only
mountrule also allows mounting anything onto that path":mount /dev/sdb1,also allows bind mounts, moves and remounts onto/dev/sdb1. Write the mount point (mount /dev/sdb1 -> /mnt/**,) oroptions=( );options indoes not avoid it. - The source word
detachedstands for a mount that is not attached anywhere yet, as seen at move_mount(2). The feature file is/sys/kernel/security/apparmor/features/mount/move_mount, which readsdetached(apparmorfs.c:2651). - Seats:
audit,allow,deny,promptandpriority=are taken;ownerandotherare refused withowner prefix not allowed on mount rules. - Examples in the tree: ok_3.sd, ok_opt_combo_1.sd.
for AppArmor developers for security researchers
In the code
- The
mnt_ruleproductions: parser_yacc.y:1277-1285;do_mnt_rule: parser_yacc.y:1798-1818;verify_mnt_conds: parser_yacc.y:1777-1796. - The scanner state
MOUNT_MODE: parser_lex.l:876-879, parser_lex.l:681-695. - The conditional table: mount.cc:313-320; the operator check: mount.cc:416, mount.cc:439 (not reachable from a profile: the scanner returns a conditional only before
=orin, parser_lex.l:437-453); collectingfstypevalues: mount.cc:408-431; variable expansion: mount.cc:641-670; the worddetached: mount.cc:986-988; theownerrefusal: mount.h:174-180.
03 One system call, five kinds of mount
The kernel tests MS_REMOUNT, MS_BIND, the propagation flags and MS_MOVE in that order; anything else is a new mount. Only new mounts have a filesystem type to compare.
Mount is one system call that does five different jobs, and the kernel decides which by looking at the flags, in a fixed order: remount, bind, a change of propagation such as private or shared, move, and if it's none of those, a new mount. Each kind carries different information. Only a new mount has a filesystem type. A remount or a propagation change has no source. So a rule only covers the kinds it can describe. Demo's rule names a type, which makes it a rule about new mounts and nothing else. A bind mount onto the same directory would need its own rule.
Details and sources
Details
- Before sorting, the kernel drops the flags
MS_KERNMOUNT,MS_NOSEC,MS_ACTIVEandMS_BORN(mount.h:26, lsm.c:718). The order of the tests isMS_REMOUNT,MS_BIND, the propagation flags,MS_MOVE, else a new mount (lsm.c:707-742). - What each kind passes on for comparison: - remount (
aa_remount): the mount point, no source, no type, all flags (mount.c:328-353); - bind (aa_bind_mount): the mount point, the resolved source path, the flags cut down toMS_REC | MS_BIND(mount.c:355-394); - propagation (aa_mount_change_type): the mount point, the flags cut down toMS_REC | MS_SILENT | MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE(mount.c:396-422); - move (aa_move_mount_old): the mount point, the source path,MS_MOVE(mount.c:424-474); - new mount (aa_new_mount): the mount point, the type, all flags, and as source a resolved path if the filesystem type needs a device, otherwise the source string as the caller gave it (mount.c:476-542). - An unknown filesystem type returns
ENODEVbefore any policy check (mount.c:492-497). - move_mount(2) goes to
aa_move_mount; a mount that is not attached has no source name (mount.c:444-450). - Which kinds a rule covers. With no options: every kind the rule's other parts allow (remount only without source and fstype; bind and move only without fstype; propagation only without fstype and not with both paths). With only
options in: the same kinds, each only if its own flag (remount,bindorrbind, a propagation flag,move) is in the list. Withoptions=: the kind named byremount, bybindorrbind, by a propagation flag or bymove, else a new mount (mount.cc:1089-1123). - A bind rule compares
bindorrbindonly:mount options=(bind ro) /a -> /b,does not requirero(run with the tree's parser; the compiled flags are the bind byte alone). - Kernel statements are read from the kernel source and were not run.
for security researchers
Attack surface
- The hooks AppArmor registers for this class are
move_mount,sb_mount,sb_umountandsb_pivotroot(lsm.c:1791-1794). None of the other calls of the new mount API (fsopen, fsconfig, fsmount, open_tree, mount_setattr) has an AppArmor hook. A mount built with them is checked only when move_mount attaches it, as a move with the source worddetached. - Known discrepancy, on the bug list as "Kernel: a bind mount made with
open_treeandmove_mountis checked as a move without a source, sodeny mount options in (bind)does not stopmount --bind": current mount(8) makes bind mounts this way, so a rule about bind mounts, allow or deny, does not apply to them, and a rule that allows moves onto the target allows them. See Known bugs. - Filesystem-specific options (the data argument of mount(2), for example
size=orupperdir=) cannot be written in a rule and are not compared: the parser refuses any word outside its flag table (mount.cc:492-496).
04 options= is exact, options in is a choice
options=(a b): exactly these flags. options in (a b): any of these flags or none. Both together: required plus optional.
This is the part of mount rules that surprises people. options= is exact. Demo's rule says rw and nosuid, so the call must carry nosuid and no other flag. And rw isn't a flag at all: it's the absence of read-only, so it adds nothing. Pass nodev as well and the call is refused. Options in is a choice: any of the listed flags may be present, and none of them is fine too. You can use both in one rule, one for what must be there and one for what may be. And if you write options= twice, you get two alternatives.
Details and sources
Details
- The "allowed" and "refused" results on the slide are derived from the compiled flags and the kernel's comparison (mount.c:132-143); nothing was run on a kernel. The compiled flags were produced with the tree's parser: demo's rule requires
nosuid;mount options in (ro, nosuid, nodev) fstype=tmpfs tmpfs -> /run/demo/,makes the three flags optional;mount options=(nosuid) options in (nodev) tmpfs -> /run/demo/,requiresnosuidand makesnodevoptional. - The words that clear a flag (
rw,suid,dev,exec,async,atime, ...) add nothing tooptions=and only take part in the conflict check. Inoptions inthey make their flag optional, the same as the setting word:options in (ro, atime)makesroandnoatimeoptional. - No
optionsat all means every flag is optional.options=with only clearing words (options=(rw)) means a mount with no flags. - The flags a kind of call does not have are ignored by the rule for that kind; see "One system call, five kinds of mount".
verbose,silentandloudshare one flag. The full table of flag words and their synonyms (r,read-only,B,R,M,make-private, ...) is in the reference below.- The kernel compares the flags of the call after the cuts it makes for each kind of call.
- Known discrepancy, on the bug list as "
options in (...)also matches no flags and the opposite words; apparmor.d(5) says it does not": apparmor.d(5) saysmount options in (ro,atime) /dev/foo -> /mnt/,does not match a mount with no flags or withrw,noatime(apparmor.d.pod:1745-1765); the compiled rule accepts both. - Known discrepancy, on the bug list as "
nouseris accepted and has no effect, and no mount rule can match flag bit 31":nouseris accepted and has no effect, and no rule,mount,included, matches a call with that flag set (mount.h:72-92). - Kernel statements are read from the kernel source and were not run.
Read more
- apparmor.d(5), Mount Rules, wiki: TechnicalDoc_Mount_Flags.
- Rule conditionals for the
inoperator.
for AppArmor developers for security researchers
In the code
extract_flags,conflicting_flags,extract_fstypeandextract_options: mount.cc:364-454. Clearing words inoptions in: mount.cc:520-525; inoptions=: mount.cc:538-549.- One policydb rule per pair of
options=andoptions inentries: mount.cc:1149-1154. - The flag masks per kind of call: mount.h:106-121.
05 The log names the field that failed
Refused mounts return EACCES and are logged as operation="mount" with name= (mount point), srcname=, fstype=, flags= and info="failed ... match". Directory mount points end in /.
Suppose the rule was written without the slash at the end of the mount point. Demo's mount fails with EACCES. The log record says operation="mount", and it carries everything the kernel compared: name is the mount point, then the type, the source and the flags. Best of all, info says which field failed first. The kernel checks the mount point, then the source, then the type, then the flags. Here it's the mount point, because the kernel's name for a directory ends in a slash and the rule's doesn't. Add the slash and the mount goes through.
Details and sources
Details
- The record on the slide is assembled, not captured: the field order comes from the fixture testcase_mount_01.in and
class="mount"afteroperationfrom testcase_remount_01.in; the values are demo's and are illustrative. - The
infotexts arefailed mntpnt match,failed srcname match,failed type match,failed flags match,failed data matchandfailed perms check(mount.c:145-153). The comparison order is fixed (mount.c:159-211).failed perms checkmeans every field matched a rule that lacks the mount permission, for example a deny rule. - The mount fields are
fstype=,srcname=,trans=,flags="..."andoptions=; each is printed only when it has a value (mount.c:92-118). For a tmpfs the source is the string the caller passed, sosrcname="tmpfs". - The flags text starts with
rworroand has no word forlazytime(mount.c:31-85). - A directory is named with a trailing
/(mount.c:214-221), so-> /run/demo,does not match and-> /run/demo/,does. - The source of a new mount is a resolved path only for filesystem types that need a device. The type is the string the caller passed, so
fstype=fusedoes not match a request forfuse.sshfs. - In complain mode the record is
ALLOWEDwith the sameinfo(testcase_mount_02.in). error=-13isEACCES.- Kernel statements are read from the kernel source and were not run.
06 Four fields and a run of flag bytes for AppArmor developers for security researchers
mnt_rule::gen_policy_re (mount.cc:1129-1192) writes \x07 mount point NUL source NUL type NUL flag bytes; do_match_mnt (mount.c:159-211) walks it.
One class, mnt_rule, serves all four keywords. A mount rule becomes a string in the policydb: the class byte seven, the mount point, a NUL, the source, a NUL, the type, a NUL, and then the flags. Flags aren't a bitmask here. Each flag is one byte, its bit number plus one, written lowest bit first. A required flag is the byte itself; an optional one is the byte or nothing. The kernel builds the same sequence from the call, walking the set bits from bit zero up, and reads the permission at the end. The bare rule expands into five of these, one for each kind of call.
Details and sources
for AppArmor developers for security researchers
Details
- The match string on the slide was produced with the tree's parser (
-D rule-exprs):\x07/run/demo/\x00tmpfs\x00(tmpfs)\x00\x02, permission 0x2.mount,gives five rules. - Class
AA_CLASS_MOUNTis 7. Permissions:AA_MAY_PIVOTROOT0x1,AA_MAY_MOUNT0x2,AA_MAY_UMOUNT0x4 (mount.h:20-22). build_mnt_flagswrites\xNNfor a required flag and(\xNN|)for an optional one and, when no flag byte results,(\xfe|)(mount.cc:716-755). The kernel'smatch_mnt_flagsfeeds one byte per set bit, from bit 0 up (mount.c:132-143).- The generators per kind of call and their flag masks: remount
MS_REMOUNT_FLAGS, bindbind|rbind, propagationMS_MAKE_FLAGS, movemove, new mount everything except the command flags (mount.h:106-121; mount.cc:817, mount.cc:890, mount.cc:948, mount.cc:996, mount.cc:1043). The choice of generator: mount.cc:1082-1127. - More dumps from the tree's parser:
mount options=(bind ro) /a -> /b,gives\x07/b\x00/a\x00[^\000]*\x00\x0d;mount options=(rprivate) -> /a,ends in\x00\x0f\x13;mount options=(move) detached -> /b,gives\x07/b\x00\x00[^\000]*\x00\x0e. - The class marker
\d7is added at priority 1001 when the feature set hasmount(parser_regex.c:1403-1405). Without it the rule is dropped with the warningmount rules not enforce(classrule-not-enforced, off by default; mount.cc:782, mount.cc:1139-1142). The spelling is the parser's; it is on the bug list under "Message typo and a stale message" (Known bugs). - Rules of the mount class that differ only in keyword are merged and their permissions ORed (rule.h:540-554, mount.cc:688-714).
do_match_mnt: mount.c:159-211.- Kernel statements are read from the kernel source and were not run.
for security researchers
Attack surface
- The kernel has code that matches the data argument of mount(2) as a fifth field (mount.c:195-207,
AA_MNT_CONT_MATCH). The parser never writes that field: the memberoptsis never assigned (mount.cc:503; on the bug list under "Dead code and unused state in the mount rule"). No rule can constrain filesystem-specific options. - Merged permissions: a
mountand aumountrule with the same paths become one object whose strings carry both bits. The kernel reads the permission at a different point of the string for each operation, and no cross-grant was found by reading.
for AppArmor developers for security researchers
Read more
07 What mount /dev/sdb1, compiles to for AppArmor developers for security researchers
mount SOURCE, also produces a rule with SOURCE as the mount point and a wide set of optional flags (mount.cc:936-948, 1097-1099). Read from the compiled rules.
Here is a rule that reads narrower than it compiles. One path and nothing else: the man page describes it as mounting that device anywhere. With no options, the parser generates a rule for every kind of call that fits. Three of them have the path as the source. The fourth is for propagation changes, which have no source, so the path goes in the mount point position. Every flag of that rule is optional, bind and move included. So the policy also matches mounts onto that path. The warning for this is off by default. Naming a mount point, or writing options with the equals sign, avoids that rule.
Details and sources
for AppArmor developers for security researchers
Details
- Run with the tree's parser (
--warn=all -D rule-exprs),mount /dev/sdb1,gives four rules, each with permission 0x2: - bind:\x07[^\000]*\x00/dev/sdb1\x00[^\000]*\x00(\x0d|)(\x0f|)- propagation:\x07/dev/sdb1\x00[^\000]*\x00[^\000]*\x00(\x01|)(\x05|)(\x06|)(\x07|)(\x08|)(\x09|)(\x0d|)(\x0e|)(\x0f|)(\x10|)(\x11|)(\x12|)(\x13|)(\x14|)(\x15|)(\x18|)(\x1a|)- move:\x07[^\000]*\x00/dev/sdb1\x00[^\000]*\x00(\x0e|)- new mount:\x07[^\000]*\x00/dev/sdb1\x00[^\000]*\x00followed by sixteen optional flag bytes. - The same run prints the warning
The use of source as mount point for propagation type flags is deprecated.Its class isdeprecated, which is off by default (mount.cc:937-938, parser.h:77);--warn=deprecatedor--warn=allshows it. - The propagation rule is generated when the rule lacks a source or lacks a mount point (mount.cc:1097-1099) and uses the source as mount point when there is no mount point (mount.cc:936-940). Its flags are masked with
MS_MAKE_FLAGS, which is every flag except the per-mount ones, not only the propagation flags (mount.cc:948, mount.h:110). mount /dev/sdb1 -> /mnt/**,gives three rules (bind, move, new mount) and no warning (run with the tree's parser).- The example call on the slide is derived from the compiled rule and the kernel source; it was not run.
for AppArmor developers for security researchers
Attack surface
- What the propagation rule matches, with
/dev/sdb1as the mount point: a bind mount of any path (the kernel sends mount point, source and the flagbind, mount.c:371-387), a move, a remount, and a new mount of any type with any ofro sync mand dirsync nosymfollow silent acl iversion lazytime, or no flags. - Known discrepancy, on the bug list as "A source-only
mountrule also allows mounting anything onto that path": apparmor.d(5) documents the rule as source-only (apparmor.d.pod:1813). - Status: confirmed. The bug list has the compiled rules and a kernel run in which a bind mount onto the rule's path succeeded under a profile with only this rule and the capability (Known bugs). The example call on the slide was not run.
- When auditing profiles, look for mount rules with one path and neither
optionsnor->. Writingmount options=(...) SOURCE -> MOUNTPOINT,gives one kind of call and no extra rule.
for AppArmor developers for security researchers
Read more
08 Mistakes and their messages
Flag words only; no conflicting pairs; conditionals before paths. Encoding of mount rule failed means the rule describes no kind of mount call.
The most common one is trying to write a filesystem option such as a size: rules know mount flags only. Next, two words that fight over the same flag, rw and ro. Then order: conditionals come before the paths. A rule that combines things no call can have, like a remount with a source, fails late, with encoding of mount rule failed. And owner has no meaning here. Be warned that three of these messages don't tell you the line, so check the mount rules you touched last.
Details and sources
Details
- The parser prints an error as
AppArmor parser error for FILE in profile FILE at line N: MESSAGE; the slide shows MESSAGE. All five rows were run with the tree's parser. Row 2 printsconflicting flag values = 1, 1before the line shown. - Known discrepancy, on the bug list as "Mount option errors bypass the parser's error reporting": three messages (
unsupported mount option value,conflicting flags in the rule,Encoding of mount rule failed) carry no file, profile or line. Encoding of mount rule failedis followed byERROR processing policydb rules for profile demo, failed to load. Rules that fail this way: a command flag withfstype(mount options=(rbind) fstype=ext4 /a -> /b,), a propagation flag with both paths (mount options=(rprivate) /a -> /b,),remountalone with a source (mount options=(remount) /run/demo/,).- Known discrepancy, on the bug list as "A remount rule with
fstype=or with a source compiles to a new-mount rule without the remount flag": with one more flag the same shape is accepted.mount options=(remount, ro) /run/demo/,compiles to a new-mount rule with the flagroand no remount; see remount rules. - An unknown conditional name gives
invalid mount conditionalwith the name, thenbad mount rule. mount options=defaults /a -> /b,givesunsupported mount option value 'defaults'.options:=is a scanner error.- A mount point without a trailing
/is not an error; it does not match a directory. - The full table of messages is in the reference below. Failing examples in the tree: the
bad_*.sdfiles in parser/tst/simple_tests/mount.
for AppArmor developers for security researchers
In the code
unsupported mount option value: mount.cc:471, mount.cc:494-495. The conflict check: mount.cc:545-546.Encoding of mount rule failed: mount.cc:1190. The conditional name check: parser_yacc.y:1788, parser_yacc.y:1803. Theownerrefusal: mount.h:176.
09 The rest of a mount's life
Mount rules allow mounts. Remount, umount and pivot_root rules cover the rest.
Demo's scratch area is mounted. What happens to it next is three more rules: remount to make it read-only, pivot_root to move the worker's root into it, and umount to take it down. The in operator comes from the conditionals deck. The capability deck covers sys_admin, which every one of these calls needs as well. And when a mount is refused, the denials deck shows how to read the record.
Details and sources
Details
[QUALIFIERS] mount [CONDITIONALS] [SOURCE] [-> MOUNTPOINT],: each part left out means any.- A refused mount returns
EACCESand is logged asoperation="mount"with the field that failed ininfo=. - Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2) and the kernel tree named on the page. The kernel behaviour was read from the source, not observed on a running kernel.
Read more
Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the line (-Q -K --skip-kernel-load --warn=all, -D rule-exprs for compiled forms), with nothing loaded into a kernel; "code" means the parser source or the kernel source was read, not run. Nothing here was observed on a running kernel.
Grammar
MOUNT RULE: [QUALIFIERS] mount [CONDITIONALS] [SOURCE] [-> MOUNTPOINT] ,
CONDITIONALS: fstype=TYPE | fstype=( TYPE ... ) | fstype in ( TYPE ... )
options=FLAG | options=( FLAG ... ) | options in ( FLAG ... )
QUALIFIERS: [priority=N] [audit] [allow|deny|prompt]
vfstypeis the same asfstype;optionis the same asoptions(code).- Everything after the keyword is optional.
mount,allows any mount; one path alone is the source;-> PATHalone is the mount point (tree). - Known discrepancy, on the bug list as "A source-only
mountrule also allows mounting anything onto that path":mount /dev/sdb1,also allows bind mounts, moves and remounts onto/dev/sdb1. Write the mount point (mount /dev/sdb1 -> /mnt/**,) oroptions=( )(tree; a kernel run is on the bug list, Known bugs). - Conditionals come before the paths. A conditional after the arrow is refused (tree).
- Inside the parentheses blanks or commas separate the words (tree).
- Source, mount point and fstype are patterns and take variables (code). The mount point is not checked to be an absolute path (tree).
- The source word
detachedstands for a mount that is not attached anywhere, as seen at move_mount(2) (code).
| Seat | On a mount rule |
|---|---|
priority= | taken |
audit | taken |
allow, deny, prompt | taken: deny is not logged; prompt is in syn-prompt |
owner, other | refused: owner prefix not allowed on mount rules (tree) |
Flag words
"Sets" words name a flag that must be (or may be) present. "Clears" words name its absence: they add nothing to options= and make the flag optional in options in. The table is parser/mount.cc:247-311; bit values parser/mount.h:33-81.
| Sets | Clears | mount(2) flag | Belongs to |
|---|---|---|---|
ro, r, read-only | rw, w | MS_RDONLY | new mount, remount |
nosuid | suid | MS_NOSUID | new mount, remount |
nodev | dev | MS_NODEV | new mount, remount |
noexec | exec | MS_NOEXEC | new mount, remount |
sync | async | MS_SYNCHRONOUS | new mount, remount |
remount | MS_REMOUNT | remount | |
mand | nomand | MS_MANDLOCK | new mount, remount |
dirsync | MS_DIRSYNC | new mount, remount | |
nosymfollow | symfollow | MS_NOSYMFOLLOW | new mount, remount |
noatime | atime | MS_NOATIME | new mount, remount |
nodiratime | diratime | MS_NODIRATIME | new mount, remount |
bind, B | MS_BIND | bind | |
rbind, R | MS_BIND and MS_REC | bind | |
move, M | MS_MOVE | move | |
silent, verbose | loud | MS_SILENT | new mount, remount, propagation |
acl | noacl | MS_POSIXACL | new mount, remount |
unbindable, make-unbindable | MS_UNBINDABLE | propagation | |
runbindable, make-runbindable | MS_UNBINDABLE and MS_REC | propagation | |
private, make-private | MS_PRIVATE | propagation | |
rprivate, make-rprivate | MS_PRIVATE and MS_REC | propagation | |
slave, make-slave | MS_SLAVE | propagation | |
rslave, make-rslave | MS_SLAVE and MS_REC | propagation | |
shared, make-shared | MS_SHARED | propagation | |
rshared, make-rshared | MS_SHARED and MS_REC | propagation | |
relatime | norelatime | MS_RELATIME | new mount, remount |
iversion | noiversion | MS_I_VERSION | new mount, remount |
strictatime | nostrictatime | MS_STRICTATIME | new mount, remount |
lazytime | nolazytime | MS_LAZYTIME | new mount, remount |
nouser | user | MS_NOUSER | no effect (known discrepancy) |
- A remount rule keeps every flag except
move, the propagation flags included (parser/mount.h:114-120). - Any other word, a filesystem option such as
size=1mor the worddefaultsincluded, is refused (tree).
What options mean
| The rule has | Meaning |
|---|---|
no options | every flag is optional; every kind of call the rest of the rule allows |
options=(a b) | exactly the flags a and b; every other flag absent |
options=(rw) (clearing words only) | a mount with no flags |
options in (a b) | any of a and b, or none |
options=(a) options in (b) | a required, b optional |
options=(a) options=(b) | two alternatives: exactly a, or exactly b |
Kinds of mount call
The kernel tests the flags of mount(2) in this order (linux:security/apparmor/lsm.c:707-742, code).
| Kind | Selected by | The kernel compares | Covered by a rule with | Example |
|---|---|---|---|---|
| remount | MS_REMOUNT | mount point, flags | options= naming remount, no source, no fstype; or a remount rule | mount options=(remount, ro) -> /mnt/, |
| bind | MS_BIND in mount(2) | mount point, source, bind or rbind | options= naming bind or rbind, no fstype | mount options=(bind) /a/ -> /b/, |
| propagation | MS_SHARED, MS_PRIVATE, MS_SLAVE, MS_UNBINDABLE | mount point, propagation flags | options= naming a propagation flag, one path, no fstype | mount options=(rprivate) -> /mnt/, |
| move | MS_MOVE | mount point, source | options= naming move, no fstype | mount options=(move) /a/ -> /b/, |
| new mount | none of the above | mount point, source, type, flags | any other options=; any rule with fstype | mount fstype=tmpfs options=(rw, nosuid) tmpfs -> /run/demo/, |
A rule with no options covers every kind its other parts allow; with only options in a kind is covered when its flag is in the list (mount options in (ro, nodev) /a -> /b/, covers new mounts only) (parser/mount.cc:1089-1104, code; tree).
Names the kernel compares
| Field | What it is |
|---|---|
| mount point | the path of the target; a directory ends in / |
| source | bind and move: the resolved path; new mount: a resolved path if the filesystem type needs a device, otherwise the string the caller passed; remount and propagation: none; detached for a mount that is not attached |
| type | the string the caller passed (fuse.sshfs is not fuse); new mounts only |
Read from linux:security/apparmor/mount.c:214-221, 328-542 (code).
The log record
| Field | Meaning |
|---|---|
operation="mount" | every kind of mount call, a remount included |
class="mount" | on current kernels; the fixture below is older |
info= | failed mntpnt match, failed srcname match, failed type match, failed flags match, failed data match or failed perms check: the first field that did not match |
error=-13 | EACCES |
name= | the mount point |
fstype= | the type, when the call has one |
srcname= | the source, when the call has one |
flags= | the flags as words, starting with rw or ro |
A record from the tree (libraries/libapparmor/testsuite/test_multi/testcase_mount_01.in):
apparmor="DENIED" operation="mount" info="failed mntpnt match" error=-13 ... name="/tmp/.../mountpoint/" ... comm="mount" fstype="ext2" srcname="/dev/loop0/" flags="rw, mand"
Format strings: linux:security/apparmor/mount.c:31-118, 145-153 (code).
Errors and warnings
| Rule | Message | Has line number |
|---|---|---|
mount options=(rw, nosuid, size=1m) tmpfs -> /run/demo/, | unsupported mount option value 'size=1m' | no |
mount options=defaults /a -> /b, | unsupported mount option value 'defaults' | no |
mount options=(rw, ro) tmpfs -> /run/demo/, | conflicting flag values = 1, 1 then conflicting flags in the rule | no |
mount tmpfs -> /run/demo/ options=(rw), | syntax error, unexpected TOK_CONDID, expecting TOK_END_OF_RULE | yes |
mount options=(remount) /dev/sda1 -> /run/demo/, | Encoding of mount rule failed | no |
mount options=(rbind) fstype=ext4 /a -> /b, | Encoding of mount rule failed | no |
mount options=(rprivate) /a -> /b, | Encoding of mount rule failed | no |
| an unknown conditional name | invalid mount conditional with the name, then bad mount rule | yes |
a conditional after -> | mount point conditions not currently supported | yes |
mount options:=ro /a -> /b, | Lexer found unexpected character: ':' (0x3a) in state: MOUNT_MODE | yes |
owner mount, | owner prefix not allowed on mount rules | yes |
mount /dev/sdb1, with --warn=deprecated | warning The use of source as mount point for propagation type flags is deprecated. | yes |
any mount rule, no mount in the feature set, --warn=rule-not-enforced | warning mount rules not enforce |
Rows with a rule are from the tree's parser; the others are read from the parser source (code).
Feature files
File under /sys/kernel/security/apparmor/features/ | Content | Meaning |
|---|---|---|
mount/mask | mount umount pivot_root | the kernel mediates the mount class |
mount/move_mount | detached | the kernel reports a mount that is not attached as source detached |
Without mount in the feature set every rule of the mount class is dropped, and the warning for that is off by default (code). See syn-abi and adm-features.
for AppArmor developers for security researchers
In the parser and the kernel
- One class,
mnt_rule, formount,remount,umountandpivot_root; policydb classAA_CLASS_MOUNT7; permissionsAA_MAY_PIVOTROOT0x1,AA_MAY_MOUNT0x2,AA_MAY_UMOUNT0x4 (parser/mount.h:129-131). - Match string of a mount rule:
\x07mount point NUL source NUL type NUL flag bytes (parser/mount.cc:1129-1192). Demo's line is\x07/run/demo/\x00tmpfs\x00(tmpfs)\x00\x02with 0x2 (tree). - A flag byte is the bit number + 1, written from bit 0 up:
\xNNrequired,(\xNN|)optional,(\xfe|)when no flag byte results (parser/mount.cc:716-755). - Five generators, chosen in
gen_flag_rules(parser/mount.cc:1082-1127): remount, bind, propagation, move, new mount, each with its own flag mask (parser/mount.h:106-121).mount,produces all five (tree). mount options=ro options in (nosuid) /dev/x -> /mnt/,compiles to the flag bytes\x01(\x02|);mount options=ro options=nosuid /dev/x -> /mnt/,to two rules (tree).- Kernel:
sb_mountsorts the call (linux:security/apparmor/lsm.c:707-742);do_match_mntwalks mount point, NUL, source, NUL, type, NUL, one byte per set flag, and testsAA_MAY_MOUNT(linux:security/apparmor/mount.c:159-211);match_mnt_flags(linux:security/apparmor/mount.c:132-143). - Hooks of the class:
move_mount,sb_mount,sb_umount,sb_pivotroot(linux:security/apparmor/lsm.c:1791-1794). - Grammar and scanner:
parser/parser_yacc.y:1277-1300, 1777-1838,parser/parser_lex.l:876-879.
for AppArmor developers for security researchers
Known discrepancies
None of these is taught as intended behaviour. All are on the bug list as confirmed; see Known bugs.
mount SOURCE,also compiles to a rule with SOURCE as the mount point and seventeen optional flags,bindandmoveamong them; reproduce withmount /dev/sdb1,and-D rule-exprs(tree). Confirmed by a kernel run on the bug list.options in (ro,atime)accepts a mount with no flags and one withnoatime; apparmor.d(5) says it does not (tree, compiled flags(\x01|)(\x0b|)). Not run on a kernel.nouseris accepted and has no effect:mount options=(nouser) /a -> /b,compiles to a mount without flags, and no rule matches a call with that flag set (tree).- Dead code and unused state in the mount rule: the filesystem-option ("data") field is never written, and two error messages cannot be reached (code).
- A bind mount made with open_tree and move_mount is checked as a move without a source; bind rules do not apply to it (kernel; on the bug list).
unsupported mount option value,conflicting flags in the ruleandEncoding of mount rule failedare printed without file, profile or line (tree).
Not determined: which flags mount(8) passes for a given command line.
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
FILE ACCESS
- Globbing (AARE) — patterns in source mount point and fstype
PREAMBLE AND REUSE
- The abi rule and the abi files — the feature set that has or lacks the mount class
QUALIFIERS
- allow and deny — deny and audit on mount rules
RULE CLASSES
- Remount rules — changing the flags of an existing mount
- Umount rules — taking a mount down
- pivot_root rules — moving the root into a mount
- Rule conditionals — the in operator and the list syntax
- Capability rules — sys_admin which a mount also needs
- The all rule — the rule that includes every mount
SECURITY · threat model and limits
- What is not mediated — what no rule class covers
RUNNING THE PARSER
- Reading a denial — reading the mount record