LKML Archive on
help / color / mirror / Atom feed
From: "Leibowitz, Michael" <>
To: <>
Cc: <>
Subject: RE: CLONE_NEWNS and bind mounts to make "chroot" jail
Date: Sun, 2 Mar 2008 22:56:40 -0800	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

If I understand correctly, the following should accomplish what I'm
looking for.  However, pivot_root gives me EBUSY.  I played around with
moving the mount --bind /jail /jail to before the unshared, as well as
making old_root a bind mount to itself.  However, pivot_root always
seems to fail.  Is there something obvious that I'm doing wrong?  The
following is my test code (error checking has been removed for clarity,
except for pivot_root).  

  char *newargv[]= { "sh", NULL };

  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 */


>Serge replies:
>Try a few more things.  Since you had entered /jail, you can view '/'
>looking at .. .  But if you look at /, you dereference your
>task->fsroot.  You never changed that, so it points to the original
>mount.  If however you 'ls ..', you should see your 'jail' directory.
>However it won't have the /bin and /lib mounted because you didn't
>	mount --rbind /jail /
>What you really want to do is
>	mount --bind /jail /jail
>to make sure it's a mountpoint, then set up the new /jail using bind
>mounts like you're doing (and likely some rbinds in some places), then
>use pivot_root() to change your root.  Then umount2("/old_root",

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

  reply	other threads:[~2008-03-03  6:58 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 [this message]
2008-03-04 21:45     ` serge
2008-03-05  6:23       ` Leibowitz, Michael
     [not found] <>
     [not found] ` <>
     [not found]   ` <>
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:

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

  git send-email \ \ \ \ \
    --subject='RE: CLONE_NEWNS and bind mounts to make "chroot" jail' \

* 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).