From owner-freebsd-hackers@freebsd.org Sun Sep 27 19:07:45 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8A6C4424DA3 for ; Sun, 27 Sep 2020 19:07:45 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BzwC536N5z46qZ for ; Sun, 27 Sep 2020 19:07:45 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 4300013E6A for ; Sun, 27 Sep 2020 19:07:45 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-qk1-f170.google.com with SMTP id o5so8118738qke.12 for ; Sun, 27 Sep 2020 12:07:45 -0700 (PDT) X-Gm-Message-State: AOAM532ETZOAXt8YRUfQAur61Z0kQqbOAHbwTBKmtJJZbxoVNA7vO7xF AjhST7TX+Ksj8u+IKYzfhMzdac8efVTMB8hAq4w= X-Google-Smtp-Source: ABdhPJzd9aFbZAIjqIg5bsih9DgX9OnqCogpxs9r+wzNn62jKd1icBC9Gv5AclMpxtnNMpYIx7LTtt7CT0siQ58rp5I= X-Received: by 2002:a05:620a:ce3:: with SMTP id c3mr9170513qkj.103.1601233664818; Sun, 27 Sep 2020 12:07:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kyle Evans Date: Sun, 27 Sep 2020 14:07:33 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Is it possible to exit the chroot(2) environment? To: Warner Losh Cc: Yuri , Freebsd hackers list Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Sep 2020 19:07:45 -0000 On Sun, Sep 27, 2020 at 2:03 PM Warner Losh wrote: > > On Sun, Sep 27, 2020 at 12:30 PM Yuri 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. */ Thanks, Kyle Evans