All of lore.kernel.org
 help / color / mirror / Atom feed
* How do I make a clean mount namespace?
@ 2014-04-22 22:12 Andy Lutomirski
  2014-04-23 20:01 ` Richard Weinberger
  2014-04-24  2:39 ` Al Viro
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Lutomirski @ 2014-04-22 22:12 UTC (permalink / raw)
  To: linux-kernel, Linux FS Devel

I want to set up a little container.  So I unshare the mount namespace
and mount something somewhere (say /mnt) that I want to be my new
root.  Now what?

pivot_root("/mnt", "/mnt/garbage") seems to frequently return -EBUSY.

mounting /mnt onto / using MS_MOVE seems to succeed, but / still
points at the old root.

Am I missing a clean way to do this?  I want a way to say "make this
mountpoint be the root of the whole mount namespace and lazy-unmount
everything outside it".  If there is no straightforward way to do
that, can we add one?

--Andy

-- 
Andy Lutomirski
AMA Capital Management, LLC

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do I make a clean mount namespace?
  2014-04-22 22:12 How do I make a clean mount namespace? Andy Lutomirski
@ 2014-04-23 20:01 ` Richard Weinberger
  2014-04-24  0:54   ` Andy Lutomirski
  2014-04-24  2:39 ` Al Viro
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2014-04-23 20:01 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: linux-kernel, Linux FS Devel

On Wed, Apr 23, 2014 at 12:12 AM, Andy Lutomirski <luto@amacapital.net> wrote:
> I want to set up a little container.  So I unshare the mount namespace
> and mount something somewhere (say /mnt) that I want to be my new
> root.  Now what?
>
> pivot_root("/mnt", "/mnt/garbage") seems to frequently return -EBUSY.
>
> mounting /mnt onto / using MS_MOVE seems to succeed, but / still
> points at the old root.
>
> Am I missing a clean way to do this?  I want a way to say "make this
> mountpoint be the root of the whole mount namespace and lazy-unmount
> everything outside it".  If there is no straightforward way to do
> that, can we add one?

I fear you have to read /proc/mounts and umount() everything in the
correct order.
If you find a better way, please tell. :-)

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do I make a clean mount namespace?
  2014-04-23 20:01 ` Richard Weinberger
@ 2014-04-24  0:54   ` Andy Lutomirski
  2014-04-24  2:24     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Lutomirski @ 2014-04-24  0:54 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: linux-kernel, Linux FS Devel

On Wed, Apr 23, 2014 at 1:01 PM, Richard Weinberger
<richard.weinberger@gmail.com> wrote:
> On Wed, Apr 23, 2014 at 12:12 AM, Andy Lutomirski <luto@amacapital.net> wrote:
>> I want to set up a little container.  So I unshare the mount namespace
>> and mount something somewhere (say /mnt) that I want to be my new
>> root.  Now what?
>>
>> pivot_root("/mnt", "/mnt/garbage") seems to frequently return -EBUSY.
>>
>> mounting /mnt onto / using MS_MOVE seems to succeed, but / still
>> points at the old root.
>>
>> Am I missing a clean way to do this?  I want a way to say "make this
>> mountpoint be the root of the whole mount namespace and lazy-unmount
>> everything outside it".  If there is no straightforward way to do
>> that, can we add one?
>
> I fear you have to read /proc/mounts and umount() everything in the
> correct order.
> If you find a better way, please tell. :-)
>

How about adding a new syscall:

int change_root_mount(const char *path, unsigned long flags);

This requires CAP_SYS_ADMIN and it requires that the caller is not
chrooted.  path must be a mountpoint and flags must be zero.

It lazy-unmounts everything outside path, and it moves path to /.
When it's done, the current process's root is '/'.  If you want to
retain temporary access to outside things, you can keep an fd open.
If the old root is shared, it is made private.  It's okay for path to
be shared (I think).

If other things are already running in the current mount namespace,
then their root directory stays the same, so they keep working, but
they may be a little confused.

I think this could replace pivot_root for most use cases, and it could
simplify programs like switch_root.

Thoughts?

--Andy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do I make a clean mount namespace?
  2014-04-24  0:54   ` Andy Lutomirski
