This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: can I use chroot() multiple times in one program


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]