Open alban opened 6 years ago
I wonder if the mount("", ".", ... MS_REC|MS_SLAVE after the pivot_root reverts the effect.
It shouldn't. In that context, .
is the oldroot not the new one. (Or at least it was when I wrote this comment.) But you're right that this line is quite suspect:
mount("", "/", 0xc4200f6ebc, MS_PRIVATE, NULL) = 0
Hmmm...
I can reproduce this failure, exactly as @alban described.
First of all, the slave mount after pivot_root
is already correct. It should remain there as @cyphar said. Without that part, mount propagation affects the host, and the host gets broken.
The main problem is that in prepareRoot()
the host rootfs is mounted with the given flag such as MS_SHARED
, and after that, the container rootfs is mounted with MS_PRIVATE
. As a result, the original flag is overridden. This is not an issue if the given flag is MS_PRIVATE
or MS_SLAVE
, but it is definitely an issue when MS_SHARED
is given.
Though a tricky thing is that we need to call rootfsParentMountPrivate()
to prevent pivot_root
from failing. So I came up with an approach of checking for mount flags before calling rootfsParentMountPrivate()
, and doing chroot()
instead of pivotRoot()
. I'll create a PR.
Tested with runc from git today (
git describe
=v1.0.0-rc5-17-g9facb87f
).How to test with
rootfsPropagation=shared
:How to test with
rootfsPropagation=private
:At a first glance, changing the flag
rootfsPropagation
appears to do the correct thing: the line 1 of the strace log usesMS_SHARED
orMS_PRIVATE
depending on therootfsPropagation
flag.However,
cat /proc/self/mountinfo
in the container shows that it does not work. I have to runmount --make-shared /
manually in the container to make it shared.The
mount
call for therootfsPropagation
is not done on the rootfs but on the oldrootfs, before the pivot_root. Since it is not recursive, it has not effect on the container rootfs. Then I tried--linux-rootfs-propagation=rshared
but it still does not work. I wonder if themount("", ".", ... MS_REC|MS_SLAVE
after thepivot_root
reverts the effect.