LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Leibowitz, Michael" <michael.leibowitz@intel.com>
To: <serge@hallyn.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: CLONE_NEWNS and bind mounts to make "chroot" jail
Date: Tue, 4 Mar 2008 22:23:28 -0800	[thread overview]
Message-ID: <1204698208.30451.5.camel@mleibowi.jf.intel.com> (raw)
In-Reply-To: <20080304214500.GA7035@vino.hallyn.com>

[-- Attachment #1: Type: text/plain, Size: 1208 bytes --]

I'm not 100% sure if this is what you meant, but I did get the following
to work: 

chdir("/jail"); 
unshare(CLONE_NEWNS);
mount("/jail", "/jail", NULL, MS_BIND, NULL);
pivot_root("/jail", "/jail/old_root");
chdir("/");
mount("/old_root/bin", "bin", NULL, MS_BIND, NULL);
mount("/old_root/usr", "usr", NULL, MS_BIND, NULL);
mount("/old_root/lib", "lib", NULL, MS_BIND, NULL);
umount2("/old_root", MNT_DETACH);
exec("/busybox");

Thanks for the help.  

On Tue, 2008-03-04 at 15:45 -0600, serge@hallyn.com wrote:
> Quoting Leibowitz, Michael (michael.leibowitz@intel.com):
> Yes, you
> 	cd /jail
> 	mount --bind /jail /jail
> 	pivot_root . old_root
> 
> but . is now mounted over.
> >   char *newargv[]= { "sh", NULL };
> > 
> >   chdir("/jail");
> >   unshare(CLONE_NEWNS));
> >   mount("/jail", "/jail", NULL, MS_BIND, NULL));
> >   mount("/bin", "bin", NULL, MS_BIND, NULL));
> >   mount("/usr", "usr", NULL, MS_BIND, NULL));
> >   mount("/lib", "lib", NULL, MS_BIND, NULL));
> >   if (pivot_root(".", "old_root")) perror("pivot_root . old_root");
> >   exec("./bash-static"); /* copied to /jail prior to running */

-- 
Michael Leibowitz <michael.leibowitz@intel.com>

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2008-03-05  6:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-01 17:05 Leibowitz, Michael
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 [this message]
     [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=1204698208.30451.5.camel@mleibowi.jf.intel.com \
    --to=michael.leibowitz@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serge@hallyn.com \
    --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).