can I use chroot() multiple times in one program

Ángel González keisial@gmail.com
Tue Jan 12 16:05:00 GMT 2010


Wu Zhou wrote:
> Hello all,
>
> I have a question about the usage of chroot(). Could I do something like this:
>
>   chroot("/chroot");
>   do_something();
>
>   chroot("/"); // want the root directory back to "/"
>   do_something();
>   
Now your chroot is the old /chroot. Thus you are chrooting to where you
were.
You may be able to escape the chroot by keeping a file descriptor to the
original chroot
See http://www.bpfh.net/simes/computing/chroot-break.html

Note that you are not guaranteed to be able to escape a chroot()

>   chroot("/chroot");
>   do_something();
>
> I had a try, after the second chroot("/"), I use system() to call a
> python script in the original root directoy, it reports that
>
> sh: /tmp/python-script: not found
>   
Instead of trying to break the chroot, you should move the python script
into the chroot (you'll
need to also move the interpreter and its libs).



More information about the Libc-help mailing list