From nobody Wed Sep 3 13:56:07 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cH3zq3GVsz66SKh; Wed, 03 Sep 2025 13:56:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cH3zq2PGMz3kWn; Wed, 03 Sep 2025 13:56:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756907767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=puwIlRK4rBZJl7pVMRYxUswX33/2Oq60RDHxSSAqAJU=; b=A4vDwhFtukD9k0V2YHGMlOFn6Yc3creNn3TMmgHZe+SxAEctb5GGjhl0clvdTurunq390h 9zu93bNQklGJwqMfHngPwTWhpgz7P3ka9gnmBTR9YikyXk+BH4zPZQR3+A2sHu4QRh54Oy KfNsjR0rUL/FEY8s7qryZNlbHpNwfeUtMULFNxEsePndWFKjsFi+x6IZskblIwe5dYq+Ft NVwt/FSf0IVyVU51JhEQFDIAAdHrJTVXg+uIYONkHNhpPjpEL1ZlTxPKBTzU3LooknHbY/ wpTv5mZigpaHn1rT+4MB4IyWnaq9JHKpGhdd7nOQEXttNJNDy8hHbu9mzVThAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756907767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=puwIlRK4rBZJl7pVMRYxUswX33/2Oq60RDHxSSAqAJU=; b=L+iWm51Aut4XxaIi+gK+sejJittJqlHZO91g2vkwe2t2a/F4axDfXx3X7QX5M7XZysR6n5 f43RJ4d0LbKt9z/q4IxRCKqYeRXGzlXTQ2cMXTky7FdMCnJBnJIMhXCef5XriLXNuTY/hI SzyEb6c/XIbGtLhx3bjN/4oDOCeF2+0lm27QJEVvrZG3potvaDg4cCst4hYbSCpHQ4gr8o fUp0ovdQt1ndSRurAoHfiRfP+b9GPtVL2Ak9U5LMJUxG/z+zT/3yyOExOnVibdHHqF7cyZ JoENEhrgoEh9Kyh9AdH2NvqnAndNLXGHq5wqr5nWtRLd9RD/D6aQawOndBNFLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756907767; a=rsa-sha256; cv=none; b=AENaS7bVMOCJ7ZX2GFZdmjXNO1m+34ztJ7iDPwoVA99PkXmWzEzGsf6nU4VKOTesW9OXh8 t412485ghqdhpyNRvelUbF5EM2igSNAx1DcpwP39Rd4VkKz+0ojjStHUb+oN5moIjsh1CY +CZnwaqyvsqumRRtYrAkvuN8/50eVcgRd0MdylKEOK0z20qt3sQ+ETmFs0+xjEGErFrPPN Luv5vZz6+msEZElpb/f+KV3hIYda13oYWpnB8AANn15P322mb5q9Wzn3Pjxmg/xZR1ZQkK MwjnNHoP3nkmStP70yiN1jL3stecBltIiAZbCywWx/khn123ha7gu9mwvRQquA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cH3zq1wL0z4Yw; Wed, 03 Sep 2025 13:56:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 583Du7PP031674; Wed, 3 Sep 2025 13:56:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 583Du79g031671; Wed, 3 Sep 2025 13:56:07 GMT (envelope-from git) Date: Wed, 3 Sep 2025 13:56:07 GMT Message-Id: <202509031356.583Du79g031671@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 938fbab6f52a - stable/14 - chroot.2: Update errors and unprivileged use List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 938fbab6f52aae1872202411a976fcfb6797a2c9 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=938fbab6f52aae1872202411a976fcfb6797a2c9 commit 938fbab6f52aae1872202411a976fcfb6797a2c9 Author: Ed Maste AuthorDate: 2025-08-02 17:17:40 +0000 Commit: Ed Maste CommitDate: 2025-09-03 13:55:53 +0000 chroot.2: Update errors and unprivileged use Include errors common to chroot and fchroot in a single list, followed by errors unique to each. Unprivileged chroot is permitted if the security.bsd.unprivileged_chroot sysctl is set to 1. Make note of this and update the EPERM description. Reported by: kevans Reviewed by: kevans, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51703 (cherry picked from commit 95f8c3e1ed0c3075411444381a5a4baef4ed8fda) --- lib/libc/sys/chroot.2 | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/libc/sys/chroot.2 b/lib/libc/sys/chroot.2 index af37a58794b8..cf17b9ab577c 100644 --- a/lib/libc/sys/chroot.2 +++ b/lib/libc/sys/chroot.2 @@ -25,9 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)chroot.2 8.1 (Berkeley) 6/4/93 -.\" -.Dd September 29, 2020 +.Dd August 2, 2025 .Dt CHROOT 2 .Os .Sh NAME @@ -60,7 +58,12 @@ It should be noted that .Fn chroot has no effect on the process's current directory. .Pp -This call is restricted to the super-user. +This call is restricted to the super-user, unless the +.Ql security.bsd.unprivileged_chroot +sysctl variable is set to 1 +and the process has enabled the +.Dv PROC_NO_NEW_PRIVS_CTL +.Xr procctl 2 . .Pp Depending on the setting of the .Ql kern.chroot_allow_open_directories @@ -99,14 +102,37 @@ still present on other systems. .Sh ERRORS The .Fn chroot +and +.Fn fchroot +system calls +will fail and the root directory will be unchanged if: +.Bl -tag -width Er +.It Bq Er EPERM +The effective user ID is not the super-user and the +.Ql security.bsd.unprivileged_chroot +sysctl is 0. +.It Bq Er EPERM +The effective user ID is not the super-user and the +process has not enabled the +.Dv PROC_NO_NEW_PRIVS_CTL +.Xr procctl 2 . +.It Bq Er EPERM +One or more filedescriptors are open directories and the +.Ql kern.chroot_allow_open_directories +sysctl is not set to permit this. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er EINTEGRITY +Corrupted data was detected while reading from the file system. +.El +.Pp +The +.Fn chroot system call will fail and the root directory will be unchanged if: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path name is not a directory. -.It Bq Er EPERM -The effective user ID is not the super-user, or one or more -filedescriptors are open directories. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. @@ -121,10 +147,6 @@ The .Fa dirname argument points outside the process's allocated address space. -.It Bq Er EIO -An I/O error occurred while reading from or writing to the file system. -.It Bq Er EINTEGRITY -Corrupted data was detected while reading from the file system. .El .Sh SEE ALSO .Xr chdir 2 ,