xref: /freebsd-14.2/lib/libc/sys/procctl.2 (revision 22dca7ac)
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 April 15, 2023
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_EXITING
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.It Dv REAPER_PIDINFO_ZOMBIE
324The reported process is in the zombie state, ready to be reaped.
325.It Dv REAPER_PIDINFO_STOPPED
326The reported process is stopped by a SIGSTOP/SIGTSTP signal.
327.It Dv REAPER_PIDINFO_EXITING
328The reported process is in the process of exiting (but not yet a zombie).
329.El
330.It Dv PROC_REAP_KILL
331Request to deliver a signal to some subset of the descendants of the reaper.
332The
333.Fa data
334parameter must point to a
335.Vt procctl_reaper_kill
336structure, which is used both for parameters and status return.
337.Bd -literal
338struct procctl_reaper_kill {
339	int	rk_sig;
340	u_int	rk_flags;
341	pid_t	rk_subtree;
342	u_int	rk_killed;
343	pid_t	rk_fpid;
344};
345.Ed
346The
347.Fa rk_sig
348field specifies the signal to be delivered.
349Zero is not a valid signal number, unlike for
350.Xr kill 2 .
351The
352.Fa rk_flags
353field further directs the operation.
354It is or-ed from the following flags:
355.Bl -tag -width REAPER_KILL_CHILDREN
356.It Dv REAPER_KILL_CHILDREN
357Deliver the specified signal only to direct children of the reaper.
358.It Dv REAPER_KILL_SUBTREE
359Deliver the specified signal only to descendants that were forked by
360the direct child with pid specified in the
361.Fa rk_subtree
362field.
363.El
364If neither the
365.Dv REAPER_KILL_CHILDREN
366nor the
367.Dv REAPER_KILL_SUBTREE
368flags are specified, all current descendants of the reaper are signalled.
369.Pp
370If a signal was delivered to any process, the return value from the request
371is zero.
372In this case, the
373.Fa rk_killed
374field identifies the number of processes signalled.
375The
376.Fa rk_fpid
377field is set to the pid of the first process for which signal
378delivery failed, e.g., due to permission problems.
379If no such process exists, the
380.Fa rk_fpid
381field is set to -1.
382.It Dv PROC_TRACE_CTL
383Enable or disable tracing of the specified process(es), according to the
384value of the integer argument.
385Tracing includes attachment to the process using the
386.Xr ptrace 2
387and
388.Xr ktrace 2 ,
389debugging sysctls,
390.Xr hwpmc 4 ,
391.Xr dtrace 1 ,
392and core dumping.
393Possible values for the
394.Fa data
395argument are:
396.Bl -tag -width PROC_TRACE_CTL_DISABLE_EXEC
397.It Dv PROC_TRACE_CTL_ENABLE
398Enable tracing, after it was disabled by
399.Dv PROC_TRACE_CTL_DISABLE .
400Only allowed for self.
401.It Dv PROC_TRACE_CTL_DISABLE
402Disable tracing for the specified process.
403Tracing is re-enabled when the process changes the executing
404program with the
405.Xr execve 2
406syscall.
407A child inherits the trace settings from the parent on
408.Xr fork 2 .
409.It Dv PROC_TRACE_CTL_DISABLE_EXEC
410Same as
411.Dv PROC_TRACE_CTL_DISABLE ,
412but the setting persists for the process even after
413.Xr execve 2 .
414.El
415.It Dv PROC_TRACE_STATUS
416Returns the current tracing status for the specified process in
417the integer variable pointed to by
418.Fa data .
419If tracing is disabled,
420.Fa data
421is set to -1.
422If tracing is enabled, but no debugger is attached by the
423.Xr ptrace 2
424syscall,
425.Fa data
426is set to 0.
427If a debugger is attached,
428.Fa data
429is set to the pid of the debugger process.
430.It Dv PROC_TRAPCAP_CTL
431Controls the capability mode sandbox actions for the specified
432sandboxed processes,
433on a return from any syscall which gives either a
434.Er ENOTCAPABLE
435or
436.Er ECAPMODE
437error.
438If the control is enabled, such errors from the syscalls cause
439delivery of the synchronous
440.Dv SIGTRAP
441signal to the thread immediately before returning from the syscalls.
442.Pp
443Possible values for the
444.Fa data
445argument are:
446.Bl -tag -width PROC_TRAPCAP_CTL_DISABLE
447.It Dv PROC_TRAPCAP_CTL_ENABLE
448Enable the
449.Dv SIGTRAP
450signal delivery on capability mode access violations.
451The enabled mode is inherited by the children of the process,
452and is kept after
453.Xr fexecve 2
454calls.
455.It Dv PROC_TRAPCAP_CTL_DISABLE
456Disable the signal delivery on capability mode access violations.
457Note that the global sysctl
458.Dv kern.trap_enotcap
459might still cause the signal to be delivered.
460See
461.Xr capsicum 4 .
462.El
463.Pp
464On signal delivery, the
465.Va si_errno
466member of the
467.Fa siginfo
468signal handler parameter is set to the syscall error value,
469and the
470.Va si_code
471member is set to
472.Dv TRAP_CAP .
473The system call number is stored in the
474.Va si_syscall
475field of the
476.Fa siginfo
477signal handler parameter.
478The other system call parameters can be read from the
479.Fa ucontext_t
480but the system call number is typically stored in the register
481that also contains the return value and so is unavailable in the
482signal handler.
483.Pp
484See
485.Xr capsicum 4
486for more information about the capability mode.
487.It Dv PROC_TRAPCAP_STATUS
488Return the current status of signalling capability mode access
489violations for the specified process.
490The integer value pointed to by the
491.Fa data
492argument is set to the
493.Dv PROC_TRAPCAP_CTL_ENABLE
494value if the process control enables signal delivery, and to
495.Dv PROC_TRAPCAP_CTL_DISABLE
496otherwise.
497.Pp
498See the note about sysctl
499.Dv kern.trap_enotcap
500above, which gives independent global control of signal delivery.
501.It Dv PROC_PDEATHSIG_CTL
502Request the delivery of a signal when the parent of the calling
503process exits.
504.Fa idtype
505must be
506.Dv P_PID
507and
508.Fa id
509must be the either caller's pid or zero, with no difference in effect.
510The value is cleared for child processes
511and when executing set-user-ID or set-group-ID binaries.
512.Fa data
513must point to a value of type
514.Vt int
515indicating the signal
516that should be delivered to the caller.
517Use zero to cancel a previously requested signal delivery.
518.It Dv PROC_PDEATHSIG_STATUS
519Query the current signal number that will be delivered when the parent
520of the calling process exits.
521.Fa idtype
522must be
523.Dv P_PID
524and
525.Fa id
526must be the either caller's pid or zero, with no difference in effect.
527.Fa data
528must point to a memory location that can hold a value of type
529.Vt int .
530If signal delivery has not been requested, it will contain zero
531on return.
532.It Dv PROC_STACKGAP_CTL
533Controls the stack gaps in the specified process.
534A stack gap is the part of the growth area for a
535.Dv MAP_STACK
536mapped region that is reserved and never filled by memory.
537Instead, the process is guaranteed to receive a
538.Dv SIGSEGV
539signal on accessing pages in the gap.
540Gaps protect against stack overflow corrupting memory adjacent
541to the stack.
542.Pp
543The
544.Fa data
545argument must point to an integer variable containing flags.
546The following flags are allowed:
547.Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
548.It Dv PROC_STACKGAP_ENABLE
549This flag is only accepted for consistency with
550.Dv PROC_STACKGAP_STATUS .
551If stack gaps are enabled, the flag is ignored.
552If disabled, the flag causes an
553.Ev EINVAL
554error to be returned.
555After gaps are disabled in a process, they can only be re-enabled when an
556.Xr execve 2
557is performed.
558.It Dv PROC_STACKGAP_DISABLE
559Disable stack gaps for the process.
560For existing stacks, the gap is no longer a reserved part of the growth
561area and can be filled by memory on access.
562.It Dv PROC_STACKGAP_ENABLE_EXEC
563Enable stack gaps for programs started after an
564.Xr execve 2
565by the specified process.
566.It Dv PROC_STACKGAP_DISABLE_EXEC
567Inherit disabled stack gaps state after
568.Xr execve 2 .
569In other words, if the currently executing program has stack gaps disabled,
570they are kept disabled on exec.
571If gaps were enabled, they are kept enabled after exec.
572.El
573.Pp
574The stack gap state is inherited from the parent on
575.Xr fork 2 .
576.It Dv PROC_STACKGAP_STATUS
577Returns the current stack gap state for the specified process.
578.Fa data
579must point to an integer variable, which is used to return a bitmask
580consisting of the following flags:
581.Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
582.It Dv PROC_STACKGAP_ENABLE
583Stack gaps are enabled.
584.It Dv PROC_STACKGAP_DISABLE
585Stack gaps are disabled.
586.It Dv PROC_STACKGAP_ENABLE_EXEC
587Stack gaps are enabled in the process after
588.Xr execve 2 .
589.It Dv PROC_STACKGAP_DISABLE_EXEC
590Stack gaps are disabled in the process after
591.Xr execve 2 .
592.El
593.It Dv PROC_NO_NEW_PRIVS_CTL
594Allows one to ignore the SUID and SGID bits on the program
595images activated by
596.Xr execve 2
597in the specified process and its future descendants.
598The
599.Fa data
600parameter must point to the integer variable holding the following
601value:
602.Bl -tag -width PROC_NO_NEW_PRIVS_ENABLE
603.It Dv PROC_NO_NEW_PRIVS_ENABLE
604Request SUID and SGID bits to be ignored.
605.El
606.Pp
607It is not possible to disable it once it has been enabled.
608.It Dv PROC_NO_NEW_PRIVS_STATUS
609Returns the current status of SUID/SGID enablement for the target process.
610The
611.Fa data
612parameter must point to the integer variable, where one of the
613following values is written:
614.Bl -tag -width PROC_NO_NEW_PRIVS_DISABLE
615.It Dv PROC_NO_NEW_PRIVS_ENABLE
616.It Dv PROC_NO_NEW_PRIVS_DISABLE
617.El
618.It Dv PROC_WXMAP_CTL
619Controls the 'write exclusive against execution' permissions for the
620mappings in the process address space.
621It overrides the global settings established by the
622.Dv kern.elf{32/64}.allow_wx
623sysctl,
624and the corresponding bit in the ELF control note, see
625.Xr elfctl 1 .
626.Pp
627The
628.Fa data
629parameter must point to the integer variable holding one of the
630following values:
631.Bl -tag -width PROC_WX_MAPPINGS_DISALLOW_EXEC
632.It Dv PROC_WX_MAPPINGS_PERMIT
633Enable creation of mappings that have both write and execute
634protection attributes, in the specified process' address space.
635.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
636In the new address space created by
637.Xr execve 2 ,
638disallow creation of mappings that have both write and execute
639permissions.
640.El
641.Pp
642Once creation of writeable and executable mappings is allowed,
643it is impossible (and pointless) to disallow it.
644The only way to ensure the absence of such mappings after they
645were enabled in a given process, is to set the
646.Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
647flag and
648.Xr execve 2
649an image.
650.It Dv PROC_WXMAP_STATUS
651Returns the current status of the 'write exclusive against execution'
652enforcement for the specified process.
653The
654.Dv data
655parameter must point to the integer variable, where one of the
656following values is written:
657.Bl -tag -width PROC_WX_MAPPINGS_DISALLOW_EXEC
658.It Dv PROC_WX_MAPPINGS_PERMIT
659Creation of simultaneously writable and executable mapping is permitted,
660otherwise the process cannot create such mappings.
661.It Dv PROC_WX_MAPPINGS_DISALLOW_EXEC
662After
663.Xr execve 2 ,
664the new address space should disallow creation of simultaneously
665writable and executable mappings.
666.El
667.Pp
668Additionally, if the address space of the process disallows
669creation of simultaneously writable and executable mappings and
670it is guaranteed that no such mapping was created since address space
671creation, the
672.Dv PROC_WXORX_ENFORCE
673flag is set in the returned value.
674.El
675.Sh x86 MACHINE-SPECIFIC REQUESTS
676.Bl -tag -width PROC_KPTI_STATUS
677.It Dv PROC_KPTI_CTL
678AMD64 only.
679Controls the Kernel Page Table Isolation (KPTI) option for the children
680of the specified process.
681For the command to work, the
682.Va vm.pmap.kpti
683tunable must be enabled on boot.
684It is not possible to change the KPTI setting for a running process,
685except at the
686.Xr execve 2 ,
687where the address space is reinitialized.
688.Pp
689The
690.Fa data
691parameter must point to an integer variable containing one of the
692following commands:
693.Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
694.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
695Enable KPTI after
696.Xr execve 2 .
697.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
698Disable KPTI after
699.Xr execve 2 .
700Only root or a process having the
701.Va PRIV_IO
702privilege might use this option.
703.El
704.It Dv PROC_KPTI_STATUS
705Returns the current KPTI status for the specified process.
706.Fa data
707must point to the integer variable, which returns the
708following statuses:
709.Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
710.It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
711.It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
712.El
713.Pp
714The status is or-ed with the
715.Va PROC_KPTI_STATUS_ACTIVE
716in case KPTI is active for the current address space of the process.
717.Sh NOTES
718Disabling tracing on a process should not be considered a security
719feature, as it is bypassable both by the kernel and privileged processes,
720and via other system mechanisms.
721As such, it should not be utilized to reliably protect cryptographic
722keying material or other confidential data.
723.Pp
724Note that processes can trivially bypass the 'no simultaneously
725writable and executable mappings' policy by first marking some mapping
726as writeable and write code to it, then removing write and adding
727execute permission.
728This may be legitimately required by some programs, such as JIT compilers.
729.Sh RETURN VALUES
730If an error occurs, a value of -1 is returned and
731.Va errno
732is set to indicate the error.
733.Sh ERRORS
734The
735.Fn procctl
736system call
737will fail if:
738.Bl -tag -width Er
739.It Bq Er EFAULT
740The
741.Fa data
742parameter points outside the process's allocated address space.
743.It Bq Er EINVAL
744The
745.Fa cmd
746argument specifies an unsupported command.
747.Pp
748The
749.Fa idtype
750argument specifies an unsupported identifier type.
751.It Bq Er EPERM
752The calling process does not have permission to perform the requested
753operation on any of the selected processes.
754.It Bq Er ESRCH
755No processes matched the requested
756.Fa idtype
757and
758.Fa id .
759.It Bq Er EINVAL
760An invalid operation or flag was passed in
761.Fa data
762for a
763.Dv PROC_SPROTECT
764command.
765.It Bq Er EPERM
766The
767.Fa idtype
768argument is not equal to
769.Dv P_PID ,
770or
771.Fa id
772is not equal to the pid of the calling process, for
773.Dv PROC_REAP_ACQUIRE
774or
775.Dv PROC_REAP_RELEASE
776requests.
777.It Bq Er EINVAL
778Invalid or undefined flags were passed to a
779.Dv PROC_REAP_KILL
780request.
781.It Bq Er EINVAL
782An invalid or zero signal number was requested for a
783.Dv PROC_REAP_KILL
784request.
785.It Bq Er EINVAL
786The
787.Dv PROC_REAP_RELEASE
788request was issued by the
789.Xr init 8
790process.
791.It Bq Er EBUSY
792The
793.Dv PROC_REAP_ACQUIRE
794request was issued by a process that had already acquired reaper status
795and has not yet released it.
796.It Bq Er EBUSY
797The
798.Dv PROC_TRACE_CTL
799request was issued for a process already being traced.
800.It Bq Er EPERM
801The
802.Dv PROC_TRACE_CTL
803request to re-enable tracing of the process
804.Po Dv PROC_TRACE_CTL_ENABLE Pc ,
805or to disable persistence of
806.Dv PROC_TRACE_CTL_DISABLE
807on
808.Xr execve 2
809was issued for a non-current process.
810.It Bq Er EINVAL
811The value of the integer
812.Fa data
813parameter for the
814.Dv PROC_TRACE_CTL
815or
816.Dv PROC_TRAPCAP_CTL
817request is invalid.
818.It Bq Er EINVAL
819The
820.Dv PROC_PDEATHSIG_CTL
821or
822.Dv PROC_PDEATHSIG_STATUS
823request referenced an unsupported
824.Fa id ,
825.Fa idtype
826or invalid signal number.
827.El
828.Sh SEE ALSO
829.Xr dtrace 1 ,
830.Xr proccontrol 1 ,
831.Xr protect 1 ,
832.Xr cap_enter 2 ,
833.Xr kill 2 ,
834.Xr ktrace 2 ,
835.Xr mmap 2 ,
836.Xr mprotect 2 ,
837.Xr ptrace 2 ,
838.Xr wait 2 ,
839.Xr capsicum 4 ,
840.Xr hwpmc 4 ,
841.Xr init 8
842.Sh HISTORY
843The
844.Fn procctl
845function appeared in
846.Fx 10.0 .
847.Pp
848The reaper facility is based on a similar feature of Linux and
849DragonflyBSD, and first appeared in
850.Fx 10.2 .
851.Pp
852The
853.Dv PROC_PDEATHSIG_CTL
854facility is based on the prctl(PR_SET_PDEATHSIG, ...) feature of Linux,
855and first appeared in
856.Fx 11.2 .
857.Pp
858The ASLR support was added to system for the checklists compliance in
859.Fx 13.0 .
860