Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 496040 - sys-kernel/hardened-sources is missing apparmor patches for mediate mounts
Summary: sys-kernel/hardened-sources is missing apparmor patches for mediate mounts
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: The Gentoo Linux Hardened Team
URL: https://git.kernel.org/cgit/linux/ker...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-26 01:59 UTC by Marco Schinkel
Modified: 2014-10-25 14:44 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
apparmor: mount and network mediation patch for 3.11.7-r1 (apparmor-mount-and-network-mediation-3.11.7.patch,45.52 KB, patch)
2014-02-25 19:43 UTC, Artem Sidorenko
Details | Diff
apparmor: mount and network mediation patch for 3.12.8-r1 and 3.13.2-r1 (apparmor-mount-and-network-mediation-3.12.8.patch,46.03 KB, patch)
2014-02-25 19:44 UTC, Artem Sidorenko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Schinkel 2013-12-26 01:59:26 UTC
The patches are needed to secure lxc.

See https://wiki.ubuntu.com/LxcSecurity 

(a guest can remount the host's devpts. Simply doing 'mount -t devpts devpts /dev/pts' will overlay its private (newinstance) )

Reproducible: Always

Steps to Reproduce:
1. emerge hardened-sources, use lxc and apparmor
2. try mounting devpts in container
3. works
Actual Results:  
Mounting devpts in an LCX container succeeds.

Expected Results:  
It should not be possible to mount devpts _IN_ a LXC container!

The patches in the upstream apparmor kernel repo used by Ubuntu should be included in hardened-sources.
Comment 1 Michael Palimaka (kensington) gentoo-dev 2013-12-28 14:58:14 UTC
Which kernel are you using currently?
Comment 2 Anthony Basile gentoo-dev 2013-12-28 15:03:22 UTC
(In reply to Michael Palimaka (kensington) from comment #1)
> Which kernel are you using currently?

@kensington: if we need to include patches in the hardened-sources patchset for apparmor, please pass them on to me.  But my understanding is that we didn't need any extra patches and that its all upstream.
Comment 3 Michael Palimaka (kensington) gentoo-dev 2013-12-28 16:05:56 UTC
(In reply to Anthony Basile from comment #2)
> But my understanding is that we
> didn't need any extra patches and that its all upstream.

It is. The patch in $URL appears to add additional features to support mediating of mount operations, and there is an additional patch for network mediation.

In the past I avoided trying to have patches included in hardened-sources due to maintenance issues stemming from continual rebasing...but I have no idea if that is still the case.
Comment 4 Marco Schinkel 2013-12-31 14:26:20 UTC
I am now using a patched hardened 3.12.6 kernel. And it seems to work. The patches are (at least the mount patches) are absolutely needed to create secure LXC containers. Without the patches, everybody can mount the host devpts into the container and access root PTYs in the host, which is obviously a problem. Thats probably why those patches are already included even in ubuntu kernels. 

The network patches are of course very useful too.
Comment 5 Artem Sidorenko 2014-02-25 19:43:04 UTC
Created attachment 371250 [details, diff]
apparmor: mount and network mediation patch for 3.11.7-r1
Comment 6 Artem Sidorenko 2014-02-25 19:44:10 UTC
Created attachment 371252 [details, diff]
apparmor: mount and network mediation patch for 3.12.8-r1 and 3.13.2-r1
Comment 7 Artem Sidorenko 2014-02-25 19:57:43 UTC
The both attached patches contain the commits from https://git.kernel.org/cgit/linux/kernel/git/jj/linux-apparmor.git/log/?h=v3.11-aa2.8 and https://git.kernel.org/cgit/linux/kernel/git/jj/linux-apparmor.git/log/?h=v3.12-aa2.8 and implement the mount and network mediation. Here submitted patches contain one change for the lsm.c file comparing to the origin, otherwise they couldn't be applied.

I've tested the patches on 3.11.7-r1, 3.12.8-r1 and 3.13.2-r1, I got it applied and the kernel built

The network mediation patches solve the issue with apparmor profiles from portage tree (s. example with warnings http://forums.gentoo.org/viewtopic-t-980588-start-0.html)

This patches are not taken yet by kernel upstream, but they are implemented within kernels shipped by ubuntu and suse. 
I suggest to take them to gentoo on the same way till they are merged upstream, apparmor functionality within gentoo is limited without this patches.
Comment 8 Michael Palimaka (kensington) gentoo-dev 2014-03-14 01:37:03 UTC
@blueness, if you want to include them, I can assist with collecting the latest not-yet-upstreamed apparmor kernel patches. The caveat is I don't actually use them so I can't personally vouch for them, but they seem to be used fine by a number of downstreams.
Comment 9 Anthony Basile gentoo-dev 2014-03-14 12:05:27 UTC
(In reply to Michael Palimaka (kensington) from comment #8)
> @blueness, if you want to include them, I can assist with collecting the
> latest not-yet-upstreamed apparmor kernel patches. The caveat is I don't
> actually use them so I can't personally vouch for them, but they seem to be
> used fine by a number of downstreams.

I don't think this is a good idea.
Comment 10 Dainius Masiliūnas 2014-10-24 17:02:08 UTC
So what gives? As noted by Artem in comment #7, without the patches even the default AppArmor profiles (provided by sec-policy/apparmor-profiles) fail to get enforced due to missing network support. That greatly reduces the usability of AppArmor in general.
Comment 11 Artem Sidorenko 2014-10-24 17:25:39 UTC
@Dainius as I've nothing to add to points, and as I can understand the reasons of Anthony (still if they weren't explained) I maintain this patches by myself in my overlay[1] and try to follow the hardenedsources in portage, so far no problems.

[1] https://github.com/artem-sidorenko/portage-2realities
Comment 12 Dainius Masiliūnas 2014-10-24 18:39:35 UTC
Well, for what it's worth, I applied the patch attached to this bug manually, it did apply correctly, but the kernel wouldn't compile citing that in the aa_umount function "struct path path = { mnt, mnt->mnt_root };" is invalid. Splitting it to have "path.mnt = mnt", "path.dentry = mnt->mnt_root" makes it compile again.

In your repository I see the same code, so it might also have the same problem, although I haven't tested it (yet). Thanks for maintaining the patches, though.
Comment 13 Michael Palimaka (kensington) gentoo-dev 2014-10-25 14:44:00 UTC
(In reply to Dainius Masiliūnas from comment #10)
> So what gives? As noted by Artem in comment #7, without the patches even the
> default AppArmor profiles (provided by sec-policy/apparmor-profiles) fail to
> get enforced due to missing network support. That greatly reduces the
> usability of AppArmor in general.

AppArmor support in Gentoo is pretty much limited to what upstream provides due to manpower/interest. The hardened team isn't able to take care of yet another MAC and although I'm the primary AppArmor maintainer, my interest is more academic so I can't vouch for and maintain a patch set for hardened-sources.