Skip to content

0049 sysctl: Revise meaning of CTLFLAG_PRISON #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions share/man/man9/sysctl.9
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 1, 2020
.Dd November 7, 2024
.Dt SYSCTL 9
.Os
.Sh NAME
Expand Down Expand Up @@ -901,7 +901,13 @@
This sysctl can be written to only if the effective securelevel of the
process is \[<=] 0.
.It Dv CTLFLAG_PRISON
This sysctl can be written to by processes in
It indicates that this sysctl variable may vary per
.Xr jail 2 .
All such variables can be listed using
.Fl J

Check warning on line 907 in share/man/man9/sysctl.9

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
option of
.Xr sysctl 8 .
Also, if it is not read-only then it can be written to by processes in
.Xr jail 2 .
.It Dv CTLFLAG_SKIP
When iterating the sysctl name space, do not list this sysctl.
Expand Down
12 changes: 6 additions & 6 deletions sys/kern/kern_jail.c
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,7 @@
}

SYSCTL_OID(_security_jail, OID_AUTO, list,
CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE, NULL, 0,
sysctl_jail_list, "S", "List of active jails");

static int
Expand All @@ -4371,7 +4371,7 @@
}

SYSCTL_PROC(_security_jail, OID_AUTO, jailed,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE, NULL, 0,
sysctl_jail_jailed, "I", "Process in jail?");

static int
Expand All @@ -4391,7 +4391,7 @@
}

SYSCTL_PROC(_security_jail, OID_AUTO, vnet,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE, NULL, 0,
sysctl_jail_vnet, "I", "Jail owns vnet?");

#if defined(INET) || defined(INET6)
Expand Down Expand Up @@ -4427,10 +4427,10 @@
if (arg1 != NULL)
i ^= arg2;
/*
* The sysctls don't have CTLFLAGS_PRISON, so assume prison0
* The sysctls don't have CTLFLAG_PRISON, so assume prison0
* for writing.
*/
mtx_lock(&prison0.pr_mtx);

Check warning on line 4433 in sys/kern/kern_jail.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
jail_default_allow = (jail_default_allow & ~arg2) | i;
mtx_unlock(&prison0.pr_mtx);
return (0);
Expand Down Expand Up @@ -4513,14 +4513,14 @@
}

SYSCTL_PROC(_security_jail_children, OID_AUTO, max,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
NULL, offsetof(struct prison, pr_childmax), sysctl_jail_children,
"I", "Maximum number of child jails");
SYSCTL_PROC(_security_jail_children, OID_AUTO, cur,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
NULL, offsetof(struct prison, pr_childcount), sysctl_jail_children,
"I", "Current number of child jails");

Check warning on line 4523 in sys/kern/kern_jail.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
/*
* Nodes to describe jail parameters. Maximum length of string parameters
* is returned in the string itself, and the other parameters exist merely
Expand Down
4 changes: 2 additions & 2 deletions sys/kern/kern_mib.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
}

SYSCTL_PROC(_kern, KERN_OSRELEASE, osrelease,
CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE,

Check warning on line 558 in sys/kern/kern_mib.c

View workflow job for this annotation

GitHub Actions / Style Checker

line over 80 characters
NULL, 0, sysctl_osrelease, "A", "Operating system release");

/*
Expand All @@ -578,10 +578,10 @@
* /usr/include/osreldate.h
*/
SYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate,
CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
NULL, 0, sysctl_osreldate, "I", "Kernel release date");

/*

Check warning on line 584 in sys/kern/kern_mib.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
* The build-id is copied from the ELF section .note.gnu.build-id. The linker
* script defines two variables to expose the beginning and end. LLVM
* currently uses a SHA-1 hash, but other formats can be supported by checking
Expand Down
2 changes: 1 addition & 1 deletion sys/sys/sysctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
#define CTLFLAG_DORMANT 0x20000000 /* This sysctl is not active yet */
#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
#define CTLFLAG_PRISON 0x04000000 /* Per jail, prisoned root can fiddle */
#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
#define CTLMASK_SECURE 0x00F00000 /* Secure level */

Check warning on line 87 in sys/sys/sysctl.h

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */
#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
Expand Down