FreeBSD/src b516c23lib/libc/gen posix_spawn.c

do_posix_spawn(): use bool

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+3-3lib/libc/gen/posix_spawn.c
+3-31 files

FreeBSD/src 70fb92clibexec/rtld-elf map_object.c

rtld: unify the return path for map_object()

Reviewed by:    kevans
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57908
DeltaFile
+4-6libexec/rtld-elf/map_object.c
+4-61 files

FreeBSD/src 559f456libexec/rtld-elf xmalloc.c rtld.c

rtld: add spinlock around the crt malloc calls

Right now, the rtld malloc is called under the write-locked rtld bind
lock. A future change adds places where only read-locked rtld bind lock
is held, and then the spinlock protects the malloc structures from the
parallel updates.

Reviewed by:    kevans
Tested by:      Marek Zarychta <zarychtam at plan-b.pwste.edu.pl>
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57908
DeltaFile
+71-1libexec/rtld-elf/xmalloc.c
+0-25libexec/rtld-elf/rtld.c
+71-262 files

FreeBSD/src 1e370f0libexec/rtld-elf rtld.c map_object.c

rtld: stop using unbound alloca()

For DoneList allocations, its size depends on the number of loaded DSOs.
Small images could be served by alloca(), but large donelists need to
go into heap.

For map_object(), alloca size is the number of segments in the object.

In both cases, over-grown situations would cause a stack overflow.

PR:     295991
Noted and reviewed by:  kevans
Tested by:      Marek Zarychta <zarychtam at plan-b.pwste.edu.pl>
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57908
DeltaFile
+58-24libexec/rtld-elf/rtld.c
+3-1libexec/rtld-elf/map_object.c
+2-0libexec/rtld-elf/rtld.h
+63-253 files

FreeBSD/src f9a0147lib/libc/net protocols, sys/netinet in.h

protocols: remove IPPROTO_DIVERT
DeltaFile
+0-3sys/netinet/in.h
+0-1lib/libc/net/protocols
+0-42 files

FreeBSD/src bdd0c4dsys/net bpf_ifnet.c, sys/netinet6 in6_ifattach.c nd6.c

netinet6: cleanse safeguards against IFT_PFLOG

This "interface" type is no more.  Leave the constant in if_types.h, we
probably need an exp-run before removing it.
DeltaFile
+3-3sys/netinet6/in6_ifattach.c
+0-5sys/net/bpf_ifnet.c
+2-2sys/netinet6/nd6.c
+0-1sys/netinet6/in6.c
+5-114 files

FreeBSD/src bcf4e3csys/net if_loop.c

loopback: use new names for checksum offloading flags

No functional change intended.

Reviewed by:            tuexen
MFC after:              1 week
Differential Revision:  https://reviews.freebsd.org/D57945
DeltaFile
+5-6sys/net/if_loop.c
+5-61 files

FreeBSD/src 309e4f0tests/sys/mac/do consistency.sh Makefile

MAC/do: Add consistency tests

Test that:
1. Concurrent changes to different parameters on the same jail are
   independent/atomic.
2. Inheritance works.
3. Relaxing only parent jail rules does not leak to a subjail thanks to
   sequential consistency.
4. Sysctl knobs and jail parameters stay consistent.

Some of these tests may be extended in the future with several layers of
jails (there is only a single subjail currently).

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 851499046d25fbe5841a55fb7bfcc879522f59a8)
DeltaFile
+211-0tests/sys/mac/do/consistency.sh
+1-1tests/sys/mac/do/Makefile
+212-12 files

FreeBSD/src 0ab20f7tests/sys/mac/do common.sh

MAC/do: Tests: Add support for exec paths, jail parameters, subjails

And also allow configuration of the mdo(1) executable path.

This commit only contains new or modified infrastructure.  No functional
change intended at this point.

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit a95ff5ef7d1ffcb701913028253a4700cd9a1459)
DeltaFile
+110-9tests/sys/mac/do/common.sh
+110-91 files

FreeBSD/src 406c84ashare/man/man4 mac_do.4

mac_do.4: Document executable paths, default jail values and consistency

While here, fix the bug of mentioning 'enable' as a possible value for
the 'mac.do' jail parameter whereas it is 'new' instead.

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 39818654ae879788807d3a87c2d75cc700cc7113)
DeltaFile
+143-46share/man/man4/mac_do.4
+143-461 files

FreeBSD/src 9dea58fsys/security/mac_do mac_do.c, tests/sys/mac/do invalid_configs.sh

MAC/do: Fix double-free on parse error after "executable paths" feature

parse_rules() has been calling toast_rules() in case of a parse error in
order to deallocate the 'struct rule' objects it has constructed up to
that point.

toast_rules() would take a pointer to a full 'struct rules' object, and
besides freeing all 'struct rule' referenced by it, would also free the
holding 'struct rules' itself.

With the introduction of the "executable paths" feature, and the
embedding of 'struct rules' into 'struct conf', meaning that the
lifecycle for 'struct rules' was no longer independent, toast_rules()
was changed not to free the passed 'struct rules' (as it was a field of
a 'struct conf' object).  Unfortunately, this change was not completed
with a reinitialization of the rules list head, so the 'struct conf'
object would continue to reference just-freed rules, which then would be
freed a second time on destruction of that container.


    [18 lines not shown]
DeltaFile
+8-8sys/security/mac_do/mac_do.c
+14-0tests/sys/mac/do/invalid_configs.sh
+22-82 files

FreeBSD/src 531c3easys/security/mac_do mac_do.c

MAC/do: Update copyright

Update years for the Foundation.

While here, remove the initial '/*-' which has been useless for a long
time.

While here, add a missing space on bapt@'s copyright line (approved by
him).

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit fcb0018634c77fe32ed99bca00f856af18ed240b)
DeltaFile
+3-3sys/security/mac_do/mac_do.c
+3-31 files

FreeBSD/src 29c5581sys/security/mac_do mac_do.c

MAC/do: Do not skip blanks when parsing executable paths

The kind of tolerance we apply to parsing rules, whose format we have
defined, cannot be applied to paths since blank characters are allowed
there.

There is still the limitation that no escape character is currently
supported, and so it is not possible to configure a path having a ':'
character.

Reviewed by:    bapt
Fixes:          9818224174c4 ("MAC/do: Executable paths feature (GSoC 2025's final state)")
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 1fa1e3f3950fc0593ab73ea075c24c9bfbe8afd6)
DeltaFile
+1-1sys/security/mac_do/mac_do.c
+1-11 files

FreeBSD/src ac9d12fsys/security/mac_do mac_do.c

MAC/do: Serialize installing/modifying some jail's configuration

See the immediately preceding commit for explanations on what this is
fixing.

When setting 'mac.do' to 'inherit' on a jail with 'mac.do.rules' and
'mac.do.exec_paths' also specified in the same call, ensure that the
check that these passed parameters are the same as those to be inherited
is atomic with respect to enabling the inheritance (i.e., removing the
jail's 'struct conf' object).  (See previous commit "MAC/do: Fix the
recent logic to set jail parameters, make it more tolerant" as for why
this check exists.)

Because we currently only modify a single configuration object per
transaction, we introduce the parse_and_commit_conf() wrapper around
parse_and_set_conf() to remove duplicated code that would ensue from
calling the latter directly, namely, releasing the 'mac_do_rwl' lock and
freeing the old configuration object (if any).


    [11 lines not shown]
DeltaFile
+76-23sys/security/mac_do/mac_do.c
+76-231 files

FreeBSD/src d344d17sys/security/mac_do mac_do.c

MAC/do: Support for atomically modifying configurations

As mentioned in previous commits "MAC/do: parse_and_set_conf(): Require
the model configuration" and "MAC/do: Sequential consistency for
configuration retrieval", the introduction of the "executable path"
feature, more fundamentally, the fact that there is now more than one
per-jail parameter and that parameters can be independently modified or
copied, causes an atomicity problem in case of concurrent accesses to of
a jail's applicable configuration.

Partially modifying a configuration is indeed akin to
a read-modify-write operation, where the read is either to the current
or an inherited configuration.  More precisely, once pointed to by
a jail, a configuration object is immutable, and changing the jail's
configuration means making the jail point to another configuration
object.  To change a jail's configuration, a new configuration object is
thus built, and if only some parameters have been explicitly specified,
those that have not been are set by copying the corresponding values
from an existing configuration object (in case of partial modification

    [36 lines not shown]
DeltaFile
+49-15sys/security/mac_do/mac_do.c
+49-151 files

FreeBSD/src 84af2a5sys/security/mac_do mac_do.c

MAC/do: Sequential consistency for configuration retrieval

Since the inception of mac_do(4), find_conf(), used to retrieve the
applicable configuration, has been weakly consistent with respect to
concurrent modifications to configuration inheritance that influence its
result (and it has been sequentially consistent with respect to other
configuration modifications, which the initial executable paths feature
and introduction of implicit parameters broke and which will be fixed in
a subsequent commit).

Indeed, find_conf() climbs the jail tree to find an applicable
configuration, which is not an atomic operation.  It examines the
current jail's configuration pointer for each browsed jail, which does
not prevent concurrent modifications of the configuration pointer for
jails below or above it.  Modifications above the current jail are not
a problem, since if climbing needs to continue (i.e., the current jail
inherits), these modifications will be seen if performed before that
check (and may or may not be seen if performed after that check).
However, modifications below the current jail impair sequential

    [50 lines not shown]
DeltaFile
+69-53sys/security/mac_do/mac_do.c
+69-531 files

FreeBSD/src a6398c2sys/security/mac_do mac_do.c

MAC/do: Comment to explain the main invariant for configurations

Once visible, configuration structures must *never* change.

Spell that out in a comment to help future readers/contributors
understand the design.

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 5bedb5e44757ba83dba9d618f5b951416cf44345)
DeltaFile
+5-0sys/security/mac_do/mac_do.c
+5-01 files

