History log of /src/usr.sbin/jail/command.c (Results 1 – 25 of 247)
Revision Date Author Comments
# 78c4f821 13-Mar-2026 Gleb Smirnoff <glebius@FreeBSD.org>

jail: fix crash with startup commands on a jail without name

Jail name is optional, thus don't try setenv(NULL).

Fixes: d8f021add40c321c4578da55dae52fb93c7ccb5f


# 02944d8c 26-Jul-2025 Kyle Evans <kevans@FreeBSD.org>

jail: consistently populate the KP_JID and KP_NAME parameters

The gaps here, specifically, were:
- When we have to discover a running jail's jid from name, we should
populate the missing jid pa

jail: consistently populate the KP_JID and KP_NAME parameters

The gaps here, specifically, were:
- When we have to discover a running jail's jid from name, we should
populate the missing jid param
- When we populate jid/name from the config, if the name is a jid we
wouldn't populate the name; now we do both.
- When we create a jail, we should populate jid and name with whatever
details we have now that we didn't both.

As a consequence, we can cleanup a few things:
- vnet.interface and zfs.dataset can just always use the jid
- Trying to populate JNAME should always work now, where it would be
a little crashy before if you create a jail that didn't have a name
or jid on the command line
- We can simplify the just-prior JID population now that we'll keep a
stringified jid in our intparams.

This primarily fixes the below, but the issues with vnet.interface and
zfs.dataset were pre-existing.

Fixes: d8f021add40c3 ("jail: add JID, JNAME and JPATH to env [...]")
Reviewed by: jamie
Differential Revision: https://reviews.freebsd.org/D51502

show more ...


# d8f021ad 05-Mar-2025 Quentin Thébault <quentin.thebault@defenso.fr>

jail: add JID, JNAME and JPATH to environment for exec.* commands

Although variable substitution is available in the jail configuration
file, the jail identifier is often not since it is dynamically

jail: add JID, JNAME and JPATH to environment for exec.* commands

Although variable substitution is available in the jail configuration
file, the jail identifier is often not since it is dynamically
attributed at run time.

In order to facilitate scripting of exec.* commands executed on the
system, this change sets the JID, JNAME and JPATH environment variables.

These variables are not added when using exec.clean. Neither are they
for commands executed inside jails, to avoid disclosing information
about the host system.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1609
Closes: https://github.com/freebsd/freebsd-src/pull/1609

show more ...


# 5cf70549 12-Aug-2024 Jamie Gritton <jamie@FreeBSD.org>

jail: only chdir to user's home directory when user is specified

jail(8) with the "exec.clean" parameter not only cleans the enviromnent
variables before running commands, but also changes to the us

jail: only chdir to user's home directory when user is specified

jail(8) with the "exec.clean" parameter not only cleans the enviromnent
variables before running commands, but also changes to the user's home
directory. While this makes sense when auser is specified (via one of
the exec.*_user parameters), it leads to all commands being run in the
jail's /root directory even in the absence of an explicitly specified
user. This can lead to problems when e.g. rc scripts are run from that
non-world-readable directory, and run counter to expectations that jail
startup is analogous to system startup.

Restrict this behvaiour to only users exlicitly specified, either via
the command line or jail parameters, but not the implicit root user.
While this changes long-stand practice, it's the more intuitive action.

jexec(8) has the same problem, and the same fix.

PR: 277210
Reported by: johannes.kunde at gmail
Differential Revision: https://reviews.freebsd.org/D46226

show more ...


# e0dfe185 17-Jan-2024 Alexander Leidinger <netchild@FreeBSD.org>

jail(8): add support for ZFS datasets

Add zfs.dataset to jail(8) to add a list of ZFS datasets.
Bump FreeBSD version for jail managers to switch to native
dataset support.

Datasets are attached to

jail(8): add support for ZFS datasets

Add zfs.dataset to jail(8) to add a list of ZFS datasets.
Bump FreeBSD version for jail managers to switch to native
dataset support.

Datasets are attached to the jail after the jail creation and
before the execution of any start command. Unlike current
implementations in jail managers which attach datasets after
the start command, this allows the zfs rc.d script to mount
the datasets on start.

Discussed with: jamie

show more ...


# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix

show more ...


# e8d7ae91 15-Dec-2022 Jamie Gritton <jamie@FreeBSD.org>

jail: fix a NULL pointer derefence in parsing ip6.addr settings.

This is the counterpart to bd24e861b4ef, which did the same for ip4.
PR: 268377
Reported by: ahkithaama at proton.me


# 466df976 04-Mar-2021 Kyle Evans <kevans@FreeBSD.org>

jail(8): reset to root cpuset before attaching to run commands

