[lkml]   [2008]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: CLONE_NEWNS and bind mounts to make "chroot" jail
    Quoting Leibowitz, Michael (
    > 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:

    Try a few more things. Since you had entered /jail, you can view '/' by
    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",


    > 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
    > --
    > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    > the body of a message to
    > More majordomo info at
    > Please read the FAQ at

     \ /
      Last update: 2008-03-02 03:33    [W:0.050 / U:73.072 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site