Date: Sun, 27 Sep 2020 14:42:32 -0500 From: Kyle Evans <kevans@freebsd.org> Cc: Warner Losh <imp@bsdimp.com>, Yuri <yuri@rawbw.com>, Freebsd hackers list <freebsd-hackers@freebsd.org> Subject: Re: Is it possible to exit the chroot(2) environment? Message-ID: <CACNAnaF-psLeTzwk=HygP4ESEynRyR-m62T1FAjw=ON6J2PVTg@mail.gmail.com> In-Reply-To: <CACNAnaFVg2yZnWbfC=MmPfQ==XZYssHFuz%2BCjz%2B67TkZ108qRA@mail.gmail.com> References: <b6412618-02ec-1dbd-f474-b4412d7b774b@rawbw.com> <CANCZdfqJ14-Cpvi9%2Bd%2BHRgWbHk7vDUNNOKLUVOC9iBUqZKX=Pw@mail.gmail.com> <CACNAnaFVg2yZnWbfC=MmPfQ==XZYssHFuz%2BCjz%2B67TkZ108qRA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Sep 27, 2020 at 2:07 PM Kyle Evans <kevans@freebsd.org> wrote: > > On Sun, Sep 27, 2020 at 2:03 PM Warner Losh <imp@bsdimp.com> wrote: > > > > On Sun, Sep 27, 2020 at 12:30 PM Yuri <yuri@rawbw.com> wrote: > > > > > This line > > > > > > https://github.com/rpm-software-management/rpm/blob/master/lib/rpmchroot.c#L155 > > > calls chroot(".") in order to exit from the chroot environment. > > > > > > > Interesting. FreeBSD doesn't allow that. > > > > > > > It apparently succeeds on Linux (this is rpm), but it fails on FreeBSD > > > with "Operation not permitted", while executed under sudo. > > > > > > The chroot(2) man page doesn't mention anything about exiting the chroot > > > environment. > > > > > > > True. Such behavior is undefined. There's no defined notion of exiting a > > chroot. It doesn't seem to be documented in the few examples of the > > chroot(2) call linux man pages I've found. Do you have documentation on > > what, exactly, it's supposed to do? > > > > I'm almost certain they just aren't restricting you from chrooting to > a directory out of the chroot if you have a reference to it, so it > probably does something like: > > chdir("/"); > chroot("/some/root"); > /* Do stuff, but never chdir */ > chroot("."); /* Working directory is still the real root. */ > I think the original report needs a ktrace to narrow down what's really going on... kevans@shiva:~/grep$ cat chr.c #include <unistd.h> #include <stdio.h> int main(int argc, char *argv[]) { printf("chdir %d\n", chdir("/")); printf("chroot %d\n", chroot("/tmp")); printf("chroot %d\n", chroot(".")); return (0); } kevans@shiva:~/grep$ sudo ./a.out chdir 0 chroot 0 chroot 0 Sprinkling some stat() calls in between reveals that chroot(2) is working in both cases and properly entering/exiting the chroot.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACNAnaF-psLeTzwk=HygP4ESEynRyR-m62T1FAjw=ON6J2PVTg>