LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Leibowitz, Michael" <michael.leibowitz@intel.com>
To: <linux-kernel@vger.kernel.org>
Subject: CLONE_NEWNS and bind mounts to make "chroot" jail
Date: Sat, 1 Mar 2008 09:05:18 -0800	[thread overview]
Message-ID: <645B0EE4078B7C49A6C12F5E7B3B6C2603D3D607@orsmsx418.amr.corp.intel.com> (raw)

I have been trying to use the combination of CLONE_NEWNS and bind mounts
to create a better (than) chroot jail.  I wish to have the ability to
bind (ro will be possible in the future, I understand) certain
directories into the jail (perhaps /bin, /lib, /usr), but not have
parallel directories in the jail (no /etc, ..., /home). 

I have heard that this should be possible, but have yet to get a working
solution.

I have tried something analogous to:
chdir("/jail");
unshare(CLONE_NEWNS);
/* mount(8) syntax given for simplicity, but mount(2) used below */
mount --bind / /jail/old_root
mount --bind /jail/old_root/bin /jail/bin
mount --bind /jail/old_root/usr /jail/usr
mount --bind /jail/old_root/lib /jail/lib
mount --bind /jail /               # does nothing?
umount2("/old_root", MNT_DETACH);  # never happens.
exec("bin/sh");

When bin/sh runs, I can still see old_root from /jail and the bind of
/jail over / seems to have not done anything.  

Is it possible to create such a jail with bind mounts?  Is there a
recommended method for doing so?  Thank you for your time.

--
Michael Leibowitz
Software Engineer, UMG
Intel Corporation
michael.leibowitz at intel.com



             reply	other threads:[~2008-03-01 17:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-01 17:05 Leibowitz, Michael [this message]
2008-03-02  2:26 ` serge
2008-03-03  6:56   ` Leibowitz, Michael
2008-03-04 21:45     ` serge
2008-03-05  6:23       ` Leibowitz, Michael
     [not found] <a2DnP-4KR-9@gated-at.bofh.it>
     [not found] ` <a2M7M-1rM-5@gated-at.bofh.it>
     [not found]   ` <a3cOQ-1eQ-3@gated-at.bofh.it>
2008-03-03 15:54     ` Bodo Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=645B0EE4078B7C49A6C12F5E7B3B6C2603D3D607@orsmsx418.amr.corp.intel.com \
    --to=michael.leibowitz@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: CLONE_NEWNS and bind mounts to make "chroot" jail' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).