Skip to content

Conversation

@zyga
Copy link
Contributor

@zyga zyga commented Oct 12, 2018

This patch adds a workaround for apparmor and overlayfs not playing
together on the ephemeral Ubuntu 18.10 server images. On such images
there's an overlayfs mounted over / with the upper directory in
/media/root-rw/overlay. Snapd detects this and generates a directive
with read access to said directory. At runtime we get a denial, however,
one that looks like this:

[ 1588.858154] audit: type=1400 audit(1539338016.165:576):
apparmor="DENIED" operation="open" profile="/usr/lib/snapd/snap-confine"
name="/overlay/" pid=8735 comm="snap-confine"
profile="/usr/lib/snapd/snap-confine" requested_mask="r"
denied_mask="r" fsuid=0 ouid=0

As we can see apparmor decided to resolve the path to "/overlay/" (which
notably does not exist in the filesystem at all). The reason for that is
not understood but as a special-case workaround we detect this and
return "/overlay" instead.

Bug-Link: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1797218
Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

This patch adds a workaround for apparmor and overlayfs not playing
together on the ephemeral Ubuntu 18.10 server images. On such images
there's an overlayfs mounted over / with the upper directory in
/media/root-rw/overlay. Snapd detects this and generates a directive
with read access to said directory. At runtime we get a denial, however,
one that looks like this:

    [ 1588.858154] audit: type=1400 audit(1539338016.165:576):
    apparmor="DENIED" operation="open" profile="/usr/lib/snapd/snap-confine"
    name="/overlay/" pid=8735 comm="snap-confine"
    profile="/usr/lib/snapd/snap-confine" requested_mask="r"
    denied_mask="r" fsuid=0 ouid=0

As we can see apparmor decided to resolve the path to "/overlay/" (which
notably does not exist in the filesystem at all). The reason for that is
not understood but as a special-case workaround we detect this and
return "/overlay" instead.

Bug-Link: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1797218
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Copy link

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving but please adjust the comments. Feel free to add more precise details if desired.

}

if dir == "/media/root-rw/overlay" {
// Apparmor doesn't really support overlayfs correctly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this editorial comment.

// apparmor resolves the path the rules look for "/overlay"
// for some unknown reason. As a quick hack to unblock the
// Ubuntu 18.10 release, detect this condition and return
// the path that apparmor would detect.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this comment. Something like the following:

// On the Ubuntu server ephemeral image, '/' is setup via
// overlayroot (on at least 18.10), which uses a combination
// of overlayfs and chroot. This differs from the livecd setup
// so special case the detection logic to look for the known
// upperdir for this configuration, and return the required
// path. See LP: #1797218 for details.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
@smoser
Copy link

smoser commented Oct 12, 2018

For reference, here is /proc/mounts from an overlay root system:
http://paste.ubuntu.com/p/Tm5GfhG9rM/

The relevant mounts are below. I suspect that '/overlay' is from '/media/root-rw/overlay'.

/dev/sda1 /media/root-ro ext4 ro,relatime 0 0
tmpfs-root /media/root-rw tmpfs rw,relatime 0 0
overlayroot / overlay rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_ 0 0

The code that does that is overlayroot/scripts/init-bottom/overlayroot
those mounts are made and then 'mount --move' is done

Copy link

@smoser smoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bug is actually in the general reading of /proc/mounts, specifically here. It assumes that the source (fs_spec per fstab(5)) is a directory path ('/cow'). That isn't really guaranteed and is really just a happenstance of the live-cd setup.

The real fix I think would be to read upper-dir and traverse backwards through /proc/mounts to find what other mounts (specifically fs_file per fstab(5)) that upper is on.

}

if dir == "/media/root-rw/overlay" {
// On the Ubuntu server ephemeral image, '/' is setup via
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may help you to have a more specific comment here.

It's not "Ubuntu server" that does this.
Its 'overlayroot' (package) that sets things up this way.

overlayroot package is configured by kernel command line or /etc/overlayroot.conf or /etc/overlayroot.local.conf in all supported Ubuntu. The package is installed by default in Ubuntu Server but is available in Ubuntu since 12.04.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just note that the 'overlay' portion of '/media/root-rw/overlay' is configurable via overlayroot.conf or kernel command line. overlayroot=tmpfs:dir=/mydir . dir defaults to '/overlay'.

if dir == "/media/root-rw/overlay" {
// On the Ubuntu server ephemeral image, '/' is setup via
// overlayroot (on at least 18.10), which uses a combination
// of overlayfs and chroot. This differs from the livecd setup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no chroot us used. pivot is done into the rootfs from the initramfs, but that is the common path of initramfs.

}, {
mountinfo: "31 1 0:26 / / rw,relatime shared:1 - overlay overlay rw,lowerdir=//filesystem.squashfs,upperdir=/cow/bad\"upper,workdir=/cow/work",
}, {
// The special cased version for 18.10 server release
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference 'overlayroot' here rather than 'Ubuntu 18.10 server release'.

@raharper
Copy link
Contributor

Could you expand on why returning /overlay resolves the issue? I would have expected that it should return the complete upperdir path.

@mvo5 mvo5 added this to the 2.36 milestone Oct 12, 2018
@zyga
Copy link
Contributor Author

zyga commented Oct 12, 2018

@raharper because (probably due to pivot_root) this is what the apparmor denial specifies. For whatever reason apparmor chooses to use /overlay we just match that behaviour.

@zyga zyga requested a review from mvo5 October 12, 2018 16:10
@mvo5 mvo5 merged commit 32eab8a into canonical:master Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants