From owner-freebsd-hackers@freebsd.org Sun Sep 27 19:06:28 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 92A83424A47 for ; Sun, 27 Sep 2020 19:06:28 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bzw9b4QKHz46XH for ; Sun, 27 Sep 2020 19:06:27 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qk1-x732.google.com with SMTP id w16so8169534qkj.7 for ; Sun, 27 Sep 2020 12:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b92q8Bztoen0P9eGRbfitOhnmzEvdm6yuKgWNEn427c=; b=hrjDP2JGltIs1YNjLoYPfj8aX/NIDLvixbV6W8Jlt7ZKrMuDUrebpZHBrRMBShX7aV mVmOT+Hv7bhS7nHZm/elgyAXxNxIQnXj9brDq2PkYujrxB24+fRJ3dRH9jXwB3RU9B85 bxgOYN7hBVenpn9ddLBlOvnNscqxNnhL3wBXw/h9i7Y6Noy3+VfAOX7xwcTxjbpXye2b 2Jx0vaKKI82IjaN7RxwBHvBIDUIT/aYK9+JnHNPSoZoL/qy7ofS0mhKXgeMFXxb78px1 Jw0apeY27AgEAGGgVxPsqQ2efzkzx1n8i5TsZ1T2FQvLLLpsbRKJyndD5HUu9Too8R8E a8Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b92q8Bztoen0P9eGRbfitOhnmzEvdm6yuKgWNEn427c=; b=QhfOvwiFgqqB22hjB3XSmaE3/W81uTCG3JG9s7eG1iPCkYSzxiaBAYSxdYXHUDiFL/ y5CNzb2x8a5XJzoCePoLw2vxGkDtPLlmadNw0bbgyBU2XqgmM4UErt5WI5C91AYqJ5aM 7cIZjzWGkdvQVOCV64eWkvEpovhAYd9EXOp5tFWYz6QO58dDxcdtg6mv1A4rbFbHlTUt lYhOM4JGnDQCNQpyfHLiSmrXLrZlwhD6c5iLPstBG28QK/U5o80vJW6Pf2u6tpOG+GUK p5VBM0QwT/q8NQn+Ar1t0B48hRQ5RPi5+dvm8dWa4mr0o9cCGGf6nebLwDxIyblNfTx4 3wFA== X-Gm-Message-State: AOAM533ZaY940wQ7mhcG+/96F05aA3l39b5McBG62tWfHy3z7TbDA5lT /6MdQlBYEUFn4efpM08X+m7/3y8Af5tSGzBNp1pQfcr5fIYvI1TI X-Google-Smtp-Source: ABdhPJzkOnuRIvYE0TJlYSwqecPx+p7n6v5hW4Ve7LSzqyZE5jpKbYgGZei0uZZHr52yPnCvqPYQTvVFHLVkUwipAN8= X-Received: by 2002:ae9:ee06:: with SMTP id i6mr8988456qkg.380.1601233586072; Sun, 27 Sep 2020 12:06:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Sun, 27 Sep 2020 13:06:15 -0600 Message-ID: Subject: Re: Is it possible to exit the chroot(2) environment? To: Yuri Cc: Freebsd hackers list X-Rspamd-Queue-Id: 4Bzw9b4QKHz46XH X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20150623.gappssmtp.com header.s=20150623 header.b=hrjDP2JG; dmarc=none; spf=none (mx1.freebsd.org: domain of wlosh@bsdimp.com has no SPF policy when checking 2607:f8b0:4864:20::732) smtp.mailfrom=wlosh@bsdimp.com X-Spamd-Result: default: False [-0.70 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com:s=20150623]; NEURAL_HAM_MEDIUM(-0.99)[-0.991]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(0.27)[0.267]; NEURAL_HAM_LONG(-0.98)[-0.979]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::732:from]; R_SPF_NA(0.00)[no SPF record]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com]; MAILMAN_DEST(0.00)[freebsd-hackers]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 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:06:28 -0000 On Sun, Sep 27, 2020 at 1:02 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? > > 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). > Also, what happens when you set kern.chroot_allow_open_directories=2 ? Warner