@ 2014-04-24  2:24     ` Al Viro
  0 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2014-04-24  2:24 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: Richard Weinberger, linux-kernel, Linux FS Devel

On Wed, Apr 23, 2014 at 05:54:31PM -0700, Andy Lutomirski wrote:

> This requires CAP_SYS_ADMIN and it requires that the caller is not
> chrooted.  path must be a mountpoint and flags must be zero.
> 
> It lazy-unmounts everything outside path, and it moves path to /.
> When it's done, the current process's root is '/'.  If you want to
> retain temporary access to outside things, you can keep an fd open.
> If the old root is shared, it is made private.  It's okay for path to
> be shared (I think).
> 
> If other things are already running in the current mount namespace,
> then their root directory stays the same, so they keep working, but
> they may be a little confused.
> 
> I think this could replace pivot_root for most use cases, and it could
> simplify programs like switch_root.
> 
> Thoughts?

chdir(new);
pivot_root(".", old);
umount(old, MNT_DETACH);
chroot(".");

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do I make a clean mount namespace?
  2014-04-22 22:12 How do I make a clean mount namespace? Andy Lutomirski
  2014-04-23 20:01 ` Richard Weinberger
@ 2014-04-24  2:39 ` Al Viro
  2014-04-24  5:06   ` Andy Lutomirski
  1 sibling, 1 reply; 6+ messages in thread
From: Al Viro @ 2014-04-24  2:39 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: linux-kernel, Linux FS Devel

On Tue, Apr 22, 2014 at 03:12:11PM -0700, Andy Lutomirski wrote:
> I want to set up a little container.  So I unshare the mount namespace
> and mount something somewhere (say /mnt) that I want to be my new
> root.  Now what?
> 
> pivot_root("/mnt", "/mnt/garbage") seems to frequently return -EBUSY.

RTFM.  Literally - man 2 pivot_root and look for the only place where
it mentions EBUSY.

If you get that error, check what you've got in /proc/mounts (in the
namespace your process is in, obviously) just before the syscall.
With these arguments you really want /mnt to be a mountpoint.  If your
new root really lives on the same fs as the old one, just do
mount --bind /mnt /mnt before any other mounts.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do I make a clean mount namespace?
  2014-04-24  2:39 ` Al Viro
@ 2014-04-24  5:06   ` Andy Lutomirski
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Lutomirski @ 2014-04-24  5:06 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-kernel, Linux FS Devel

On Wed, Apr 23, 2014 at 7:39 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Tue, Apr 22, 2014 at 03:12:11PM -0700, Andy Lutomirski wrote:
>> I want to set up a little container.  So I unshare the mount namespace
>> and mount something somewhere (say /mnt) that I want to be my new
>> root.  Now what?
>>
>> pivot_root("/mnt", "/mnt/garbage") seems to frequently return -EBUSY.
>
> RTFM.  Literally - man 2 pivot_root and look for the only place where
> it mentions EBUSY.
>
> If you get that error, check what you've got in /proc/mounts (in the
> namespace your process is in, obviously) just before the syscall.
> With these arguments you really want /mnt to be a mountpoint.  If your
> new root really lives on the same fs as the old one, just do
> mount --bind /mnt /mnt before any other mounts.

Wow -- thanks!  I read that part, but I'm apparently bad at following
directions.

Should I expect things to work if I unshare mounts but don't do a
mount --make-rprivate / before the pivot_rot?

--Andy

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-24  5:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-22 22:12 How do I make a clean mount namespace? Andy Lutomirski
2014-04-23 20:01 ` Richard Weinberger
2014-04-24  0:54   ` Andy Lutomirski
2014-04-24  2:24     ` Al Viro
2014-04-24  2:39 ` Al Viro
2014-04-24  5:06   ` Andy Lutomirski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.