FreeBSD/src ddad099sys/security/mac_do mac_do.c

MAC/do: Allocate only one default configuration

When mac_do(4) is loaded, all jails get the same default configuration
(disabled, with only one allowed executable path: '/usr/bin/mdo').
Share it between all jails instead of creating a separate copy for each.

Reviewed by:    bapt
Fixes:          9818224174c4 ("MAC/do: Executable paths feature (GSoC 2025's final state)")
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 31ef4ee2e3570b8f438b9b3fb09b3d87c87419ff)
DeltaFile
+12-12sys/security/mac_do/mac_do.c
+12-121 files

FreeBSD/src d0ff872sys/security/mac_do mac_do.c

MAC/do: Visually separate some file sections

With additional empty lines.

No functional change (intended).

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 01e2b0ce1820adf475e372ec72371dffca17a7af)
DeltaFile
+2-0sys/security/mac_do/mac_do.c
+2-01 files

FreeBSD/src ab2f2f1sys/security/mac_do mac_do.c

MAC/do: Fix reporting of "mac.do" post-"executable paths"

In mac_do_jail_get(), computation of 'jsys' had not been updated to take
into account executable paths.

Reviewed by:    bapt
Fixes:          9818224174c4 ("MAC/do: Executable paths feature (GSoC 2025's final state)")
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 888a84ceeded9ef69903e352827cdef58163027e)
DeltaFile
+2-3sys/security/mac_do/mac_do.c
+2-31 files

FreeBSD/src 31d9802sys/security/mac_do mac_do.c

MAC/do: Configuration: Fix default values: Remove jail creation method

mac_do_jail_create() would create a default configuration on the
just-created jail, erroneously causing mac_do_jail_set() to then
retrieve it and use it as a model when determining the default values
for not-specified parameters, instead of using the configuration
applicable to the parent jail.

Setting a default configuration in mac_do_jail_create() had been done as
a kind of defensive measure to prevent a created jail not to have
a configuration (effectively making it inherit from an ancestor jail,
which is a security hazard except if explicitly requested).  However,
this measure was never really effective (osd_jail_call(PR_METHOD_CREATE)
in kern_jail_set() calls the PR_PETHOD_CREATE methods in an unspecified
order, and stops at the first error), so we are forced to rely in any
case on the fact that an error in a PR_METHOD_CREATE or PR_METHOD_SET
method leads to stopping the jail creation process (which is the case
today; see kern_jail_set()).


    [7 lines not shown]
DeltaFile
+6-14sys/security/mac_do/mac_do.c
+6-141 files

FreeBSD/src e764038sys/security/mac_do mac_do.c

MAC/do: Fix the recent logic to set jail parameters, make it more tolerant

The logic introduced in the initial commit for the "executable paths"
feature did not match the specification we discussed in that specifying
an empty value (for rules or executable paths) on "mac.do" being "new"
would be treated as an absence of value and trigger a copy from the
currently applicable configuration, instead of being an override that
deactivates mac_do(4) in the jail.  Fix that by distinguishing both
cases.

More generally, a non-explicitly specified parameter is set to the same
value it has in the currently applicable configuration (that of the
closest ancestor jail that has one; 'prison0' (the host) always has
one), with an exception in the disable case.

On disable (explicit: "mac.do" to "disable", implicit: no parameters
passed, or at least one is empty), now accept parameters with
a non-empty value as long as at least one of them is empty (which alone
is enough to disable mac_do(4)).  If no parameters are passed, both are

    [26 lines not shown]
DeltaFile
+145-66sys/security/mac_do/mac_do.c
+145-661 files

FreeBSD/src b338e09sys/security/mac_do mac_do.c

MAC/do: Constify is_null_or_empty()

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 37bc08d5fe9933f41574bf477080d729daf19928)
DeltaFile
+1-1sys/security/mac_do/mac_do.c
+1-11 files

