1 .\" Copyright (c) 2013 Hudson River Trading LLC
2 .\" Written by: John H. Baldwin <jhb@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Copyright (c) 2014 The FreeBSD Foundation
6 .\" Portions of this documentation were written by Konstantin Belousov
7 .\" under sponsorship from the FreeBSD Foundation.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
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
43 .Fn procctl "idtype_t idtype" "id_t id" "int cmd" "void *data"
47 system call provides for control over processes.
52 arguments specify the set of processes to control.
53 If multiple processes match the identifier,
57 to control as many of the selected processes as possible.
58 An error is only returned if no selected processes successfully complete
60 The following identifier types are supported:
61 .Bl -tag -width P_PGID
63 Control the process with the process ID
66 Control processes belonging to the process group with the ID
70 The control request to perform is specified by the
73 The following commands are supported:
74 .Bl -tag -width PROC_TRAPCAP_STATUS
76 Controls the Address Space Layout Randomization (ASLR) in the program
80 in the specified process or its descendants that did not changed
81 the control nor modified it by other means.
84 parameter must point to the integer variable holding one of the following
86 .Bl -tag -width PROC_ASLR_FORCE_DISABLE
87 .It Dv PROC_ASLR_FORCE_ENABLE
88 Request that ASLR is enabled after execution, even if it is disabled
90 The image flag and set-uid might prevent ASLR enablement still.
91 .It Dv PROC_ASLR_FORCE_DISABLE
92 Request that ASLR is disabled after execution.
94 .Dv PROC_ASLR_FORCE_ENABLE
96 .It Dv PROC_ASLR_NOFORCE
97 Use the system-wide configured policy for ASLR.
99 .It Dv PROC_ASLR_STATUS
100 Returns the current status of ASLR enablement for the target process.
103 parameter must point to the integer variable, where one of the
104 following values is written:
105 .Bl -tag -width PROC_ASLR_FORCE_DISABLE
106 .It Dv PROC_ASLR_FORCE_ENABLE
107 .It Dv PROC_ASLR_FORCE_DISABLE
108 .It Dv PROC_ASLR_NOFORCE
111 If the currently executed image in the process itself has ASLR enabled,
114 flag is or-ed with the value listed above.
115 .It Dv PROC_PROTMAX_CTL
116 Controls implicit application of PROT_MAX protection equal to the
120 syscall, in the target process.
123 parameter must point to the integer variable holding one of the following
125 .Bl -tag -width PROC_PROTMAX_FORCE_DISABLE
126 .It Dv PROC_PROTMAX_FORCE_ENABLE
127 Enables implicit PROT_MAX application,
128 even if it is disabled system-wide by the sysctl
129 .Va vm.imply_prot_max .
130 The image flag might still prevent the enablement.
131 .It Dv PROC_PROTMAX_FORCE_DISABLE
132 Request that implicit application of PROT_MAX be disabled.
134 .Dv PROC_PROTMAX_FORCE_ENABLE
136 .It Dv PROC_PROTMAX_NOFORCE
137 Use the system-wide configured policy for PROT_MAX.
139 .It Dv PROC_PROTMAX_STATUS
140 Returns the current status of implicit PROT_MAX enablement for the
144 parameter must point to the integer variable, where one of the
145 following values is written:
146 .Bl -tag -width PROC_PROTMAX_FORCE_DISABLE
147 .It Dv PROC_PROTMAX_FORCE_ENABLE
148 .It Dv PROC_PROTMAX_FORCE_DISABLE
149 .It Dv PROC_PROTMAX_NOFORCE
152 If the currently executed image in the process itself has implicit PROT_MAX
153 application enabled, the
154 .Dv PROC_PROTMAX_ACTIVE
155 flag is or-ed with the value listed above.
157 Set process protection state.
158 This is used to mark a process as protected from being killed if the system
159 exhausts the available memory and swap.
162 parameter must point to an integer containing an operation and zero or more
164 The following operations are supported:
165 .Bl -tag -width PPROT_CLEAR
167 Mark the selected processes as protected.
169 Clear the protected state of selected processes.
172 The following optional flags are supported:
173 .Bl -tag -width PPROT_DESCEND
175 Apply the requested operation to all child processes of each selected process
176 in addition to each selected process.
180 mark all future child processes of each selected process as protected.
181 Future child processes will also mark all of their future child processes.
183 .It Dv PROC_REAP_ACQUIRE
184 Acquires the reaper status for the current process.
185 Reaper status means that children orphaned by the reaper's descendants
186 that were forked after the acquisition of reaper status are reparented to the
188 After system initialization,
190 is the default reaper.
191 .It Dv PROC_REAP_RELEASE
192 Release the reaper state for the current process.
193 The reaper of the current process becomes the new reaper of the
194 current process's descendants.
195 .It Dv PROC_REAP_STATUS
196 Provides information about the reaper of the specified process,
197 or the process itself when it is a reaper.
200 argument must point to a
201 .Vt procctl_reaper_status
202 structure which is filled in by the syscall on successful return.
204 struct procctl_reaper_status {
207 u_int rs_descendants;
214 may have the following flags returned:
215 .Bl -tag -width REAPER_STATUS_REALINIT
216 .It Dv REAPER_STATUS_OWNED
217 The specified process has acquired reaper status and has not
219 When the flag is returned, the specified process
221 pid, identifies the reaper, otherwise the
223 field of the structure is set to the pid of the reaper
224 for the specified process id.
225 .It Dv REAPER_STATUS_REALINIT
226 The specified process is the root of the reaper tree, i.e.,
232 field returns the number of children of the reaper among the descendants.
233 It is possible to have a child whose reaper is not the specified process,
234 since the reaper for any existing children is not reset on the
235 .Dv PROC_REAP_ACQUIRE
239 field returns the total number of descendants of the reaper(s),
240 not counting descendants of the reaper in the subtree.
243 field returns the reaper pid.
246 returns the pid of one reaper child if there are any descendants.
247 .It Dv PROC_REAP_GETPIDS
248 Queries the list of descendants of the reaper of the specified process.
249 The request takes a pointer to a
250 .Vt procctl_reaper_pids
255 struct procctl_reaper_pids {
257 struct procctl_reaper_pidinfo *rp_pids;
262 field must point to an array of
263 .Vt procctl_reaper_pidinfo
264 structures, to be filled in on return,
267 field must specify the size of the array,
268 into which no more than
270 elements will be filled in by the kernel.
273 .Vt "struct procctl_reaper_pidinfo"
274 structure provides some information about one of the reaper's descendants.
275 Note that for a descendant that is not a child, it may be incorrectly
276 identified because of a race in which the original child process exited
277 and the exited process's pid was reused for an unrelated process.
279 struct procctl_reaper_pidinfo {
287 field is the process id of the descendant.
290 field provides the pid of the child of the reaper, which is the (grand-)parent
294 field returns the following flags, further describing the descendant:
295 .Bl -tag -width REAPER_PIDINFO_REAPER
296 .It Dv REAPER_PIDINFO_VALID
297 Set to indicate that the
298 .Vt procctl_reaper_pidinfo
299 structure was filled in by the kernel.
302 array and testing the
303 .Dv REAPER_PIDINFO_VALID
304 flag allows the caller to detect the end
305 of the returned array.
306 .It Dv REAPER_PIDINFO_CHILD
309 field identifies the direct child of the reaper.
310 .It Dv REAPER_PIDINFO_REAPER
311 The reported process is itself a reaper.
312 The descendants of the subordinate reaper are not reported.
314 .It Dv PROC_REAP_KILL
315 Request to deliver a signal to some subset of the descendants of the reaper.
318 parameter must point to a
319 .Vt procctl_reaper_kill
320 structure, which is used both for parameters and status return.
322 struct procctl_reaper_kill {
332 field specifies the signal to be delivered.
333 Zero is not a valid signal number, unlike for
337 field further directs the operation.
338 It is or-ed from the following flags:
339 .Bl -tag -width REAPER_KILL_CHILDREN
340 .It Dv REAPER_KILL_CHILDREN
341 Deliver the specified signal only to direct children of the reaper.
342 .It Dv REAPER_KILL_SUBTREE
343 Deliver the specified signal only to descendants that were forked by
344 the direct child with pid specified in the
349 .Dv REAPER_KILL_CHILDREN
351 .Dv REAPER_KILL_SUBTREE
352 flags are specified, all current descendants of the reaper are signalled.
354 If a signal was delivered to any process, the return value from the request
358 field identifies the number of processes signalled.
361 field is set to the pid of the first process for which signal
362 delivery failed, e.g., due to permission problems.
363 If no such process exists, the
366 .It Dv PROC_TRACE_CTL
367 Enable or disable tracing of the specified process(es), according to the
368 value of the integer argument.
369 Tracing includes attachment to the process using the
377 Possible values for the
380 .Bl -tag -width PROC_TRACE_CTL_DISABLE_EXEC
381 .It Dv PROC_TRACE_CTL_ENABLE
382 Enable tracing, after it was disabled by
383 .Dv PROC_TRACE_CTL_DISABLE .
384 Only allowed for self.
385 .It Dv PROC_TRACE_CTL_DISABLE
386 Disable tracing for the specified process.
387 Tracing is re-enabled when the process changes the executing
391 A child inherits the trace settings from the parent on
393 .It Dv PROC_TRACE_CTL_DISABLE_EXEC
395 .Dv PROC_TRACE_CTL_DISABLE ,
396 but the setting persists for the process even after
399 .It Dv PROC_TRACE_STATUS
400 Returns the current tracing status for the specified process in
401 the integer variable pointed to by
403 If tracing is disabled,
406 If tracing is enabled, but no debugger is attached by the
411 If a debugger is attached,
413 is set to the pid of the debugger process.
414 .It Dv PROC_TRAPCAP_CTL
415 Controls the capability mode sandbox actions for the specified
417 on a return from any syscall which gives either a
422 If the control is enabled, such errors from the syscalls cause
423 delivery of the synchronous
425 signal to the thread immediately before returning from the syscalls.
427 Possible values for the
430 .Bl -tag -width PROC_TRAPCAP_CTL_DISABLE
431 .It Dv PROC_TRAPCAP_CTL_ENABLE
434 signal delivery on capability mode access violations.
435 The enabled mode is inherited by the children of the process,
439 .It Dv PROC_TRAPCAP_CTL_DISABLE
440 Disable the signal delivery on capability mode access violations.
441 Note that the global sysctl
442 .Dv kern.trap_enotcap
443 might still cause the signal to be delivered.
448 On signal delivery, the
452 signal handler parameter is set to the syscall error value,
460 for more information about the capability mode.
461 .It Dv PROC_TRAPCAP_STATUS
462 Return the current status of signalling capability mode access
463 violations for the specified process.
464 The integer value pointed to by the
466 argument is set to the
467 .Dv PROC_TRAPCAP_CTL_ENABLE
468 value if the process control enables signal delivery, and to
469 .Dv PROC_TRAPCAP_CTL_DISABLE
472 See the note about sysctl
473 .Dv kern.trap_enotcap
474 above, which gives independent global control of signal delivery.
475 .It Dv PROC_PDEATHSIG_CTL
476 Request the delivery of a signal when the parent of the calling
483 must be the either caller's pid or zero, with no difference in effect.
484 The value is cleared for child processes
485 and when executing set-user-ID or set-group-ID binaries.
487 must point to a value of type
489 indicating the signal
490 that should be delivered to the caller.
491 Use zero to cancel a previously requested signal delivery.
492 .It Dv PROC_PDEATHSIG_STATUS
493 Query the current signal number that will be delivered when the parent
494 of the calling process exits.
500 must be the either caller's pid or zero, with no difference in effect.
502 must point to a memory location that can hold a value of type
504 If signal delivery has not been requested, it will contain zero
506 .It Dv PROC_STACKGAP_CTL
507 Controls the stack gaps in the specified process.
508 A stack gap is the part of the growth area for a
510 mapped region that is reserved and never filled by memory.
511 Instead, the process is guaranteed to receive a
513 signal on accessing pages in the gap.
514 Gaps protect against stack overflow corrupting memory adjacent
519 argument must point to an integer variable containing flags.
520 The following flags are allowed:
521 .Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
522 .It Dv PROC_STACKGAP_ENABLE
523 This flag is only accepted for consistency with
524 .Dv PROC_STACKGAP_STATUS .
525 If stack gaps are enabled, the flag is ignored.
526 If disabled, the flag causes an
528 error to be returned.
529 After gaps are disabled in a process, they can only be re-enabled when an
532 .It Dv PROC_STACKGAP_DISABLE
533 Disable stack gaps for the process.
534 For existing stacks, the gap is no longer a reserved part of the growth
535 area and can be filled by memory on access.
536 .It Dv PROC_STACKGAP_ENABLE_EXEC
537 Enable stack gaps for programs started after an
539 by the specified process.
540 .It Dv PROC_STACKGAP_DISABLE_EXEC
541 Inherit disabled stack gaps state after
543 In other words, if the currently executing program has stack gaps disabled,
544 they are kept disabled on exec.
545 If gaps were enabled, they are kept enabled after exec.
548 The stack gap state is inherited from the parent on
550 .It Dv PROC_STACKGAP_STATUS
551 Returns the current stack gap state for the specified process.
553 must point to an integer variable, which is used to return a bitmask
554 consisting of the following flags:
555 .Bl -tag -width PROC_STACKGAP_DISABLE_EXEC
556 .It Dv PROC_STACKGAP_ENABLE
557 Stack gaps are enabled.
558 .It Dv PROC_STACKGAP_DISABLE
559 Stack gaps are disabled.
560 .It Dv PROC_STACKGAP_ENABLE_EXEC
561 Stack gaps are enabled in the process after
563 .It Dv PROC_STACKGAP_DISABLE_EXEC
564 Stack gaps are disabled in the process after
568 .Sh x86 MACHINE-SPECIFIC REQUESTS
569 .Bl -tag -width PROC_KPTI_STATUS
572 Controls the Kernel Page Table Isolation (KPTI) option for the children
573 of the specified process.
574 For the command to work, the
576 tunable must be enabled on boot.
577 It is not possible to change the KPTI setting for a running process,
580 where the address space is reinitialized.
584 parameter must point to an integer variable containing one of the
586 .Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
587 .It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
590 .It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
593 Only root or a process having the
595 privilege might use this option.
597 .It Dv PROC_KPTI_STATUS
598 Returns the current KPTI status for the specified process.
600 must point to the integer variable, which returns the
602 .Bl -tag -width PROC_KPTI_CTL_DISABLE_ON_EXEC
603 .It Dv PROC_KPTI_CTL_ENABLE_ON_EXEC
604 .It Dv PROC_KPTI_CTL_DISABLE_ON_EXEC
607 The status is or-ed with the
608 .Va PROC_KPTI_STATUS_ACTIVE
609 in case KPTI is active for the current address space of the process.
611 Disabling tracing on a process should not be considered a security
612 feature, as it is bypassable both by the kernel and privileged processes,
613 and via other system mechanisms.
614 As such, it should not be utilized to reliably protect cryptographic
615 keying material or other confidential data.
617 If an error occurs, a value of -1 is returned and
619 is set to indicate the error.
629 parameter points outside the process's allocated address space.
633 argument specifies an unsupported command.
637 argument specifies an unsupported identifier type.
639 The calling process does not have permission to perform the requested
640 operation on any of the selected processes.
642 No processes matched the requested
647 An invalid operation or flag was passed in
655 argument is not equal to
659 is not equal to the pid of the calling process, for
660 .Dv PROC_REAP_ACQUIRE
662 .Dv PROC_REAP_RELEASE
665 Invalid or undefined flags were passed to a
669 An invalid or zero signal number was requested for a
674 .Dv PROC_REAP_RELEASE
675 request was issued by the
680 .Dv PROC_REAP_ACQUIRE
681 request was issued by a process that had already acquired reaper status
682 and has not yet released it.
686 request was issued for a process already being traced.
690 request to re-enable tracing of the process
691 .Po Dv PROC_TRACE_CTL_ENABLE Pc ,
692 or to disable persistence of
693 .Dv PROC_TRACE_CTL_DISABLE
696 was issued for a non-current process.
698 The value of the integer
707 .Dv PROC_PDEATHSIG_CTL
709 .Dv PROC_PDEATHSIG_STATUS
710 request referenced an unsupported
713 or invalid signal number.
735 The reaper facility is based on a similar feature of Linux and
736 DragonflyBSD, and first appeared in
740 .Dv PROC_PDEATHSIG_CTL
741 facility is based on the prctl(PR_SET_PDEATHSIG, ...) feature of Linux,
742 and first appeared in
745 The ASLR support was added to system for the checklists compliance in