Recent changes have made it such that attaching to a jail will augment
the attaching process' cpu mask with the jail's cpuset. While th

jail(8): reset to root cpuset before attaching to run commands

Recent changes have made it such that attaching to a jail will augment
the attaching process' cpu mask with the jail's cpuset. While this is
convenient for allowing the administrator to cpuset arbitrary programs
that will attach to a jail, this is decidedly not convenient for
executing long-running daemons during jail creation.

This change inserts a reset of the process cpuset to the root cpuset
between the fork and attach to execute a command. This allows commands
executed to have the widest mask possible, and the administrator can
cpuset(1) it back down inside the jail as needed.

With this applied, one should be able to change a jail's cpuset at
exec.poststart in addition to exec.created. The former was made
difficult if jail(8) itself was running with a constrained set, as then
some processes may have been spawned inside the jail with a non-root
set. The latter is the preferred option so that processes starting in
the jail are constrained appropriately up front.

Note that all system commands are still run with the process' initial
cpuset applied.

PR: 253724
MFC after: 3 days
Reviewed by: jamie
Differential Revision: https://reviews.freebsd.org/D29008

show more ...


# 66005c45 14-May-2020 Ryan Moeller <freqlabs@FreeBSD.org>

jail: Add exec.prepare and exec.release command hooks

This change introduces new jail command hooks that run before and after any
other actions.

The exec.prepare hook can be used for example to inv

jail: Add exec.prepare and exec.release command hooks

This change introduces new jail command hooks that run before and after any
other actions.

The exec.prepare hook can be used for example to invoke a script that checks
if the jail's root exists, creating it if it does not. Since arbitrary
variables in jail.conf can be passed to the command, it can be pretty useful
for templating jails.

An example use case for exec.release would be to remove the filesystem of an
ephemeral jail.

The names "prepare" and "release" are borrowed from the names of similar hooks
in libvirt.

Reviewed by: jamie, manpages, mmacy
Approved by: mmacy (mentor)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D24829

show more ...


# be659d72 18-Jan-2019 Dmitry Morozovsky <marck@FreeBSD.org>

Clarify error messages a bit.

X-Found-With: r343112
MFC after: 1 month


# bd24e861 17-Jan-2019 Eugene Grosbein <eugen@FreeBSD.org>

jail(8): stop crashing with SIGSEGV inside run_command() function
while processing not entirely correct jail.conf(5) file
having something like "ip4.addr = 127.0.0.1;" and no "ip4 = ...;"
so extrap v

jail(8): stop crashing with SIGSEGV inside run_command() function
while processing not entirely correct jail.conf(5) file
having something like "ip4.addr = 127.0.0.1;" and no "ip4 = ...;"
so extrap variable stays NULL.

Reported by: marck
MFC after: 1 month

show more ...


# 3611ec60 18-Aug-2018 Dimitry Andric <dim@FreeBSD.org>

Merge ^/head r337646 through r338014.


# 02944d8c 26-Jul-2025 Kyle Evans <kevans@FreeBSD.org>

jail: consistently populate the KP_JID and KP_NAME parameters

The gaps here, specifically, were:
- When we have to discover a running jail's jid from name, we should
populate the missing jid pa

jail: consistently populate the KP_JID and KP_NAME parameters

The gaps here, specifically, were:
- When we have to discover a running jail's jid from name, we should
populate the missing jid param
- When we populate jid/name from the config, if the name is a jid we
wouldn't populate the name; now we do both.
- When we create a jail, we should populate jid and name with whatever
details we have now that we didn't both.

As a consequence, we can cleanup a few things:
- vnet.interface and zfs.dataset can just always use the jid
- Trying to populate JNAME should always work now, where it would be
a little crashy before if you create a jail that didn't have a name
or jid on the command line
- We can simplify the just-prior JID population now that we'll keep a
stringified jid in our intparams.

This primarily fixes the below, but the issues with vnet.interface and
zfs.dataset were pre-existing.

Fixes: d8f021add40c3 ("jail: add JID, JNAME and JPATH to env [...]")
Reviewed by: jamie
Differential Revision: https://reviews.freebsd.org/D51502

show more ...


# d8f021ad 05-Mar-2025 Quentin Thébault <quentin.thebault@defenso.fr>

jail: add JID, JNAME and JPATH to environment for exec.* commands

Although variable substitution is available in the jail configuration
file, the jail identifier is often not since it is dynamically

jail: add JID, JNAME and JPATH to environment for exec.* commands

Although variable substitution is available in the jail configuration
file, the jail identifier is often not since it is dynamically
attributed at run time.

In order to facilitate scripting of exec.* commands executed on the
system, this change sets the JID, JNAME and JPATH environment variables.