FreeBSD/src 67ec8dbsys/security/mac_do mac_do.c

MAC/do: Fix obsolete wording in a comment ("ascendant" => "ancestor")

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit dbf8f0895ad86fea10adbd678873f8af0bd7558c)
DeltaFile
+1-1sys/security/mac_do/mac_do.c
+1-11 files

FreeBSD/src 619213csys/security/mac_do mac_do.c

MAC/do: parse_and_set_conf(): Require the model configuration

This change is a prerequisite for the next change in caller
mac_do_jail_set(), which for semantic correctness needs to rely on
a stable model configuration.

The two other callers already call find_conf() to retrieve the
applicable configuration, so for these a second call to find_conf() can
be saved.

However, this does not fix (actually, makes slightly worse) an atomicity
problem when multiple threads concurrently change some jail's
configuration (or the configuration inherited by a jail), which has
existed since the introduction of executable paths due to being able to
change only rules or executable paths independently (and the possibility
of not specifying them and having them copied from the currently
applicable configuration).  Before tackling it in later commits, we
first focus on fixing the semantics of configuration changes in the very
next patches.

    [7 lines not shown]
DeltaFile
+38-28sys/security/mac_do/mac_do.c
+38-281 files

FreeBSD/src 0466e93sys/security/mac_do mac_do.c

MAC/do: parse_and_set_conf(): Obey empty parameters; Add doc

parse_and_set_conf() is meant to be used in all situations when there is
a need to set or modify some jail's MAC/do configuration.  This entails
passing the information of whether some parameter was explicitly
specified.  For example, an administrator setting/modifying jail
parameters may not specify executable paths but only rules, in which
case the executable paths value is copied from the currently-applicable
configuration.  The sysctl(8) knobs case always leverages this feature,
since setting a knob changes one parameter at a time.

Currently, a NULL or empty string argument is treated as a non-specified
parameter.  This causes a bug where disabling MAC/do in a jail does not
actually work because, to this end, parse_and_set_conf() is passed an
empty string which it then interprets as a request to copy the currently
applicable configuration's value, which may well not be empty.

Fix this problem by only treating NULL as a marker for a non-specified
parameter, in accordance with the original design for this function.

    [13 lines not shown]
DeltaFile
+14-14sys/security/mac_do/mac_do.c
+14-141 files

FreeBSD/src ce8846dsys/security/mac_do mac_do.c

MAC/do: Remove superfluous configuration initialization

Configuration objects would be initialized (zeroed, and some
STAILQ_INIT() called) multiple times.  Make sure they are so only once,
and add assertions to check that this is actually the case for functions
that expect it.

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 11b567e94ad2a1b4baf768d77c6f1fb2018cfe83)
DeltaFile
+24-10sys/security/mac_do/mac_do.c
+24-101 files

FreeBSD/src bef2b6esys/security/mac_do mac_do.c

MAC/do: clone_rules(): Readability improvements, constification

Constify in order to let the compiler check that source and destination
arguments are passed in the proper order in the different calls.

No functional change (intended).

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit ce59a4181593f59028d3a26f2b63dcf2c8041d79)
DeltaFile
+13-11sys/security/mac_do/mac_do.c
+13-111 files

FreeBSD/src c8394ffsys/security/mac_do mac_do.c

MAC/do: Move static assertions on constants close to their definitions

And document more clearly their purpose.

Reviewed by:    bapt
MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/38

(cherry picked from commit 4e27cc086b3f9e029160da8830abacb06a2f9e39)
DeltaFile
+6-4sys/security/mac_do/mac_do.c
+6-41 files

FreeBSD/src e4ab958sys/security/mac_do mac_do.c

MAC/do: Fix releasing a nonexistent reference on configuration parsing error

On parsing error, parse_and_set_conf(), introduced with the recent
"executable paths" feature, has been calling drop_conf() on the
being-built configuration.  However, that configuration structure is
allocated through alloc_conf(), which does not grab a reference.
Calling drop_conf() on it, which releases a reference, is thus
erroneous, and causes the underlying counter to saturate, translating
into a memory leak.

To fix this bug, make alloc_conf() grab a reference on the newly-created
'struct conf', and rename it to new_conf() to be more in line with what
it does.  Keep set_conf() as is, i.e., grabbing an additional reference
on behalf of the jail that is going to hold the configuration.
Consequently, make sure that callers of alloc_conf() unconditionally
drop the reference acquired by the latter before returning (i.e., even
if set_conf() has been called).

While here, since hold_conf() is always used to obtain additional

    [17 lines not shown]
DeltaFile
+10-6sys/security/mac_do/mac_do.c
+10-61 files