]> git.ipfire.org Git - thirdparty/lxc.git/commit
apparmor: improve behavior when kernel lacks mount restrictions (v2)
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Sat, 20 Sep 2014 03:47:38 +0000 (03:47 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 22 Sep 2014 21:28:27 +0000 (17:28 -0400)
commit7aff4f43fd84b021db12b2ffed1a4aa1b4cf65ef
tree0138d161c1f0a463d7bffed8241a4b2da4043254
parent2d489f9e87fa0cccd8a1762680a43eeff2fe1b6e
apparmor: improve behavior when kernel lacks mount restrictions (v2)

(Dwight, I took the liberty of adding your Ack but the code did
change a bit to continue passing the char *label from attach.
Tested that "lxc-start -n u1 -s lxc.aa_profile=p2; lxc-attach -n u1"
does attach you to the p2 profile)

Apparmor policies require mount restrictions to fullfill many of
their promises - for instance if proc can be mounted anywhere,
then 'deny /proc/sysrq-trigger w' prevents only accidents, not
malice.

The mount restrictions are not available in the upstream kernel.
We can detect their presence through /sys.  In the past, when
we detected it missing, we would not enable apparmor.  But that
prevents apparmor from helping to prevent accidents.

At the same time, if the user accidentaly boots a kernel which
has regressed, we do not want them starting the container thinking
they are more protected than they are.

This patch:

1. adds a lxc.aa_allow_incomplete = 1 container config flag.  If
not set, then any container which is not set to run unconfined
will refuse to run.   If set, then the container will run with
apparmor protection.

2. to pass this flag to the apparmor driver, we pass the container
configuration (lxc_conf) to the lsm_label_set hook.

3. add a testcase.  To test the case were a kernel does not
provide mount restrictions, we mount an empty directory over
the /sys/kernel/security/apparmor/features/mount directory.  In
order to have that not be unmounted in a new namespace, we must
test using unprivileged containers (who cannot remove bind mounts
which hide existing mount contents).

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/attach.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/lsm/apparmor.c
src/lxc/lsm/lsm.c
src/lxc/lsm/lsm.h
src/lxc/lsm/nop.c
src/lxc/lsm/selinux.c
src/lxc/start.c
src/tests/Makefile.am
src/tests/lxc-test-apparmor-mount [new file with mode: 0755]