]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/prctl.2
prctl.2: tfix
[thirdparty/man-pages.git] / man2 / prctl.2
CommitLineData
fea681da 1.\" Copyright (C) 1998 Andries Brouwer (aeb@cwi.nl)
73d3ac53 2.\" and Copyright (C) 2002, 2006, 2008, 2012, 2013 Michael Kerrisk <mtk.manpages@gmail.com>
af5f9508 3.\" and Copyright Guillem Jover <guillem@hadrons.org>
3cd5e983 4.\" and Copyright (C) 2014 Dave Hansen / Intel
fea681da 5.\"
93015253 6.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
7.\" Permission is granted to make and distribute verbatim copies of this
8.\" manual provided the copyright notice and this permission notice are
9.\" preserved on all copies.
10.\"
11.\" Permission is granted to copy and distribute modified versions of this
12.\" manual under the conditions for verbatim copying, provided that the
13.\" entire resulting derived work is distributed under the terms of a
14.\" permission notice identical to this one.
c13182ef 15.\"
fea681da
MK
16.\" Since the Linux kernel and libraries are constantly changing, this
17.\" manual page may be incorrect or out-of-date. The author(s) assume no
18.\" responsibility for errors or omissions, or for damages resulting from
19.\" the use of the information contained herein. The author(s) may not
20.\" have taken the same level of care in the production of this manual,
21.\" which is licensed free of charge, as they might when working
22.\" professionally.
c13182ef 23.\"
fea681da
MK
24.\" Formatted or processed versions of this manual, if unaccompanied by
25.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 26.\" %%%LICENSE_END
fea681da
MK
27.\"
28.\" Modified Thu Nov 11 04:19:42 MET 1999, aeb: added PR_GET_PDEATHSIG
29.\" Modified 27 Jun 02, Michael Kerrisk
c13182ef 30.\" Added PR_SET_DUMPABLE, PR_GET_DUMPABLE,
fea681da 31.\" PR_SET_KEEPCAPS, PR_GET_KEEPCAPS
e87fdd92
MK
32.\" Modified 2006-08-30 Guillem Jover <guillem@hadrons.org>
33.\" Updated Linux versions where the options where introduced.
34.\" Added PR_SET_TIMING, PR_GET_TIMING, PR_SET_NAME, PR_GET_NAME,
35.\" PR_SET_UNALIGN, PR_GET_UNALIGN, PR_SET_FPEMU, PR_GET_FPEMU,
36.\" PR_SET_FPEXC, PR_GET_FPEXC
8ab8b43f
MK
37.\" 2008-04-29 Serge Hallyn, Document PR_CAPBSET_READ and PR_CAPBSET_DROP
38.\" 2008-06-13 Erik Bosman, <ejbosman@cs.vu.nl>
39.\" Document PR_GET_TSC and PR_SET_TSC.
40.\" 2008-06-15 mtk, Document PR_SET_SECCOMP, PR_GET_SECCOMP
bc02b3ea 41.\" 2009-10-03 Andi Kleen, document PR_MCE_KILL
06afe673 42.\" 2012-04 Cyrill Gorcunov, Document PR_SET_MM
bc02b3ea
MK
43.\" 2012-04-25 Michael Kerrisk, Document PR_TASK_PERF_EVENTS_DISABLE and
44.\" PR_TASK_PERF_EVENTS_ENABLE
34447828 45.\" 2012-09-20 Kees Cook, update PR_SET_SECCOMP for mode 2
f83fe154 46.\" 2012-09-20 Kees Cook, document PR_SET_NO_NEW_PRIVS, PR_GET_NO_NEW_PRIVS
934487a0
MK
47.\" 2012-10-25 Michael Kerrisk, Document PR_SET_TIMERSLACK and
48.\" PR_GET_TIMERSLACK
491b2e75 49.\" 2013-01-10 Kees Cook, document PR_SET_PTRACER
31cc8387 50.\" 2012-02-04 Michael Kerrisk, document PR_{SET,GET}_CHILD_SUBREAPER
03979794 51.\" 2014-11-10 Dave Hansen, document PR_MPX_{EN,DIS}ABLE_MANAGEMENT
fea681da 52.\"
e14baeeb 53.\"
3df541c0 54.TH PRCTL 2 2016-07-17 "Linux" "Linux Programmer's Manual"
fea681da
MK
55.SH NAME
56prctl \- operations on a process
57.SH SYNOPSIS
521bf584 58.nf
fea681da
MK
59.B #include <sys/prctl.h>
60.sp
521bf584
MK
61.BI "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 ,
62.BI " unsigned long " arg4 ", unsigned long " arg5 );
63.fi
fea681da 64.SH DESCRIPTION
e511ffb6 65.BR prctl ()
fea681da 66is called with a first argument describing what to do
1a329b56 67(with values defined in \fI<linux/prctl.h>\fP), and further
c4bb193f 68arguments with a significance depending on the first one.
fea681da 69The first argument can be:
03547431
MK
70.\"
71.TP
72.BR PR_CAP_AMBIENT " (since Linux 4.3)"
73.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
74Reads or changes the ambient capability set, according to the value of
75.IR arg2 ,
76which must be one of the following:
77.RS
78.\"
79.TP
80.B PR_CAP_AMBIENT_RAISE
81The capability specified in
82.I arg3
83is added to the ambient set.
84The specified capability must already be present in
85both the permitted and the inheritable sets of the process.
86This operation is not permitted if the
87.B SECBIT_NO_CAP_AMBIENT_RAISE
88securebit is set.
89.TP
90.B PR_CAP_AMBIENT_LOWER
91The capability specified in
92.I arg3
93is removed from the ambient set.
94.TP
95.B PR_CAP_AMBIENT_IS_SET
96The
bf7bc8b8 97.BR prctl ()
03547431
MK
98call returns 1 if the capability in
99.I arg3
100is in the ambient set and 0 if it is not.
101.TP
102.BR PR_CAP_AMBIENT_CLEAR_ALL
103All capabilities will be removed from the ambient set.
104This operation requires setting
105.I arg3
106to zero.
107.RE
269e3b97
MK
108.IP
109In all of the above operations,
110.I arg4
111and
112.I arg5
113must be specified as 0.
fea681da 114.TP
2e781e20 115.BR PR_CAPBSET_READ " (since Linux 2.6.25)"
8ab8b43f
MK
116Return (as the function result) 1 if the capability specified in
117.I arg2
118is in the calling thread's capability bounding set,
119or 0 if it is not.
120(The capability constants are defined in
121.IR <linux/capability.h> .)
122The capability bounding set dictates
123whether the process can receive the capability through a
2914a14d 124file's permitted capability set on a subsequent call to
8ab8b43f
MK
125.BR execve (2).
126
127If the capability specified in
128.I arg2
129is not valid, then the call fails with the error
130.BR EINVAL .
131.TP
132.BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
133If the calling thread has the
134.B CAP_SETPCAP
af53fcb5 135capability within its user namespace, then drop the capability specified by
8ab8b43f
MK
136.I arg2
137from the calling thread's capability bounding set.
138Any children of the calling thread will inherit the newly
139reduced bounding set.
140
141The call fails with the error:
142.B EPERM
2914a14d 143if the calling thread does not have the
8ab8b43f
MK
144.BR CAP_SETPCAP ;
145.BR EINVAL
146if
147.I arg2
148does not represent a valid capability; or
149.BR EINVAL
150if file capabilities are not enabled in the kernel,
151in which case bounding sets are not supported.
73d3ac53
MK
152.TP
153.BR PR_SET_CHILD_SUBREAPER " (since Linux 3.4)"
154.\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b
155If
156.I arg2
157is nonzero,
158set the "child subreaper" attribute of the calling process;
159if
160.I arg2
161is zero, unset the attribute.
8b41eea4 162
36127c0e 163When a process is marked as a child subreaper,
73d3ac53
MK
164all of the children that it creates, and their descendants,
165will be marked as having a subreaper.
166In effect, a subreaper fulfills the role of
167.BR init (1)
168for its descendant processes.
169Upon termination of a process
170that is orphaned (i.e., its immediate parent has already terminated)
171and marked as having a subreaper,
172the nearest still living ancestor subreaper
173will receive a
174.BR SIGCHLD
1a8e1c2f 175signal and will be able to
73d3ac53
MK
176.BR wait (2)
177on the process to discover its termination status.
73d3ac53
MK
178.TP
179.BR PR_GET_CHILD_SUBREAPER " (since Linux 3.4)"
180Return the "child subreaper" setting of the caller,
181in the location pointed to by
182.IR "(int\ *) arg2" .
8ab8b43f 183.TP
88989295 184.BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
2d7fc98d
MK
185Set the state of the "dumpable" flag,
186which determines whether core dumps are produced for the calling process
187upon delivery of a signal whose default behavior is to produce a core dump.
4a3713a4 188
88989295 189In kernels up to and including 2.6.12,
8ab8b43f 190.I arg2
8aad30d7
MK
191must be either 0
192.RB ( SUID_DUMP_DISABLE ,
193process is not dumpable) or 1
194.RB ( SUID_DUMP_USER ,
195process is dumpable).
0de51ed1
MK
196Between kernels 2.6.13 and 2.6.17,
197.\" commit abf75a5033d4da7b8a7e92321d74021d1fcfb502
198the value 2 was also permitted,
88989295
MK
199which caused any binary which normally would not be dumped
200to be dumped readable by root only;
201for security reasons, this feature has been removed.
202.\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
203.\" Subject: Fix prctl privilege escalation (CVE-2006-2451)
204.\" From: Marcel Holtmann <marcel () holtmann ! org>
205.\" Date: 2006-07-12 11:12:00
206(See also the description of
2d7fc98d 207.I /proc/sys/fs/\:suid_dumpable
88989295
MK
208in
209.BR proc (5).)
4a3713a4 210
2d7fc98d
MK
211Normally, this flag is set to 1.
212However, it is reset to the current value contained in the file
213.IR /proc/sys/fs/\:suid_dumpable
214(which by default has the value 0),
a644bc48 215in the following circumstances:
2d7fc98d
MK
216.\" See kernel/cred.c::commit_creds() (Linux 3.18 sources)
217.RS
218.IP * 3
a644bc48 219The process's effective user or group ID is changed.
2d7fc98d 220.IP *
a644bc48 221The process's filesystem user or group ID is changed (see
2d7fc98d
MK
222.BR credentials (7)).
223.IP *
a644bc48 224The process executes
2d7fc98d 225.RB ( execve (2))
a644bc48 226a set-user-ID or set-group-ID program,
2d7fc98d 227or a program that has capabilities (see
a644bc48 228.BR capabilities (7)).
5d28ea3e 229.\" Also certain namespace operations;
2d7fc98d
MK
230.RE
231.IP
cadcf1b1 232Processes that are not dumpable can not be attached via
6fdbc779 233.BR ptrace (2)
982d8cf7
MK
234.BR PTRACE_ATTACH ;
235see
236.BR ptrace (2)
237for further details.
161946a2
MK
238
239If a process is not dumpable,
240the ownership of files in the process's
241.IR /proc/[pid]
242directory is affected as described in
243.BR proc (5).
64536a1b 244.TP
88989295
MK
245.BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
246Return (as the function result) the current state of the calling
247process's dumpable flag.
248.\" Since Linux 2.6.13, the dumpable flag can have the value 2,
249.\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
c7094399 250.\" flags has a nonzero value. This was fixed in 2.6.14.
64536a1b 251.TP
8ab8b43f 252.BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
c13182ef 253Set the endian-ness of the calling process to the value given
64536a1b 254in \fIarg2\fP, which should be one of the following:
8ab8b43f 255.\" Respectively 0, 1, 2
64536a1b
MK
256.BR PR_ENDIAN_BIG ,
257.BR PR_ENDIAN_LITTLE ,
258or
0daa9e92 259.B PR_ENDIAN_PPC_LITTLE
64536a1b 260(PowerPC pseudo little endian).
e87fdd92 261.TP
8ab8b43f
MK
262.BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
263Return the endian-ness of the calling process,
264in the location pointed to by
265.IR "(int\ *) arg2" .
64a53a67
ES
266.TP
267.BR PR_SET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305
MK
268.\" commit 9791554b45a2acc28247f66a5fd5bbc212a6b8c8
269On the MIPS architecture,
270user-space code can be built using an ABI which permits linking
271with code that has more restrictive floating-point (FP) requirements.
272For example, user-space code may be built to target the O32 FPXX ABI
b3073df8 273and linked with code built for either one of the more restrictive
89507305 274FP32 or FP64 ABIs.
b3073df8 275When more restrictive code is linked in,
89507305
MK
276the overall requirement for the process is to use the more
277restrictive floating-point mode.
278
07d6076e 279Because the kernel has no means of knowing in advance
89507305 280which mode the process should be executed in,
07d6076e
MK
281and because these restrictions can
282change over the lifetime of the process, the
283.B PR_SET_FP_MODE
284operation is provided to allow control of the floating-point mode
285from user space.
64a53a67
ES
286
287.\" https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
288The
289.I (unsigned int) arg2
89507305 290argument is a bit mask describing the floating-point mode used:
64a53a67
ES
291.RS
292.TP
fb90e0c7 293.BR PR_FP_MODE_FR
64a53a67
ES
294When this bit is
295.I unset
296(so called
297.BR FR=0 " or " FR0
07d6076e 298mode), the 32 floating-point registers are 32-bit wide,
b3073df8
MK
299and 64-bit registers are represented as pair of registers
300(even- and odd- numbered,
89507305
MK
301with the even-numbered register containing the lower 32 bits,
302and the odd-numbered register containing the higher 32 bits).
303
64a53a67
ES
304When this bit is
305.I set
07d6076e
MK
306(on supported hardware),
307the 32 floating-point registers are 64-bit wide (so called
64a53a67 308.BR FR=1 " or " FR1
89507305 309mode).
b3073df8 310Note that modern MIPS implementations (MIPS R6 and newer) support
64a53a67
ES
311.B FR=1
312mode only.
313
07d6076e 314
89507305 315Applications that use the O32 FP32 ABI can operate only when this bit is
64a53a67
ES
316.I unset
317.RB ( FR=0 ;
318or they can be used with FRE enabled, see below).
89507305
MK
319Applications that use the O32 FP64 ABI
320(and the O32 FP64A ABI, which exists to
321provide the ability to operate with existing FP32 code; see below)
322can operate only when this bit is
64a53a67
ES
323.I set
324.RB ( FR=1 ).
ffb0dafc 325Applications that use the O32 FPXX ABI can operate with either
07d6076e
MK
326.BR FR=0
327or
328.BR FR=1 .
64a53a67 329.TP
fb90e0c7 330.BR PR_FP_MODE_FRE
07d6076e 331Enable emulation of 32-bit floating-point mode.
b3073df8 332When this mode is enabled,
07d6076e
MK
333it emulates 32-bit floating-point operations
334by raising a reserved-instruction exception
b3073df8 335on every instruction that uses 32-bit formats and
89507305
MK
336the kernel then handles the instruction in software.
337(The problem lies in the discrepancy of handling odd-numbered registers
338which are the high 32 bits of 64-bit registers with even numbers in
64a53a67 339.B FR=0
89507305 340mode and the lower 32-bit parts of odd-numbered 64-bit registers in
64a53a67 341.B FR=1
89507305
MK
342mode.)
343Enabling this bit is necessary when code with the O32 FP32 ABI should operate
344with code with compatible the O32 FPXX or O32 FP64A ABIs (which require
64a53a67 345.B FR=1
b3073df8
MK
346FPU mode) or when it is executed on newer hardware (MIPS R6 onwards)
347which lacks
64a53a67 348.B FR=0
89507305 349mode support when a binary with the FP32 ABI is used.
64a53a67 350.IP
89507305
MK
351Note that this mode makes sense only when the FPU is in 64-bit mode
352.RB ( FR=1 ).
64a53a67 353.IP
89507305 354Note that the use of emulation inherently has a significant performance hit
b3073df8 355and should be avoided if possible.
64a53a67
ES
356.RE
357.IP
07d6076e
MK
358In the N32/N64 ABI, 64-bit floating-point mode is always used,
359so FPU emulation is not required and the FPU always operates in
64a53a67
ES
360.B FR=1
361mode.
362.IP
07d6076e
MK
363This option is mainly intended for use by the dynamic linker
364.RB ( ld.so (8)).
64a53a67 365.IP
89507305
MK
366The arguments
367.IR arg3 ,
368.IR arg4 ,
369and
370.IR arg5
64a53a67
ES
371are ignored.
372.TP
373.BR PR_GET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305 374Get the current floating-point mode (see the description of
64a53a67
ES
375.B PR_SET_FP_MODE
376for details).
377
89507305 378On success,
07d6076e 379the call returns a bit mask which represents the current floating-point mode.
89507305
MK
380
381The arguments
382.IR arg2 ,
383.IR arg3 ,
384.IR arg4 ,
385and
386.IR arg5
64a53a67 387are ignored.
8ab8b43f 388.TP
8ab8b43f 389.BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
e87fdd92 390Set floating-point emulation control bits to \fIarg2\fP.
7626d2ce
MK
391Pass
392.B PR_FPEMU_NOPRINT
393to silently emulate floating-point operation accesses, or
394.B PR_FPEMU_SIGFPE
395to not emulate floating-point operations and send
8bd58774
MK
396.B SIGFPE
397instead.
e87fdd92 398.TP
8ab8b43f
MK
399.BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
400Return floating-point emulation control bits,
401in the location pointed to by
402.IR "(int\ *) arg2" .
e87fdd92 403.TP
8ab8b43f 404.BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
1c44bd5b
MK
405Set floating-point exception mode to \fIarg2\fP.
406Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
c45bd688
MK
407\fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
408\fBPR_FP_EXC_OVF\fP for floating-point overflow,
409\fBPR_FP_EXC_UND\fP for floating-point underflow,
410\fBPR_FP_EXC_RES\fP for floating-point inexact result,
411\fBPR_FP_EXC_INV\fP for floating-point invalid operation,
e87fdd92 412\fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
b28f6e56 413\fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
e87fdd92
MK
414\fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
415\fBPR_FP_EXC_PRECISE\fP for precise exception mode.
416.TP
8ab8b43f
MK
417.BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
418Return floating-point exception mode,
419in the location pointed to by
420.IR "(int\ *) arg2" .
421.TP
88989295
MK
422.BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
423Set the state of the thread's "keep capabilities" flag,
88ee5c1c
JW
424which determines whether the thread's permitted
425capability set is cleared when a change is made to the thread's user IDs
426such that the thread's real UID, effective UID, and saved set-user-ID
c7094399 427all become nonzero when at least one of them previously had the value 0.
028cb080
MK
428By default, the permitted capability set is cleared when such a change is made;
429setting the "keep capabilities" flag prevents it from being cleared.
88989295 430.I arg2
028cb080
MK
431must be either 0 (permitted capabilities are cleared)
432or 1 (permitted capabilities are kept).
433(A thread's
434.I effective
435capability set is always cleared when such a credential change is made,
436regardless of the setting of the "keep capabilities" flag.)
437The "keep capabilities" value will be reset to 0 on subsequent calls to
88989295
MK
438.BR execve (2).
439.TP
440.BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
88ee5c1c 441Return (as the function result) the current state of the calling thread's
88989295
MK
442"keep capabilities" flag.
443.TP
03547431
MK
444.BR PR_MCE_KILL " (since Linux 2.6.32)"
445Set the machine check memory corruption kill policy for the current thread.
446If
447.I arg2
448is
449.BR PR_MCE_KILL_CLEAR ,
450clear the thread memory corruption kill policy and use the system-wide default.
451(The system-wide default is defined by
452.IR /proc/sys/vm/memory_failure_early_kill ;
453see
454.BR proc (5).)
455If
456.I arg2
457is
458.BR PR_MCE_KILL_SET ,
459use a thread-specific memory corruption kill policy.
460In this case,
461.I arg3
462defines whether the policy is
463.I early kill
464.RB ( PR_MCE_KILL_EARLY ),
465.I late kill
466.RB ( PR_MCE_KILL_LATE ),
467or the system-wide default
468.RB ( PR_MCE_KILL_DEFAULT ).
469Early kill means that the thread receives a
470.B SIGBUS
471signal as soon as hardware memory corruption is detected inside
472its address space.
473In late kill mode, the process is killed only when it accesses a corrupted page.
474See
475.BR sigaction (2)
476for more information on the
477.BR SIGBUS
478signal.
479The policy is inherited by children.
480The remaining unused
481.BR prctl ()
482arguments must be zero for future compatibility.
88989295 483.TP
03547431
MK
484.BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
485Return the current per-process machine check kill policy.
486All unused
487.BR prctl ()
488arguments must be zero.
88989295 489.TP
03547431
MK
490.BR PR_SET_MM " (since Linux 3.3)"
491.\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
492Modify certain kernel memory map descriptor fields
493of the calling process.
494Usually these fields are set by the kernel and dynamic loader (see
495.BR ld.so (8)
496for more information) and a regular application should not use this feature.
497However, there are cases, such as self-modifying programs,
498where a program might find it useful to change its own memory map.
499This feature is available only if the kernel is built with the
500.BR CONFIG_CHECKPOINT_RESTORE
501option enabled.
502The calling process must have the
503.BR CAP_SYS_RESOURCE
504capability.
505The value in
506.I arg2
507is one of the options below, while
508.I arg3
509provides a new value for the option.
510.RS
511.TP
512.BR PR_SET_MM_START_CODE
513Set the address above which the program text can run.
514The corresponding memory area must be readable and executable,
515but not writable or sharable (see
516.BR mprotect (2)
0fcc276f 517and
03547431
MK
518.BR mmap (2)
519for more information).
f83fe154 520.TP
03547431
MK
521.BR PR_SET_MM_END_CODE
522Set the address below which the program text can run.
523The corresponding memory area must be readable and executable,
524but not writable or sharable.
f83fe154 525.TP
03547431
MK
526.BR PR_SET_MM_START_DATA
527Set the address above which initialized and
528uninitialized (bss) data are placed.
529The corresponding memory area must be readable and writable,
530but not executable or sharable.
88989295 531.TP
03547431
MK
532.B PR_SET_MM_END_DATA
533Set the address below which initialized and
534uninitialized (bss) data are placed.
535The corresponding memory area must be readable and writable,
536but not executable or sharable.
88989295 537.TP
03547431
MK
538.BR PR_SET_MM_START_STACK
539Set the start address of the stack.
540The corresponding memory area must be readable and writable.
491b2e75 541.TP
03547431
MK
542.BR PR_SET_MM_START_BRK
543Set the address above which the program heap can be expanded with
544.BR brk (2)
545call.
546The address must be greater than the ending address of
547the current program data segment.
548In addition, the combined size of the resulting heap and
549the size of the data segment can't exceed the
550.BR RLIMIT_DATA
551resource limit (see
552.BR setrlimit (2)).
553.TP
554.BR PR_SET_MM_BRK
555Set the current
556.BR brk (2)
557value.
558The requirements for the address are the same as for the
559.BR PR_SET_MM_START_BRK
560option.
561.P
562The following options are available since Linux 3.5.
563.\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
564.TP
565.BR PR_SET_MM_ARG_START
566Set the address above which the program command line is placed.
567.TP
568.BR PR_SET_MM_ARG_END
569Set the address below which the program command line is placed.
570.TP
571.BR PR_SET_MM_ENV_START
572Set the address above which the program environment is placed.
573.TP
574.BR PR_SET_MM_ENV_END
575Set the address below which the program environment is placed.
576.IP
577The address passed with
578.BR PR_SET_MM_ARG_START ,
579.BR PR_SET_MM_ARG_END ,
580.BR PR_SET_MM_ENV_START ,
581and
582.BR PR_SET_MM_ENV_END
583should belong to a process stack area.
584Thus, the corresponding memory area must be readable, writable, and
585(depending on the kernel configuration) have the
586.BR MAP_GROWSDOWN
587attribute set (see
588.BR mmap (2)).
589.TP
590.BR PR_SET_MM_AUXV
591Set a new auxiliary vector.
592The
593.I arg3
594argument should provide the address of the vector.
595The
596.I arg4
597is the size of the vector.
598.TP
599.BR PR_SET_MM_EXE_FILE
600.\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
601Supersede the
602.IR /proc/pid/exe
603symbolic link with a new one pointing to a new executable file
604identified by the file descriptor provided in
605.I arg3
606argument.
607The file descriptor should be obtained with a regular
608.BR open (2)
609call.
610.IP
611To change the symbolic link, one needs to unmap all existing
612executable memory areas, including those created by the kernel itself
613(for example the kernel usually creates at least one executable
614memory area for the ELF
615.IR \.text
616section).
617.IP
618The second limitation is that such transitions can be done only once
619in a process life time.
620Any further attempts will be rejected.
621This should help system administrators monitor unusual
622symbolic-link transitions over all processes running on a system.
623.RE
624.TP
625.BR PR_MPX_ENABLE_MANAGEMENT ", " PR_MPX_DISABLE_MANAGEMENT " (since Linux 3.19) "
626.\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c
627.\" See also http://lwn.net/Articles/582712/
628.\" See also https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
629Enable or disable kernel management of Memory Protection eXtensions (MPX)
630bounds tables.
631The
632.IR arg2 ,
633.IR arg3 ,
634.IR arg4 ,
635and
636.IR arg5
637.\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88
638arguments must be zero.
639
640MPX is a hardware-assisted mechanism for performing bounds checking on
641pointers.
642It consists of a set of registers storing bounds information
643and a set of special instruction prefixes that tell the CPU on which
644instructions it should do bounds enforcement.
645There is a limited number of these registers and
646when there are more pointers than registers,
647their contents must be "spilled" into a set of tables.
648These tables are called "bounds tables" and the MPX
649.BR prctl ()
650operations control
651whether the kernel manages their allocation and freeing.
652
653When management is enabled, the kernel will take over allocation
654and freeing of the bounds tables.
655It does this by trapping the #BR exceptions that result
656at first use of missing bounds tables and
657instead of delivering the exception to user space,
658it allocates the table and populates the bounds directory
659with the location of the new table.
660For freeing, the kernel checks to see if bounds tables are
661present for memory which is not allocated, and frees them if so.
662
663Before enabling MPX management using
664.BR PR_MPX_ENABLE_MANAGEMENT ,
665the application must first have allocated a user-space buffer for
666the bounds directory and placed the location of that directory in the
667.I bndcfgu
668register.
669
670These calls will fail if the CPU or kernel does not support MPX.
671Kernel support for MPX is enabled via the
672.BR CONFIG_X86_INTEL_MPX
673configuration option.
674You can check whether the CPU supports MPX by looking for the 'mpx'
675CPUID bit, like with the following command:
676
677 cat /proc/cpuinfo | grep ' mpx '
678
679A thread may not switch in or out of long (64-bit) mode while MPX is
680enabled.
681
682All threads in a process are affected by these calls.
683
684The child of a
685.BR fork (2)
686inherits the state of MPX management.
687During
688.BR execve (2),
689MPX management is reset to a state as if
690.BR PR_MPX_DISABLE_MANAGEMENT
691had been called.
692
693For further information on Intel MPX, see the kernel source file
694.IR Documentation/x86/intel_mpx.txt .
695.TP
696.BR PR_SET_NAME " (since Linux 2.6.9)"
697Set the name of the calling thread,
698using the value in the location pointed to by
699.IR "(char\ *) arg2" .
700The name can be up to 16 bytes long,
701.\" TASK_COMM_LEN in include/linux/sched.h
702including the terminating null byte.
703(If the length of the string, including the terminating null byte,
704exceeds 16 bytes, the string is silently truncated.)
705This is the same attribute that can be set via
706.BR pthread_setname_np (3)
707and retrieved using
708.BR pthread_getname_np (3).
709The attribute is likewise accessible via
710.IR /proc/self/task/[tid]/comm ,
711where
712.I tid
713is the name of the calling thread.
714.TP
715.BR PR_GET_NAME " (since Linux 2.6.11)"
716Return the name of the calling thread,
717in the buffer pointed to by
718.IR "(char\ *) arg2" .
719The buffer should allow space for up to 16 bytes;
720the returned string will be null-terminated.
721.TP
722.BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
723Set the calling process's
724.I no_new_privs
725bit to the value in
726.IR arg2 .
727With
728.I no_new_privs
729set to 1,
730.BR execve (2)
731promises not to grant privileges to do anything
732that could not have been done without the
733.BR execve (2)
734call (for example,
735rendering the set-user-ID and set-group-ID mode bits,
736and file capabilities non-functional).
737Once set, this bit cannot be unset.
738The setting of this bit is inherited by children created by
739.BR fork (2)
740and
741.BR clone (2),
742and preserved across
743.BR execve (2).
744
745For more information, see the kernel source file
746.IR Documentation/prctl/no_new_privs.txt .
747.TP
748.BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
749Return (as the function result) the value of the
750.I no_new_privs
751bit for the current process.
752A value of 0 indicates the regular
753.BR execve (2)
754behavior.
755A value of 1 indicates
756.BR execve (2)
757will operate in the privilege-restricting mode described above.
758.TP
759.BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
760Set the parent death signal
761of the calling process to \fIarg2\fP (either a signal value
762in the range 1..maxsig, or 0 to clear).
763This is the signal that the calling process will get when its
764parent dies.
765This value is cleared for the child of a
766.BR fork (2)
767and (since Linux 2.4.36 / 2.6.23)
768when executing a set-user-ID or set-group-ID binary,
769or a binary that has associated capabilities (see
770.BR capabilities (7)).
771This value is preserved across
772.BR execve (2).
773
774.IR Warning :
775.\" https://bugzilla.kernel.org/show_bug.cgi?id=43300
776the "parent" in this case is considered to be the
777.I thread
778that created this process.
779In other words, the signal will be sent when that thread terminates
780(via, for example,
781.BR pthread_exit (3)),
782rather than after all of the threads in the parent process terminate.
783.TP
784.BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
785Return the current value of the parent process death signal,
786in the location pointed to by
787.IR "(int\ *) arg2" .
788.TP
789.BR PR_SET_PTRACER " (since Linux 3.4)"
790.\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
791.\" commit bf06189e4d14641c0148bea16e9dd24943862215
792This is meaningful only when the Yama LSM is enabled and in mode 1
793("restricted ptrace", visible via
794.IR /proc/sys/kernel/yama/ptrace_scope ).
795When a "ptracer process ID" is passed in \fIarg2\fP,
796the caller is declaring that the ptracer process can
797.BR ptrace (2)
798the calling process as if it were a direct process ancestor.
799Each
800.B PR_SET_PTRACER
801operation replaces the previous "ptracer process ID".
802Employing
803.B PR_SET_PTRACER
804with
805.I arg2
806set to 0 clears the caller's "ptracer process ID".
807If
808.I arg2
809is
810.BR PR_SET_PTRACER_ANY ,
811the ptrace restrictions introduced by Yama are effectively disabled for the
812calling process.
813
814For further information, see the kernel source file
815.IR Documentation/security/Yama.txt .
816.TP
817.BR PR_SET_SECCOMP " (since Linux 2.6.23)"
818.\" See http://thread.gmane.org/gmane.linux.kernel/542632
819.\" [PATCH 0 of 2] seccomp updates
820.\" andrea@cpushare.com
821Set the secure computing (seccomp) mode for the calling thread, to limit
822the available system calls.
823The more recent
824.BR seccomp (2)
825system call provides a superset of the functionality of
826.BR PR_SET_SECCOMP .
827
828The seccomp mode is selected via
829.IR arg2 .
830(The seccomp constants are defined in
831.IR <linux/seccomp.h> .)
34447828
KC
832
833With
8ab8b43f 834.IR arg2
34447828 835set to
b1248a9d 836.BR SECCOMP_MODE_STRICT ,
8ab8b43f
MK
837the only system calls that the thread is permitted to make are
838.BR read (2),
839.BR write (2),
85fbef74
MK
840.BR _exit (2)
841(but not
842.BR exit_group (2)),
fea681da 843and
8ab8b43f
MK
844.BR sigreturn (2).
845Other system calls result in the delivery of a
846.BR SIGKILL
847signal.
34447828 848Strict secure computing mode is useful for number-crunching applications
8ab8b43f
MK
849that may need to execute untrusted byte code,
850perhaps obtained by reading from a pipe or socket.
33a0ccb2 851This operation is available only
d6ef3d57
MK
852if the kernel is configured with
853.B CONFIG_SECCOMP
854enabled.
34447828
KC
855
856With
857.IR arg2
858set to
b1248a9d 859.BR SECCOMP_MODE_FILTER " (since Linux 3.5),"
6239dfb2
MK
860the system calls allowed are defined by a pointer
861to a Berkeley Packet Filter passed in
862.IR arg3 .
863This argument is a pointer to
864.IR "struct sock_fprog" ;
865it can be designed to filter
d6ef3d57 866arbitrary system calls and system call arguments.
33a0ccb2 867This mode is available only if the kernel is configured with
d6ef3d57
MK
868.B CONFIG_SECCOMP_FILTER
869enabled.
34447828 870
1733db35
MK
871If
872.BR SECCOMP_MODE_FILTER
873filters permit
874.BR fork (2),
990e3887 875then the seccomp mode is inherited by children created by
1733db35
MK
876.BR fork (2);
877if
878.BR execve (2)
fa1d2749 879is permitted, then the seccomp mode is preserved across
1733db35
MK
880.BR execve (2).
881If the filters permit
a26ec136 882.BR prctl ()
1733db35
MK
883calls, then additional filters can be added;
884they are run in order until the first non-allow result is seen.
885
6239dfb2
MK
886For further information, see the kernel source file
887.IR Documentation/prctl/seccomp_filter.txt .
8ab8b43f
MK
888.TP
889.BR PR_GET_SECCOMP " (since Linux 2.6.23)"
5e91816c
MK
890Return (as the function result)
891the secure computing mode of the calling thread.
34447828
KC
892If the caller is not in secure computing mode, this operation returns 0;
893if the caller is in strict secure computing mode, then the
8ab8b43f
MK
894.BR prctl ()
895call will cause a
896.B SIGKILL
897signal to be sent to the process.
d6ef3d57 898If the caller is in filter mode, and this system call is allowed by the
8eeb062d
MK
899seccomp filters, it returns 2; otherwise, the process is killed with a
900.BR SIGKILL
901signal.
33a0ccb2 902This operation is available only
d6ef3d57
MK
903if the kernel is configured with
904.B CONFIG_SECCOMP
905enabled.
787843e7
MK
906
907Since Linux 3.8, the
908.IR Seccomp
909field of the
910.IR /proc/[pid]/status
911file provides a method of obtaining the same information,
912without the risk that the process is killed; see
913.BR proc (5).
88989295
MK
914.TP
915.BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
916Set the "securebits" flags of the calling thread to the value supplied in
03547431
MK
917.IR arg2 .
918See
919.BR capabilities (7).
88989295 920.TP
03547431
MK
921.BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
922Return (as the function result)
923the "securebits" flags of the calling thread.
924See
925.BR capabilities (7).
926.TP
927.BR PR_SET_THP_DISABLE " (since Linux 3.15)"
928.\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
929Set the state of the "THP disable" flag for the calling thread.
930If
931.I arg2
932has a nonzero value, the flag is set, otherwise it is cleared.
933Setting this flag provides a method
934for disabling transparent huge pages
935for jobs where the code cannot be modified, and using a malloc hook with
936.BR madvise (2)
937is not an option (i.e., statically allocated data).
938The setting of the "THP disable" flag is inherited by a child created via
939.BR fork (2)
940and is preserved across
941.BR execve (2).
942.\"
06afe673
MK
943.TP
944.BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
945Disable all performance counters attached to the calling process,
946regardless of whether the counters were created by
947this process or another process.
948Performance counters created by the calling process for other
949processes are unaffected.
66a9882e 950For more information on performance counters, see the Linux kernel source file
06afe673
MK
951.IR tools/perf/design.txt .
952.IP
03547431
MK
953Originally called
954.BR PR_TASK_PERF_COUNTERS_DISABLE ;
955.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
956renamed (with same numerical value)
957in Linux 2.6.32.
958.\"
03979794 959.TP
03547431
MK
960.BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
961The converse of
962.BR PR_TASK_PERF_EVENTS_DISABLE ;
963enable performance counters attached to the calling process.
964.IP
965Originally called
966.BR PR_TASK_PERF_COUNTERS_ENABLE ;
967.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
968renamed
969.\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
970in Linux 2.6.32.
971.\"
972.TP
973.BR PR_GET_THP_DISABLE " (since Linux 3.15)"
974Return (via the function result) the current setting of the "THP disable"
975flag for the calling thread:
976either 1, if the flag is set, or 0, if it is not.
977.TP
978.BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
979.\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
980Retrieve the
981.I clear_child_tid
982address set by
983.BR set_tid_address (2)
984and the
985.BR clone (2)
986.B CLONE_CHILD_CLEARTID
987flag, in the location pointed to by
988.IR "(int\ **)\ arg2" .
989This feature is available only if the kernel is built with the
990.BR CONFIG_CHECKPOINT_RESTORE
991option enabled.
992.TP
993.BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
994.\" See https://lwn.net/Articles/369549/
995.\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
3780f8a5
MK
996Each thread has two associated timer slack values:
997a "default" value, and a "current" value.
998This operation sets the "current" timer slack value for the calling thread.
999If the nanosecond value supplied in
1000.IR arg2
1001is greater than zero, then the "current" value is set to this value.
03547431
MK
1002If
1003.I arg2
1004is less than or equal to zero,
1005.\" It seems that it's not possible to set the timer slack to zero;
1006.\" The minimum value is 1? Seems a little strange.
3780f8a5
MK
1007the "current" timer slack is reset to the
1008thread's "default" timer slack value.
1009
1010The "current" timer slack is used by the kernel to group timer expirations
03547431
MK
1011for the calling thread that are close to one another;
1012as a consequence, timer expirations for the thread may be
1013up to the specified number of nanoseconds late (but will never expire early).
1014Grouping timer expirations can help reduce system power consumption
1015by minimizing CPU wake-ups.
03979794 1016
03547431
MK
1017The timer expirations affected by timer slack are those set by
1018.BR select (2),
1019.BR pselect (2),
1020.BR poll (2),
1021.BR ppoll (2),
1022.BR epoll_wait (2),
1023.BR epoll_pwait (2),
1024.BR clock_nanosleep (2),
1025.BR nanosleep (2),
1026and
1027.BR futex (2)
1028(and thus the library functions implemented via futexes, including
1029.\" List obtained by grepping for futex usage in glibc source
1030.BR pthread_cond_timedwait (3),
1031.BR pthread_mutex_timedlock (3),
1032.BR pthread_rwlock_timedrdlock (3),
1033.BR pthread_rwlock_timedwrlock (3),
1034and
1035.BR sem_timedwait (3)).
03979794 1036
03547431
MK
1037Timer slack is not applied to threads that are scheduled under
1038a real-time scheduling policy (see
1039.BR sched_setscheduler (2)).
03979794 1040
03547431 1041When a new thread is created,
3780f8a5 1042the two timer slack values are made the same as the "current" value
03547431 1043of the creating thread.
3780f8a5
MK
1044Thereafter, a thread can adjust its "current" timer slack value via
1045.BR PR_SET_TIMERSLACK .
1046The "default" value can't be changed.
03547431
MK
1047The timer slack values of
1048.IR init
1049(PID 1), the ancestor of all processes,
1050are 50,000 nanoseconds (50 microseconds).
1051The timer slack values are preserved across
1052.BR execve (2).
c1f78aba
MK
1053
1054Since Linux 4.6, the "current" timer slack value of any process
1055can be examined and changed via the file
1056.IR /proc/[pid]/timerslack_ns .
1057See
1058.BR proc (5).
e81a96ec 1059.TP
03547431
MK
1060.BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
1061Return (as the function result)
3780f8a5 1062the "current" timer slack value of the calling thread.
4bf25b89 1063.TP
03547431
MK
1064.BR PR_SET_TIMING " (since Linux 2.6.0-test4)"
1065Set whether to use (normal, traditional) statistical process timing or
1066accurate timestamp-based process timing, by passing
1067.B PR_TIMING_STATISTICAL
1068.\" 0
1069or
1070.B PR_TIMING_TIMESTAMP
1071.\" 1
1072to \fIarg2\fP.
1073.B PR_TIMING_TIMESTAMP
1074is not currently implemented
1075(attempting to set this mode will yield the error
1076.BR EINVAL ).
1077.\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
1078.\" and looking at the patch history, it appears
1079.\" that it never did anything.
4bf25b89 1080.TP
03547431
MK
1081.BR PR_GET_TIMING " (since Linux 2.6.0-test4)"
1082Return (as the function result) which process timing method is currently
1083in use.
4bf25b89 1084.TP
03547431
MK
1085.BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
1086Set the state of the flag determining whether the timestamp counter
1087can be read by the process.
1088Pass
1089.B PR_TSC_ENABLE
1090to
1091.I arg2
1092to allow it to be read, or
1093.B PR_TSC_SIGSEGV
1094to generate a
1095.B SIGSEGV
1096when the process tries to read the timestamp counter.
4bf25b89 1097.TP
03547431
MK
1098.BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
1099Return the state of the flag determining whether the timestamp counter
1100can be read,
1101in the location pointed to by
1102.IR "(int\ *) arg2" .
1103.TP
1104.B PR_SET_UNALIGN
1105(Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
1106PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22)
1107Set unaligned access control bits to \fIarg2\fP.
1108Pass
1109\fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
1110or \fBPR_UNALIGN_SIGBUS\fP to generate
1111.B SIGBUS
1112on unaligned user access.
1113.TP
1114.B PR_GET_UNALIGN
1115(see
1116.B PR_SET_UNALIGN
1117for information on versions and architectures)
1118Return unaligned access control bits, in the location pointed to by
1119.IR "(int\ *) arg2" .
47297adb 1120.SH RETURN VALUE
8ab8b43f
MK
1121On success,
1122.BR PR_GET_DUMPABLE ,
1123.BR PR_GET_KEEPCAPS ,
f83fe154 1124.BR PR_GET_NO_NEW_PRIVS ,
5745985f 1125.BR PR_GET_THP_DISABLE ,
8ab8b43f
MK
1126.BR PR_CAPBSET_READ ,
1127.BR PR_GET_TIMING ,
c42db321 1128.BR PR_GET_TIMERSLACK ,
8ab8b43f 1129.BR PR_GET_SECUREBITS ,
ed31c572 1130.BR PR_MCE_KILL_GET ,
0c3e75cb 1131.BR PR_CAP_AMBIENT + PR_CAP_AMBIENT_IS_SET ,
8ab8b43f
MK
1132and (if it returns)
1133.BR PR_GET_SECCOMP
2fda57bd 1134return the nonnegative values described above.
fea681da
MK
1135All other
1136.I option
1137values return 0 on success.
1138On error, \-1 is returned, and
1139.I errno
1140is set appropriately.
1141.SH ERRORS
1142.TP
0478944d
MK
1143.B EACCES
1144.I option
1145is
4ab9f1db
MK
1146.BR PR_SET_SECCOMP
1147and
1148.I arg2
1149is
1150.BR SECCOMP_MODE_FILTER ,
1151but the process does not have the
1152.BR CAP_SYS_ADMIN
1153capability or has not set the
1154.IR no_new_privs
1155attribute (see the discussion of
1156.BR PR_SET_NO_NEW_PRIVS
1157above).
1158.TP
1159.B EACCES
1160.I option
1161is
0478944d
MK
1162.BR PR_SET_MM ,
1163and
1164.I arg3
1165is
1166.BR PR_SET_MM_EXE_FILE ,
1167the file is not executable.
1168.TP
1169.B EBADF
1170.I option
1171is
1172.BR PR_SET_MM ,
1173.I arg3
1174is
1175.BR PR_SET_MM_EXE_FILE ,
1176and the file descriptor passed in
1177.I arg4
1178is not valid.
1179.TP
1180.B EBUSY
1181.I option
1182is
1183.BR PR_SET_MM ,
1184.I arg3
1185is
1186.BR PR_SET_MM_EXE_FILE ,
1187and this the second attempt to change the
1188.I /proc/pid/exe
1189symbolic link, which is prohibited.
1190.TP
8ab8b43f
MK
1191.B EFAULT
1192.I arg2
1193is an invalid address.
1194.TP
e35a0512
KC
1195.B EFAULT
1196.I option
1197is
1198.BR PR_SET_SECCOMP ,
1199.I arg2
1200is
1201.BR SECCOMP_MODE_FILTER ,
1202the system was built with
64c626f7 1203.BR CONFIG_SECCOMP_FILTER ,
e35a0512
KC
1204and
1205.I arg3
1206is an invalid address.
1207.TP
fea681da
MK
1208.B EINVAL
1209The value of
1210.I option