These variables are not added when using exec.clean. Neither are they
for commands executed inside jails, to avoid disclosing information
about the host system.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1609
Closes: https://github.com/freebsd/freebsd-src/pull/1609

show more ...


# 5cf70549 12-Aug-2024 Jamie Gritton <jamie@FreeBSD.org>

jail: only chdir to user's home directory when user is specified

jail(8) with the "exec.clean" parameter not only cleans the enviromnent
variables before running commands, but also changes to the us

jail: only chdir to user's home directory when user is specified

jail(8) with the "exec.clean" parameter not only cleans the enviromnent
variables before running commands, but also changes to the user's home
directory. While this makes sense when auser is specified (via one of
the exec.*_user parameters), it leads to all commands being run in the
jail's /root directory even in the absence of an explicitly specified
user. This can lead to problems when e.g. rc scripts are run from that
non-world-readable directory, and run counter to expectations that jail
startup is analogous to system startup.

Restrict this behvaiour to only users exlicitly specified, either via
the command line or jail parameters, but not the implicit root user.
While this changes long-stand practice, it's the more intuitive action.

jexec(8) has the same problem, and the same fix.

PR: 277210
Reported by: johannes.kunde at gmail
Differential Revision: https://reviews.freebsd.org/D46226

show more ...


# e0dfe185 17-Jan-2024 Alexander Leidinger <netchild@FreeBSD.org>

jail(8): add support for ZFS datasets

Add zfs.dataset to jail(8) to add a list of ZFS datasets.
Bump FreeBSD version for jail managers to switch to native
dataset support.

Datasets are attached to

jail(8): add support for ZFS datasets

Add zfs.dataset to jail(8) to add a list of ZFS datasets.
Bump FreeBSD version for jail managers to switch to native
dataset support.

Datasets are attached to the jail after the jail creation and
before the execution of any start command. Unlike current
implementations in jail managers which attach datasets after
the start command, this allows the zfs rc.d script to mount
the datasets on start.

Discussed with: jamie

show more ...


# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix

show more ...


# e8d7ae91 15-Dec-2022 Jamie Gritton <jamie@FreeBSD.org>

jail: fix a NULL pointer derefence in parsing ip6.addr settings.

This is the counterpart to bd24e861b4ef, which did the same for ip4.
PR: 268377
Reported by: ahkithaama at proton.me


# 466df976 04-Mar-2021 Kyle Evans <kevans@FreeBSD.org>

jail(8): reset to root cpuset before attaching to run commands

Recent changes have made it such that attaching to a jail will augment
the attaching process' cpu mask with the jail's cpuset. While th

jail(8): reset to root cpuset before attaching to run commands

Recent changes have made it such that attaching to a jail will augment
the attaching process' cpu mask with the jail's cpuset. While this is
convenient for allowing the administrator to cpuset arbitrary programs
that will attach to a jail, this is decidedly not convenient for
executing long-running daemons during jail creation.

This change inserts a reset of the process cpuset to the root cpuset
between the fork and attach to execute a command. This allows commands
executed to have the widest mask possible, and the administrator can
cpuset(1) it back down inside the jail as needed.

With this applied, one should be able to change a jail's cpuset at
exec.poststart in addition to exec.created. The former was made
difficult if jail(8) itself was running with a constrained set, as then
some processes may have been spawned inside the jail with a non-root
set. The latter is the preferred option so that processes starting in
the jail are constrained appropriately up front.

Note that all system commands are still run with the process' initial
cpuset applied.

PR: 253724
MFC after: 3 days
Reviewed by: jamie
Differential Revision: https://reviews.freebsd.org/D29008

show more ...


# 66005c45 14-May-2020 Ryan Moeller <freqlabs@FreeBSD.org>

jail: Add exec.prepare and exec.release command hooks

This change introduces new jail command hooks that run before and after any
other actions.

The exec.prepare hook can be used for example to inv

jail: Add exec.prepare and exec.release command hooks

This change introduces new jail command hooks that run before and after any
other actions.

The exec.prepare hook can be used for example to invoke a script that checks
if the jail's root exists, creating it if it does not. Since arbitrary
variables in jail.conf can be passed to the command, it can be pretty useful
for templating jails.

An example use case for exec.release would be to remove the filesystem of an
ephemeral jail.

The names "prepare" and "release" are borrowed from the names of similar hooks
in libvirt.

Reviewed by: jamie, manpages, mmacy
Approved by: mmacy (mentor)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D24829

show more ...


# be659d72 18-Jan-2019 Dmitry Morozovsky <marck@FreeBSD.org>

Clarify error messages a bit.

X-Found-With: r343112
MFC after: 1 month


12345678910