Manual Pages for Linux CentOS command on man prctl
MyWebUniversity

Manual Pages for Linux CentOS command on man prctl

PRCTL(2) Linux Programmer's Manual PRCTL(2)

NAME

prctl - operations on a process SYNOPSIS

#include int prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); DESCRIPTION prctl() is called with a first argument describing what to do (with values defined in ), and further arguments with a sig‐ nificance depending on the first one. The first argument can be: PRCAPBSETREAD (since Linux 2.6.25) Return (as the function result) 1 if the capability specified in arg2 is in the calling thread's capability bounding set, or 0 if it is not. (The capability constants are defined in .) The capability bounding set dictates whether the process can receive the capability through a file's permitted capability set on a subsequent call to execve(2). If the capability specified in arg2 is not valid, then the call fails with the error EINVAL. PRCAPBSETDROP (since Linux 2.6.25) If the calling thread has the CAPSETPCAP capability, then drop the capability specified by arg2 from the calling thread's capa‐ bility bounding set. Any children of the calling thread will inherit the newly reduced bounding set. The call fails with the error: EPERM if the calling thread does not have the CAPSETPCAP; EINVAL if arg2 does not represent a valid capability; or EINVAL if file capabilities are not enabled in the kernel, in which case bounding sets are not supported. PRSETCHILDSUBREAPER (since Linux 3.4) If arg2 is nonzero, set the "child subreaper" attribute of the calling process; if arg2 is zero, unset the attribute. When a process is marked as a child subreaper, all of the children that it creates, and their descendants, will be marked as having a subreaper. In effect, a subreaper fulfills the role of init(1) for its descendant processes. Upon termination of a process that is orphaned (i.e., its immediate parent has already termi‐ nated) and marked as having a subreaper, the nearest still liv‐ ing ancestor subreaper will receive a SIGCHLD signal and be able to wait(2) on the process to discover its termination status. PRGETCHILDSUBREAPER (since Linux 3.4) Return the "child subreaper" setting of the caller, in the loca‐ tion pointed to by (int *) arg2. PRSETDUMPABLE (since Linux 2.3.20) Set the state of the flag determining whether core dumps are produced for the calling process upon delivery of a signal whose default behavior is to produce a core dump. (Normally, this flag is set for a process by default, but it is cleared when a

set-user-ID or set-group-ID program is executed and also by var‐ ious system calls that manipulate process UIDs and GIDs). In kernels up to and including 2.6.12, arg2 must be either 0 (process is not dumpable) or 1 (process is dumpable). Between kernels 2.6.13 and 2.6.17, the value 2 was also permitted, which caused any binary which normally would not be dumped to be dumped readable by root only; for security reasons, this feature has been removed. (See also the description of /proc/sys/fs/suiddumpable in proc(5).) Processes that are not dumpable can not be attached via ptrace(2) PTRACEATTACH. PRGETDUMPABLE (since Linux 2.3.20) Return (as the function result) the current state of the calling process's dumpable flag. PRSETENDIAN (since Linux 2.6.18, PowerPC only)

Set the endian-ness of the calling process to the value given in arg2, which should be one of the following: PRENDIANBIG, PRENDIANLITTLE, or PRENDIANPPCLITTLE (PowerPC pseudo little endian). PRGETENDIAN (since Linux 2.6.18, PowerPC only)

Return the endian-ness of the calling process, in the location pointed to by (int *) arg2. PRSETFPEMU (since Linux 2.4.18, 2.5.9, only on ia64)

Set floating-point emulation control bits to arg2. Pass PRFPEMUNOPRINT to silently emulate fp operations accesses, or PRFPEMUSIGFPE to not emulate fp operations and send SIGFPE instead. PRGETFPEMU (since Linux 2.4.18, 2.5.9, only on ia64)

Return floating-point emulation control bits, in the location pointed to by (int *) arg2. PRSETFPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)

Set floating-point exception mode to arg2. Pass PRFPEXCSWENABLE to use FPEXC for FP exception enables,

PRFPEXCDIV for floating-point divide by zero, PRFPEXCOVF

for floating-point overflow, PRFPEXCUND for floating-point

underflow, PRFPEXCRES for floating-point inexact result,

PRFPEXCINV for floating-point invalid operation, PRFPEXCDISABLED for FP exceptions disabled, PRFPEXCNONRE‐ COV for async nonrecoverable exception mode, PRFPEXCASYNC for async recoverable exception mode, PRFPEXCPRECISE for precise exception mode. PRGETFPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)

Return floating-point exception mode, in the location pointed to by (int *) arg2. PRSETKEEPCAPS (since Linux 2.2.18) Set the state of the thread's "keep capabilities" flag, which determines whether the threads's permitted capability set is cleared when a change is made to the threads's user IDs such

that the threads's real UID, effective UID, and saved set-user- ID all become nonzero when at least one of them previously had the value 0. By default, the permitted capability set is cleared when such a change is made; setting the "keep capabili‐ ties" flag prevents it from being cleared. arg2 must be either 0 (permitted capabilities are cleared) or 1 (permitted capabili‐ ties are kept). (A thread's effective capability set is always cleared when such a credential change is made, regardless of the setting of the "keep capabilities" flag.) The "keep capabili‐ ties" value will be reset to 0 on subsequent calls to execve(2). PRGETKEEPCAPS (since Linux 2.2.18) Return (as the function result) the current state of the calling threads's "keep capabilities" flag. PRSETNAME (since Linux 2.6.9) Set the name of the calling thread, using the value in the loca‐ tion pointed to by (char *) arg2. The name can be up to 16

bytes long, and should be null-terminated if it contains fewer bytes. This is the same attribute that can be set via pthreadsetnamenp(3) and retrieved using pthreadgetnamenp(3). The attribute is likewise accessible via /proc/self/task/[tid]/comm, where tid is the name of the calling thread. PRGETNAME (since Linux 2.6.11) Return the name of the calling thread, in the buffer pointed to by (char *) arg2. The buffer should allow space for up to 16

bytes; the returned string will be null-terminated if it is shorter than that. PRSETNONEWPRIVS (since Linux 3.5) Set the calling process's nonewprivs bit to the value in arg2. With nonewprivs set to 1, execve(2) promises not to grant privileges to do anything that could not have been done without

the execve(2) call (for example, rendering the set-user-ID and

set-group-ID permission bits, and file capabilities non-func‐ tional). Once set, this bit cannot be unset. The setting of this bit is inherited by children created by fork(2) and clone(2), and preserved across execve(2). For more information, see the kernel source file Documenta‐ tion/prctl/nonewprivs.txt. PRGETNONEWPRIVS (since Linux 3.5) Return the value of the nonewprivs bit for the current process. A value of 0 indicates the regular execve(2) behavior.

A value of 1 indicates execve(2) will operate in the privilege- restricting mode described above. PRSETPDEATHSIG (since Linux 2.1.57) Set the parent process death signal of the calling process to arg2 (either a signal value in the range 1..maxsig, or 0 to clear). This is the signal that the calling process will get when its parent dies. This value is cleared for the child of a

fork(2) and (since Linux 2.4.36 / 2.6.23) when executing a set-

user-ID or set-group-ID binary. PRGETPDEATHSIG (since Linux 2.3.15) Return the current value of the parent process death signal, in the location pointed to by (int *) arg2. PRSETPTRACER (since Linux 3.4) This is meaningful only when the Yama LSM is enabled and in mode 1 ("restricted ptrace", visible via /proc/sys/ker‐ nel/yama/ptracescope). When a "ptracer process ID" is passed in arg2, the caller is declaring that the ptracer process can ptrace(2) the calling process as if it were a direct process ancestor. Each PRSETPTRACER operation replaces the previous "ptracer process ID". Employing PRSETPTRACER with arg2 set to 0 clears the caller's "ptracer process ID". If arg2 is PRSETPTRACERANY, the ptrace restrictions introduced by Yama are effectively disabled for the calling process. For further information, see the kernel source file Documenta‐ tion/security/Yama.txt. PRSETSECCOMP (since Linux 2.6.23) Set the secure computing (seccomp) mode for the calling thread, to limit the available system calls. The seccomp mode is selected via arg2. (The seccomp constants are defined in .) With arg2 set to SECCOMPMODESTRICT the only system calls that the thread is permitted to make are read(2), write(2), exit(2), and sigreturn(2). Other system calls result in the delivery of a SIGKILL signal. Strict secure computing mode is useful for

number-crunching applications that may need to execute untrusted byte code, perhaps obtained by reading from a pipe or socket. This operation is available only if the kernel is configured with CONFIGSECCOMP enabled. With arg2 set to SECCOMPMODEFILTER (since Linux 3.5) the sys‐ tem calls allowed are defined by a pointer to a Berkeley Packet Filter passed in arg3. This argument is a pointer to struct sockfprog; it can be designed to filter arbitrary system calls and system call arguments. This mode is available only if the kernel is configured with CONFIGSECCOMPFILTER enabled. If SECCOMPMODEFILTER filters permit fork(2), then the seccomp mode is inherited by children created by fork(2); if execve(2) is permitted, then the seccomp mode is preserved across execve(2). If the filters permit prctl() calls, then additional

