xref: /freebsd-13.1/lib/libc/sys/procctl.2 (revision c802b970)
1.\" Copyright (c) 2013 Hudson River Trading LLC
2.\" Written by: John H. Baldwin <[email protected]>
3.\" All rights reserved.
4.\"
5.\" Copyright (c) 2014 The FreeBSD Foundation
6.\" Portions of this documentation were written by Konstantin Belousov
7.\" under sponsorship from the FreeBSD Foundation.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $FreeBSD$
31.\"
32.Dd September 2, 2021
33.Dt PROCCTL 2
34.Os
35.Sh NAME
36.Nm procctl
37.Nd control processes
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In sys/procctl.h
42.Ft int
43.Fn procctl "idtype_t idtype" "id_t id" "int cmd" "void *data"
44.Sh DESCRIPTION
45The
46.Fn procctl
47system call provides for control over processes.
48The
49.Fa idtype
50and
51.Fa id
52arguments specify the set of processes to control.
53If multiple processes match the identifier,
54.Nm
55will make a
56.Dq best effort
57to control as many of the selected processes as possible.
58An error is only returned if no selected processes successfully complete
59the request.
60The following identifier types are supported:
61.Bl -tag -width P_PGID
62.It Dv P_PID
63Control the process with the process ID
64.Fa id .
65.Fa id
66zero is a shortcut for the calling process ID.
67.It Dv P_PGID
68Control processes belonging to the process group with the ID
69.Fa id .
70.El
71.Pp
72The control request to perform is specified by the
73.Fa cmd
74argument.
75.Pp
76All status changing requests
77.Dv *_CTL
78require the caller to have the right to debug the target.
79All status query requests
80.DV *_STATUS
81require the caller to have the right to observe the target.
82.Pp
83The following commands are supported:
84.Bl -tag -width PROC_TRAPCAP_STATUS
85.It Dv PROC_ASLR_CTL
86Controls the Address Space Layout Randomization (ASLR) in the program
87images created
88by
89.Xr execve 2
90in the specified process or its descendants that did not changed
91the control nor modified it by other means.
92The
93.Fa data
94parameter must point to the integer variable holding one of the following
95values:
96.Bl -tag -width PROC_ASLR_FORCE_DISABLE
97.It Dv PROC_ASLR_FORCE_ENABLE
98Request that ASLR is enabled after execution, even if it is disabled
99system-wide.
100The image flag and set-uid might prevent ASLR enablement still.
101.It Dv PROC_ASLR_FORCE_DISABLE
102Request that ASLR is disabled after execution.
103Same notes as for
104.Dv PROC_ASLR_FORCE_ENABLE
105apply.
106.It Dv PROC_ASLR_NOFORCE
107Use the system-wide configured policy for ASLR.
108.El
109.It Dv PROC_ASLR_STATUS
110Returns the current status of ASLR enablement for the target process.
111The
112.Fa data
113parameter must point to the integer variable, where one of the
114following values is written:
115.Bl -tag -width PROC_ASLR_FORCE_DISABLE
116.It Dv PROC_ASLR_FORCE_ENABLE
117.It Dv PROC_ASLR_FORCE_DISABLE
118.It Dv PROC_ASLR_NOFORCE
119.El
120.Pp
121If the currently executed image in the process itself has ASLR enabled,
122the
123.Dv PROC_ASLR_ACTIVE
124flag is or-ed with the value listed above.
125.It Dv PROC_PROTMAX_CTL
126Controls implicit application of PROT_MAX protection equal to the
127.Fa prot
128argument of the
129.Xr mmap 2
130syscall, in the target process.
131The
132.Fa data
133parameter must point to the integer variable holding one of the following
134values:
135.Bl -tag -width PROC_PROTMAX_FORCE_DISABLE
136.It Dv PROC_PROTMAX_FORCE_ENABLE
137Enables implicit PROT_MAX application,
138even if it is disabled system-wide by the sysctl
139.Va vm.imply_prot_max .
140The image flag might still prevent the enablement.
141.It Dv PROC_PROTMAX_FORCE_DISABLE
142Request that implicit application of PROT_MAX be disabled.
143Same notes as for
144.Dv PROC_PROTMAX_FORCE_ENABLE
145apply.
146.It Dv PROC_PROTMAX_NOFORCE
147Use the system-wide configured policy for PROT_MAX.
148.El
149.It Dv PROC_PROTMAX_STATUS
150Returns the current status of implicit PROT_MAX enablement for the
151target process.
152The
153.Fa data
154parameter must point to the integer variable, where one of the
155following values is written:
156.Bl -tag -width PROC_PROTMAX_FORCE_DISABLE
157.It Dv PROC_PROTMAX_FORCE_ENABLE
158.It Dv PROC_PROTMAX_FORCE_DISABLE
159.It Dv PROC_PROTMAX_NOFORCE
160.El
161.Pp
162If the currently executed image in the process itself has implicit PROT_MAX
163application enabled, the
164.Dv PROC_PROTMAX_ACTIVE
165flag is or-ed with the value listed above.
166.It Dv PROC_SPROTECT
167Set process protection state.
168This is used to mark a process as protected from being killed if the system
169exhausts the available memory and swap.
170The
171.Fa data
172parameter must point to an integer containing an operation and zero or more
173optional flags.
174The following operations are supported:
175.Bl -tag -width PPROT_CLEAR
176.It Dv PPROT_SET
177Mark the selected processes as protected.
178.It Dv PPROT_CLEAR
179Clear the protected state of selected processes.
180.El
181.Pp
182The following optional flags are supported:
183.Bl -tag -width PPROT_DESCEND
184.It Dv PPROT_DESCEND
185Apply the requested operation to all child processes of each selected process
186in addition to each selected process.
187.It Dv PPROT_INHERIT
188When used with
189.Dv PPROT_SET ,
190mark all future child processes of each selected process as protected.
191Future child processes will also mark all of their future child processes.
192.El
193.It Dv PROC_REAP_ACQUIRE
194Acquires the reaper status for the current process.
195Reaper status means that children orphaned by the reaper's descendants
196that were forked after the acquisition of reaper status are reparented to the
197reaper process.
198After system initialization,
199.Xr init 8
200is the default reaper.
201.It Dv PROC_REAP_RELEASE
202Release the reaper state for the current process.
203The reaper of the current process becomes the new reaper of the
204current process's descendants.
205.It Dv PROC_REAP_STATUS
206Provides information about the reaper of the specified process,
207or the process itself when it is a reaper.
208The
209.Fa data
210argument must point to a
211.Vt procctl_reaper_status
212structure which is filled in by the syscall on successful return.
213.Bd -literal
214struct procctl_reaper_status {
215	u_int	rs_flags;
216	u_int	rs_children;
217	u_int	rs_descendants;
218	pid_t	rs_reaper;
219	pid_t	rs_pid;
220};
221.Ed
222The
223.Fa rs_flags
224may have the following flags returned:
225.Bl -tag -width REAPER_STATUS_REALINIT
226.It Dv REAPER_STATUS_OWNED
227The specified process has acquired reaper status and has not
228released it.
229When the flag is returned, the specified process
230.Fa id ,
231pid, identifies the reaper, otherwise the
232.Fa rs_reaper
233field of the structure is set to the pid of the reaper
234for the specified process id.
235.It Dv REAPER_STATUS_REALINIT
236The specified process is the root of the reaper tree, i.e.,
237.Xr init 8 .
238.El
239.Pp
240The
241.Fa rs_children
242field returns the number of children of the reaper among the descendants.
243It is possible to have a child whose reaper is not the specified process,
244since the reaper for any existing children is not reset on the
245.Dv PROC_REAP_ACQUIRE
246operation.
247The
248.Fa rs_descendants
249field returns the total number of descendants of the reaper(s),
250not counting descendants of the reaper in the subtree.
251The
252.Fa rs_reaper
253field returns the reaper pid.
254The
255.Fa rs_pid
256returns the pid of one reaper child if there are any descendants.
257.It Dv PROC_REAP_GETPIDS
258Queries the list of descendants of the reaper of the specified process.
259The request takes a pointer to a
260.Vt procctl_reaper_pids
261structure in the
262.Fa data
263parameter.
264.Bd -literal
265struct procctl_reaper_pids {
266	u_int	rp_count;
267	struct procctl_reaper_pidinfo *rp_pids;
268};
269.Ed
270When called, the
271.Fa rp_pids
272field must point to an array of
273.Vt procctl_reaper_pidinfo
274structures, to be filled in on return,
275and the
276.Fa rp_count
277field must specify the size of the array,
278into which no more than
279.Fa rp_count
280elements will be filled in by the kernel.
281.Pp
282The
283.Vt "struct procctl_reaper_pidinfo"
284structure provides some information about one of the reaper's descendants.
285Note that for a descendant that is not a child, it may be incorrectly
286identified because of a race in which the original child process exited
287and the exited process's pid was reused for an unrelated process.
288.Bd -literal
289struct procctl_reaper_pidinfo {
290	pid_t	pi_pid;
291	pid_t	pi_subtree;
292	u_int	pi_flags;
293};
294.Ed
295The
296.Fa pi_pid
297field is the process id of the descendant.
298The
299.Fa pi_subtree
300field provides the pid of the child of the reaper, which is the (grand-)parent
301of the process.
302The
303.Fa pi_flags
304field returns the following flags, further describing the descendant:
305.Bl -tag -width REAPER_PIDINFO_REAPER
306.It Dv REAPER_PIDINFO_VALID
307Set to indicate that the
308.Vt procctl_reaper_pidinfo
309structure was filled in by the kernel.
310Zero-filling the
311.Fa rp_pids
312array and testing the
313.Dv REAPER_PIDINFO_VALID
314flag allows the caller to detect the end
315of the returned array.
316.It Dv REAPER_PIDINFO_CHILD
317The
318.Fa pi_pid
319field identifies the direct child of the reaper.
320.It Dv REAPER_PIDINFO_REAPER
321The reported process is itself a reaper.
322The descendants of the subordinate reaper are not reported.
323.El
324.It Dv PROC_REAP_KILL
325Request to deliver a signal to some subset of the descendants of the reaper.
326The
327.Fa data
328parameter must point to a
329.Vt procctl_reaper_kill
330structure, which is used both for parameters and status return.
331.Bd -literal
332struct procctl_reaper_kill {
333	int	rk_sig;
334	u_int	rk_flags;
335	pid_t	rk_subtree;
336	u_int	rk_killed;
337	pid_t	rk_fpid;
338};
339.Ed
340The
341.Fa rk_sig
342field specifies the signal to be delivered.
343Zero is not a valid signal number, unlike for
344.Xr kill 2 .
345The
346.Fa rk_flags
347field further directs the operation.
348It is or-ed from the following flags:
349.Bl -tag -width REAPER_KILL_CHILDREN
350.It Dv REAPER_KILL_CHILDREN
351Deliver the specified signal only to direct children of the reaper.
352.It Dv REAPER_KILL_SUBTREE
353Deliver the specified signal only to descendants that were forked by
354the direct child with pid specified in the
355.Fa rk_subtree
356field.
357.El
358If neither the
359.Dv REAPER_KILL_CHILDREN
360nor the
361.Dv REAPER_KILL_SUBTREE
362flags are specified, all current descendants of the reaper are signalled.
363.Pp
364If a signal was delivered to any process, the return value from the request
365is zero.
366In this case, the
367.Fa rk_killed
368field identifies the number of processes signalled.
369The
370.Fa rk_fpid
371field is set to the pid of the first process for which signal
372delivery failed, e.g., due to permission problems.
373If no such process exists, the
374.Fa rk_fpid
375field is set to -1.
376.It Dv PROC_TRACE_CTL
377Enable or disable tracing of the specified process(es), according to the
378value of the integer argument.
379Tracing includes attachment to the process using the
380.Xr ptrace 2
381and
382.Xr ktrace 2 ,
383debugging sysctls,
384.Xr hwpmc 4 ,
385.Xr dtrace 1 ,
386and core dumping.
387Possible values for the
388.Fa data
389argument are:
390.Bl -tag -width PROC_TRACE_CTL_DISABLE_EXEC
391.It Dv PROC_TRACE_CTL_ENABLE
392Enable tracing, after it was disabled by
393.Dv PROC_TRACE_CTL_DISABLE .
394Only allowed for self.
395.It Dv PROC_TRACE_CTL_DISABLE
396Disable tracing for the specified process.
397Tracing is re-enabled when the process changes the executing
398program with the
399.Xr execve 2
400syscall.
401A child inherits the trace settings from the parent on
402.Xr fork 2 .
403.It Dv PROC_TRACE_CTL_DISABLE_EXEC
404Same as
405.Dv PROC_TRACE_CTL_DISABLE ,
406but the setting persists for the process even after
407.Xr execve 2 .
408.El
409.It Dv PROC_TRACE_STATUS
410Returns the current tracing status for the specified process in
411the integer variable pointed to by
412.Fa data .
413If tracing is disabled,
414.Fa data
415is set to -1.
416If tracing is enabled, but no debugger is attached by the
417.Xr ptrace 2
418syscall,
419.Fa data
420is set to 0.
421If a debugger is attached,
422.Fa data
423is set to the pid of the debugger process.
424.It Dv PROC_TRAPCAP_CTL
425Controls the capability mode sandbox actions for the specified
426sandboxed processes,
427on a return from any syscall which gives either a
428.Er ENOTCAPABLE
429or
430.Er ECAPMODE
431error.
432If the control is enabled, such errors from the syscalls cause
433delivery of the synchronous
434.Dv SIGTRAP
435signal to the thread immediately before returning from the syscalls.
436.Pp
437Possible values for the
438.Fa data
439argument are:
440.Bl -tag -width PROC_TRAPCAP_CTL_DISABLE
441.It Dv PROC_TRAPCAP_CTL_ENABLE
442Enable the
443.Dv SIGTRAP
444signal delivery on capability mode access violations.
445The enabled mode is inherited by the children of the process,
446and is kept after
447.Xr fexecve 2
448calls.
449.It Dv PROC_TRAPCAP_CTL_DISABLE
450Disable the signal delivery on capability mode access violations.
451Note that the global sysctl
452.Dv kern.trap_enotcap
453might still cause the signal to be delivered.
454See
455.Xr capsicum 4 .
456.El
457.Pp
458On signal delivery, the
459.Va si_errno
460member of the
461.Fa siginfo
462signal handler parameter is set to the syscall error value,
463and the
464.Va si_code
465member is set to
466.Dv TRAP_CAP .
467.Pp
468See
469.Xr capsicum 4
470for more information about the capability mode.
471.It Dv PROC_TRAPCAP_STATUS
472Return the current status of signalling capability mode access
473violations for the specified process.
474The integer value pointed to by the
475.Fa data
476argument is set to the
477.Dv PROC_TRAPCAP_CTL_ENABLE
478value if the process control enables signal delivery, and to
479.Dv PROC_TRAPCAP_CTL_DISABLE
480otherwise.
481.Pp
482See the note about sysctl
483.Dv kern.trap_enotcap
484above, which gives independent global control of signal delivery.
485.It Dv PROC_PDEATHSIG_CTL
486Request the delivery of a signal when the parent of the calling
487process exits.
488.Fa idtype
489must be
490.Dv P_PID
491and
492.Fa id
493must be the either caller's pid or zero, with no difference in effect.
494The value is cleared for child processes
495and when executing set-user-ID or set-group-ID binaries.
496.Fa data
497must point to a value of type
498.Vt int
499indicating the signal
500that should be delivered to the caller.
501Use zero to cancel a previously requested signal delivery.
502.It Dv PROC_PDEATHSIG_STATUS
503Query the current signal number that will be delivered when the parent
504of the calling process exits.
505.Fa idtype
506must be
507.Dv P_PID
508and
509.Fa id
510must be the either caller's pid or zero, with no difference in effect.
511.Fa data
512must point to a memory location that can hold a value of type
513.Vt int .
514If signal delivery has not been requested, it will contain zero
515on return.
516.It Dv PROC_STACKGAP_CTL
517Controls the stack gaps in the specified process.
518A stack gap is the part of the growth area for a
519.Dv MAP_STACK
520mapped region that is reserved and never filled by memory.
521Instead, the process is guaranteed to receive a
522.Dv SIGSEGV
523signal on accessing pages in the gap.
524Gaps protect against stack overflow corrupting memory adjacent
525to the stack.
526.Pp
527The
528.Fa data
529argument must point to an integer variable containing flags.
530The following flags are allowed:
531.Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
532.It Dv PROC_STACKGAP_ENABLE
533This flag is only accepted for consistency with
534.Dv PROC_STACKGAP_STATUS .
535If stack gaps are enabled, the flag is ignored.
536If disabled, the flag causes an
537.Ev EINVAL
538error to be returned.
539After gaps are disabled in a process, they can only be re-enabled when an
540.Xr execve 2
541is performed.
542.It Dv PROC_STACKGAP_DISABLE
543Disable stack gaps for the process.
544For existing stacks, the gap is no longer a reserved part of the growth
545area and can be filled by memory on access.
546.It Dv PROC_STACKGAP_ENABLE_EXEC
547Enable stack gaps for programs started after an
548.Xr execve 2
549by the specified process.
550.It Dv PROC_STACKGAP_DISABLE_EXEC
551Inherit disabled stack gaps state after
552.Xr execve 2 .
553In other words, if the currently executing program has stack gaps disabled,
554they are kept disabled on exec.
555If gaps were enabled, they are kept enabled after exec.
556.El
557.Pp
558The stack gap state is inherited from the parent on
559.Xr fork 2 .
560.It Dv PROC_STACKGAP_STATUS
561Returns the current stack gap state for the specified process.
562.Fa data
563must point to an integer variable, which is used to return a bitmask
564consisting of the following flags:
565.Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
566.It Dv PROC_STACKGAP_ENABLE
567Stack gaps are enabled.
568.It Dv PROC_STACKGAP_DISABLE
569Stack gaps are disabled.
570.It Dv PROC_STACKGAP_ENABLE_EXEC
571Stack gaps are enabled in the process after
572.Xr execve 2 .
573.It Dv PROC_STACKGAP_DISABLE_EXEC
574Stack gaps are disabled in the process after
575.Xr execve 2 .
576.El
577.It Dv PROC_NO_NEW_PRIVS_CTL
578Allows one to ignore the SUID and SGID bits on the program
579images activated by
580.Xr execve 2
581in the specified process and its future descendants.
582The
583.Fa data
584parameter must point to the integer variable holding the following
585value:
586.Bl -tag -width PROC_NO_NEW_PRIVS_ENABLE
587.It Dv PROC_NO_NEW_PRIVS_ENABLE
588Request SUID and SGID bits to be ignored.
589.El
590.Pp
591It is not possible to disable it once it has been enabled.
592.It Dv PROC_NO_NEW_PRIVS_STATUS
593Returns the current status of SUID/SGID enablement for the target process.
594The
595.Fa data
596parameter must point to the integer variable, where one of the
597following values is written:
598.Bl -tag -width PROC_NO_NEW_PRIVS_DISABLE
599.It Dv PROC_NO_NEW_PRIVS_ENABLE
600.It Dv PROC_NO_NEW_PRIVS_DISABLE
601.El
602.It Dv PROC_WXMAP_CTL
603Controls the 'write exclusive against execution' permissions for the
604mappings in the process address space.
605It overrides the global settings established by the
606.Dv kern.elf{32/64}.allow_wx
607sysctl,
608and the corresponding bit in the ELF control note, see
609.Xr elfctl 1 .
610.Pp
611The
612.Fa data
613parameter must point to the integer variable holding one of the
614following values:
615.Bl -tag -width PROC_WX_MAPPINGS_DISALLOW_EXEC
616.It Dv PROC_WX_MAPPINGS_PERMIT
617Enable creation of mappings that have both write and execute
618protection attributes, in the specified process' address space.
619.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
620In the new address space created by
621.Xr execve 2 ,
622disallow creation of mappings that have both write and execute
623permissions.
624.El
625.Pp
626Once creation of writeable and executable mappings is allowed,
627it is impossible (and pointless) to disallow it.
628The only way to ensure the absence of such mappings after they
629were enabled in a given process, is to set the
630.Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
631flag and
632.Xr execve 2
633an image.
634.It Dv PROC_WXMAP_STATUS
635Returns the current status of the 'write exclusive against execution'
636enforcement for the specified process.
637The
638.Dv data
639parameter must point to the integer variable, where one of the
640following values is written:
641.Bl -tag -width PROC_WX_MAPPINGS_DISALLOW_EXEC
642.It Dv PROC_WX_MAPPINGS_PERMIT
643Creation of simultaneously writable and executable mapping is permitted,
644otherwise the process cannot create such mappings.
645.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
646After
647.Xr execve 2 ,
648the new address space should disallow creation of simultaneously
649writable and executable mappings.
650.El
651.Pp
652Additionally, if the address space of the process disallows
653creation of simultaneously writable and executable mappings and
654it is guaranteed that no such mapping was created since address space
655creation, the
656.Dv PROC_WXORX_ENFORCE
657flag is set in the returned value.
658.El
659.Sh x86 MACHINE-SPECIFIC REQUESTS
660.Bl -tag -width PROC_KPTI_STATUS
661.It Dv PROC_KPTI_CTL
662AMD64 only.
663Controls the Kernel Page Table Isolation (KPTI) option for the children
664of the specified process.
665For the command to work, the
666.Va vm.pmap.kpti
667tunable must be enabled on boot.
668It is not possible to change the KPTI setting for a running process,
669except at the
670.Xr execve 2 ,
671where the address space is reinitialized.
672.Pp
673The
674.Fa data
675parameter must point to an integer variable containing one of the
676following commands:
677.Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
678.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
679Enable KPTI after
680.Xr execve 2 .
681.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
682Disable KPTI after
683.Xr execve 2 .
684Only root or a process having the
685.Va PRIV_IO
686privilege might use this option.
687.El
688.It Dv PROC_KPTI_STATUS
689Returns the current KPTI status for the specified process.
690.Fa data
691must point to the integer variable, which returns the
692following statuses:
693.Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
694.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
695.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
696.El
697.Pp
698The status is or-ed with the
699.Va PROC_KPTI_STATUS_ACTIVE
700in case KPTI is active for the current address space of the process.
701.Sh NOTES
702Disabling tracing on a process should not be considered a security
703feature, as it is bypassable both by the kernel and privileged processes,
704and via other system mechanisms.
705As such, it should not be utilized to reliably protect cryptographic
706keying material or other confidential data.
707.Pp
708Note that processes can trivially bypass the 'no simultaneously
709writable and executable mappings' policy by first marking some mapping
710as writeable and write code to it, then removing write and adding
711execute permission.
712This may be legitimately required by some programs, such as JIT compilers.
713.Sh RETURN VALUES
714If an error occurs, a value of -1 is returned and
715.Va errno
716is set to indicate the error.
717.Sh ERRORS
718The
719.Fn procctl
720system call
721will fail if:
722.Bl -tag -width Er
723.It Bq Er EFAULT
724The
725.Fa data
726parameter points outside the process's allocated address space.
727.It Bq Er EINVAL
728The
729.Fa cmd
730argument specifies an unsupported command.
731.Pp
732The
733.Fa idtype
734argument specifies an unsupported identifier type.
735.It Bq Er EPERM
736The calling process does not have permission to perform the requested
737operation on any of the selected processes.
738.It Bq Er ESRCH
739No processes matched the requested
740.Fa idtype
741and
742.Fa id .
743.It Bq Er EINVAL
744An invalid operation or flag was passed in
745.Fa data
746for a
747.Dv PROC_SPROTECT
748command.
749.It Bq Er EPERM
750The
751.Fa idtype
752argument is not equal to
753.Dv P_PID ,
754or
755.Fa id
756is not equal to the pid of the calling process, for
757.Dv PROC_REAP_ACQUIRE
758or
759.Dv PROC_REAP_RELEASE
760requests.
761.It Bq Er EINVAL
762Invalid or undefined flags were passed to a
763.Dv PROC_REAP_KILL
764request.
765.It Bq Er EINVAL
766An invalid or zero signal number was requested for a
767.Dv PROC_REAP_KILL
768request.
769.It Bq Er EINVAL
770The
771.Dv PROC_REAP_RELEASE
772request was issued by the
773.Xr init 8
774process.
775.It Bq Er EBUSY
776The
777.Dv PROC_REAP_ACQUIRE
778request was issued by a process that had already acquired reaper status
779and has not yet released it.
780.It Bq Er EBUSY
781The
782.Dv PROC_TRACE_CTL
783request was issued for a process already being traced.
784.It Bq Er EPERM
785The
786.Dv PROC_TRACE_CTL
787request to re-enable tracing of the process
788.Po Dv PROC_TRACE_CTL_ENABLE Pc ,
789or to disable persistence of
790.Dv PROC_TRACE_CTL_DISABLE
791on
792.Xr execve 2
793was issued for a non-current process.
794.It Bq Er EINVAL
795The value of the integer
796.Fa data
797parameter for the
798.Dv PROC_TRACE_CTL
799or
800.Dv PROC_TRAPCAP_CTL
801request is invalid.
802.It Bq Er EINVAL
803The
804.Dv PROC_PDEATHSIG_CTL
805or
806.Dv PROC_PDEATHSIG_STATUS
807request referenced an unsupported
808.Fa id ,
809.Fa idtype
810or invalid signal number.
811.El
812.Sh SEE ALSO
813.Xr dtrace 1 ,
814.Xr proccontrol 1 ,
815.Xr protect 1 ,
816.Xr cap_enter 2 ,
817.Xr kill 2 ,
818.Xr ktrace 2 ,
819.Xr mmap 2 ,
820.Xr mprotect 2 ,
821.Xr ptrace 2 ,
822.Xr wait 2 ,
823.Xr capsicum 4 ,
824.Xr hwpmc 4 ,
825.Xr init 8
826.Sh HISTORY
827The
828.Fn procctl
829function appeared in
830.Fx 10.0 .
831.Pp
832The reaper facility is based on a similar feature of Linux and
833DragonflyBSD, and first appeared in
834.Fx 10.2 .
835.Pp
836The
837.Dv PROC_PDEATHSIG_CTL
838facility is based on the prctl(PR_SET_PDEATHSIG, ...) feature of Linux,
839and first appeared in
840.Fx 11.2 .
841.Pp
842The ASLR support was added to system for the checklists compliance in
843.Fx 13.0 .
844