PROCCTL(2) | System Calls Manual | PROCCTL(2) |
procctl
— control
processes
Standard C Library (libc, -lc)
#include
<sys/procctl.h>
int
procctl
(idtype_t
idtype, id_t id,
int cmd,
void *arg);
The
procctl
()
system call provides for control over processes. The
idtype and id arguments specify
the set of processes to control. If multiple processes match the identifier,
procctl
will make a “best effort” to
control as many of the selected processes as possible. An error is only
returned if no selected processes successfully complete the request. The
following identifier types are supported:
P_PID
P_PGID
The control request to perform is specified by the cmd argument. The following commands are supported:
PROC_SPROTECT
PPROT_SET
PPROT_CLEAR
The following optional flags are supported:
PPROT_DESCEND
PPROT_INHERIT
PPROT_SET
, mark all future
child processes of each selected process as protected. Future child
processes will also mark all of their future child processes.PROC_REAP_ACQUIRE
PROC_REAP_RELEASE
PROC_REAP_STATUS
struct procctl_reaper_status { u_int rs_flags; u_int rs_children; u_int rs_descendants; pid_t rs_reaper; pid_t rs_pid; };
REAPER_STATUS_OWNED
REAPER_STATUS_REALINIT
The rs_children field returns the number
of children of the reaper among the descendants. It is possible to have
a child whose reaper is not the specified process, since the reaper for
any existing children is not reset on the
PROC_REAP_ACQUIRE
operation. The
rs_descendants field returns the total number of
descendants of the reaper(s), not counting descendants of the reaper in
the subtree. The rs_reaper field returns the
reaper pid. The rs_pid returns the pid of one
reaper child if there are any descendants.
PROC_REAP_GETPIDS
struct procctl_reaper_pids { u_int rp_count; struct procctl_reaper_pidinfo *rp_pids; };
The struct procctl_reaper_pidinfo structure provides some information about one of the reaper's descendants. Note that for a descendant that is not a child, it may be incorrectly identified because of a race in which the original child process exited and the exited process's pid was reused for an unrelated process.
struct procctl_reaper_pidinfo { pid_t pi_pid; pid_t pi_subtree; u_int pi_flags; };
REAPER_PIDINFO_VALID
REAPER_PIDINFO_VALID
flag allows the caller to
detect the end of the returned array.REAPER_PIDINFO_CHILD
REAPER_PIDINFO_REAPER
PROC_REAP_KILL
struct procctl_reaper_kill { int rk_sig; u_int rk_flags; pid_t rk_subtree; u_int rk_killed; pid_t rk_fpid; };
REAPER_KILL_CHILDREN
REAPER_KILL_SUBTREE
REAPER_KILL_CHILDREN
nor the
REAPER_KILL_SUBTREE
flags are specified, all
current descendants of the reaper are signalled.
If a signal was delivered to any process, the return value from the request is zero. In this case, the rk_killed field identifies the number of processes signalled. The rk_fpid field is set to the pid of the first process for which signal delivery failed, e.g., due to permission problems. If no such process exists, the rk_fpid field is set to -1.
PROC_TRACE_CTL
PROC_TRACE_CTL_ENABLE
PROC_TRACE_CTL_DISABLE
. Only allowed for
self.PROC_TRACE_CTL_DISABLE
PROC_TRACE_CTL_DISABLE_EXEC
PROC_TRACE_CTL_DISABLE
, but the
setting persists for the process even after
execve(2).PROC_TRACE_STATUS
PROC_TRAPCAP_CTL
ENOTCAPABLE
or ECAPMODE
error. If the control is enabled, such errors from the syscalls cause
delivery of the synchronous SIGTRAP
signal to the
thread immediately before returning from the syscalls.
Possible values for the data argument are:
PROC_TRAPCAP_CTL_ENABLE
SIGTRAP
signal delivery on
capability mode access violations. The enabled mode is inherited by
the children of the process, and is kept after
fexecve(2) calls.PROC_TRAPCAP_CTL_DISABLE
kern.trap_enotcap
might
still cause the signal to be delivered. See
capsicum(4).On signal delivery, the si_errno member
of the siginfo signal handler parameter is set to
the syscall error value, and the si_code member is
set to TRAP_CAP
.
See capsicum(4) for more information about the capability mode.
PROC_TRAPCAP_STATUS
PROC_TRAPCAP_CTL_ENABLE
value if the process
control enables signal delivery, and to
PROC_TRAPCAP_CTL_DISABLE
otherwise.
See the note about sysctl
kern.trap_enotcap
above, which gives independent
global control of signal delivery.
PROC_PDEATHSIG_CTL
P_PID
and id must be the either caller's pid or zero, with
no difference in effect. The value is cleared for child processes and when
executing set-user-ID or set-group-ID binaries. arg
must point to a value of type int indicating the
signal that should be delivered to the caller. Use zero to cancel a
previously requested signal delivery.PROC_PDEATHSIG_STATUS
P_PID
and id must be the
either caller's pid or zero, with no difference in effect.
arg must point to a memory location that can hold a
value of type int. If signal delivery has not been
requested, it will contain zero on return.Disabling tracing on a process should not be considered a security feature, as it is bypassable both by the kernel and privileged processes, and via other system mechanisms. As such, it should not be utilized to reliably protect cryptographic keying material or other confidential data.
If an error occurs, a value of -1 is returned and errno is set to indicate the error.
The procctl
() system call will fail
if:
EFAULT
]EINVAL
]The idtype argument specifies an unsupported identifier type.
EPERM
]ESRCH
]EINVAL
]PROC_SPROTECT
command.EPERM
]P_PID
, or id is not equal to
the pid of the calling process, for
PROC_REAP_ACQUIRE
or
PROC_REAP_RELEASE
requests.EINVAL
]PROC_REAP_KILL
request.EINVAL
]PROC_REAP_KILL
request.EINVAL
]PROC_REAP_RELEASE
request was issued by the
init(8) process.EBUSY
]PROC_REAP_ACQUIRE
request was issued by a
process that had already acquired reaper status and has not yet released
it.EBUSY
]PROC_TRACE_CTL
request was issued for a
process already being traced.EPERM
]PROC_TRACE_CTL
request to re-enable tracing of
the process (PROC_TRACE_CTL_ENABLE
), or to disable
persistence of PROC_TRACE_CTL_DISABLE
on
execve(2) was issued for a non-current process.EINVAL
]PROC_TRACE_CTL
or
PROC_TRAPCAP_CTL
request is invalid.EINVAL
]PROC_PDEATHSIG_CTL
or
PROC_PDEATHSIG_STATUS
request referenced an
unsupported id, idtype or
invalid signal number.dtrace(1), cap_enter(2,) kill(2), ktrace(2), ptrace(2), wait(2), capsicum(4), hwpmc(4), init(8)
The procctl
() function appeared in
FreeBSD 10.0. The reaper facility is based on a
similar feature of Linux and DragonflyBSD, and first appeared in
FreeBSD 10.2. The
PROC_PDEATHSIG_CTL
facility is based on the
prctl(PR_SET_PDEATHSIG, ...) feature of Linux, and first appeared in
FreeBSD 11.2.
May 12, 2018 | Debian |