Merge lp://qastaging/~chipaca/snap-confine/unshare into lp://qastaging/~snappy-dev/snap-confine/trunk

Proposed by John Lenton
Status: Merged
Merged at revision: 63
Proposed branch: lp://qastaging/~chipaca/snap-confine/unshare
Merge into: lp://qastaging/~snappy-dev/snap-confine/trunk
Diff against target: 173 lines (+68/-10)
5 files modified
debian/usr.bin.ubuntu-core-launcher (+7/-0)
src/Makefile (+1/-1)
src/main.c (+38/-1)
src/utils.c (+13/-7)
src/utils.h (+9/-1)
To merge this branch: bzr merge lp://qastaging/~chipaca/snap-confine/unshare
Reviewer Review Type Date Requested Status
Tyler Hicks (community) Approve
Michael Vogt (community) Approve
Jamie Strandboge Pending
Review via email: mp+258367@code.qastaging.launchpad.net

Commit message

Set up a private mount namespace for /tmp.

Description of the change

Missing here:
 * tests. Not sure if we can test this; you need CAP_SYS_ADMIN to call unshare().
 * apparmor or seccomp or something is blocking this. Need jdstrand's eyes.

To post a comment you must log in.
64. By John Lenton

move setup_private_mount to the right place

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

one small comment

Revision history for this message
John Lenton (chipaca) :
65. By John Lenton

made a comment about kernel and libc versions

66. By John Lenton

"are require" indeed

67. By John Lenton

aslo commented on MS_ vars

Revision history for this message
John Lenton (chipaca) wrote :

One thing this branch does, without mentioning it (until now), is that if something fails you now get to see the error string and not just the error code.

You're welcome.

68. By John Lenton

fixes to apparmor profile as per jdstrand

Revision history for this message
John Lenton (chipaca) wrote :

The DENIEDs you get without the changes suggested by jdstrand are:

without the first (rw, private) one:

audit: type=1400 audit(1431102661.774:53): apparmor="DENIED" operation="mount" info="failed mntpnt match" error=-13 profile="/usr/bin/ubuntu-core-launcher" name="/tmp/" pid=1928 comm="ubuntu-core-lau" flags="rw, private"

without the second (rw, bind) one:

audit: type=1400 audit(1431103430.829:55): apparmor="DENIED" operation="mount" info="failed flags match" error=-13 profile="/usr/bin/ubuntu-core-launcher" name="/tmp/" pid=1942 comm="ubuntu-core-lau" srcname="/tmp/snaps.1000/hello-world.canonical/1.0.15/tmp/" flags="rw, bind"

Revision history for this message
Michael Vogt (mvo) wrote :

Yay, nice! Code looks good!

review: Approve
Revision history for this message
Tyler Hicks (tyhicks) wrote :

I have an (inline) question about the use of stat(2).

review: Needs Information
Revision history for this message
Tyler Hicks (tyhicks) wrote :

The changes in this MP can be used by an unprivileged user to grant access to files/directories that are not intended to be reachable by that user.

For example, assume that mode on /root is set to 700, meaning that an unprivileged user cannot enter the /root directory. If a user running ubuntu-core-launcher sets SNAP_APP_TMPDIR to /root/foo, ubuntu-core-launcher will fail if /root/foo does not exist. However, it will succeed when /root/foo does exist.

Also, if /root/foo/bar was (lazily) set to be world-readable, then it could opened for reading at /tmp/bar.

review: Needs Fixing
Revision history for this message
John Lenton (chipaca) wrote :

Good catch. I'll change it so that the launcher deduces the tmpdir from the app name.

69. By John Lenton

fixed issues found in review (and then some).

Revision history for this message
John Lenton (chipaca) wrote :

Just pushed a thing that deduces the tmpdir from appname+version and creates it.

This means we need to change the wrapper scripts, but also that the wrapper script can do less.

In a future branch, we should change the wrapper scripts one (last?) more time, to pass all the information in explicitly and have the launcher create the right environ from scratch.

Also, we should probably make the tests work again.

Revision history for this message
Tyler Hicks (tyhicks) wrote :

I didn't get to finish my review before my EOD but I have found an issue where an unprivileged user can still traverse paths that they shouldn't have access to and, at least, have arbitrary directories created:

tyhicks$ mkdir /tmp/snaps.1000
tyhicks$ ln -s /root /tmp/snaps.1000/cat
tyhicks$ sudo ls /root
tyhicks$ ./ubuntu-core-launcher cat BAD apparmor /apps/cat/cat
unable to make /tmp/ private. errmsg: Invalid argument
tyhicks$ sudo ls /root
BAD

I'll look some more tomorrow.

review: Needs Fixing
Revision history for this message
Tyler Hicks (tyhicks) wrote :

Note that the above issue is due to two things:

1) Predictable directory names used in /tmp
2) Continuing if mkdir(2) returns an error with errno set to EEXIST

This allows attackers to create symlinks in /tmp that the launcher follows.

70. By John Lenton

moved back to not requiring the version; use mkdtemp to create the tempdir

71. By John Lenton

drop now spurious includes

Revision history for this message
Tyler Hicks (tyhicks) wrote :

Hi John - This code is looking much more simple now. Thanks for all of the changes.

I have two small changes that need to be made (mentioned inline) and one remaining question.

How are all of the /tmp/snap.UID_appname_XXXXXX directories supposed to be cleaned up after the snap exits?

review: Needs Fixing
Revision history for this message
Tyler Hicks (tyhicks) wrote :

Here are the changes need to make the apparmor profile work (requires the two inline changes that I mentioned):

=== modified file 'debian/usr.bin.ubuntu-core-launcher'
--- debian/usr.bin.ubuntu-core-launcher 2015-05-08 16:50:56 +0000
+++ debian/usr.bin.ubuntu-core-launcher 2015-05-20 20:12:09 +0000
@@ -50,7 +50,10 @@
     # read apparmor to figure out if we need cgroups
     /var/lib/apparmor/clicks/* r,

- # make /tmp/ private, and bind-mount a private /tmp
+ # set up snap-specific private /tmp dir
+ capability chown,
+ /tmp/ w,
+ /tmp/snap.*/ w,
     mount options=(rw private) -> /tmp/,
- mount options=(rw bind) /tmp/snaps.[0-9]*/**/tmp/ -> /tmp/,
+ mount options=(rw bind) /tmp/snap.*/ -> /tmp/,
 }

72. By John Lenton

address issues raised by tyhicks in review

Revision history for this message
John Lenton (chipaca) wrote :

Thank you for the review!
Fixed the missing /tmp/ (d'oh), moved the chown (good idea! added a comment so we remember why), done the changes to the apparmor profile.

I suspect the cleanest way to go about clenaing up /tmp/ is to have something like tmpreaper, but we haven't really discussed it yet.

Revision history for this message
Tyler Hicks (tyhicks) wrote :

This looks good to me. As you mentioned, there is the outstanding issue of /tmp/snap.* directories being left behind. This could result in a denial of service if mkdtemp() can no longer create a unique directory but I'm not too worried about that in terms of security. It is more of a usability issue, IMO. This gets my ack.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches