xref: /freebsd/lib/libsys/procctl.2 (revision d2ffe67fd5d94a1415b09971a736967505185fe9)
18269e767SBrooks Davis.\" Copyright (c) 2013 Hudson River Trading LLC
28269e767SBrooks Davis.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
38269e767SBrooks Davis.\" All rights reserved.
48269e767SBrooks Davis.\"
58269e767SBrooks Davis.\" Copyright (c) 2014 The FreeBSD Foundation
68269e767SBrooks Davis.\" Portions of this documentation were written by Konstantin Belousov
78269e767SBrooks Davis.\" under sponsorship from the FreeBSD Foundation.
88269e767SBrooks Davis.\"
98269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
108269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
118269e767SBrooks Davis.\" are met:
128269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
138269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
148269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
158269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
168269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
178269e767SBrooks Davis.\"
188269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
228269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288269e767SBrooks Davis.\" SUCH DAMAGE.
298269e767SBrooks Davis.\"
30*d2ffe67fSVicki Pfau.Dd April 21, 2025
318269e767SBrooks Davis.Dt PROCCTL 2
328269e767SBrooks Davis.Os
338269e767SBrooks Davis.Sh NAME
348269e767SBrooks Davis.Nm procctl
358269e767SBrooks Davis.Nd control processes
368269e767SBrooks Davis.Sh LIBRARY
378269e767SBrooks Davis.Lb libc
388269e767SBrooks Davis.Sh SYNOPSIS
398269e767SBrooks Davis.In sys/procctl.h
408269e767SBrooks Davis.Ft int
418269e767SBrooks Davis.Fn procctl "idtype_t idtype" "id_t id" "int cmd" "void *data"
428269e767SBrooks Davis.Sh DESCRIPTION
438269e767SBrooks DavisThe
448269e767SBrooks Davis.Fn procctl
458269e767SBrooks Davissystem call provides for control over processes.
468269e767SBrooks DavisThe
478269e767SBrooks Davis.Fa idtype
488269e767SBrooks Davisand
498269e767SBrooks Davis.Fa id
508269e767SBrooks Davisarguments specify the set of processes to control.
518269e767SBrooks DavisIf multiple processes match the identifier,
528269e767SBrooks Davis.Nm
538269e767SBrooks Daviswill make a
548269e767SBrooks Davis.Dq best effort
558269e767SBrooks Davisto control as many of the selected processes as possible.
568269e767SBrooks DavisAn error is only returned if no selected processes successfully complete
578269e767SBrooks Davisthe request.
588269e767SBrooks DavisThe following identifier types are supported:
598269e767SBrooks Davis.Bl -tag -width P_PGID
608269e767SBrooks Davis.It Dv P_PID
618269e767SBrooks DavisControl the process with the process ID
628269e767SBrooks Davis.Fa id .
638269e767SBrooks Davis.Fa id
648269e767SBrooks Daviszero is a shortcut for the calling process ID.
658269e767SBrooks Davis.It Dv P_PGID
668269e767SBrooks DavisControl processes belonging to the process group with the ID
678269e767SBrooks Davis.Fa id .
688269e767SBrooks Davis.El
698269e767SBrooks Davis.Pp
708269e767SBrooks DavisThe control request to perform is specified by the
718269e767SBrooks Davis.Fa cmd
728269e767SBrooks Davisargument.
738269e767SBrooks Davis.Pp
748269e767SBrooks DavisAll status changing requests
758277c790SJohn Baldwin.Pq Dv *_CTL
768269e767SBrooks Davisrequire the caller to have the right to debug the target.
778269e767SBrooks DavisAll status query requests
788277c790SJohn Baldwin.Pq Dv *_STATUS
798269e767SBrooks Davisrequire the caller to have the right to observe the target.
808269e767SBrooks Davis.Pp
818269e767SBrooks DavisThe following commands are supported:
82dabf006aSKyle Evans.Bl -tag -width PROC_LOGSIGEXIT_STATUS
838269e767SBrooks Davis.It Dv PROC_ASLR_CTL
848277c790SJohn BaldwinControls Address Space Layout Randomization (ASLR) in program
858269e767SBrooks Davisimages created
868269e767SBrooks Davisby
878269e767SBrooks Davis.Xr execve 2
888269e767SBrooks Davisin the specified process or its descendants that do not either change
898269e767SBrooks Davisthe control or modify it by other means.
908269e767SBrooks DavisThe
918269e767SBrooks Davis.Fa data
928277c790SJohn Baldwinparameter must point to an integer variable holding one of the following
938269e767SBrooks Davisvalues:
948277c790SJohn Baldwin.Bl -tag -width Ds
958269e767SBrooks Davis.It Dv PROC_ASLR_FORCE_ENABLE
968269e767SBrooks DavisRequest that ASLR is enabled after execution, even if it is disabled
978269e767SBrooks Davissystem-wide.
988269e767SBrooks Davis.It Dv PROC_ASLR_FORCE_DISABLE
998277c790SJohn BaldwinRequest that ASLR is disabled after execution, even if it is enabled
1008277c790SJohn Baldwinsystem-wide.
1018269e767SBrooks Davis.It Dv PROC_ASLR_NOFORCE
1028269e767SBrooks DavisUse the system-wide configured policy for ASLR.
1038269e767SBrooks Davis.El
1048277c790SJohn Baldwin.Pp
1058277c790SJohn BaldwinNote that the
1068277c790SJohn Baldwin.Xr elfctl 1
1078277c790SJohn Baldwin.Dq noaslr
1088277c790SJohn Baldwinflag takes precedence over this control.
1098277c790SJohn BaldwinExecuting a binary with this flag set will never use ASLR.
1108277c790SJohn BaldwinSimilarly, executing a set-user-ID or set-group-ID binary ignores this
1118277c790SJohn Baldwincontrol and only honors the
1128277c790SJohn Baldwin.Xr elfctl 1
1138277c790SJohn Baldwinflag and system-wide policy.
1148269e767SBrooks Davis.It Dv PROC_ASLR_STATUS
1158269e767SBrooks DavisReturns the current status of ASLR enablement for the target process.
1168269e767SBrooks DavisThe
1178269e767SBrooks Davis.Fa data
1188277c790SJohn Baldwinparameter must point to an integer variable, where one of the
1198269e767SBrooks Davisfollowing values is written:
1208277c790SJohn Baldwin.Bl -tag -width Ds
1218269e767SBrooks Davis.It Dv PROC_ASLR_FORCE_ENABLE
1228269e767SBrooks Davis.It Dv PROC_ASLR_FORCE_DISABLE
1238269e767SBrooks Davis.It Dv PROC_ASLR_NOFORCE
1248269e767SBrooks Davis.El
1258269e767SBrooks Davis.Pp
1268269e767SBrooks DavisIf the currently executed image in the process itself has ASLR enabled,
1278269e767SBrooks Davisthe
1288269e767SBrooks Davis.Dv PROC_ASLR_ACTIVE
1298269e767SBrooks Davisflag is or-ed with the value listed above.
130dabf006aSKyle Evans.It Dv PROC_LOGSIGEXIT_CTL
131dabf006aSKyle EvansControls the logging of exits due to signals that would normally cause a core
132dabf006aSKyle Evansdump.
133dabf006aSKyle EvansThe
134dabf006aSKyle Evans.Va arg
135dabf006aSKyle Evansparameter must point to an integer variable holding one of the following values:
136*d2ffe67fSVicki Pfau.Bl -tag -width PROC_LOGSIGEXIT_CTL_FORCE_DISABLE
137*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_FORCE_ENABLE
138dabf006aSKyle EvansEnables logging of exits due to signals that would normally cause a core dump.
139dabf006aSKyle EvansLogging is done via
140dabf006aSKyle Evans.Xr log 9
141dabf006aSKyle Evanswith a log level of
142dabf006aSKyle Evans.Dv LOG_INFO .
143*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_FORCE_DISABLE
144dabf006aSKyle EvansDisables the logging of exits due to signals that would normally cause a core
145dabf006aSKyle Evansdump.
146*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_NOFORCE
147dabf006aSKyle EvansThe logging behavior is delegated to the
148dabf006aSKyle Evans.Xr sysctl 3
149dabf006aSKyle EvansMIB variable
150dabf006aSKyle Evans.Va kern.logsigexit .
151dabf006aSKyle Evans.El
152dabf006aSKyle Evans.It Dv PROC_LOGSIGEXIT_STATUS
153dabf006aSKyle EvansReturns the current status of logging for the target process.
154dabf006aSKyle EvansThe
155dabf006aSKyle Evans.Va arg
156dabf006aSKyle Evansparameter must point to an integer variable, where one of the following values
157dabf006aSKyle Evansis written:
158*d2ffe67fSVicki Pfau.Bl -tag -width PROC_LOGSIGEXIT_CTL_FORCE_DISABLE
159*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_FORCE_ENABLE
160*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_FORCE_DISABLE
161*d2ffe67fSVicki Pfau.It Dv PROC_LOGSIGEXIT_CTL_NOFORCE
162dabf006aSKyle Evans.El
1638269e767SBrooks Davis.It Dv PROC_PROTMAX_CTL
1648277c790SJohn BaldwinControls the maximum protection used for
1658269e767SBrooks Davis.Xr mmap 2
1668277c790SJohn Baldwinrequests in the target process that do not specify
1678277c790SJohn Baldwinan explicit maximum protection in the
1688277c790SJohn Baldwin.Fa prot
1698277c790SJohn Baldwinargument via
1708277c790SJohn Baldwin.Dv PROT_MAX .
1718277c790SJohn BaldwinThe maximum protection limits the permissions a mapping can be assigned by
1728277c790SJohn Baldwin.Xr mprotect 2 .
1738277c790SJohn BaldwinIf an explicit maximum protection is not provided,
1748277c790SJohn Baldwinthe maximum protection for a new mapping is set to either
1758277c790SJohn Baldwin.Dv PROT_READ | PROT_WRITE | PROT_EXEC
1768277c790SJohn Baldwin.Pq RWX
1778277c790SJohn Baldwinor the protection specified in
1788277c790SJohn Baldwin.Fa prot .
1798277c790SJohn BaldwinMappings created with
1808277c790SJohn Baldwin.Fa prot
1818277c790SJohn Baldwinset to
1828277c790SJohn Baldwin.Dv PROT_NONE
1838277c790SJohn Baldwinalways use RWX maximum protection.
1848277c790SJohn Baldwin.Pp
1858269e767SBrooks DavisThe
1868269e767SBrooks Davis.Fa data
1878277c790SJohn Baldwinparameter must point to an integer variable holding one of the following
1888269e767SBrooks Davisvalues:
1898277c790SJohn Baldwin.Bl -tag -width Ds
1908269e767SBrooks Davis.It Dv PROC_PROTMAX_FORCE_ENABLE
1918277c790SJohn BaldwinUse the permissions in
1928277c790SJohn Baldwin.Fa prot
1938277c790SJohn Baldwinas the implicit maximum protection,
1948277c790SJohn Baldwineven if RWX permissions are requested by the sysctl
1958269e767SBrooks Davis.Va vm.imply_prot_max .
1968269e767SBrooks Davis.It Dv PROC_PROTMAX_FORCE_DISABLE
1978277c790SJohn BaldwinUse RWX as the implicit maximum protection,
1988277c790SJohn Baldwineven if constrained permissions are requested by the sysctl
1998277c790SJohn Baldwin.Va vm.imply_prot_max .
2008269e767SBrooks Davis.It Dv PROC_PROTMAX_NOFORCE
2018277c790SJohn BaldwinUse the system-wide configured policy for the implicit PROT_MAX control.
2028269e767SBrooks Davis.El
2038277c790SJohn Baldwin.Pp
2048277c790SJohn BaldwinNote that the
2058277c790SJohn Baldwin.Xr elfctl 1
2068277c790SJohn Baldwin.Dq noprotmax
2078277c790SJohn Baldwinflag takes precedence over this control.
2088277c790SJohn BaldwinExecuting a binary with this flag set will always use RWX as the implicit
2098277c790SJohn Baldwinmaximum protection.
2108269e767SBrooks Davis.It Dv PROC_PROTMAX_STATUS
2118277c790SJohn BaldwinReturns the current status of the implicit PROT_MAX control for the
2128269e767SBrooks Davistarget process.
2138269e767SBrooks DavisThe
2148269e767SBrooks Davis.Fa data
2158277c790SJohn Baldwinparameter must point to an integer variable, where one of the
2168269e767SBrooks Davisfollowing values is written:
2178277c790SJohn Baldwin.Bl -tag -width Ds
2188269e767SBrooks Davis.It Dv PROC_PROTMAX_FORCE_ENABLE
2198269e767SBrooks Davis.It Dv PROC_PROTMAX_FORCE_DISABLE
2208269e767SBrooks Davis.It Dv PROC_PROTMAX_NOFORCE
2218269e767SBrooks Davis.El
2228269e767SBrooks Davis.Pp
2238277c790SJohn BaldwinIf the currently executed image in the process itself has the implicit PROT_MAX
2248277c790SJohn Baldwincontrol enabled, the
2258269e767SBrooks Davis.Dv PROC_PROTMAX_ACTIVE
2268269e767SBrooks Davisflag is or-ed with the value listed above.
2278269e767SBrooks Davis.It Dv PROC_SPROTECT
2288269e767SBrooks DavisSet process protection state.
2298269e767SBrooks DavisThis is used to mark a process as protected from being killed if the system
2308277c790SJohn Baldwinexhausts available memory and swap.
2318269e767SBrooks DavisThe
2328269e767SBrooks Davis.Fa data
2338269e767SBrooks Davisparameter must point to an integer containing an operation and zero or more
2348269e767SBrooks Davisoptional flags.
2358269e767SBrooks DavisThe following operations are supported:
2368277c790SJohn Baldwin.Bl -tag -width Ds
2378269e767SBrooks Davis.It Dv PPROT_SET
2388269e767SBrooks DavisMark the selected processes as protected.
2398269e767SBrooks Davis.It Dv PPROT_CLEAR
2408269e767SBrooks DavisClear the protected state of selected processes.
2418269e767SBrooks Davis.El
2428269e767SBrooks Davis.Pp
2438269e767SBrooks DavisThe following optional flags are supported:
2448277c790SJohn Baldwin.Bl -tag -width Ds
2458269e767SBrooks Davis.It Dv PPROT_DESCEND
2468269e767SBrooks DavisApply the requested operation to all child processes of each selected process
2478269e767SBrooks Davisin addition to each selected process.
2488269e767SBrooks Davis.It Dv PPROT_INHERIT
2498269e767SBrooks DavisWhen used with
2508269e767SBrooks Davis.Dv PPROT_SET ,
2518269e767SBrooks Davismark all future child processes of each selected process as protected.
2528269e767SBrooks DavisFuture child processes will also mark all of their future child processes.
2538269e767SBrooks Davis.El
2548269e767SBrooks Davis.It Dv PROC_REAP_ACQUIRE
2558277c790SJohn BaldwinEnable orphaned process reaping for future children of the current process.
2568277c790SJohn Baldwin.Pp
2578277c790SJohn BaldwinIf a parent process exits before one or more of its children processes,
2588277c790SJohn Baldwinthe remaining children processes are orphaned.
2598277c790SJohn BaldwinWhen an orphaned process exits,
2608277c790SJohn Baldwinit is reparented to a reaper process that is responsible for harvesting
2618277c790SJohn Baldwinthe terminated process via
2628277c790SJohn Baldwin.Xr wait 2 .
2638277c790SJohn BaldwinWhen this control is enabled,
2648277c790SJohn Baldwinthe current process becomes the reaper process for future children and their
2658277c790SJohn Baldwindescendants.
2668277c790SJohn BaldwinExisting child processes continue to use the reaper assigned when the child
2678277c790SJohn Baldwinwas created via
2688277c790SJohn Baldwin.Xr fork 2 .
2698277c790SJohn BaldwinIf a reaper process exits,
2708277c790SJohn Baldwinall of the processes for whom it was the reaper are reassigned to the reaper
2718277c790SJohn Baldwinprocess's reaper.
2728277c790SJohn Baldwin.Pp
2738269e767SBrooks DavisAfter system initialization,
2748269e767SBrooks Davis.Xr init 8
2758269e767SBrooks Davisis the default reaper.
2768269e767SBrooks Davis.It Dv PROC_REAP_RELEASE
2778277c790SJohn BaldwinDisable orphaned process reaping for the current process.
2788277c790SJohn Baldwin.Pp
2798277c790SJohn BaldwinAny processes for whom the current process was the reaper are reassigned to
2808277c790SJohn Baldwinthe current process's reaper.
2818269e767SBrooks Davis.It Dv PROC_REAP_STATUS
2828277c790SJohn BaldwinProvides a consistent snapshot of information about the reaper
2838277c790SJohn Baldwinof the specified process,
2848277c790SJohn Baldwinor the process itself if it is a reaper.
2858269e767SBrooks DavisThe
2868269e767SBrooks Davis.Fa data
2878269e767SBrooks Davisargument must point to a
2888269e767SBrooks Davis.Vt procctl_reaper_status
2898277c790SJohn Baldwinstructure which is filled in by the system call on successful return.
2908269e767SBrooks Davis.Bd -literal
2918269e767SBrooks Davisstruct procctl_reaper_status {
2928269e767SBrooks Davis	u_int	rs_flags;
2938269e767SBrooks Davis	u_int	rs_children;
2948269e767SBrooks Davis	u_int	rs_descendants;
2958269e767SBrooks Davis	pid_t	rs_reaper;
2968269e767SBrooks Davis	pid_t	rs_pid;
2978269e767SBrooks Davis};
2988269e767SBrooks Davis.Ed
2998277c790SJohn Baldwin.Pp
3008269e767SBrooks DavisThe
3018269e767SBrooks Davis.Fa rs_flags
3028269e767SBrooks Davismay have the following flags returned:
3038277c790SJohn Baldwin.Bl -tag -width Ds
3048269e767SBrooks Davis.It Dv REAPER_STATUS_OWNED
3058277c790SJohn BaldwinThe specified process is a reaper.
3068277c790SJohn BaldwinWhen this flag is returned, the specified process
3078269e767SBrooks Davis.Fa id ,
3088277c790SJohn Baldwinpid, identifies a reaper, otherwise the
3098269e767SBrooks Davis.Fa rs_reaper
3108269e767SBrooks Davisfield of the structure is set to the pid of the reaper
3118269e767SBrooks Davisfor the specified process id.
3128269e767SBrooks Davis.It Dv REAPER_STATUS_REALINIT
3138269e767SBrooks DavisThe specified process is the root of the reaper tree, i.e.,
3148269e767SBrooks Davis.Xr init 8 .
3158269e767SBrooks Davis.El
3168269e767SBrooks Davis.Pp
3178269e767SBrooks DavisThe
3188269e767SBrooks Davis.Fa rs_children
3198277c790SJohn Baldwinfield returns the number of processes that can be reaped by the reaper that
3208277c790SJohn Baldwinare also children of the reaper.
3218269e767SBrooks DavisIt is possible to have a child whose reaper is not the specified process,
3228277c790SJohn Baldwinsince the reaper for existing children is not changed by
3238277c790SJohn Baldwin.Dv PROC_REAP_ACQUIRE .
3248269e767SBrooks DavisThe
3258269e767SBrooks Davis.Fa rs_descendants
3268277c790SJohn Baldwinfield returns the total number of processes that can be reaped by the reaper.
3278269e767SBrooks DavisThe
3288269e767SBrooks Davis.Fa rs_reaper
3298277c790SJohn Baldwinfield returns the reaper's pid.
3308269e767SBrooks DavisThe
3318269e767SBrooks Davis.Fa rs_pid
3328277c790SJohn Baldwinreturns the pid of one reaper child if there are any processes that can be
3338277c790SJohn Baldwinreapead;
3348277c790SJohn Baldwinotherwise, it is set to \-1.
3358269e767SBrooks Davis.It Dv PROC_REAP_GETPIDS
3368277c790SJohn BaldwinQueries the list of processes that can be reaped
3378277c790SJohn Baldwinby the reaper of the specified process.
3388269e767SBrooks DavisThe request takes a pointer to a
3398269e767SBrooks Davis.Vt procctl_reaper_pids
3408269e767SBrooks Davisstructure in the
3418269e767SBrooks Davis.Fa data
3428269e767SBrooks Davisparameter.
3438269e767SBrooks Davis.Bd -literal
3448269e767SBrooks Davisstruct procctl_reaper_pids {
3458269e767SBrooks Davis	u_int	rp_count;
3468269e767SBrooks Davis	struct procctl_reaper_pidinfo *rp_pids;
3478269e767SBrooks Davis};
3488269e767SBrooks Davis.Ed
3498277c790SJohn Baldwin.Pp
3508269e767SBrooks DavisWhen called, the
3518269e767SBrooks Davis.Fa rp_pids
3528269e767SBrooks Davisfield must point to an array of
3538277c790SJohn Baldwin.Fa rp_count
3548269e767SBrooks Davis.Vt procctl_reaper_pidinfo
3558277c790SJohn Baldwinstructures.
3568277c790SJohn BaldwinThe kernel will populate these structures with information about the
3578277c790SJohn Baldwinreaper's descendants.
3588269e767SBrooks Davis.Pp
3598269e767SBrooks DavisThe
3608269e767SBrooks Davis.Vt "struct procctl_reaper_pidinfo"
3618269e767SBrooks Davisstructure provides some information about one of the reaper's descendants.
3628269e767SBrooks DavisNote that for a descendant that is not a child, it may be incorrectly
3638269e767SBrooks Davisidentified because of a race in which the original child process exited
3648269e767SBrooks Davisand the exited process's pid was reused for an unrelated process.
3658269e767SBrooks Davis.Bd -literal
3668269e767SBrooks Davisstruct procctl_reaper_pidinfo {
3678269e767SBrooks Davis	pid_t	pi_pid;
3688269e767SBrooks Davis	pid_t	pi_subtree;
3698269e767SBrooks Davis	u_int	pi_flags;
3708269e767SBrooks Davis};
3718269e767SBrooks Davis.Ed
3728277c790SJohn Baldwin.Pp
3738269e767SBrooks DavisThe
3748269e767SBrooks Davis.Fa pi_pid
3758269e767SBrooks Davisfield is the process id of the descendant.
3768269e767SBrooks DavisThe
3778269e767SBrooks Davis.Fa pi_subtree
3788277c790SJohn Baldwinfield provides the pid of the direct child of the reaper which is
3798277c790SJohn Baldwinthe (grand-)parent of the descendant process.
3808269e767SBrooks DavisThe
3818269e767SBrooks Davis.Fa pi_flags
3828269e767SBrooks Davisfield returns the following flags, further describing the descendant:
3838277c790SJohn Baldwin.Bl -tag -width Ds
3848269e767SBrooks Davis.It Dv REAPER_PIDINFO_VALID
3858269e767SBrooks DavisSet to indicate that the
3868269e767SBrooks Davis.Vt procctl_reaper_pidinfo
3878269e767SBrooks Davisstructure was filled in by the kernel.
3888269e767SBrooks DavisZero-filling the
3898269e767SBrooks Davis.Fa rp_pids
3908269e767SBrooks Davisarray and testing the
3918269e767SBrooks Davis.Dv REAPER_PIDINFO_VALID
3928269e767SBrooks Davisflag allows the caller to detect the end
3938269e767SBrooks Davisof the returned array.
3948269e767SBrooks Davis.It Dv REAPER_PIDINFO_CHILD
3958269e767SBrooks DavisThe
3968269e767SBrooks Davis.Fa pi_pid
3978277c790SJohn Baldwinfield identifies a direct child of the reaper.
3988269e767SBrooks Davis.It Dv REAPER_PIDINFO_REAPER
3998269e767SBrooks DavisThe reported process is itself a reaper.
4008269e767SBrooks DavisThe descendants of the subordinate reaper are not reported.
4018269e767SBrooks Davis.It Dv REAPER_PIDINFO_ZOMBIE
4028269e767SBrooks DavisThe reported process is in the zombie state, ready to be reaped.
4038269e767SBrooks Davis.It Dv REAPER_PIDINFO_STOPPED
4048269e767SBrooks DavisThe reported process is stopped by a SIGSTOP/SIGTSTP signal.
4058269e767SBrooks Davis.It Dv REAPER_PIDINFO_EXITING
4068269e767SBrooks DavisThe reported process is in the process of exiting (but not yet a zombie).
4078269e767SBrooks Davis.El
4088269e767SBrooks Davis.It Dv PROC_REAP_KILL
4098269e767SBrooks DavisRequest to deliver a signal to some subset of the descendants of the reaper.
4108269e767SBrooks DavisThe
4118269e767SBrooks Davis.Fa data
4128269e767SBrooks Davisparameter must point to a
4138269e767SBrooks Davis.Vt procctl_reaper_kill
4148269e767SBrooks Davisstructure, which is used both for parameters and status return.
4158269e767SBrooks Davis.Bd -literal
4168269e767SBrooks Davisstruct procctl_reaper_kill {
4178269e767SBrooks Davis	int	rk_sig;
4188269e767SBrooks Davis	u_int	rk_flags;
4198269e767SBrooks Davis	pid_t	rk_subtree;
4208269e767SBrooks Davis	u_int	rk_killed;
4218269e767SBrooks Davis	pid_t	rk_fpid;
4228269e767SBrooks Davis};
4238269e767SBrooks Davis.Ed
4248277c790SJohn Baldwin.Pp
4258269e767SBrooks DavisThe
4268269e767SBrooks Davis.Fa rk_sig
4278269e767SBrooks Davisfield specifies the signal to be delivered.
4288269e767SBrooks DavisZero is not a valid signal number, unlike for
4298269e767SBrooks Davis.Xr kill 2 .
4308269e767SBrooks DavisThe
4318269e767SBrooks Davis.Fa rk_flags
4328269e767SBrooks Davisfield further directs the operation.
4338269e767SBrooks DavisIt is or-ed from the following flags:
4348277c790SJohn Baldwin.Bl -tag -width Ds
4358269e767SBrooks Davis.It Dv REAPER_KILL_CHILDREN
4368269e767SBrooks DavisDeliver the specified signal only to direct children of the reaper.
4378269e767SBrooks Davis.It Dv REAPER_KILL_SUBTREE
4388269e767SBrooks DavisDeliver the specified signal only to descendants that were forked by
4398269e767SBrooks Davisthe direct child with pid specified in the
4408269e767SBrooks Davis.Fa rk_subtree
4418269e767SBrooks Davisfield.
4428269e767SBrooks Davis.El
4438277c790SJohn Baldwin.Pp
4448269e767SBrooks DavisIf neither the
4458269e767SBrooks Davis.Dv REAPER_KILL_CHILDREN
4468269e767SBrooks Davisnor the
4478269e767SBrooks Davis.Dv REAPER_KILL_SUBTREE
4488269e767SBrooks Davisflags are specified, all current descendants of the reaper are signalled.
4498269e767SBrooks Davis.Pp
4508269e767SBrooks DavisIf a signal was delivered to any process, the return value from the request
4518269e767SBrooks Davisis zero.
4528269e767SBrooks DavisIn this case, the
4538269e767SBrooks Davis.Fa rk_killed
4548269e767SBrooks Davisfield identifies the number of processes signalled.
4558269e767SBrooks DavisThe
4568269e767SBrooks Davis.Fa rk_fpid
4578269e767SBrooks Davisfield is set to the pid of the first process for which signal
4588269e767SBrooks Davisdelivery failed, e.g., due to permission problems.
4598269e767SBrooks DavisIf no such process exists, the
4608269e767SBrooks Davis.Fa rk_fpid
4618277c790SJohn Baldwinfield is set to \-1.
4628269e767SBrooks Davis.It Dv PROC_TRACE_CTL
4638269e767SBrooks DavisEnable or disable tracing of the specified process(es), according to the
4648269e767SBrooks Davisvalue of the integer argument.
4658277c790SJohn BaldwinTracing includes inspecting the process via
4668277c790SJohn Baldwin.Xr ptrace 2 ,
4678269e767SBrooks Davis.Xr ktrace 2 ,
4688269e767SBrooks Davisdebugging sysctls,
4698269e767SBrooks Davis.Xr hwpmc 4 ,
4708277c790SJohn Baldwinor
4718277c790SJohn Baldwin.Xr dtrace 1
4728277c790SJohn Baldwinas well as dumping core.
4738269e767SBrooks DavisPossible values for the
4748269e767SBrooks Davis.Fa data
4758269e767SBrooks Davisargument are:
4768277c790SJohn Baldwin.Bl -tag -width Ds
4778269e767SBrooks Davis.It Dv PROC_TRACE_CTL_ENABLE
4788269e767SBrooks DavisEnable tracing, after it was disabled by
4798269e767SBrooks Davis.Dv PROC_TRACE_CTL_DISABLE .
4808269e767SBrooks DavisOnly allowed for self.
4818269e767SBrooks Davis.It Dv PROC_TRACE_CTL_DISABLE
4828269e767SBrooks DavisDisable tracing for the specified process.
4838269e767SBrooks DavisTracing is re-enabled when the process changes the executing
4848269e767SBrooks Davisprogram with the
4858269e767SBrooks Davis.Xr execve 2
4868277c790SJohn Baldwinsystem call.
4878269e767SBrooks DavisA child inherits the trace settings from the parent on
4888269e767SBrooks Davis.Xr fork 2 .
4898269e767SBrooks Davis.It Dv PROC_TRACE_CTL_DISABLE_EXEC
4908269e767SBrooks DavisSame as
4918269e767SBrooks Davis.Dv PROC_TRACE_CTL_DISABLE ,
4928269e767SBrooks Davisbut the setting persists for the process even after
4938269e767SBrooks Davis.Xr execve 2 .
4948269e767SBrooks Davis.El
4958269e767SBrooks Davis.It Dv PROC_TRACE_STATUS
4968269e767SBrooks DavisReturns the current tracing status for the specified process in
4978269e767SBrooks Davisthe integer variable pointed to by
4988269e767SBrooks Davis.Fa data .
4998269e767SBrooks DavisIf tracing is disabled,
5008269e767SBrooks Davis.Fa data
5018277c790SJohn Baldwinis set to \-1.
5028269e767SBrooks DavisIf tracing is enabled, but no debugger is attached by the
5038269e767SBrooks Davis.Xr ptrace 2
5048277c790SJohn Baldwinsystem call,
5058269e767SBrooks Davis.Fa data
5068269e767SBrooks Davisis set to 0.
5078269e767SBrooks DavisIf a debugger is attached,
5088269e767SBrooks Davis.Fa data
5098269e767SBrooks Davisis set to the pid of the debugger process.
5108269e767SBrooks Davis.It Dv PROC_TRAPCAP_CTL
5118269e767SBrooks DavisControls the capability mode sandbox actions for the specified
5128277c790SJohn Baldwinsandboxed processes
5138277c790SJohn Baldwinon a return from any system call which fails with either an
5148269e767SBrooks Davis.Er ENOTCAPABLE
5158269e767SBrooks Davisor
5168269e767SBrooks Davis.Er ECAPMODE
5178269e767SBrooks Daviserror.
5188277c790SJohn BaldwinIf this control is enabled and a system call fails with one of these errors,
5198277c790SJohn Baldwina synchronous
5208269e767SBrooks Davis.Dv SIGTRAP
5218277c790SJohn Baldwinsignal is delivered to the thread immediately before returning from the
5228277c790SJohn Baldwinsystem call.
5238269e767SBrooks Davis.Pp
5248269e767SBrooks DavisPossible values for the
5258269e767SBrooks Davis.Fa data
5268269e767SBrooks Davisargument are:
5278277c790SJohn Baldwin.Bl -tag -width Ds
5288269e767SBrooks Davis.It Dv PROC_TRAPCAP_CTL_ENABLE
5298277c790SJohn BaldwinEnable
5308269e767SBrooks Davis.Dv SIGTRAP
5318269e767SBrooks Davissignal delivery on capability mode access violations.
5328269e767SBrooks DavisThe enabled mode is inherited by the children of the process,
5338269e767SBrooks Davisand is kept after
5348269e767SBrooks Davis.Xr fexecve 2
5358269e767SBrooks Daviscalls.
5368269e767SBrooks Davis.It Dv PROC_TRAPCAP_CTL_DISABLE
5378277c790SJohn BaldwinDisable
5388277c790SJohn Baldwin.Dv SIGTRAP
5398277c790SJohn Baldwinsignal delivery on capability mode access violations.
5408269e767SBrooks DavisNote that the global sysctl
5418269e767SBrooks Davis.Dv kern.trap_enotcap
5428269e767SBrooks Davismight still cause the signal to be delivered.
5438269e767SBrooks DavisSee
5448269e767SBrooks Davis.Xr capsicum 4 .
5458269e767SBrooks Davis.El
5468269e767SBrooks Davis.Pp
5478269e767SBrooks DavisOn signal delivery, the
5488269e767SBrooks Davis.Va si_errno
5498269e767SBrooks Davismember of the
5508269e767SBrooks Davis.Fa siginfo
5518277c790SJohn Baldwinsignal handler parameter is set to the system call error value,
5528269e767SBrooks Davisand the
5538269e767SBrooks Davis.Va si_code
5548269e767SBrooks Davismember is set to
5558269e767SBrooks Davis.Dv TRAP_CAP .
5568269e767SBrooks DavisThe system call number is stored in the
5578269e767SBrooks Davis.Va si_syscall
5588269e767SBrooks Davisfield of the
5598269e767SBrooks Davis.Fa siginfo
5608269e767SBrooks Davissignal handler parameter.
5618269e767SBrooks DavisThe other system call parameters can be read from the
5628269e767SBrooks Davis.Fa ucontext_t
5638269e767SBrooks Davisbut the system call number is typically stored in the register
5648269e767SBrooks Davisthat also contains the return value and so is unavailable in the
5658269e767SBrooks Davissignal handler.
5668269e767SBrooks Davis.Pp
5678269e767SBrooks DavisSee
5688269e767SBrooks Davis.Xr capsicum 4
5698277c790SJohn Baldwinfor more information about capability mode.
5708269e767SBrooks Davis.It Dv PROC_TRAPCAP_STATUS
5718277c790SJohn BaldwinReturn the current status of raising
5728277c790SJohn Baldwin.Dv SIGTRAP
5738277c790SJohn Baldwinfor capability mode access violations by the specified process.
5748269e767SBrooks DavisThe integer value pointed to by the
5758269e767SBrooks Davis.Fa data
5768269e767SBrooks Davisargument is set to the
5778269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL_ENABLE
5788277c790SJohn Baldwinvalue if
5798277c790SJohn Baldwin.Dv SIGTRAP
5808277c790SJohn Baldwindelivery is enabled, and to
5818269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL_DISABLE
5828269e767SBrooks Davisotherwise.
5838269e767SBrooks Davis.Pp
5848269e767SBrooks DavisSee the note about sysctl
5858269e767SBrooks Davis.Dv kern.trap_enotcap
5868269e767SBrooks Davisabove, which gives independent global control of signal delivery.
5878269e767SBrooks Davis.It Dv PROC_PDEATHSIG_CTL
5888269e767SBrooks DavisRequest the delivery of a signal when the parent of the calling
5898269e767SBrooks Davisprocess exits.
5908269e767SBrooks Davis.Fa idtype
5918269e767SBrooks Davismust be
5928269e767SBrooks Davis.Dv P_PID
5938269e767SBrooks Davisand
5948269e767SBrooks Davis.Fa id
5958269e767SBrooks Davismust be the either caller's pid or zero, with no difference in effect.
5968269e767SBrooks DavisThe value is cleared for child processes
5978269e767SBrooks Davisand when executing set-user-ID or set-group-ID binaries.
5988269e767SBrooks Davis.Fa data
5998269e767SBrooks Davismust point to a value of type
6008269e767SBrooks Davis.Vt int
6018269e767SBrooks Davisindicating the signal
6028269e767SBrooks Davisthat should be delivered to the caller.
6038269e767SBrooks DavisUse zero to cancel a previously requested signal delivery.
6048269e767SBrooks Davis.It Dv PROC_PDEATHSIG_STATUS
6058269e767SBrooks DavisQuery the current signal number that will be delivered when the parent
6068269e767SBrooks Davisof the calling process exits.
6078269e767SBrooks Davis.Fa idtype
6088269e767SBrooks Davismust be
6098269e767SBrooks Davis.Dv P_PID
6108269e767SBrooks Davisand
6118269e767SBrooks Davis.Fa id
6128269e767SBrooks Davismust be the either caller's pid or zero, with no difference in effect.
6138269e767SBrooks Davis.Fa data
6148269e767SBrooks Davismust point to a memory location that can hold a value of type
6158269e767SBrooks Davis.Vt int .
6168269e767SBrooks DavisIf signal delivery has not been requested, it will contain zero
6178269e767SBrooks Davison return.
6188269e767SBrooks Davis.It Dv PROC_STACKGAP_CTL
6198277c790SJohn BaldwinControls stack gaps in the specified process.
6208277c790SJohn BaldwinA stack gap is one or more virtual memory pages at the end of the
6218277c790SJohn Baldwingrowth area for a
6228269e767SBrooks Davis.Dv MAP_STACK
6238277c790SJohn Baldwinmapping that is reserved and never backed by memory.
6248277c790SJohn BaldwinInstead, the process is guaranteed to receive a synchronous
6258269e767SBrooks Davis.Dv SIGSEGV
6268277c790SJohn Baldwinsignal for each access to pages in the gap.
6278277c790SJohn BaldwinThe number of pages reserved for each stack is set by the sysctl
6288277c790SJohn Baldwin.Va security.bsd.stack_guard_page .
6298277c790SJohn Baldwin.Pp
6308277c790SJohn BaldwinGaps protect against stack overflows by preventing them from corrupting memory
6318277c790SJohn Baldwinadjacent to the stack.
6328269e767SBrooks Davis.Pp
6338269e767SBrooks DavisThe
6348269e767SBrooks Davis.Fa data
6358269e767SBrooks Davisargument must point to an integer variable containing flags.
6368269e767SBrooks DavisThe following flags are allowed:
6378277c790SJohn Baldwin.Bl -tag -width Ds
6388269e767SBrooks Davis.It Dv PROC_STACKGAP_ENABLE
6398269e767SBrooks DavisThis flag is only accepted for consistency with
6408269e767SBrooks Davis.Dv PROC_STACKGAP_STATUS .
6418269e767SBrooks DavisIf stack gaps are enabled, the flag is ignored.
6428277c790SJohn BaldwinIf stack gaps are disabled, the request fails with
6438277c790SJohn Baldwin.Ev EINVAL .
6448269e767SBrooks DavisAfter gaps are disabled in a process, they can only be re-enabled when an
6458269e767SBrooks Davis.Xr execve 2
6468269e767SBrooks Davisis performed.
6478269e767SBrooks Davis.It Dv PROC_STACKGAP_DISABLE
6488269e767SBrooks DavisDisable stack gaps for the process.
6498277c790SJohn BaldwinFor existing stacks, the gap is no longer reserved
6508277c790SJohn Baldwinand can be filled by memory on access.
6518269e767SBrooks Davis.It Dv PROC_STACKGAP_ENABLE_EXEC
6528277c790SJohn BaldwinEnable stack gaps for the new address space constructed by any future
6538269e767SBrooks Davis.Xr execve 2
6548277c790SJohn Baldwinin the specified process.
6558269e767SBrooks Davis.It Dv PROC_STACKGAP_DISABLE_EXEC
6568269e767SBrooks DavisInherit disabled stack gaps state after
6578269e767SBrooks Davis.Xr execve 2 .
6588269e767SBrooks DavisIn other words, if the currently executing program has stack gaps disabled,
6598269e767SBrooks Davisthey are kept disabled on exec.
6608269e767SBrooks DavisIf gaps were enabled, they are kept enabled after exec.
6618269e767SBrooks Davis.El
6628269e767SBrooks Davis.Pp
6638269e767SBrooks DavisThe stack gap state is inherited from the parent on
6648269e767SBrooks Davis.Xr fork 2 .
6658269e767SBrooks Davis.It Dv PROC_STACKGAP_STATUS
6668269e767SBrooks DavisReturns the current stack gap state for the specified process.
6678269e767SBrooks Davis.Fa data
6688269e767SBrooks Davismust point to an integer variable, which is used to return a bitmask
6698269e767SBrooks Davisconsisting of the following flags:
6708277c790SJohn Baldwin.Bl -tag -width Ds
6718269e767SBrooks Davis.It Dv PROC_STACKGAP_ENABLE
6728269e767SBrooks DavisStack gaps are enabled.
6738269e767SBrooks Davis.It Dv PROC_STACKGAP_DISABLE
6748269e767SBrooks DavisStack gaps are disabled.
6758269e767SBrooks Davis.It Dv PROC_STACKGAP_ENABLE_EXEC
6768269e767SBrooks DavisStack gaps are enabled in the process after
6778269e767SBrooks Davis.Xr execve 2 .
6788269e767SBrooks Davis.It Dv PROC_STACKGAP_DISABLE_EXEC
6798269e767SBrooks DavisStack gaps are disabled in the process after
6808269e767SBrooks Davis.Xr execve 2 .
6818269e767SBrooks Davis.El
6828277c790SJohn Baldwin.Pp
6838277c790SJohn BaldwinNote that the
6848277c790SJohn Baldwin.Xr elfctl 1
6858277c790SJohn Baldwin.Dq nostackgap
6868277c790SJohn Baldwinflag takes precedence over this setting for individual process address spaces.
6878277c790SJohn BaldwinExecuting a binary with this flag set will never use stack gaps in the address
6888277c790SJohn Baldwinspace constructed by
6898277c790SJohn Baldwin.Xr execve 2 .
6908277c790SJohn BaldwinHowever, the controls value can still be inherited by child processes, and
6918277c790SJohn Baldwinexecuting a binary without this flag set will revert to the behavior specified
6928277c790SJohn Baldwinby the control.
6938269e767SBrooks Davis.It Dv PROC_NO_NEW_PRIVS_CTL
6948277c790SJohn BaldwinAllows one to ignore the set-user-ID and set-group-ID bits on the program
6958269e767SBrooks Davisimages activated by
6968269e767SBrooks Davis.Xr execve 2
6978269e767SBrooks Davisin the specified process and its future descendants.
6988269e767SBrooks DavisThe
6998269e767SBrooks Davis.Fa data
7008277c790SJohn Baldwinparameter must point to an integer variable holding the following
7018269e767SBrooks Davisvalue:
7028277c790SJohn Baldwin.Bl -tag -width Ds
7038269e767SBrooks Davis.It Dv PROC_NO_NEW_PRIVS_ENABLE
7048277c790SJohn BaldwinRequest set-user-ID and set-group-ID bits to be ignored.
7058269e767SBrooks Davis.El
7068269e767SBrooks Davis.Pp
7078277c790SJohn BaldwinIt is not possible to disable this control once it has been enabled.
7088269e767SBrooks Davis.It Dv PROC_NO_NEW_PRIVS_STATUS
7098277c790SJohn BaldwinReturns the current status of set-ID bits enablement for the target process.
7108269e767SBrooks DavisThe
7118269e767SBrooks Davis.Fa data
7128277c790SJohn Baldwinparameter must point to an integer variable, where one of the
7138269e767SBrooks Davisfollowing values is written:
7148277c790SJohn Baldwin.Bl -tag -width Ds
7158269e767SBrooks Davis.It Dv PROC_NO_NEW_PRIVS_ENABLE
7168269e767SBrooks Davis.It Dv PROC_NO_NEW_PRIVS_DISABLE
7178269e767SBrooks Davis.El
7188269e767SBrooks Davis.It Dv PROC_WXMAP_CTL
7198277c790SJohn BaldwinControls the creation of mappings with both write and execute permissions
7208277c790SJohn Baldwinin a process's address space.
7218269e767SBrooks DavisThe
7228269e767SBrooks Davis.Fa data
7238277c790SJohn Baldwinparameter must point to an integer variable holding one of the
7248269e767SBrooks Davisfollowing values:
7258277c790SJohn Baldwin.Bl -tag -width Ds
7268269e767SBrooks Davis.It Dv PROC_WX_MAPPINGS_PERMIT
7278269e767SBrooks DavisEnable creation of mappings that have both write and execute
7288277c790SJohn Baldwinpermissions in the specified process' current and future address spaces.
7298269e767SBrooks Davis.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
7308277c790SJohn BaldwinIn a new address space created by a future call to
7318269e767SBrooks Davis.Xr execve 2 ,
7328269e767SBrooks Davisdisallow creation of mappings that have both write and execute
7338269e767SBrooks Davispermissions.
7348269e767SBrooks Davis.El
7358269e767SBrooks Davis.Pp
7368277c790SJohn BaldwinIf both flags are set,
7378277c790SJohn Baldwin.Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
7388277c790SJohn Baldwintakes precedence during
7398277c790SJohn Baldwin.Xr execve 2 .
7408277c790SJohn BaldwinIf neither flag is set,
7418277c790SJohn Baldwinmappings with write and execute permissions are only permitted if the
7428277c790SJohn Baldwin.Dv kern.elf{32/64}.allow_wx
7438277c790SJohn Baldwinsysctl is non-zero or the
7448277c790SJohn Baldwin.Xr elfctl 1
7458277c790SJohn Baldwin.Dq wxneeded
7468277c790SJohn Baldwinflag is set in the ELF control note.
7478277c790SJohn Baldwin.Pp
7488277c790SJohn BaldwinOnce creation of writeable and executable mappings is enabled for a process,
7498277c790SJohn Baldwinit is impossible (and pointless) to disable it.
7508269e767SBrooks DavisThe only way to ensure the absence of such mappings after they
7518277c790SJohn Baldwinwere enabled in a given process is to set the
7528269e767SBrooks Davis.Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
7538269e767SBrooks Davisflag and
7548269e767SBrooks Davis.Xr execve 2
7558269e767SBrooks Davisan image.
7568269e767SBrooks Davis.It Dv PROC_WXMAP_STATUS
7578277c790SJohn BaldwinReturns the current status of the controls over creation of mappings with
7588277c790SJohn Baldwinboth write and execute permissions for the specified process.
7598269e767SBrooks DavisThe
7608269e767SBrooks Davis.Dv data
7618277c790SJohn Baldwinparameter must point to an integer variable, where one of the
7628269e767SBrooks Davisfollowing values is written:
7638277c790SJohn Baldwin.Bl -tag -width Ds
7648269e767SBrooks Davis.It Dv PROC_WX_MAPPINGS_PERMIT
7658277c790SJohn BaldwinCreation of simultaneously writable and executable mappings are permitted;
7668277c790SJohn Baldwinotherwise, the process cannot create such mappings.
7678269e767SBrooks Davis.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
7688269e767SBrooks DavisAfter
7698269e767SBrooks Davis.Xr execve 2 ,
7708277c790SJohn Baldwinthe new address space will not permit creation of simultaneously
7718269e767SBrooks Daviswritable and executable mappings.
7728269e767SBrooks Davis.El
7738269e767SBrooks Davis.Pp
7748277c790SJohn BaldwinAdditionally, if the address space of the process does not permit
7758269e767SBrooks Daviscreation of simultaneously writable and executable mappings and
7768269e767SBrooks Davisit is guaranteed that no such mapping was created since address space
7778269e767SBrooks Daviscreation, the
7788269e767SBrooks Davis.Dv PROC_WXORX_ENFORCE
7798269e767SBrooks Davisflag is set in the returned value.
7808269e767SBrooks Davis.El
7818269e767SBrooks Davis.Sh x86 MACHINE-SPECIFIC REQUESTS
7828269e767SBrooks Davis.Bl -tag -width PROC_KPTI_STATUS
7838269e767SBrooks Davis.It Dv PROC_KPTI_CTL
7848269e767SBrooks DavisAMD64 only.
7858269e767SBrooks DavisControls the Kernel Page Table Isolation (KPTI) option for the children
7868269e767SBrooks Davisof the specified process.
7878277c790SJohn BaldwinThis control is only meaningful if KPTI has been enabled globally by the
7888269e767SBrooks Davis.Va vm.pmap.kpti
7898277c790SJohn Baldwintunable.
7908269e767SBrooks DavisIt is not possible to change the KPTI setting for a running process,
7918277c790SJohn Baldwinonly for new address spaces constructed by a future
7928277c790SJohn Baldwin.Xr execve 2 .
7938269e767SBrooks Davis.Pp
7948269e767SBrooks DavisThe
7958269e767SBrooks Davis.Fa data
7968269e767SBrooks Davisparameter must point to an integer variable containing one of the
7978269e767SBrooks Davisfollowing commands:
7988277c790SJohn Baldwin.Bl -tag -width Ds
7998269e767SBrooks Davis.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
8008269e767SBrooks DavisEnable KPTI after
8018269e767SBrooks Davis.Xr execve 2 .
8028269e767SBrooks Davis.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
8038269e767SBrooks DavisDisable KPTI after
8048269e767SBrooks Davis.Xr execve 2 .
8058269e767SBrooks DavisOnly root or a process having the
8068269e767SBrooks Davis.Va PRIV_IO
8078277c790SJohn Baldwinprivilege can use this option.
8088269e767SBrooks Davis.El
8098269e767SBrooks Davis.It Dv PROC_KPTI_STATUS
8108269e767SBrooks DavisReturns the current KPTI status for the specified process.
8118269e767SBrooks Davis.Fa data
8128277c790SJohn Baldwinmust point to an integer variable, where one of the
8138277c790SJohn Baldwinfollowing values is written:
8148277c790SJohn Baldwin.Bl -tag -width Ds
8158269e767SBrooks Davis.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
8168269e767SBrooks Davis.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
8178269e767SBrooks Davis.El
8188269e767SBrooks Davis.Pp
8198277c790SJohn BaldwinThe status is or-ed with
8208269e767SBrooks Davis.Va PROC_KPTI_STATUS_ACTIVE
8218277c790SJohn Baldwinif KPTI is active for the current address space of the process.
82265005636SGraham Percival.El
8238269e767SBrooks Davis.Sh NOTES
8248269e767SBrooks DavisDisabling tracing on a process should not be considered a security
8258277c790SJohn Baldwinfeature, as it is bypassable both by the kernel and privileged processes
8268269e767SBrooks Davisand via other system mechanisms.
8278269e767SBrooks DavisAs such, it should not be utilized to reliably protect cryptographic
8288269e767SBrooks Daviskeying material or other confidential data.
8298269e767SBrooks Davis.Pp
8308269e767SBrooks DavisNote that processes can trivially bypass the 'no simultaneously
8318269e767SBrooks Daviswritable and executable mappings' policy by first marking some mapping
8328277c790SJohn Baldwinas writeable, writing code to it, then removing write and adding
8338269e767SBrooks Davisexecute permission.
8348277c790SJohn BaldwinThis may be legitimately required by some programs such as JIT compilers.
8358269e767SBrooks Davis.Sh RETURN VALUES
8368277c790SJohn BaldwinIf an error occurs, a value of \-1 is returned and
8378269e767SBrooks Davis.Va errno
8388269e767SBrooks Davisis set to indicate the error.
8398269e767SBrooks Davis.Sh ERRORS
8408269e767SBrooks DavisThe
8418269e767SBrooks Davis.Fn procctl
8428269e767SBrooks Davissystem call
8438269e767SBrooks Daviswill fail if:
8448269e767SBrooks Davis.Bl -tag -width Er
8458269e767SBrooks Davis.It Bq Er EFAULT
8468269e767SBrooks DavisThe
8478269e767SBrooks Davis.Fa data
8488269e767SBrooks Davisparameter points outside the process's allocated address space.
8498269e767SBrooks Davis.It Bq Er EINVAL
8508269e767SBrooks DavisThe
8518269e767SBrooks Davis.Fa cmd
8528269e767SBrooks Davisargument specifies an unsupported command.
8538269e767SBrooks Davis.Pp
8548269e767SBrooks DavisThe
8558269e767SBrooks Davis.Fa idtype
8568269e767SBrooks Davisargument specifies an unsupported identifier type.
8578269e767SBrooks Davis.It Bq Er EPERM
8588269e767SBrooks DavisThe calling process does not have permission to perform the requested
8598269e767SBrooks Davisoperation on any of the selected processes.
8608269e767SBrooks Davis.It Bq Er ESRCH
8618269e767SBrooks DavisNo processes matched the requested
8628269e767SBrooks Davis.Fa idtype
8638269e767SBrooks Davisand
8648269e767SBrooks Davis.Fa id .
865e3ebc5f5SGleb Popov.It Bq Er ESRCH
866e3ebc5f5SGleb PopovNo descendant processes can be found matching criteria specified in the
867e3ebc5f5SGleb Popov.Dv PROC_REAP_KILL
868e3ebc5f5SGleb Popovrequest.
8698269e767SBrooks Davis.It Bq Er EINVAL
8708269e767SBrooks DavisAn invalid operation or flag was passed in
8718269e767SBrooks Davis.Fa data
8728269e767SBrooks Davisfor a
8738269e767SBrooks Davis.Dv PROC_SPROTECT
8748269e767SBrooks Daviscommand.
8758269e767SBrooks Davis.It Bq Er EPERM
8768269e767SBrooks DavisThe
8778269e767SBrooks Davis.Fa idtype
8788269e767SBrooks Davisargument is not equal to
8798269e767SBrooks Davis.Dv P_PID ,
8808269e767SBrooks Davisor
8818269e767SBrooks Davis.Fa id
8828269e767SBrooks Davisis not equal to the pid of the calling process, for
8838269e767SBrooks Davis.Dv PROC_REAP_ACQUIRE
8848269e767SBrooks Davisor
8858269e767SBrooks Davis.Dv PROC_REAP_RELEASE
8868269e767SBrooks Davisrequests.
8878269e767SBrooks Davis.It Bq Er EINVAL
8888269e767SBrooks DavisInvalid or undefined flags were passed to a
8898269e767SBrooks Davis.Dv PROC_REAP_KILL
8908269e767SBrooks Davisrequest.
8918269e767SBrooks Davis.It Bq Er EINVAL
8928269e767SBrooks DavisAn invalid or zero signal number was requested for a
8938269e767SBrooks Davis.Dv PROC_REAP_KILL
8948269e767SBrooks Davisrequest.
8958269e767SBrooks Davis.It Bq Er EINVAL
8968277c790SJohn BaldwinA
8978269e767SBrooks Davis.Dv PROC_REAP_RELEASE
8988269e767SBrooks Davisrequest was issued by the
8998269e767SBrooks Davis.Xr init 8
9008269e767SBrooks Davisprocess.
9018269e767SBrooks Davis.It Bq Er EBUSY
9028277c790SJohn BaldwinA
9038269e767SBrooks Davis.Dv PROC_REAP_ACQUIRE
9048277c790SJohn Baldwinrequest was issued by a process that is already a reaper process.
9058269e767SBrooks Davis.It Bq Er EBUSY
9068277c790SJohn BaldwinA
9078269e767SBrooks Davis.Dv PROC_TRACE_CTL
9088277c790SJohn Baldwinrequest was issued for a process being traced.
9098269e767SBrooks Davis.It Bq Er EPERM
9108277c790SJohn BaldwinA
9118269e767SBrooks Davis.Dv PROC_TRACE_CTL
9128269e767SBrooks Davisrequest to re-enable tracing of the process
9138269e767SBrooks Davis.Po Dv PROC_TRACE_CTL_ENABLE Pc ,
9148269e767SBrooks Davisor to disable persistence of
9158269e767SBrooks Davis.Dv PROC_TRACE_CTL_DISABLE
9168269e767SBrooks Davison
9178269e767SBrooks Davis.Xr execve 2
9188277c790SJohn Baldwinspecified a target process other than the calling process.
9198269e767SBrooks Davis.It Bq Er EINVAL
9208269e767SBrooks DavisThe value of the integer
9218269e767SBrooks Davis.Fa data
9228269e767SBrooks Davisparameter for the
9238269e767SBrooks Davis.Dv PROC_TRACE_CTL
9248269e767SBrooks Davisor
9258269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL
9268269e767SBrooks Davisrequest is invalid.
9278269e767SBrooks Davis.It Bq Er EINVAL
9288269e767SBrooks DavisThe
9298269e767SBrooks Davis.Dv PROC_PDEATHSIG_CTL
9308269e767SBrooks Davisor
9318269e767SBrooks Davis.Dv PROC_PDEATHSIG_STATUS
9328269e767SBrooks Davisrequest referenced an unsupported
9338269e767SBrooks Davis.Fa id ,
9348269e767SBrooks Davis.Fa idtype
9358269e767SBrooks Davisor invalid signal number.
9368269e767SBrooks Davis.El
9378269e767SBrooks Davis.Sh SEE ALSO
9388269e767SBrooks Davis.Xr dtrace 1 ,
9398277c790SJohn Baldwin.Xr elfctl 1 ,
9408269e767SBrooks Davis.Xr proccontrol 1 ,
9418269e767SBrooks Davis.Xr protect 1 ,
9428269e767SBrooks Davis.Xr cap_enter 2 ,
9438269e767SBrooks Davis.Xr kill 2 ,
9448269e767SBrooks Davis.Xr ktrace 2 ,
9458269e767SBrooks Davis.Xr mmap 2 ,
9468269e767SBrooks Davis.Xr mprotect 2 ,
9478269e767SBrooks Davis.Xr ptrace 2 ,
9488269e767SBrooks Davis.Xr wait 2 ,
9498269e767SBrooks Davis.Xr capsicum 4 ,
9508269e767SBrooks Davis.Xr hwpmc 4 ,
9518269e767SBrooks Davis.Xr init 8
9528269e767SBrooks Davis.Sh HISTORY
9538269e767SBrooks DavisThe
9548269e767SBrooks Davis.Fn procctl
9558269e767SBrooks Davisfunction appeared in
9563dd24879SDavid E. O'Brien.Fx 9.3 .
9578269e767SBrooks Davis.Pp
9588277c790SJohn BaldwinThe reaper facility is based on a similar feature in Linux and
9598269e767SBrooks DavisDragonflyBSD, and first appeared in
9608269e767SBrooks Davis.Fx 10.2 .
9618269e767SBrooks Davis.Pp
9628269e767SBrooks DavisThe
9638269e767SBrooks Davis.Dv PROC_PDEATHSIG_CTL
9648277c790SJohn Baldwinfacility is based on the
9658277c790SJohn Baldwin.Ql prctl(PR_SET_PDEATHSIG, ...)
9668277c790SJohn Baldwinfeature in Linux,
9678269e767SBrooks Davisand first appeared in
9688269e767SBrooks Davis.Fx 11.2 .
9698269e767SBrooks Davis.Pp
9708277c790SJohn BaldwinASLR support was added for checklist compliance in
9718269e767SBrooks Davis.Fx 13.0 .
972