Remount rules
changing mount options for application developers for administrators for security researchers
A remount rule allows changing the flags of an existing mount. It is a mount rule with the remount flag added and the single path read as the mount point. Without options any other flags may accompany the remount. With options=( ) the flags must be exactly those. A refusal is logged as operation mount with remount among the flags.
On the map: rule classes
▶ Watch this deck — 8 scenes, ~5 min
Worth seeing first
- Mount rules — the mount rule, its options and the flag table
01 demo makes its scratch area read-only
remount [options...] MOUNTPOINT, allows changing the flags of an existing mount.
Demo has filled its scratch area and now wants it read-only before the worker starts. That's not a new mount. It's a change to an existing one, which the mount system call does when you pass the remount flag. The mount rule on line fourteen doesn't cover it. Line fifteen does: remount, the flags, and the mount point. There's no source and no type, because nothing new is being mounted.
Details and sources
Details
- The kernel treats a mount(2) call with
MS_REMOUNTas a remount before testing anything else (lsm.c:722-724) and compares the mount point and the full flags, with no source and no type (mount.c:328-353). The hook issb_mount(lsm.c:707-742). - The permission is the mount permission; there is no separate remount permission.
- A remount is a mount(2) call:
EPERMwithoutcapability sys_admin,, after the rule has been checked (namespace.c:4279-4283). - A remount sets the flags to those of the call: this call leaves nosuid out, and the mount loses it (namespace.c:3506-3541). A program that wants to keep it passes it again, and the rule must then name it; see "Which other flags may come along".
remount options=(ro) /run/demo/,is line 15 of demo's profile; it compiles with no warning (run with the tree's parser). The programdemoand its profile are invented for the map.- The flags of the call on the slide illustrate a remount to read-only. Which flags mount(8) passes for a command line was not determined, so the slide shows the system call and not a shell command.
- Kernel statements are read from the kernel source and were not run.
Read more
- apparmor.d(5), Mount Rules.
- Mount rules for the five kinds of mount call.
for AppArmor developers for security researchers
In the code
- The mount permission is
AA_MAY_MOUNT(0x2) (mount.h:21).
02 remount, options, a mount point
[QUALIFIERS] remount [options=... | options in ...] [MOUNTPOINT],. The one path is the mount point.
The shape is the mount rule's, with the paths simplified. The keyword, the options conditional with equals or with in, and one path, which here is the mount point. No arrow. Leave out the path and it's every mount point. Leave out the options and any flags may come with the remount. The qualifiers work as for mount rules.
Details and sources
Details
- The conditional names are those of mount rules (
options,option,fstype,vfstype), but a remount has no filesystem type to compare. - 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":remount fstype=ext4 /a,is accepted and allows new ext4 mounts onto/a, and no remount. Do not writefstype=in a remount rule. - The mount point is a pattern and, for a directory, ends in
/. - Seats:
audit,allow,deny,promptandpriority=are taken;ownerandotherare refused withowner prefix not allowed on mount rules. - Examples in the tree:
remount /foo,(ok_22.sd);remount,(plasmashell:14). - The arrow gives
syntax error, unexpected TOK_ARROW, expecting TOK_END_OF_RULE(run with the tree's parser).
Read more
for AppArmor developers for security researchers
In the code
TOK_REMOUNT opt_conds opt_id TOK_END_OF_RULEcallsdo_mnt_rule($2, NULL, NULL, $3, AA_DUMMY_REMOUNT)(parser_yacc.y:1287-1290).
03 A mount rule, written shorter
remount options=(F) PATH, = mount options=(remount, F) -> PATH,.
Remount isn't really a new kind of rule. It's a mount rule that the parser completes for you. The keyword puts the remount flag into your options, and the path you wrote goes into the mount point position. You could write the long form yourself, with mount, remount in the options, and an arrow. They compile to the same thing. The short form saves you from one trap: in a mount rule a single path is the source, and a remount with a source can't be expressed at all.
Details and sources
Details
- Run with the tree's parser,
remount options=(ro) /run/demo/,andmount options=(remount, ro) -> /run/demo/,compile to the same rule: the mount point/run/demo/, any source, any type, and the two flagsroandremount, both required. - The difference without options:
remount /a,requires the remount flag and lets every other remount flag be present or absent, whilemount options=(remount) -> /a,requires the remount flag alone (run with the tree's parser). mount options=(remount) /run/demo/,printsEncoding of mount rule failed, without a line number, followed byERROR processing policydb rules for profile demo, failed to load(run with the tree's parser). A failing example in the tree: bad_opt_8.sd.
Read more
for AppArmor developers for security researchers
In the code
- The keyword adds
MS_REMOUNTto everyoptions=set (mount.cc:541-542) and the placeholder permission is replaced by the mount permission (mount.cc:578-580). - The compiled string of both forms:
\x07/run/demo/\x00[^\000]*\x00[^\000]*\x00\x01\x06, permission 0x2.
04 Which other flags may come along
remount options=(ro) P,: exactly remount + ro. remount options in (ro, nosuid) P,: remount plus any of those. remount P,: remount plus anything.
Options means the same here as in a mount rule, with one addition: the remount flag is always part of the set. So demo's rule, options= ro, allows a remount whose flags are exactly remount and read-only. A program that repeats the other flags of the mount, say nosuid, sends a different set and is refused. Options in is the forgiving form: any of these, or none. And a remount rule with no options at all allows any flags, which includes remounting read-write again. Pick the exact form when the direction matters.
Details and sources
Details
- The "allowed" and "refused" cells are derived from the compiled flags and the kernel's flag comparison (mount.c:132-143, mount.c:328-353); nothing was run on a kernel. The compiled flags were produced with the tree's parser: row 1 requires
roandremount; row 2 requiresremountand makesroandnosuidoptional; row 3 requiresremountand makes every other remount flag optional. - The kernel passes the full flags of a remount call, propagation flags included; programs do pass them together with remount.
- The flags a remount rule can name are all flags except
move:remount options=(move) /a,is accepted and themoveis dropped (run with the tree's parser). remount options=(bind) /a,requiresbindandremount: that is the call that changes the per-mount flags of a bind mount.- Clearing words (
rw,suid, ...) add nothing tooptions=:remount options=(rw) /a,allows a remount with no other flag. remount options=(rw, ro) /a,givesconflicting flag values = 33, 1, thenconflicting flags in the rule.- Kernel statements are read from the kernel source and were not run.
Read more
- apparmor.d(5), Mount Rules, wiki: TechnicalDoc_Mount_Flags.
- Mount rules for the flag table.
for AppArmor developers for security researchers
In the code
- The remount flag added to each
options=set: mount.cc:541-542; the defaults without options: mount.cc:561-563, mount.cc:570-571; the flags a remount rule keeps (MS_REMOUNT_FLAGS) and why propagation flags are among them: mount.h:114-120.
05 What demo and the log see
A remount is logged as operation="mount" with remount in flags=. info="failed flags match" means the path matched and the flags did not.
A refused remount fails with EACCES like any mount. In the log, don't look for the word remount as the operation: the operation is mount, and remount is one of the flags. There's no source and no type in the record, because a remount has neither. Info tells you which field failed. Here it's the flags: the rule wanted exactly read-only, and the call also carried nosuid. Copy the flags from the record into the rule, or use options in.
Details and sources
Details
- The record on the slide is assembled from the fixture testcase_remount_01.in (
apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="/home/user/test/testmount" name="/tmp/foo/" pid=14155 comm="testmount" flags="ro, remount") with demo's values, which are illustrative.info="failed flags match"is from the kernel's table of texts (mount.c:145-153) and the order of the words inflags=from the kernel's format code (mount.c:31-85). - A remount is audited as
operation="mount";remountappears among the flags (lsm.c:722-724, mount.c:328-353). - A remount has no source and no type, so the record has no
srcname=and nofstype=, and both are compared as empty.infois usuallyfailed mntpnt matchorfailed flags match. It isfailed srcname matchorfailed type matchwhen the mount point matches only rules that name a source or a type, as demo's line 14 does before line 15 is added, andfailed perms checkwhen every field matched a rule without the permission (mount.c:179-189). - The mount point is named with a trailing
/for a directory. - A complain-mode example with a long flag list: testcase_mount_02.in (
flags="rw, nosuid, nodev, remount, bind, silent, relatime"). - The profile must mediate the mount class for the check to happen; see mount rules.
- Both fixes on the slide compile (run with the tree's parser).
error=-13isEACCES. - Kernel statements are read from the kernel source and were not run.
Read more
- apparmor.net: Denials quick guide.
- Reading denials, mount rules for the
infotexts.
06 A placeholder permission that turns into a flag for AppArmor developers for security researchers
AA_DUMMY_REMOUNT (mount.h:134) -> MS_REMOUNT added (mount.cc:541-542, 561-571) -> gen_policy_remount (mount.cc:786-859); kernel aa_remount (mount.c:328-353).
There is no remount permission in the kernel, so the parser needs a way to carry the keyword from the grammar to the rule. It uses a placeholder permission bit. The constructor sees it, adds the remount flag to every exact set, or makes it the exact set if there are no options, with every other flag optional, and swaps the placeholder for the ordinary mount permission. From there the remount generator writes the mount point, any source, any type, and the flag bytes. The kernel's remount path passes only the mount point and the flags. And that generator only runs when the rule has no source and no fstype.
Details and sources
for AppArmor developers for security researchers
Details
AA_DUMMY_REMOUNTis 0x40000000 (mount.h:134). The constructor addsMS_REMOUNTto everyoptions=set (mount.cc:541-542), uses it as the required set when there is nooptions=(mount.cc:559-571) and replaces the placeholder byAA_MAY_MOUNT(mount.cc:578-580).gen_policy_remount: mount.cc:786-859. It is chosen when the flags containremountand the rule has neither source nor fstype (mount.cc:1105-1107).MS_REMOUNT_FLAGSis every flag exceptmove(mount.h:114-120).- Flag bytes:
rois\x01,remountis\x06(bit number + 1). - Dumps from the tree's parser: demo's line gives
\x07/run/demo/\x00[^\000]*\x00[^\000]*\x00\x01\x06with 0x2;remount /run/demo/,gives...\x00(\x01|)(\x02|)(\x03|)(\x04|)(\x05|)\x06(\x07|)...;remount options in (ro) /a,gives(\x01|)\x06;remount options=(bind) /a,gives\x06\x0d. - Kernel:
aa_remount(mount.c:328-353). - Kernel statements are read from the kernel source and were not run.
for security researchers
Attack surface
- 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":mount options=(remount, ro) /run/demo/,(the long form with the path in the source position and one more flag) is accepted and compiles to\x07[^\000]*\x00/run/demo/\x00[^\000]*\x00\x01: a new mount with source/run/demo/onto any mount point with the flagro, and no remount (run with the tree's parser). Withremountalone the same shape fails to encode. - 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":remount fstype=ext4 /a,is accepted and compiles to a new-mount rule without the remount flag,\x07/a\x00[^\000]*\x00(ext4)\x00(\x01|)(\x02|)(\x03|)(\x04|)(\x05|)(\x07|)...: new mounts of that type from any source onto/awith any combination of the ordinary flags, and no remount. The cause is the order of the tests: with an fstype the remount branch is skipped and the last branch still sees optional flags (mount.cc:559-571, mount.cc:1105-1106, mount.cc:1118-1123, mount.cc:1043). The long formmount options=(remount) fstype=ext4 -> /a,fails withEncoding of mount rule failed. - When auditing, look for
remountrules withfstype=orvfstype=. Both are on the bug list as confirmed on the parser side; see Known bugs. They were not run on a kernel. - A remount rule covers mount(2) with the remount flag. mount_setattr(2), which changes the read-only, nosuid, nodev and noexec flags of a mount, has no AppArmor hook, so a remount rule,
deny remountincluded, is not asked about it (read from the kernel source, lsm.c:1791-1794; not run on a kernel). See what is not mediated. - A remount rule without options also allows remounting read-write or dropping
nosuid,nodevornoexec. That is how the rule reads, but it is worth a second look in a profile meant to keep a mount restricted.
for AppArmor developers for security researchers
Read more
07 Mistakes and their messages
One path with a trailing /, flag words only, no arrow.
An arrow is a syntax error, because there's only one path. The words rw and ro together conflict. Filesystem options such as a size can't be written, only flags. Owner isn't allowed. And, as with the other mount rules, the mount point of a directory needs its slash, which the parser won't remind you of.
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. Rows 1 to 4 were run with the tree's parser. - Row 2 prints two lines,
conflicting flag values = 33, 1andconflicting flags in the rule. The numbers are the two flag masks in decimal: 33 is remount plus ro. - Known discrepancy, on the bug list as "Mount option errors bypass the parser's error reporting": the option errors of rows 2 and 3 carry no file, profile or line.
- An unknown conditional gives
invalid mount conditional foo, thenbad mount rule. The long form with a source,mount options=(remount) /run/demo/,, givesEncoding of mount rule failed. - Row 5 is accepted by the parser; that it does not match a directory is derived from the kernel's naming of mount points and was not run.
Read more
- apparmor.d(5), Mount Rules.
- Mount rules for the full message table.
08 Before and after the remount
Remount rules are mount rules with the remount flag. The flag table is in the mount deck.
The scratch area is read-only now. The complete table of flag words, and the difference between options= and options in, are in the mount deck. Next in demo's story is pivot_root, and at the end, umount. The conditionals deck has the list syntax, and the denials deck explains the record.
Details and sources
Details
[QUALIFIERS] remount [options=... | options in ...] [MOUNTPOINT],is the same rule asmount options=(remount, ...) -> MOUNTPOINT,.- A refused remount returns
EACCESand is logged asoperation="mount"withremountinflags=. - 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
REMOUNT RULE: [QUALIFIERS] remount [CONDITIONALS] [MOUNTPOINT] , CONDITIONALS: options=FLAG | options=( FLAG ... ) | options in ( FLAG ... ) QUALIFIERS: [priority=N] [audit] [allow|deny|prompt]
- The one path is the mount point. There is no source and no arrow (tree).
remount options=(F) P,is the same rule asmount options=(remount, F) -> P,(tree).optionis the same word asoptions(code).
| Seat | On a remount 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) |
remount and the long form
| Rule | Required flags | Optional flags |
|---|---|---|
remount P, | remount | every other flag except move |
remount options=(ro) P, | remount, ro | none |
remount options in (ro, nosuid) P, | remount | ro, nosuid |
mount options=(remount) -> P, | remount | none |
mount options=(remount, ro) -> P, | remount, ro | none |
mount options=(remount) S -> P, | error: Encoding of mount rule failed |
All rows are from the tree's parser.
Flags in a remount rule
- Every flag word of a mount rule except
move; the table is in syn-mount.remount options=(move) P,is accepted and themoveis dropped (tree). remount options=(bind) P,requiresbindandremount: the call that changes the per-mount flags of a bind mount (tree).- Clearing words (
rw,suid, ...) add nothing tooptions=;remount options=(rw) P,allows a remount with no other flag (tree). - Propagation flags may accompany a remount, because programs pass them together (
parser/mount.h:114-120, code).
The log record
| Field | Meaning |
|---|---|
operation="mount" | a remount is logged as a mount |
class="mount" | always |
info= | failed mntpnt match, failed flags match or failed perms check; failed srcname match, failed type match (the mount point matched only a rule with a source or a type) |
error=-13 | EACCES |
name= | the mount point; a directory ends in / |
flags= | the flags as words; remount is among them |
A record from the tree (libraries/libapparmor/testsuite/test_multi/testcase_remount_01.in):
apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="/home/user/test/testmount" name="/tmp/foo/" pid=14155 comm="testmount" flags="ro, remount"
Errors and warnings
| Rule | Message | Has line number |
|---|---|---|
remount /run/demo/ -> /mnt/, | syntax error, unexpected TOK_ARROW, expecting TOK_END_OF_RULE | yes |
remount options=(rw, ro) /run/demo/, | conflicting flag values = 33, 1 then conflicting flags in the rule | no |
remount options=(ro, size=1m) /run/demo/, | unsupported mount option value 'size=1m' | no |
owner remount /run/demo/, | owner prefix not allowed on mount rules | yes |
mount options=(remount) /run/demo/, | Encoding of mount rule failed | no |
remount /run/demo, | none; the rule does not match a directory | |
any remount rule, no mount in the feature set, --warn=rule-not-enforced | warning mount rules not enforce |
Rows with an error message are from the tree's parser.
for AppArmor developers for security researchers
In the parser and the kernel
- Grammar action:
do_mnt_rule($2, NULL, NULL, $3, AA_DUMMY_REMOUNT)(parser/parser_yacc.y:1287-1290); the placeholder is 0x40000000 (parser/mount.h:134). - Constructor:
MS_REMOUNTis added to everyoptions=set (parser/mount.cc:541-542); withoutoptions=the required set is{remount}and the optional set every other remount flag (parser/mount.cc:559-571); the permission becomesAA_MAY_MOUNT(parser/mount.cc:578-580). gen_policy_remountwrites mount point, any source, any type, flags masked withMS_REMOUNT_FLAGS(parser/mount.cc:786-859,parser/mount.h:114-120). Demo's line is\x07/run/demo/\x00[^\000]*\x00[^\000]*\x00\x01\x06with 0x2 (tree).- Kernel:
sb_mounttestsMS_REMOUNTfirst (linux:security/apparmor/lsm.c:722-724);aa_remountpasses the mount point and the flags (linux:security/apparmor/mount.c:328-353).
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.
remount fstype=ext4 /a,is accepted and compiles to a new-mount rule for type ext4 onto/awith every ordinary flag optional and no remount flag; reproduce with-D rule-exprs(tree). Not run on a kernel.mount options=(remount, ro) /run/demo/,is accepted and compiles to a new mount with source/run/demo/and the flagro, without remount (tree). Not run on a kernel.- The option errors are printed without file, profile or line (tree).
Roads from here
START HERE
- The profile language at a glance — every kind of line on one page
QUALIFIERS
- allow and deny — deny and audit on remount rules
RULE CLASSES
- Mount rules — the flag table and options= against options in
- Umount rules — removing the mount
- pivot_root rules — the fourth rule of the mount class
- Rule conditionals — the in operator and the list syntax
- Capability rules — sys_admin which a remount also needs
RUNNING THE PARSER
- Reading a denial — reading the mount record