filters can be added; they are run in order until the first non- allow result is seen. For further information, see the kernel source file Documenta‐ tion/prctl/seccompfilter.txt. PRGETSECCOMP (since Linux 2.6.23) Return the secure computing mode of the calling thread. If the caller is not in secure computing mode, this operation returns 0; if the caller is in strict secure computing mode, then the prctl() call will cause a SIGKILL signal to be sent to the process. If the caller is in filter mode, and this system call is allowed by the seccomp filters, it returns 2. This operation is available only if the kernel is configured with CONFIGSEC‐ COMP enabled. PRSETSECUREBITS (since Linux 2.6.26) Set the "securebits" flags of the calling thread to the value supplied in arg2. See capabilities(7). PRGETSECUREBITS (since Linux 2.6.26) Return (as the function result) the "securebits" flags of the calling thread. See capabilities(7). PRGETTIDADDRESS (since Linux 3.5) Retrieve the clearchildtid address set by settidaddress(2) and the clone(2) CLONECHILDCLEARTID flag, in the location pointed to by (int **) arg2. This feature is available only if the kernel is built with the CONFIGCHECKPOINTRESTORE option enabled. PRSETTIMERSLACK (since Linux 2.6.28) Set the current timer slack for the calling thread to the nanosecond value supplied in arg2. If arg2 is less than or equal to zero, reset the current timer slack to the thread's default timer slack value. The timer slack is used by the ker‐ nel to group timer expirations for the calling thread that are close to one another; as a consequence, timer expirations for the thread may be up to the specified number of nanoseconds late (but will never expire early). Grouping timer expirations can

