Is it possible to exit the chroot(2) environment?

Warner Losh imp at bsdimp.com
Sun Sep 27 19:03:08 UTC 2020


On Sun, Sep 27, 2020 at 12:30 PM Yuri <yuri at 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?

Does chroot(2) behave differently on Linux and FreeBSD, and chroot(".")
> is a valid way to exit on Linux and not on FreeBSD? Or what is going on
> here?
>

Generally, one is not supposed to exit a chroot. :) Though jail(2) exists
because it's trivially possible in most cases.

I wish somebody familiar with chroot add this information into the
> chroot(2) man page.
>

POSIX never defined the behavior (and it's been removed in newer versions
of POSIX).

Warner


More information about the freebsd-hackers mailing list