lkml.org 
[lkml]   [2008]   [Mar]   [5]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: CLONE_NEWNS and bind mounts to make "chroot" jail
DateTue, 4 Mar 2008 22:23:28 -0800
From"Leibowitz, Michael" <>
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>
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2008-03-05 07:29    [from the cache]
©2003-2008