Don't expose /etc/alternatives from the host #50

Merged
merged 4 commits into from Jun 28, 2016

Conversation

Projects
None yet
3 participants
Collaborator

zyga commented Jun 24, 2016

No description provided.

Don't expose /etc/alternatives from the host
This patch works around an issue where the /etc/ directory during snap
runtime would contain the /etc/alternatives from the host OS and due to
different filesystem layout, the symlinks there would be broken.

Fixes: https://bugs.launchpad.net/snap-confine/+bug/1580018
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

mvo5 commented Jun 24, 2016

Looks good code-wise. But did you talk to ogra about the idea to have a custom update-alternatives in the image buidl that avoids this completely?

Collaborator

zyga commented Jun 24, 2016

I'll talk to ogre about a long term solution but this is here to fix snaps that are affected by this issue in the short term.

src/mount-support.c
@@ -215,6 +215,22 @@ void setup_snappy_os_mounts()
die("cannot bind mount %s to %s", src, dst);
}
}
+ // Don't expose /etc/alternatives from the host, ensure that
@jdstrand

jdstrand Jun 24, 2016

Contributor

To help reading the code, please say something like "Since we mounted /etc from the host above, we need to put /etc/alternatives from the os snap back..." (or similar). In other words, mention /etc is exposed but /etc/alternatives should be unexposed again.

As an aside: incidentally, this is precisely the problem with using bind mounts as a security mechanism-- they are far too coarse-grained and lead to "bind mount this huge list of things" or "bind mount this big directory and then bind mount this huge list of things to unexpose what's in the bid directory". I understand that what we are doing here has nothing to do with confinement, but I thought it worth mentioning that bind mounts like this lead to twisty implementations that are hard to follow.

src/mount-support.c
+ must_snprintf(dst, sizeof dst, "%s%s", rootfs_dir,
+ etc_alternatives);
+ debug("bind mounting %s to %s", src, dst);
+ if (mount(src, dst, NULL, MS_BIND | MS_SLAVE, NULL) != 0) {
@jdstrand

jdstrand Jun 24, 2016

Contributor

LGTM but please add a note about MS_SLAVE here like we do for the source_mounts mount() call above so it is clear.

zyga added some commits Jun 28, 2016

Update comments per code review
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

@zyga zyga merged commit 4e7d3ae into master Jun 28, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@zyga zyga deleted the fix-etc-alternatives branch Jun 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment