<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/usr.sbin/chroot, branch main</title>
<subtitle>FreeBSD source tree</subtitle>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/'/>
<entry>
<title>manuals: Correct some sysctl markup</title>
<updated>2026-01-06T16:08:21+00:00</updated>
<author>
<name>Alexander Ziaee</name>
<email>ziaee@FreeBSD.org</email>
</author>
<published>2026-01-06T16:02:24+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=75866d71e8d93fe1a1ff469b8a9c6c6c9908a6c8'/>
<id>75866d71e8d93fe1a1ff469b8a9c6c6c9908a6c8</id>
<content type='text'>
This enables additional searching the manual by sysctl variable.
This syntax is standardized in style.mdoc(5).

Reported by:	bapt
MFC after:	3 days
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This enables additional searching the manual by sysctl variable.
This syntax is standardized in style.mdoc(5).

Reported by:	bapt
MFC after:	3 days
</pre>
</div>
</content>
</entry>
<entry>
<title>kern: fix setgroups(2) and getgroups(2) to match other platforms</title>
<updated>2025-08-15T04:06:09+00:00</updated>
<author>
<name>Kyle Evans</name>
<email>kevans@FreeBSD.org</email>
</author>
<published>2025-08-15T04:06:09+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=9da2fe96ff2ea227e4d5f03ef92b55aabeabb7fc'/>
<id>9da2fe96ff2ea227e4d5f03ef92b55aabeabb7fc</id>
<content type='text'>
On most other platforms observed, including OpenBSD, NetBSD, and Linux,
these system calls have long since been converted to only touching the
supplementary groups of the process.  This poses both portability and
security concerns in porting software to and from FreeBSD, as this
subtle difference is a landmine waiting to happen.  Bugs have been
discovered even in FreeBSD-local sources, since this behavior is
somewhat unintuitive (see, e.g., fix 48fd05999b0f for chroot(8)).

Now that the egid is tracked outside of cr_groups in our ucred, convert
the syscalls to deal with only supplementary groups.  Some remaining
stragglers in base that had baked in assumptions about these syscalls
are fixed in the process to avoid heartburn in conversion.

For relnotes: application developers should audit their use of both
setgroups(2) and getgroups(2) for signs that they had assumed the
previous FreeBSD behavior of using the first element for the egid.  Any
calls to setgroups() to clear groups that used a single array of the
now or soon-to-be egid can be converted to setgroups(0, NULL) calls to
clear the supplementary groups entirely on all FreeBSD versions.

Co-authored-by:	olce (but bugs are likely mine)
Relnotes:	yes (see last paragraph)
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D51648
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On most other platforms observed, including OpenBSD, NetBSD, and Linux,
these system calls have long since been converted to only touching the
supplementary groups of the process.  This poses both portability and
security concerns in porting software to and from FreeBSD, as this
subtle difference is a landmine waiting to happen.  Bugs have been
discovered even in FreeBSD-local sources, since this behavior is
somewhat unintuitive (see, e.g., fix 48fd05999b0f for chroot(8)).

Now that the egid is tracked outside of cr_groups in our ucred, convert
the syscalls to deal with only supplementary groups.  Some remaining
stragglers in base that had baked in assumptions about these syscalls
are fixed in the process to avoid heartburn in conversion.

For relnotes: application developers should audit their use of both
setgroups(2) and getgroups(2) for signs that they had assumed the
previous FreeBSD behavior of using the first element for the egid.  Any
calls to setgroups() to clear groups that used a single array of the
now or soon-to-be egid can be converted to setgroups(0, NULL) calls to
clear the supplementary groups entirely on all FreeBSD versions.

Co-authored-by:	olce (but bugs are likely mine)
Relnotes:	yes (see last paragraph)
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D51648
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot: don't setgroups() without -G having been specified</title>
<updated>2025-08-12T12:30:23+00:00</updated>
<author>
<name>Kyle Evans</name>
<email>kevans@FreeBSD.org</email>
</author>
<published>2025-08-12T12:14:38+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=babab49eee9472f628d774996de13d13d296c8c0'/>
<id>babab49eee9472f628d774996de13d13d296c8c0</id>
<content type='text'>
We previously would not have setgroups() at all, but now we would drop
our supplementary groups every time.  This broke chroot -n, probably
among other things.  We need tests here, but lets unbreak things first.

A future change may try to setgroups(2) when -u is specified in addition
to -G, so predicate the call on gidlist and don't populate that without
a grouplist.

PR:		288751
Fixes:	48fd05999b0f ("chroot: don't clobber the egid [...]")
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We previously would not have setgroups() at all, but now we would drop
our supplementary groups every time.  This broke chroot -n, probably
among other things.  We need tests here, but lets unbreak things first.

A future change may try to setgroups(2) when -u is specified in addition
to -G, so predicate the call on gidlist and don't populate that without
a grouplist.

PR:		288751
Fixes:	48fd05999b0f ("chroot: don't clobber the egid [...]")
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot: Remove always-true checks</title>
<updated>2025-08-07T18:26:46+00:00</updated>
<author>
<name>John Baldwin</name>
<email>jhb@FreeBSD.org</email>
</author>
<published>2025-08-07T17:48:36+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=3c4b3bab19ca66bbb3c53275c51d4bf863059fb2'/>
<id>3c4b3bab19ca66bbb3c53275c51d4bf863059fb2</id>
<content type='text'>
gid_t and uid_t are unsigned types, so the values are always &gt;= 0.

usr.sbin/chroot/chroot.c: In function 'resolve_group':
usr.sbin/chroot/chroot.c:68:55: error: comparison of unsigned expression in '&gt;= 0' is always true [-Werror=type-limits]
   68 |         if (errno == 0 &amp;&amp; *endp == '\0' &amp;&amp; (gid_t)gid &gt;= 0 &amp;&amp; gid &lt;= GID_MAX)
      |                                                       ^~
usr.sbin/chroot/chroot.c: In function 'resolve_user':
usr.sbin/chroot/chroot.c:87:55: error: comparison of unsigned expression in '&gt;= 0' is always true [-Werror=type-limits]
   87 |         if (errno == 0 &amp;&amp; *endp == '\0' &amp;&amp; (uid_t)uid &gt;= 0 &amp;&amp; uid &lt;= UID_MAX)
      |                                                       ^~

Reported by:	GCC
Fixes:		91eb4d2ba4de ("chroot: slightly cleanup")
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
gid_t and uid_t are unsigned types, so the values are always &gt;= 0.

usr.sbin/chroot/chroot.c: In function 'resolve_group':
usr.sbin/chroot/chroot.c:68:55: error: comparison of unsigned expression in '&gt;= 0' is always true [-Werror=type-limits]
   68 |         if (errno == 0 &amp;&amp; *endp == '\0' &amp;&amp; (gid_t)gid &gt;= 0 &amp;&amp; gid &lt;= GID_MAX)
      |                                                       ^~
usr.sbin/chroot/chroot.c: In function 'resolve_user':
usr.sbin/chroot/chroot.c:87:55: error: comparison of unsigned expression in '&gt;= 0' is always true [-Werror=type-limits]
   87 |         if (errno == 0 &amp;&amp; *endp == '\0' &amp;&amp; (uid_t)uid &gt;= 0 &amp;&amp; uid &lt;= UID_MAX)
      |                                                       ^~

Reported by:	GCC
Fixes:		91eb4d2ba4de ("chroot: slightly cleanup")
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot: slightly cleanup</title>
<updated>2025-08-03T04:15:03+00:00</updated>
<author>
<name>Kyle Evans</name>
<email>kevans@FreeBSD.org</email>
</author>
<published>2025-08-03T04:15:03+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=91eb4d2ba4def0fe0f56f0a61ad7c503fcab891b'/>
<id>91eb4d2ba4def0fe0f56f0a61ad7c503fcab891b</id>
<content type='text'>
Highlights:
 - Pull resolve_user() and resolve_group() out to make the main flow
    a bit easier to read
 - Fix some edge-cases in user/group resolution: you can have fully
    numeric usernames, and they may or may not live within the valid
    ID range.  Switch to just trying to resolve every specified
    group/user as a name, first, with a fallback to converting it to a
    numeric type and trying to resolve it as an ID.
 - Constify locals in main() that don't need to be mutable, re-sort

Reviewed by:	emaste, olce
Differential Revision:	https://reviews.freebsd.org/D51509
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Highlights:
 - Pull resolve_user() and resolve_group() out to make the main flow
    a bit easier to read
 - Fix some edge-cases in user/group resolution: you can have fully
    numeric usernames, and they may or may not live within the valid
    ID range.  Switch to just trying to resolve every specified
    group/user as a name, first, with a fallback to converting it to a
    numeric type and trying to resolve it as an ID.
 - Constify locals in main() that don't need to be mutable, re-sort

Reviewed by:	emaste, olce
Differential Revision:	https://reviews.freebsd.org/D51509
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot: Improve error message for unprivileged use</title>
<updated>2025-08-01T20:35:07+00:00</updated>
<author>
<name>Ed Maste</name>
<email>emaste@FreeBSD.org</email>
</author>
<published>2025-08-01T19:53:00+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=e6c623e9bad56271d6c5fffaaf994d27b65404e5'/>
<id>e6c623e9bad56271d6c5fffaaf994d27b65404e5</id>
<content type='text'>
When the security.bsd.unprivileged_chroot sysctl is set, chroot(2) can
be used by unprivileged users as long as the PROC_NO_NEW_PRIVS_CTL
process control is set.

chroot(8) has a -n command line flag to set this process control.
Add an explicit error for EPERM from chroot(2) if the -n flag is
necessary, but not present.

Before:
  $ chroot / /bin/sh
  chroot: /: Operation not permitted

After:
  $ chroot / /bin/sh
  chroot: unprivileged use requires -n

Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51687
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When the security.bsd.unprivileged_chroot sysctl is set, chroot(2) can
be used by unprivileged users as long as the PROC_NO_NEW_PRIVS_CTL
process control is set.

chroot(8) has a -n command line flag to set this process control.
Add an explicit error for EPERM from chroot(2) if the -n flag is
necessary, but not present.

Before:
  $ chroot / /bin/sh
  chroot: /: Operation not permitted

After:
  $ chroot / /bin/sh
  chroot: unprivileged use requires -n

Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51687
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot.8: Be more precise when describing '-u', '-g' and '-G'</title>
<updated>2025-07-28T01:11:12+00:00</updated>
<author>
<name>Olivier Certner</name>
<email>olce@FreeBSD.org</email>
</author>
<published>2025-07-25T06:36:17+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=04a6dc7974ee02004c9ccbb0c28d14a3271fb56a'/>
<id>04a6dc7974ee02004c9ccbb0c28d14a3271fb56a</id>
<content type='text'>
Reviewed by:    kevans, ziaee
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D51511
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Reviewed by:    kevans, ziaee
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D51511
</pre>
</div>
</content>
</entry>
<entry>
<title>chroot: don't clobber the egid with the first supplemental group</title>
<updated>2025-07-26T06:11:58+00:00</updated>
<author>
<name>Kyle Evans</name>
<email>kevans@FreeBSD.org</email>
</author>
<published>2025-07-26T06:11:58+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=48fd05999b0f8e822fbf7069779378d103a35f5c'/>
<id>48fd05999b0f8e822fbf7069779378d103a35f5c</id>
<content type='text'>
There are two problems here, really:

1.) If -G is specified, the egid of the runner will get clobbered by
    the first supplemental group
2.) If both -G and -g are specified, the first supplemental group will
    get clobbered by the -g group

Ideally our users shouldn't have to understand the quirks of our
setgroups(2) and the manpage doesn't describe the group list as needing
to contain the egid, so populate the egid slot as necessary.

I note that this code seems to have already been marginally aware of the
historical behavior because it was allocating NGROUPS_MAX + 1, but this
is an artifact of a later conversion to doing dynamic allocations
instead of pushing NGROUPS_MAX arrays on the stack -- the original code
did in-fact only have an NGROUPS_MAX-sized array, and the layout was
still incorrect.

MFC after:	3 days
Reviewed by:	olce
Differential Revision:	https://reviews.freebsd.org/D51508
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
There are two problems here, really:

1.) If -G is specified, the egid of the runner will get clobbered by
    the first supplemental group
2.) If both -G and -g are specified, the first supplemental group will
    get clobbered by the -g group

Ideally our users shouldn't have to understand the quirks of our
setgroups(2) and the manpage doesn't describe the group list as needing
to contain the egid, so populate the egid slot as necessary.

I note that this code seems to have already been marginally aware of the
historical behavior because it was allocating NGROUPS_MAX + 1, but this
is an artifact of a later conversion to doing dynamic allocations
instead of pushing NGROUPS_MAX arrays on the stack -- the original code
did in-fact only have an NGROUPS_MAX-sized array, and the layout was
still incorrect.

MFC after:	3 days
Reviewed by:	olce
Differential Revision:	https://reviews.freebsd.org/D51508
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove residual blank line at start of Makefile</title>
<updated>2024-07-15T22:43:39+00:00</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2024-07-15T04:46:32+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=e9ac41698b2f322d55ccf9da50a3596edb2c1800'/>
<id>e9ac41698b2f322d55ccf9da50a3596edb2c1800</id>
<content type='text'>
This is a residual of the $FreeBSD$ removal.

MFC After: 3 days (though I'll just run the command on the branches)
Sponsored by: Netflix
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a residual of the $FreeBSD$ removal.

MFC After: 3 days (though I'll just run the command on the branches)
Sponsored by: Netflix
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove copyright strings ifdef'd out</title>
<updated>2023-11-27T05:23:58+00:00</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2023-11-24T07:45:36+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=0b8224d1cc9dc6c9778ba04a75b2c8d47e5d7481'/>
<id>0b8224d1cc9dc6c9778ba04a75b2c8d47e5d7481</id>
<content type='text'>
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
</pre>
</div>
</content>
</entry>
</feed>
