From nobody Sat Aug 02 18:44:34 2025 X-Original-To: dev-commits-src-main@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 4bvWvQ6GVPz63RSx; Sat, 02 Aug 2025 18:44:34 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bvWvQ52WZz3TNS; Sat, 02 Aug 2025 18:44:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754160274; 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=5tasQGXomBopTwksVow/W5SpDlCqwvyEHetkTvZDX2E=; b=wXCqeH3U1X3zilabcKJ0RJOyrYmbzTWa482y7ow2MHMqQaBq6Owmx82uJBav9unCuZqSll BMXL89VG2LmuTfiG4Hd++8JRltRz0QgI44MXIcLmLro4O3fWlscf4Q6QsaSqckzcBgymt8 o9l3EXf7iUSUiFKhKKBBxuuEW7IQPQgXhqi0SlkXdWPng3776NtrzDx9RZJVqBFZF91fFX 4b1NpfPvw1Z0C8/esdnEFTCD7Ug46dM6i2y16+ui1Bb4EeOCNam2jErFQUFxBIKsYhmvew LS6LP+AaLgithRt/R6BK1QPs8MDZbGKAOAJNexmMKw1go/l22oy4zDW2XCR1Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754160274; 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=5tasQGXomBopTwksVow/W5SpDlCqwvyEHetkTvZDX2E=; b=qwLHzYIL/Tb1x48QfKuesf3L6obkgUPk0+ponZYT8fPcNqvgsTURSSJecpuExWuN5NsHZQ xEhmZ636Km4KEXusEcmhtPIubAAuEt9cN2XVS7/vXqffVudzZFQLrkGvYTVSKA9fhGFgqg j470tQSFBj3z2L/74wBYWqBwf34lSiizyaa9gINnAAjR/TvDS6aIqgV26+f6khG8CX+Rnw FfbrC+PhdCtJEcq/6qFrahQMAFu7w/CcVisBTXIF1vi8N2ogfMwzwrlVcwrLByySZNurWo fDgBQ6rgyVtFE/zMBxG+kClcZDLmyu5rycgE2++hssuh8ZPfg+Ic5qg+p3U43g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754160274; a=rsa-sha256; cv=none; b=diqbDFvglszKMQPdl2y8OSeO5Qb/vuvyHb9TNeSzT7se1fQc+BTjnX1lqZLzE3uFiFR/Lq llu4TCvLjvPra9uCi1tLZTsisPKC0usmV7QuZDv7usBVBHzZYMAm+YMLPT9+BeXudZMYZw goYJ3kBXFeYH5U2OMjpxwxVv9pRF6mVBPSabaogLCylTGATDBKhLS4EgivJNxCV4O1AXTw vqBel2pr3jgNNktLfw6MPZNH8qKzPQZHQnU2hkD9/C1H2dACDLP9oYEY9IJa5kLCsH/jGX RK1SE3H6Vb3/eM/F3mcM0RDonEq7GRPu5M3Mn3OgZEI3Q/nM01+1XYtE+aaC6A== 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 4bvWvQ4cy1zTsH; Sat, 02 Aug 2025 18:44:34 +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 572IiYO9060156; Sat, 2 Aug 2025 18:44:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 572IiY2V060153; Sat, 2 Aug 2025 18:44:34 GMT (envelope-from git) Date: Sat, 2 Aug 2025 18:44:34 GMT Message-Id: <202508021844.572IiY2V060153@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 95f8c3e1ed0c - main - chroot.2: Update errors and unprivileged use List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 95f8c3e1ed0c3075411444381a5a4baef4ed8fda Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=95f8c3e1ed0c3075411444381a5a4baef4ed8fda commit 95f8c3e1ed0c3075411444381a5a4baef4ed8fda Author: Ed Maste AuthorDate: 2025-08-02 17:17:40 +0000 Commit: Ed Maste CommitDate: 2025-08-02 18:43:36 +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 --- lib/libsys/chroot.2 | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/libsys/chroot.2 b/lib/libsys/chroot.2 index 4c06e3673e03..3347df5cceee 100644 --- a/lib/libsys/chroot.2 +++ b/lib/libsys/chroot.2 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 15, 2024 +.Dd August 2, 2025 .Dt CHROOT 2 .Os .Sh NAME @@ -61,7 +61,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 @@ -106,14 +111,37 @@ except it takes a file descriptor instead of path. .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. @@ -128,10 +156,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 .Pp The @@ -146,15 +170,8 @@ file descriptor. The argument .Fa fd is not a valid file descriptor. -.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. .It Bq Er ENOTDIR The file descriptor does not reference a directory. -.It Bq Er EPERM -The effective user ID is not the super-user, or one or more -filedescriptors are open directories. .El .Sh SEE ALSO .Xr chdir 2 ,