This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: can I use chroot() multiple times in one program
- From: "Ãngel GonzÃlez" <keisial at gmail dot com>
- To: Wu Zhou <woodzltc at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Tue, 12 Jan 2010 17:05:41 +0100
- Subject: Re: can I use chroot() multiple times in one program
- References: <4e8ba5bf1001120751s4cb74875iaed58ca731c97f3@mail.gmail.com>
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).