From c9e31b7fbde5f7acf48775bac4b33c5c64233246 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Fri, 24 Feb 2012 04:19:38 -0800 Subject: [PATCH] Add mount rules Add the ability to control mounting and unmounting The basic form of the rules are. [audit] [deny] mount [conds]* [device] [ -> [conds] path], [audit] [deny] remount [conds]* [path], [audit] [deny] umount [conds]* [path], [audit] [deny] pivotroot [oldroot=] -> remount is just a short cut for mount options=remount where [conds] can be fstype= options= conds follow the extended conditional syntax of allowing either: * a single value after the equals, which has the same character range as regular IDS (ie most anything but it can't be terminated with a , (comma) and if spaces or other characters are needed it can be quoted eg. options=foo options = foo options="foo bar" * a list of values after the equals, the list of values is enclosed within parenthesis () and its has a slightly reduced character set but again elements can be quoted. the separation between elements is whitespace and commas. eg. options=(foo bar) options=(foo, bar) options=(foo , bar) options=(foo,bar) The rules are flexible and follow a similar pattern as network, capability, etc. mount, # allow all mounts, but not umount or pivotroot mount fstype=procfs, # allow mounting procfs anywhere mount options=(bind, ro) /foo -> /bar, # readonly bind mount mount /dev/sda -> /mnt, mount /dev/sd** -> /mnt/**, mount fstype=overlayfs options=(rw,upperdir=/tmp/upper/,lowerdir=/) overlay -> /mnt/ umount, umount /m*, Currently variables and regexs are are supported on the device and mount point. ie. mount -> , Regexes are supported in fstype and options. The options have a further caveat that regexs only work if the option is fs specific option. eg. options=(upperdir=/tmp/*,lowerdir=/) regex's will not currently work against the standard options like ro, rw nosuid Conditionals (fstype) can only be applied to the device (source) at this time and will be disregarded in situations where the mount is manipulating an existing mount (bind, remount). Options can be specified multiple times mount option=rw option=(nosuid,upperdir=/foo), and will be combined together into a single set of values The ordering of the standard mount options (rw,ro, ...) does not matter but the ordering of fs specific options does. Specifying that the value of a particular option does not matter can be acheived by providing both the positive and negative forms of and option option=(rw,ro) options=(suid,nosuid) For the fs specific options specifying that a particular value does not matter is achieve using a regex with alternations. Improvements to the syntax and order restrictions are planned for the future. Signed-off-by: John Johansen --- parser/Makefile | 4 +- parser/mount.c | 510 +++++++++++++++++++++++ parser/mount.h | 134 ++++++ parser/parser.h | 26 ++ parser/parser_lex.l | 96 ++++- parser/parser_misc.c | 80 ++++ parser/parser_policy.c | 61 ++- parser/parser_regex.c | 365 ++++++++++++++++ parser/parser_variable.c | 82 +++- parser/parser_yacc.y | 196 ++++++++- parser/tst/simple_tests/mount/ok_1.sd | 7 + parser/tst/simple_tests/mount/ok_10.sd | 7 + parser/tst/simple_tests/mount/ok_11.sd | 7 + parser/tst/simple_tests/mount/ok_12.sd | 7 + parser/tst/simple_tests/mount/ok_14.sd | 7 + parser/tst/simple_tests/mount/ok_15.sd | 7 + parser/tst/simple_tests/mount/ok_16.sd | 7 + parser/tst/simple_tests/mount/ok_17.sd | 7 + parser/tst/simple_tests/mount/ok_18.sd | 7 + parser/tst/simple_tests/mount/ok_19.sd | 7 + parser/tst/simple_tests/mount/ok_2.sd | 7 + parser/tst/simple_tests/mount/ok_20.sd | 7 + parser/tst/simple_tests/mount/ok_21.sd | 7 + parser/tst/simple_tests/mount/ok_22.sd | 7 + parser/tst/simple_tests/mount/ok_23.sd | 7 + parser/tst/simple_tests/mount/ok_3.sd | 7 + parser/tst/simple_tests/mount/ok_4.sd | 7 + parser/tst/simple_tests/mount/ok_5.sd | 10 + parser/tst/simple_tests/mount/ok_8.sd | 9 + parser/tst/simple_tests/mount/ok_9.sd | 7 + parser/tst/simple_tests/mount/okay_13.sd | 7 + parser/tst/simple_tests/mount/okay_6.sd | 7 + parser/tst/simple_tests/mount/okay_7.sd | 7 + 33 files changed, 1675 insertions(+), 45 deletions(-) create mode 100644 parser/mount.c create mode 100644 parser/mount.h create mode 100644 parser/tst/simple_tests/mount/ok_1.sd create mode 100644 parser/tst/simple_tests/mount/ok_10.sd create mode 100644 parser/tst/simple_tests/mount/ok_11.sd create mode 100644 parser/tst/simple_tests/mount/ok_12.sd create mode 100644 parser/tst/simple_tests/mount/ok_14.sd create mode 100644 parser/tst/simple_tests/mount/ok_15.sd create mode 100644 parser/tst/simple_tests/mount/ok_16.sd create mode 100644 parser/tst/simple_tests/mount/ok_17.sd create mode 100644 parser/tst/simple_tests/mount/ok_18.sd create mode 100644 parser/tst/simple_tests/mount/ok_19.sd create mode 100644 parser/tst/simple_tests/mount/ok_2.sd create mode 100644 parser/tst/simple_tests/mount/ok_20.sd create mode 100644 parser/tst/simple_tests/mount/ok_21.sd create mode 100644 parser/tst/simple_tests/mount/ok_22.sd create mode 100644 parser/tst/simple_tests/mount/ok_23.sd create mode 100644 parser/tst/simple_tests/mount/ok_3.sd create mode 100644 parser/tst/simple_tests/mount/ok_4.sd create mode 100644 parser/tst/simple_tests/mount/ok_5.sd create mode 100644 parser/tst/simple_tests/mount/ok_8.sd create mode 100644 parser/tst/simple_tests/mount/ok_9.sd create mode 100644 parser/tst/simple_tests/mount/okay_13.sd create mode 100644 parser/tst/simple_tests/mount/okay_6.sd create mode 100644 parser/tst/simple_tests/mount/okay_7.sd diff --git a/parser/Makefile b/parser/Makefile index 15cbe62de..528d1b341 100644 --- a/parser/Makefile +++ b/parser/Makefile @@ -76,8 +76,8 @@ EXTRA_CFLAGS+=-DSUBDOMAIN_CONFDIR=\"${CONFDIR}\" SRCS = parser_common.c parser_include.c parser_interface.c parser_lex.c \ parser_main.c parser_misc.c parser_merge.c parser_symtab.c \ parser_yacc.c parser_regex.c parser_variable.c parser_policy.c \ - parser_alias.c -HDRS = parser.h parser_include.h immunix.h + parser_alias.c mount.c +HDRS = parser.h parser_include.h immunix.h mount.h TOOLS = apparmor_parser OBJECTS = $(SRCS:.c=.o) diff --git a/parser/mount.c b/parser/mount.c new file mode 100644 index 000000000..80fca854a --- /dev/null +++ b/parser/mount.c @@ -0,0 +1,510 @@ +/* + * Copyright (c) 2010 + * Canonical, Ltd. (All rights reserved) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact Novell, Inc. or Canonical + * Ltd. + */ + +/** + * The mount command, its mix of options and flags, its permissions and + * mapping are a mess. + * mount [-lhV] + * + * mount -a [-fFnrsvw] [-t vfstype] [-O optlist] + * + * mount [-fnrsvw] [-o option[,option]...] device|dir + * + * mount [-fnrsvw] [-t vfstype] [-o options] device dir + * + *---------------------------------------------------------------------- + * Mount flags of no interest for apparmor mediation + * -a, --all + * -F fork for simultaneous mount + * -f fake, do everything except that actual system call + * -h --help + * -i, --internal-only + * -n mount without writing in /etc/mtab + * -O limits what is auto mounted + * -p, --pass-fd num + * -s Tolerate sloppy mount options + * -U uuid + * -V --version + * --no-canonicalize + * + *---------------------------------------------------------------------- + * what do we do with these + * -l list? + * -L