help reduce system power consumption by minimizing CPU wake-ups. The timer expirations affected by timer slack are those set by select(2), pselect(2), poll(2), ppoll(2), epollwait(2), epollpwait(2), clocknanosleep(2), nanosleep(2), and futex(2) (and thus the library functions implemented via futexes, includ‐ ing pthreadcondtimedwait(3), pthreadmutextimedlock(3), pthreadrwlocktimedrdlock(3), pthreadrwlocktimedwrlock(3), and semtimedwait(3)). Timer slack is not applied to threads that are scheduled under a realtime scheduling policy (see schedsetscheduler(2)). Each thread has two associated timer slack values: a "default" value, and a "current" value. The current value is the one that governs grouping of timer expirations. When a new thread is created, the two timer slack values are made the same as the current value of the creating thread. Thereafter, a thread can adjust its current timer slack value via PRSETTIMERSLACK (the default value can't be changed). The timer slack values of init (PID 1), the ancestor of all processes, are 50,000 nanoseconds (50 microseconds). The timer slack values are preserved across execve(2). PRGETTIMERSLACK (since Linux 2.6.28) Return the current timer slack value of the calling thread.

PRSETTIMING (since Linux 2.6.0-test4) Set whether to use (normal, traditional) statistical process

timing or accurate timestamp-based process timing, by passing PRTIMINGSTATISTICAL or PRTIMINGTIMESTAMP to arg2. PRTIM‐ INGTIMESTAMP is not currently implemented (attempting to set this mode will yield the error EINVAL).

PRGETTIMING (since Linux 2.6.0-test4) Return (as the function result) which process timing method is currently in use. PRTASKPERFEVENTSDISABLE (since Linux 2.6.31) Disable all performance counters attached to the calling process, regardless of whether the counters were created by this process or another process. Performance counters created by the calling process for other processes are unaffected. For more information on performance counters, see the Linux kernel source file tools/perf/design.txt. Originally called PRTASKPERFCOUNTERSDISABLE; renamed (with same numerical value) in Linux 2.6.32. PRTASKPERFEVENTSENABLE (since Linux 2.6.31) The converse of PRTASKPERFEVENTSDISABLE; enable performance counters attached to the calling process. Originally called PRTASKPERFCOUNTERSENABLE; renamed in Linux 2.6.32. PRSETTSC (since Linux 2.6.26, x86 only) Set the state of the flag determining whether the timestamp counter can be read by the process. Pass PRTSCENABLE to arg2 to allow it to be read, or PRTSCSIGSEGV to generate a SIGSEGV when the process tries to read the timestamp counter. PRGETTSC (since Linux 2.6.26, x86 only) Return the state of the flag determining whether the timestamp counter can be read, in the location pointed to by (int *) arg2. PRSETUNALIGN (Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15; PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22) Set unaligned access control bits to arg2. Pass PRUNALIGNNOPRINT to silently fix up unaligned user accesses, or PRUNALIGNSIGBUS to generate SIGBUS on unaligned user access. PRGETUNALIGN (see PRSETUNALIGN for information on versions and architec‐ tures) Return unaligned access control bits, in the location pointed to by (int *) arg2. PRMCEKILL (since Linux 2.6.32) Set the machine check memory corruption kill policy for the cur‐ rent thread. If arg2 is PRMCEKILLCLEAR, clear the thread

memory corruption kill policy and use the system-wide default.

(The system-wide default is defined by /proc/sys/vm/memoryfail‐ ureearlykill; see proc(5).) If arg2 is PRMCEKILLSET, use a

thread-specific memory corruption kill policy. In this case, arg3 defines whether the policy is early kill (PRMCEKILLEARLY), late kill (PRMCEKILLLATE), or the sys‐

tem-wide default (PRMCEKILLDEFAULT). Early kill means that the thread receives a SIGBUS signal as soon as hardware memory corruption is detected inside its address space. In late kill mode, the process is killed only when it accesses a corrupted page. See sigaction(2) for more information on the SIGBUS sig‐ nal. The policy is inherited by children. The remaining unused prctl() arguments must be zero for future compatibility. PRMCEKILLGET (since Linux 2.6.32)

Return the current per-process machine check kill policy. All unused prctl() arguments must be zero. PRSETMM (since Linux 3.3) Modify certain kernel memory map descriptor fields of the call‐ ing process. Usually these fields are set by the kernel and dynamic loader (see ld.so(8) for more information) and a regular application should not use this feature. However, there are

cases, such as self-modifying programs, where a program might find it useful to change its own memory map. This feature is available only if the kernel is built with the CONFIGCHECK‐ POINTRESTORE option enabled. The calling process must have the CAPSYSRESOURCE capability. The value in arg2 is one of the options below, while arg3 provides a new value for the option. PRSETMMSTARTCODE Set the address above which the program text can run. The corresponding memory area must be readable and exe‐ cutable, but not writable or sharable (see mprotect(2) and mmap(2) for more information). PRSETMMENDCODE Set the address below which the program text can run. The corresponding memory area must be readable and exe‐ cutable, but not writable or sharable. PRSETMMSTARTDATA Set the address above which initialized and uninitialized (bss) data are placed. The corresponding memory area must be readable and writable, but not executable or sharable. PRSETMMENDDATA Set the address below which initialized and uninitialized (bss) data are placed. The corresponding memory area must be readable and writable, but not executable or sharable. PRSETMMSTARTSTACK Set the start address of the stack. The corresponding memory area must be readable and writable. PRSETMMSTARTBRK Set the address above which the program heap can be expanded with brk(2) call. The address must be greater than the ending address of the current program data seg‐ ment. In addition, the combined size of the resulting heap and the size of the data segment can't exceed the RLIMITDATA resource limit (see setrlimit(2)). PRSETMMBRK Set the current brk(2) value. The requirements for the address are the same as for the PRSETMMSTARTBRK option. PRMPXENABLEMANAGEMENT, PRMPXDISABLEMANAGEMENT (since Linux 3.19) Enable or disable kernel management of Memory Protection eXten‐ sions (MPX) bounds tables. The arg2, arg3, arg4, and arg5 argu‐ ments must be zero.

MPX is a hardware-assisted mechanism for performing bounds checking on pointers. It consists of a set of registers storing bounds information and a set of special instruction prefixes that tell the CPU on which instructions it should do bounds enforcement. There is a limited number of these registers and when there are more pointers than registers, their contents must be "spilled" into a set of tables. These tables are called "bounds tables" and the MPX prctl() operations control whether the kernel manages their allocation and freeing. When management is enabled, the kernel will take over allocation and freeing of the bounds tables. It does this by trapping the

#BR exceptions that result at first use of missing bounds tables and instead of delivering the exception to user space, it allo‐ cates the table and populates the bounds directory with the location of the new table. For freeing, the kernel checks to see if bounds tables are present for memory which is not allo‐ cated, and frees them if so. Before enabling MPX management using PRMPXENABLEMANAGEMENT,

the application must first have allocated a user-space buffer for the bounds directory and placed the location of that direc‐ tory in the bndcfgu register. These calls will fail if the CPU or kernel does not support MPX. Kernel support for MPX is enabled via the CONFIGX86INTELMPX configuration option. You can check whether the CPU supports MPX by looking for the 'mpx' CPUID bit, like with the following command: cat /proc/cpuinfo | grep ' mpx '

A thread may not switch in or out of long (64-bit) mode while MPX is enabled. All threads in a process are affected by these calls. The child of a fork(2) inherits the state of MPX management. During execve(2), MPX management is reset to a state as if PRMPXDISABLEMANAGEMENT had been called. For further information on Intel MPX, see the kernel source file Documentation/x86/intelmpx.txt. PRCAPAMBIENT (since Linux 4.3) Reads or changes the ambient capability set, according to the value of arg2, which must be one of the following: PRCAPAMBIENTRAISE The capability specified in arg3 is added to the ambient set. The specified capability must already be present in both the permitted and the inheritable sets of the process. This operation is not permitted if the SECBITNOCAPAMBIENTRAISE securebit is set. PRCAPAMBIENTLOWER The capability specified in arg3 is removed from the ambient set. PRCAPAMBIENTISSET The prctl(2) call returns 1 if the capability in arg3 is in the ambient set and 0 if it is not. PRCAPAMBIENTCLEARALL All capabilities will be removed from the ambient set. This operation requires setting arg3 to zero. RETURN VALUE On success, PRGETDUMPABLE, PRGETKEEPCAPS, PRGETNONEWPRIVS, PRCAPBSETREAD, PRGETTIMING, PRGETSECUREBITS, PRMCEKILLGET, PRCAPAMBIENT+PRCAPAMBIENTISSET, and (if it returns) PRGETSEC‐ COMP return the nonnegative values described above. All other option

values return 0 on success. On error, -1 is returned, and errno is set appropriately. ERRORS EFAULT arg2 is an invalid address. EINVAL The value of option is not recognized. EINVAL option is PRMCEKILL or PRMCEKILLGET or PRSETMM, and unused prctl() arguments were not specified as zero. EINVAL arg2 is not valid value for this option. EINVAL option is PRSETSECCOMP or PRGETSECCOMP, and the kernel was not configured with CONFIGSECCOMP. EINVAL option is PRSETMM, and one of the following is true * arg4 or arg5 is nonzero; * arg3 is greater than TASKSIZE (the limit on the size of the user address space for this architecture); * arg2 is PRSETMMSTARTCODE, PRSETMMENDCODE, PRSETMMSTARTDATA, PRSETMMENDDATA, or PRSETMMSTARTSTACK, and the permissions of the correspond‐ ing memory area are not as required; * arg2 is PRSETMMSTARTBRK or PRSETMMBRK, and arg3 is less than or equal to the end of the data segment or speci‐ fies a value that would cause the RLIMITDATA resource limit to be exceeded. EINVAL option is PRSETPTRACER and arg2 is not 0, PRSETPTRACERANY, or the PID of an existing process. EINVAL option is PRCAPAMBIENT and an unused argument (arg4, arg5, or, in the case of PRCAPAMBIENTCLEARALL, arg3) is nonzero; or arg2 has an invalid value; or arg2 is PRCAPAMBIENTLOWER, PRCAPAMBIENTRAISE, or PRCAPAMBIENTISSET and arg3 does not specify a valid capability. EPERM option is PRSETSECUREBITS, and the caller does not have the CAPSETPCAP capability, or tried to unset a "locked" flag, or tried to set a flag whose corresponding locked flag was set (see capabilities(7)). EPERM option is PRSETKEEPCAPS, and the callers's SECUREKEEPCAPSLOCKED flag is set (see capabilities(7)). EPERM option is PRCAPBSETDROP, and the caller does not have the CAPSETPCAP capability. EPERM option is PRSETMM, and the caller does not have the CAPSYSRESOURCE capability. EPERM option is PRCAPAMBIENT and arg2 is PRCAPAMBIENTRAISE, but either the capability specified in arg3 is not present in the process's permitted and inheritable capability sets, or the PRCAPAMBIENTLOWER securebit has been set. ENXIO option was PRMPXENABLEMANAGEMENT or PRMPXDISABLEMANAGEMENT and the kernel or the CPU does not support MPX management. Check that the kernel and processor have MPX support. VERSIONS The prctl() system call was introduced in Linux 2.1.57. CONFORMING TO

This call is Linux-specific. IRIX has a prctl() system call (also introduced in Linux 2.1.44 as irixprctl on the MIPS architecture), with prototype ptrdifft prctl(int option, int arg2, int arg3); and options to get the maximum number of processes per user, get the maximum number of processors the calling process can use, find out whether a specified process is currently blocked, get or set the maxi‐ mum stack size, and so on. SEE ALSO signal(2), core(5) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2013-05-21 PRCTL(2)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™