]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/prctl.2
prctl.2: Rework the PR_SET_PDEATHSIG description a little, for easier readability
[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.\"
8538a62b 54.TH PRCTL 2 2018-02-02 "Linux" "Linux Programmer's Manual"
fea681da
MK
55.SH NAME
56prctl \- operations on a process
57.SH SYNOPSIS
521bf584 58.nf
fea681da 59.B #include <sys/prctl.h>
68e4db0a 60.PP
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
1a52f4f6
MK
74Reads or changes the ambient capability set of the calling thread,
75according to the value of
03547431
MK
76.IR arg2 ,
77which must be one of the following:
78.RS
79.\"
80.TP
81.B PR_CAP_AMBIENT_RAISE
82The capability specified in
83.I arg3
84is added to the ambient set.
85The specified capability must already be present in
86both the permitted and the inheritable sets of the process.
87This operation is not permitted if the
88.B SECBIT_NO_CAP_AMBIENT_RAISE
89securebit is set.
90.TP
91.B PR_CAP_AMBIENT_LOWER
92The capability specified in
93.I arg3
94is removed from the ambient set.
95.TP
96.B PR_CAP_AMBIENT_IS_SET
97The
bf7bc8b8 98.BR prctl ()
03547431
MK
99call returns 1 if the capability in
100.I arg3
101is in the ambient set and 0 if it is not.
102.TP
103.BR PR_CAP_AMBIENT_CLEAR_ALL
104All capabilities will be removed from the ambient set.
105This operation requires setting
106.I arg3
107to zero.
108.RE
269e3b97
MK
109.IP
110In all of the above operations,
111.I arg4
112and
113.I arg5
114must be specified as 0.
cf086650
MK
115.IP
116Higher-level interfaces layered on top of the above operations are
117provided in the
118.BR libcap (3)
119library in the form of
120.BR cap_get_ambient (3),
121.BR cap_set_ambient (3),
122and
123.BR cap_reset_ambient (3).
fea681da 124.TP
2e781e20 125.BR PR_CAPBSET_READ " (since Linux 2.6.25)"
8ab8b43f
MK
126Return (as the function result) 1 if the capability specified in
127.I arg2
128is in the calling thread's capability bounding set,
129or 0 if it is not.
130(The capability constants are defined in
131.IR <linux/capability.h> .)
132The capability bounding set dictates
133whether the process can receive the capability through a
2914a14d 134file's permitted capability set on a subsequent call to
8ab8b43f 135.BR execve (2).
efeece04 136.IP
8ab8b43f
MK
137If the capability specified in
138.I arg2
139is not valid, then the call fails with the error
140.BR EINVAL .
d9a0d1d7
MK
141.IP
142A higher-level interface layered on top of this operation is provided in the
143.BR libcap (3)
144library in the form of
145.BR cap_get_bound (3).
8ab8b43f
MK
146.TP
147.BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
148If the calling thread has the
149.B CAP_SETPCAP
af53fcb5 150capability within its user namespace, then drop the capability specified by
8ab8b43f
MK
151.I arg2
152from the calling thread's capability bounding set.
153Any children of the calling thread will inherit the newly
154reduced bounding set.
efeece04 155.IP
8ab8b43f
MK
156The call fails with the error:
157.B EPERM
2914a14d 158if the calling thread does not have the
8ab8b43f
MK
159.BR CAP_SETPCAP ;
160.BR EINVAL
161if
162.I arg2
163does not represent a valid capability; or
164.BR EINVAL
165if file capabilities are not enabled in the kernel,
166in which case bounding sets are not supported.
d9a0d1d7
MK
167.IP
168A higher-level interface layered on top of this operation is provided in the
169.BR libcap (3)
170library in the form of
171.BR cap_drop_bound (3).
73d3ac53
MK
172.TP
173.BR PR_SET_CHILD_SUBREAPER " (since Linux 3.4)"
174.\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b
175If
176.I arg2
177is nonzero,
178set the "child subreaper" attribute of the calling process;
179if
180.I arg2
181is zero, unset the attribute.
efeece04 182.IP
fbc63931 183A subreaper fulfills the role of
73d3ac53
MK
184.BR init (1)
185for its descendant processes.
fbc63931
MK
186When a process becomes orphaned
187(i.e., its immediate parent terminates)
188then that process will be reparented to
189the nearest still living ancestor subreaper.
190Subsequently, calls to
191.BR getppid ()
192in the orphaned process will now return the PID of the subreaper process,
193and when the orphan terminates, it is the subreaper process that
73d3ac53
MK
194will receive a
195.BR SIGCHLD
1a8e1c2f 196signal and will be able to
73d3ac53
MK
197.BR wait (2)
198on the process to discover its termination status.
efeece04 199.IP
d59a7572
MK
200The setting of this bit is not inherited by children created by
201.BR fork (2)
202and
203.BR clone (2).
204The setting is preserved across
205.BR execve (2).
efeece04 206.IP
94e460d4
MK
207Establishing a subreaper process is useful in session management frameworks
208where a hierarchical group of processes is managed by a subreaper process
209that needs to be informed when one of the processes\(emfor example,
210a double-forked daemon\(emterminates
211(perhaps so that it can restart that process).
212Some
213.BR init (1)
214frameworks (e.g.,
215.BR systemd (1))
216employ a subreaper process for similar reasons.
73d3ac53
MK
217.TP
218.BR PR_GET_CHILD_SUBREAPER " (since Linux 3.4)"
219Return the "child subreaper" setting of the caller,
220in the location pointed to by
221.IR "(int\ *) arg2" .
8ab8b43f 222.TP
88989295 223.BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
2d7fc98d
MK
224Set the state of the "dumpable" flag,
225which determines whether core dumps are produced for the calling process
226upon delivery of a signal whose default behavior is to produce a core dump.
efeece04 227.IP
88989295 228In kernels up to and including 2.6.12,
8ab8b43f 229.I arg2
8aad30d7
MK
230must be either 0
231.RB ( SUID_DUMP_DISABLE ,
232process is not dumpable) or 1
233.RB ( SUID_DUMP_USER ,
234process is dumpable).
0de51ed1
MK
235Between kernels 2.6.13 and 2.6.17,
236.\" commit abf75a5033d4da7b8a7e92321d74021d1fcfb502
237the value 2 was also permitted,
88989295
MK
238which caused any binary which normally would not be dumped
239to be dumped readable by root only;
240for security reasons, this feature has been removed.
241.\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
242.\" Subject: Fix prctl privilege escalation (CVE-2006-2451)
243.\" From: Marcel Holtmann <marcel () holtmann ! org>
244.\" Date: 2006-07-12 11:12:00
245(See also the description of
2d7fc98d 246.I /proc/sys/fs/\:suid_dumpable
88989295
MK
247in
248.BR proc (5).)
efeece04 249.IP
2d7fc98d
MK
250Normally, this flag is set to 1.
251However, it is reset to the current value contained in the file
252.IR /proc/sys/fs/\:suid_dumpable
253(which by default has the value 0),
a644bc48 254in the following circumstances:
2d7fc98d
MK
255.\" See kernel/cred.c::commit_creds() (Linux 3.18 sources)
256.RS
41f90bb7 257.IP * 3
a644bc48 258The process's effective user or group ID is changed.
2d7fc98d 259.IP *
a644bc48 260The process's filesystem user or group ID is changed (see
2d7fc98d
MK
261.BR credentials (7)).
262.IP *
a644bc48 263The process executes
2d7fc98d 264.RB ( execve (2))
41f90bb7
MK
265a set-user-ID or set-group-ID program, resulting in a change
266of either the effective user ID or the effective group ID.
27ce08bf
KF
267.IP *
268The process executes
269.RB ( execve (2))
270a program that has file capabilities (see
271.BR capabilities (7)),
41f90bb7 272.\" See kernel/cred.c::commit_creds()
27ce08bf 273but only if the permitted capabilities
41f90bb7 274gained exceed those already permitted for the process.
5d28ea3e 275.\" Also certain namespace operations;
2d7fc98d
MK
276.RE
277.IP
cadcf1b1 278Processes that are not dumpable can not be attached via
6fdbc779 279.BR ptrace (2)
982d8cf7
MK
280.BR PTRACE_ATTACH ;
281see
282.BR ptrace (2)
283for further details.
efeece04 284.IP
161946a2
MK
285If a process is not dumpable,
286the ownership of files in the process's
287.IR /proc/[pid]
288directory is affected as described in
289.BR proc (5).
64536a1b 290.TP
88989295
MK
291.BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
292Return (as the function result) the current state of the calling
293process's dumpable flag.
294.\" Since Linux 2.6.13, the dumpable flag can have the value 2,
295.\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
c7094399 296.\" flags has a nonzero value. This was fixed in 2.6.14.
64536a1b 297.TP
8ab8b43f 298.BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
c13182ef 299Set the endian-ness of the calling process to the value given
64536a1b 300in \fIarg2\fP, which should be one of the following:
8ab8b43f 301.\" Respectively 0, 1, 2
64536a1b
MK
302.BR PR_ENDIAN_BIG ,
303.BR PR_ENDIAN_LITTLE ,
304or
0daa9e92 305.B PR_ENDIAN_PPC_LITTLE
64536a1b 306(PowerPC pseudo little endian).
e87fdd92 307.TP
8ab8b43f
MK
308.BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
309Return the endian-ness of the calling process,
310in the location pointed to by
311.IR "(int\ *) arg2" .
64a53a67
ES
312.TP
313.BR PR_SET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305
MK
314.\" commit 9791554b45a2acc28247f66a5fd5bbc212a6b8c8
315On the MIPS architecture,
316user-space code can be built using an ABI which permits linking
317with code that has more restrictive floating-point (FP) requirements.
318For example, user-space code may be built to target the O32 FPXX ABI
b3073df8 319and linked with code built for either one of the more restrictive
89507305 320FP32 or FP64 ABIs.
b3073df8 321When more restrictive code is linked in,
89507305
MK
322the overall requirement for the process is to use the more
323restrictive floating-point mode.
efeece04 324.IP
07d6076e 325Because the kernel has no means of knowing in advance
89507305 326which mode the process should be executed in,
07d6076e
MK
327and because these restrictions can
328change over the lifetime of the process, the
329.B PR_SET_FP_MODE
330operation is provided to allow control of the floating-point mode
331from user space.
efeece04 332.IP
64a53a67
ES
333.\" https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
334The
335.I (unsigned int) arg2
89507305 336argument is a bit mask describing the floating-point mode used:
64a53a67
ES
337.RS
338.TP
fb90e0c7 339.BR PR_FP_MODE_FR
64a53a67
ES
340When this bit is
341.I unset
342(so called
343.BR FR=0 " or " FR0
41a926bf
MK
344mode), the 32 floating-point registers are 32 bits wide,
345and 64-bit registers are represented as a pair of registers
b3073df8 346(even- and odd- numbered,
89507305
MK
347with the even-numbered register containing the lower 32 bits,
348and the odd-numbered register containing the higher 32 bits).
efeece04 349.IP
64a53a67
ES
350When this bit is
351.I set
07d6076e 352(on supported hardware),
41a926bf 353the 32 floating-point registers are 64 bits wide (so called
64a53a67 354.BR FR=1 " or " FR1
89507305 355mode).
b3073df8 356Note that modern MIPS implementations (MIPS R6 and newer) support
64a53a67
ES
357.B FR=1
358mode only.
efeece04
MK
359.IP
360.IP
89507305 361Applications that use the O32 FP32 ABI can operate only when this bit is
64a53a67
ES
362.I unset
363.RB ( FR=0 ;
364or they can be used with FRE enabled, see below).
89507305
MK
365Applications that use the O32 FP64 ABI
366(and the O32 FP64A ABI, which exists to
367provide the ability to operate with existing FP32 code; see below)
368can operate only when this bit is
64a53a67
ES
369.I set
370.RB ( FR=1 ).
ffb0dafc 371Applications that use the O32 FPXX ABI can operate with either
07d6076e
MK
372.BR FR=0
373or
374.BR FR=1 .
64a53a67 375.TP
fb90e0c7 376.BR PR_FP_MODE_FRE
07d6076e 377Enable emulation of 32-bit floating-point mode.
b3073df8 378When this mode is enabled,
07d6076e
MK
379it emulates 32-bit floating-point operations
380by raising a reserved-instruction exception
b3073df8 381on every instruction that uses 32-bit formats and
89507305
MK
382the kernel then handles the instruction in software.
383(The problem lies in the discrepancy of handling odd-numbered registers
384which are the high 32 bits of 64-bit registers with even numbers in
64a53a67 385.B FR=0
89507305 386mode and the lower 32-bit parts of odd-numbered 64-bit registers in
64a53a67 387.B FR=1
89507305
MK
388mode.)
389Enabling this bit is necessary when code with the O32 FP32 ABI should operate
390with code with compatible the O32 FPXX or O32 FP64A ABIs (which require
64a53a67 391.B FR=1
b3073df8
MK
392FPU mode) or when it is executed on newer hardware (MIPS R6 onwards)
393which lacks
64a53a67 394.B FR=0
89507305 395mode support when a binary with the FP32 ABI is used.
64a53a67 396.IP
89507305
MK
397Note that this mode makes sense only when the FPU is in 64-bit mode
398.RB ( FR=1 ).
64a53a67 399.IP
89507305 400Note that the use of emulation inherently has a significant performance hit
b3073df8 401and should be avoided if possible.
64a53a67
ES
402.RE
403.IP
07d6076e
MK
404In the N32/N64 ABI, 64-bit floating-point mode is always used,
405so FPU emulation is not required and the FPU always operates in
64a53a67
ES
406.B FR=1
407mode.
408.IP
07d6076e
MK
409This option is mainly intended for use by the dynamic linker
410.RB ( ld.so (8)).
64a53a67 411.IP
89507305
MK
412The arguments
413.IR arg3 ,
414.IR arg4 ,
415and
416.IR arg5
64a53a67
ES
417are ignored.
418.TP
419.BR PR_GET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305 420Get the current floating-point mode (see the description of
64a53a67
ES
421.B PR_SET_FP_MODE
422for details).
efeece04 423.IP
89507305 424On success,
07d6076e 425the call returns a bit mask which represents the current floating-point mode.
efeece04 426.IP
89507305
MK
427The arguments
428.IR arg2 ,
429.IR arg3 ,
430.IR arg4 ,
431and
432.IR arg5
64a53a67 433are ignored.
8ab8b43f 434.TP
8ab8b43f 435.BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
e87fdd92 436Set floating-point emulation control bits to \fIarg2\fP.
7626d2ce
MK
437Pass
438.B PR_FPEMU_NOPRINT
439to silently emulate floating-point operation accesses, or
440.B PR_FPEMU_SIGFPE
441to not emulate floating-point operations and send
8bd58774
MK
442.B SIGFPE
443instead.
e87fdd92 444.TP
8ab8b43f
MK
445.BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
446Return floating-point emulation control bits,
447in the location pointed to by
448.IR "(int\ *) arg2" .
e87fdd92 449.TP
8ab8b43f 450.BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
1c44bd5b
MK
451Set floating-point exception mode to \fIarg2\fP.
452Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
c45bd688
MK
453\fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
454\fBPR_FP_EXC_OVF\fP for floating-point overflow,
455\fBPR_FP_EXC_UND\fP for floating-point underflow,
456\fBPR_FP_EXC_RES\fP for floating-point inexact result,
457\fBPR_FP_EXC_INV\fP for floating-point invalid operation,
e87fdd92 458\fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
b28f6e56 459\fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
e87fdd92
MK
460\fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
461\fBPR_FP_EXC_PRECISE\fP for precise exception mode.
462.TP
8ab8b43f
MK
463.BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
464Return floating-point exception mode,
465in the location pointed to by
466.IR "(int\ *) arg2" .
467.TP
88989295 468.BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
03361448
MK
469Set the state of the calling thread's "keep capabilities" flag.
470The effect if this flag is described in
471.BR capabilities (7).
88989295 472.I arg2
03361448
MK
473must be either 0 (clear the flag)
474or 1 (set the flag).
028cb080 475The "keep capabilities" value will be reset to 0 on subsequent calls to
88989295
MK
476.BR execve (2).
477.TP
478.BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
88ee5c1c 479Return (as the function result) the current state of the calling thread's
88989295 480"keep capabilities" flag.
03361448
MK
481See
482.BR capabilities (7)
483for a description of this flag.
88989295 484.TP
03547431 485.BR PR_MCE_KILL " (since Linux 2.6.32)"
eb359b3e 486Set the machine check memory corruption kill policy for the calling thread.
03547431
MK
487If
488.I arg2
489is
490.BR PR_MCE_KILL_CLEAR ,
491clear the thread memory corruption kill policy and use the system-wide default.
492(The system-wide default is defined by
493.IR /proc/sys/vm/memory_failure_early_kill ;
494see
495.BR proc (5).)
496If
497.I arg2
498is
499.BR PR_MCE_KILL_SET ,
500use a thread-specific memory corruption kill policy.
501In this case,
502.I arg3
503defines whether the policy is
504.I early kill
505.RB ( PR_MCE_KILL_EARLY ),
506.I late kill
507.RB ( PR_MCE_KILL_LATE ),
508or the system-wide default
509.RB ( PR_MCE_KILL_DEFAULT ).
510Early kill means that the thread receives a
511.B SIGBUS
512signal as soon as hardware memory corruption is detected inside
513its address space.
514In late kill mode, the process is killed only when it accesses a corrupted page.
515See
516.BR sigaction (2)
517for more information on the
518.BR SIGBUS
519signal.
520The policy is inherited by children.
521The remaining unused
522.BR prctl ()
523arguments must be zero for future compatibility.
88989295 524.TP
03547431
MK
525.BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
526Return the current per-process machine check kill policy.
527All unused
528.BR prctl ()
529arguments must be zero.
88989295 530.TP
03547431
MK
531.BR PR_SET_MM " (since Linux 3.3)"
532.\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
533Modify certain kernel memory map descriptor fields
534of the calling process.
535Usually these fields are set by the kernel and dynamic loader (see
536.BR ld.so (8)
537for more information) and a regular application should not use this feature.
538However, there are cases, such as self-modifying programs,
539where a program might find it useful to change its own memory map.
efeece04 540.IP
03547431
MK
541The calling process must have the
542.BR CAP_SYS_RESOURCE
543capability.
544The value in
545.I arg2
546is one of the options below, while
547.I arg3
548provides a new value for the option.
a87d0921
MF
549The
550.I arg4
551and
552.I arg5
553arguments must be zero if unused.
efeece04 554.IP
261c7e1d 555Before Linux 3.10,
d2eeb68f 556.\" commit 52b3694157e3aa6df871e283115652ec6f2d31e0
261c7e1d
MF
557this feature is available only if the kernel is built with the
558.BR CONFIG_CHECKPOINT_RESTORE
559option enabled.
03547431
MK
560.RS
561.TP
562.BR PR_SET_MM_START_CODE
563Set the address above which the program text can run.
564The corresponding memory area must be readable and executable,
997d21e1 565but not writable or shareable (see
03547431 566.BR mprotect (2)
0fcc276f 567and
03547431
MK
568.BR mmap (2)
569for more information).
f83fe154 570.TP
03547431
MK
571.BR PR_SET_MM_END_CODE
572Set the address below which the program text can run.
573The corresponding memory area must be readable and executable,
997d21e1 574but not writable or shareable.
f83fe154 575.TP
03547431
MK
576.BR PR_SET_MM_START_DATA
577Set the address above which initialized and
578uninitialized (bss) data are placed.
579The corresponding memory area must be readable and writable,
997d21e1 580but not executable or shareable.
88989295 581.TP
03547431
MK
582.B PR_SET_MM_END_DATA
583Set the address below which initialized and
584uninitialized (bss) data are placed.
585The corresponding memory area must be readable and writable,
997d21e1 586but not executable or shareable.
88989295 587.TP
03547431
MK
588.BR PR_SET_MM_START_STACK
589Set the start address of the stack.
590The corresponding memory area must be readable and writable.
491b2e75 591.TP
03547431
MK
592.BR PR_SET_MM_START_BRK
593Set the address above which the program heap can be expanded with
594.BR brk (2)
595call.
596The address must be greater than the ending address of
597the current program data segment.
598In addition, the combined size of the resulting heap and
599the size of the data segment can't exceed the
600.BR RLIMIT_DATA
601resource limit (see
602.BR setrlimit (2)).
603.TP
604.BR PR_SET_MM_BRK
605Set the current
606.BR brk (2)
607value.
608The requirements for the address are the same as for the
609.BR PR_SET_MM_START_BRK
610option.
11ac5b51 611.PP
03547431
MK
612The following options are available since Linux 3.5.
613.\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
614.TP
615.BR PR_SET_MM_ARG_START
616Set the address above which the program command line is placed.
617.TP
618.BR PR_SET_MM_ARG_END
619Set the address below which the program command line is placed.
620.TP
621.BR PR_SET_MM_ENV_START
622Set the address above which the program environment is placed.
623.TP
624.BR PR_SET_MM_ENV_END
625Set the address below which the program environment is placed.
626.IP
627The address passed with
628.BR PR_SET_MM_ARG_START ,
629.BR PR_SET_MM_ARG_END ,
630.BR PR_SET_MM_ENV_START ,
631and
632.BR PR_SET_MM_ENV_END
633should belong to a process stack area.
634Thus, the corresponding memory area must be readable, writable, and
635(depending on the kernel configuration) have the
636.BR MAP_GROWSDOWN
637attribute set (see
638.BR mmap (2)).
639.TP
640.BR PR_SET_MM_AUXV
641Set a new auxiliary vector.
642The
643.I arg3
644argument should provide the address of the vector.
645The
646.I arg4
647is the size of the vector.
648.TP
649.BR PR_SET_MM_EXE_FILE
650.\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
651Supersede the
652.IR /proc/pid/exe
653symbolic link with a new one pointing to a new executable file
654identified by the file descriptor provided in
655.I arg3
656argument.
657The file descriptor should be obtained with a regular
658.BR open (2)
659call.
660.IP
661To change the symbolic link, one needs to unmap all existing
662executable memory areas, including those created by the kernel itself
663(for example the kernel usually creates at least one executable
664memory area for the ELF
665.IR \.text
666section).
667.IP
642df17c 668In Linux 4.9 and earlier, the
47bc9cec 669.\" commit 3fb4afd9a504c2386b8435028d43283216bf588e
47bc9cec 670.BR PR_SET_MM_EXE_FILE
642df17c
MK
671operation can be performed only once in a process's lifetime;
672attempting to perform the operation a second time results in the error
673.BR EPERM .
674This restriction was enforced for security reasons that were subsequently
675deemed specious,
676and the restriction was removed in Linux 4.10 because some
677user-space applications needed to perform this operation more than once.
11ac5b51 678.PP
7e3236a5
MF
679The following options are available since Linux 3.18.
680.\" commit f606b77f1a9e362451aca8f81d8f36a3a112139e
681.TP
682.BR PR_SET_MM_MAP
683Provides one-shot access to all the addresses by passing in a
684.I struct prctl_mm_map
685(as defined in \fI<linux/prctl.h>\fP).
686The
687.I arg4
688argument should provide the size of the struct.
efeece04 689.IP
7e3236a5
MF
690This feature is available only if the kernel is built with the
691.BR CONFIG_CHECKPOINT_RESTORE
692option enabled.
693.TP
694.BR PR_SET_MM_MAP_SIZE
695Returns the size of the
696.I struct prctl_mm_map
697the kernel expects.
698This allows user space to find a compatible struct.
699The
700.I arg4
701argument should be a pointer to an unsigned int.
efeece04 702.IP
7e3236a5
MF
703This feature is available only if the kernel is built with the
704.BR CONFIG_CHECKPOINT_RESTORE
705option enabled.
03547431
MK
706.RE
707.TP
708.BR PR_MPX_ENABLE_MANAGEMENT ", " PR_MPX_DISABLE_MANAGEMENT " (since Linux 3.19) "
709.\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c
710.\" See also http://lwn.net/Articles/582712/
711.\" See also https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
712Enable or disable kernel management of Memory Protection eXtensions (MPX)
713bounds tables.
714The
715.IR arg2 ,
716.IR arg3 ,
717.IR arg4 ,
718and
719.IR arg5
720.\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88
721arguments must be zero.
efeece04 722.IP
03547431
MK
723MPX is a hardware-assisted mechanism for performing bounds checking on
724pointers.
725It consists of a set of registers storing bounds information
726and a set of special instruction prefixes that tell the CPU on which
727instructions it should do bounds enforcement.
728There is a limited number of these registers and
729when there are more pointers than registers,
730their contents must be "spilled" into a set of tables.
731These tables are called "bounds tables" and the MPX
732.BR prctl ()
733operations control
734whether the kernel manages their allocation and freeing.
efeece04 735.IP
03547431
MK
736When management is enabled, the kernel will take over allocation
737and freeing of the bounds tables.
738It does this by trapping the #BR exceptions that result
739at first use of missing bounds tables and
740instead of delivering the exception to user space,
741it allocates the table and populates the bounds directory
742with the location of the new table.
743For freeing, the kernel checks to see if bounds tables are
744present for memory which is not allocated, and frees them if so.
efeece04 745.IP
03547431
MK
746Before enabling MPX management using
747.BR PR_MPX_ENABLE_MANAGEMENT ,
748the application must first have allocated a user-space buffer for
749the bounds directory and placed the location of that directory in the
750.I bndcfgu
751register.
efeece04 752.IP
a23d8efa 753These calls fail if the CPU or kernel does not support MPX.
03547431
MK
754Kernel support for MPX is enabled via the
755.BR CONFIG_X86_INTEL_MPX
756configuration option.
757You can check whether the CPU supports MPX by looking for the 'mpx'
758CPUID bit, like with the following command:
efeece04 759.IP
03547431 760 cat /proc/cpuinfo | grep ' mpx '
efeece04 761.IP
03547431
MK
762A thread may not switch in or out of long (64-bit) mode while MPX is
763enabled.
efeece04 764.IP
03547431 765All threads in a process are affected by these calls.
efeece04 766.IP
03547431
MK
767The child of a
768.BR fork (2)
769inherits the state of MPX management.
770During
771.BR execve (2),
772MPX management is reset to a state as if
773.BR PR_MPX_DISABLE_MANAGEMENT
774had been called.
efeece04 775.IP
03547431
MK
776For further information on Intel MPX, see the kernel source file
777.IR Documentation/x86/intel_mpx.txt .
778.TP
779.BR PR_SET_NAME " (since Linux 2.6.9)"
780Set the name of the calling thread,
781using the value in the location pointed to by
782.IR "(char\ *) arg2" .
783The name can be up to 16 bytes long,
784.\" TASK_COMM_LEN in include/linux/sched.h
785including the terminating null byte.
786(If the length of the string, including the terminating null byte,
787exceeds 16 bytes, the string is silently truncated.)
788This is the same attribute that can be set via
789.BR pthread_setname_np (3)
790and retrieved using
791.BR pthread_getname_np (3).
792The attribute is likewise accessible via
793.IR /proc/self/task/[tid]/comm ,
794where
795.I tid
796is the name of the calling thread.
797.TP
798.BR PR_GET_NAME " (since Linux 2.6.11)"
799Return the name of the calling thread,
800in the buffer pointed to by
801.IR "(char\ *) arg2" .
802The buffer should allow space for up to 16 bytes;
803the returned string will be null-terminated.
804.TP
805.BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
40dfb5ba 806Set the calling thread's
03547431
MK
807.I no_new_privs
808bit to the value in
809.IR arg2 .
810With
811.I no_new_privs
812set to 1,
813.BR execve (2)
814promises not to grant privileges to do anything
815that could not have been done without the
816.BR execve (2)
817call (for example,
818rendering the set-user-ID and set-group-ID mode bits,
819and file capabilities non-functional).
820Once set, this bit cannot be unset.
821The setting of this bit is inherited by children created by
822.BR fork (2)
823and
824.BR clone (2),
825and preserved across
826.BR execve (2).
efeece04 827.IP
c70fea6e
MK
828Since Linux 4.10,
829the value of a thread's
830.I no_new_privs
831bit can be viewed via the
832.I NoNewPrivs
833field in the
834.IR /proc/[pid]/status
835file.
efeece04 836.IP
03547431 837For more information, see the kernel source file
a84a5830
ES
838.IR Documentation/userspace\-api/no_new_privs.rst
839.\" commit 40fde647ccb0ae8c11d256d271e24d385eed595b
840(or
841.IR Documentation/prctl/no_new_privs.txt
842before Linux 4.13).
4d850396
MK
843See also
844.BR seccomp (2).
03547431
MK
845.TP
846.BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
847Return (as the function result) the value of the
848.I no_new_privs
40dfb5ba 849bit for the calling thread.
03547431
MK
850A value of 0 indicates the regular
851.BR execve (2)
852behavior.
853A value of 1 indicates
854.BR execve (2)
855will operate in the privilege-restricting mode described above.
856.TP
857.BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
858Set the parent death signal
859of the calling process to \fIarg2\fP (either a signal value
860in the range 1..maxsig, or 0 to clear).
861This is the signal that the calling process will get when its
862parent dies.
c5236575 863.IP
03547431
MK
864.IR Warning :
865.\" https://bugzilla.kernel.org/show_bug.cgi?id=43300
866the "parent" in this case is considered to be the
867.I thread
868that created this process.
869In other words, the signal will be sent when that thread terminates
870(via, for example,
871.BR pthread_exit (3)),
872rather than after all of the threads in the parent process terminate.
910b0689
MK
873.IP
874The parent death signal setting is cleared for the child of a
875.BR fork (2).
876It is also
877(since Linux 2.4.36 / 2.6.23)
878.\" commit d2d56c5f51028cb9f3d800882eb6f4cbd3f9099f
879cleared when executing a set-user-ID or set-group-ID binary,
880or a binary that has associated capabilities (see
881.BR capabilities (7));
882otherwise, this value is preserved across
883.BR execve (2).
03547431
MK
884.TP
885.BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
886Return the current value of the parent process death signal,
887in the location pointed to by
888.IR "(int\ *) arg2" .
889.TP
890.BR PR_SET_PTRACER " (since Linux 3.4)"
891.\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
892.\" commit bf06189e4d14641c0148bea16e9dd24943862215
893This is meaningful only when the Yama LSM is enabled and in mode 1
894("restricted ptrace", visible via
895.IR /proc/sys/kernel/yama/ptrace_scope ).
896When a "ptracer process ID" is passed in \fIarg2\fP,
897the caller is declaring that the ptracer process can
898.BR ptrace (2)
899the calling process as if it were a direct process ancestor.
900Each
901.B PR_SET_PTRACER
902operation replaces the previous "ptracer process ID".
903Employing
904.B PR_SET_PTRACER
905with
906.I arg2
907set to 0 clears the caller's "ptracer process ID".
908If
909.I arg2
910is
911.BR PR_SET_PTRACER_ANY ,
912the ptrace restrictions introduced by Yama are effectively disabled for the
913calling process.
efeece04 914.IP
03547431 915For further information, see the kernel source file
6744a500
ES
916.IR Documentation/admin\-guide/LSM/Yama.rst
917.\" commit 90bb766440f2147486a2acc3e793d7b8348b0c22
918(or
919.IR Documentation/security/Yama.txt
920before Linux 4.13).
03547431
MK
921.TP
922.BR PR_SET_SECCOMP " (since Linux 2.6.23)"
923.\" See http://thread.gmane.org/gmane.linux.kernel/542632
924.\" [PATCH 0 of 2] seccomp updates
925.\" andrea@cpushare.com
926Set the secure computing (seccomp) mode for the calling thread, to limit
927the available system calls.
928The more recent
929.BR seccomp (2)
930system call provides a superset of the functionality of
931.BR PR_SET_SECCOMP .
efeece04 932.IP
03547431
MK
933The seccomp mode is selected via
934.IR arg2 .
935(The seccomp constants are defined in
936.IR <linux/seccomp.h> .)
efeece04 937.IP
34447828 938With
8ab8b43f 939.IR arg2
34447828 940set to
b1248a9d 941.BR SECCOMP_MODE_STRICT ,
8ab8b43f
MK
942the only system calls that the thread is permitted to make are
943.BR read (2),
944.BR write (2),
85fbef74
MK
945.BR _exit (2)
946(but not
947.BR exit_group (2)),
fea681da 948and
8ab8b43f
MK
949.BR sigreturn (2).
950Other system calls result in the delivery of a
951.BR SIGKILL
952signal.
34447828 953Strict secure computing mode is useful for number-crunching applications
8ab8b43f
MK
954that may need to execute untrusted byte code,
955perhaps obtained by reading from a pipe or socket.
33a0ccb2 956This operation is available only
d6ef3d57
MK
957if the kernel is configured with
958.B CONFIG_SECCOMP
959enabled.
efeece04 960.IP
34447828
KC
961With
962.IR arg2
963set to
b1248a9d 964.BR SECCOMP_MODE_FILTER " (since Linux 3.5),"
6239dfb2
MK
965the system calls allowed are defined by a pointer
966to a Berkeley Packet Filter passed in
967.IR arg3 .
968This argument is a pointer to
969.IR "struct sock_fprog" ;
970it can be designed to filter
d6ef3d57 971arbitrary system calls and system call arguments.
33a0ccb2 972This mode is available only if the kernel is configured with
d6ef3d57
MK
973.B CONFIG_SECCOMP_FILTER
974enabled.
efeece04 975.IP
1733db35
MK
976If
977.BR SECCOMP_MODE_FILTER
978filters permit
979.BR fork (2),
990e3887 980then the seccomp mode is inherited by children created by
1733db35
MK
981.BR fork (2);
982if
983.BR execve (2)
fa1d2749 984is permitted, then the seccomp mode is preserved across
1733db35
MK
985.BR execve (2).
986If the filters permit
a26ec136 987.BR prctl ()
1733db35
MK
988calls, then additional filters can be added;
989they are run in order until the first non-allow result is seen.
efeece04 990.IP
6239dfb2 991For further information, see the kernel source file
28d96036
ES
992.IR Documentation/userspace\-api/seccomp_filter.rst
993.\" commit c061f33f35be0ccc80f4b8e0aea5dfd2ed7e01a3
994(or
995.IR Documentation/prctl/seccomp_filter.txt
996before Linux 4.13).
8ab8b43f
MK
997.TP
998.BR PR_GET_SECCOMP " (since Linux 2.6.23)"
5e91816c
MK
999Return (as the function result)
1000the secure computing mode of the calling thread.
34447828
KC
1001If the caller is not in secure computing mode, this operation returns 0;
1002if the caller is in strict secure computing mode, then the
8ab8b43f
MK
1003.BR prctl ()
1004call will cause a
1005.B SIGKILL
1006signal to be sent to the process.
d6ef3d57 1007If the caller is in filter mode, and this system call is allowed by the
8eeb062d
MK
1008seccomp filters, it returns 2; otherwise, the process is killed with a
1009.BR SIGKILL
1010signal.
33a0ccb2 1011This operation is available only
d6ef3d57
MK
1012if the kernel is configured with
1013.B CONFIG_SECCOMP
1014enabled.
efeece04 1015.IP
787843e7
MK
1016Since Linux 3.8, the
1017.IR Seccomp
1018field of the
1019.IR /proc/[pid]/status
1020file provides a method of obtaining the same information,
1021without the risk that the process is killed; see
1022.BR proc (5).
88989295
MK
1023.TP
1024.BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
1025Set the "securebits" flags of the calling thread to the value supplied in
03547431
MK
1026.IR arg2 .
1027See
1028.BR capabilities (7).
88989295 1029.TP
03547431
MK
1030.BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
1031Return (as the function result)
1032the "securebits" flags of the calling thread.
1033See
1034.BR capabilities (7).
1035.TP
dd08fcca 1036.BR PR_GET_SPECULATION_CTRL " (since Linux 4.17)"
a01c1cbc
MK
1037Returns the state of the speculation misfeature specified in
1038.IR arg2 .
1039Currently, the only permitted value for this argument is
2feab5d3
MK
1040.BR PR_SPEC_STORE_BYPASS
1041(otherwise the call fails with the error
1042.BR ENODEV ).
1043.IP
1044The return value uses bits 0-3 with the following meaning:
e23acd79
KRW
1045.RS
1046.TP
1047.BR PR_SPEC_PRCTL
2feab5d3 1048Mitigation can be controlled per thread by
e23acd79
KRW
1049.B PR_SET_SPECULATION_CTRL
1050.TP
1051.BR PR_SPEC_ENABLE
1052The speculation feature is enabled, mitigation is disabled.
1053.TP
1054.BR PR_SPEC_DISABLE
1055The speculation feature is disabled, mitigation is enabled
1056.TP
1057.BR PR_SPEC_FORCE_DISABLE
1058Same as
1059.B PR_SPEC_DISABLE
1060but cannot be undone.
1061.RE
1062.IP
2feab5d3 1063If all bits are 0,
e23acd79
KRW
1064then the CPU is not affected by the speculation misfeature.
1065.IP
1066If
1067.B PR_SPEC_PRCTL
2feab5d3 1068is set, then per-thread control of the mitigation is available.
ac3756bc 1069If not set,
e36dfb81 1070.BR prctl ()
e23acd79 1071for the speculation misfeature will fail.
a01c1cbc
MK
1072.IP
1073The
e36dfb81
MK
1074.IR arg3 ,
1075.IR arg4 ,
e23acd79
KRW
1076and
1077.I arg5
a01c1cbc 1078arguments must be specified as 0; otherwise the call fails with the error
e36dfb81 1079.BR EINVAL .
e23acd79 1080.TP
dd08fcca
MK
1081.BR PR_SET_SPECULATION_CTRL " (since Linux 4.17)"
1082.\" commit b617cfc858161140d69cc0b5cc211996b557a1c7
1083.\" commit 356e4bfff2c5489e016fdb925adbf12a1e3950ee
a01c1cbc
MK
1084Sets the state of the speculation misfeature specified in
1085.IR arg2 .
1086Currently, the only permitted value for this argument is
2feab5d3
MK
1087.B PR_SPEC_STORE_BYPASS
1088(otherwise the call fails with the error
1089.BR ENODEV ).
a01c1cbc 1090This setting is a per-thread attribute.
ac3756bc 1091The
e23acd79 1092.IR arg3
a01c1cbc
MK
1093argument is used to hand in the control value,
1094which is one of the following:
e23acd79
KRW
1095.RS
1096.TP
1097.BR PR_SPEC_ENABLE
1098The speculation feature is enabled, mitigation is disabled.
1099.TP
1100.BR PR_SPEC_DISABLE
1101The speculation feature is disabled, mitigation is enabled
1102.TP
1103.BR PR_SPEC_FORCE_DISABLE
1104Same as
1105.B PR_SPEC_DISABLE
ac3756bc
MK
1106but cannot be undone.
1107A subsequent
e23acd79
KRW
1108.B
1109prctl(..., PR_SPEC_ENABLE)
2feab5d3 1110will fail with the error
e36dfb81 1111.BR EPERM .
e23acd79
KRW
1112.RE
1113.IP
1114Any other value in
1115.IR arg3
2feab5d3 1116will result in the call failing with the error
e23acd79 1117.BR ERANGE .
a01c1cbc
MK
1118.IP
1119The
2feab5d3 1120.I arg4
e23acd79
KRW
1121and
1122.I arg5
a01c1cbc 1123arguments must be specified as 0; otherwise the call fails with the error
e36dfb81 1124.BR EINVAL .
e23acd79 1125.IP
a01c1cbc
MK
1126The speculation feature can also be controlled by the
1127.B spec_store_bypass_disable
1128boot parameter.
1129This parameter may enforce a read-only policy which will result in the
1130.BR prctl (2)
1131call failing with the error
e23acd79 1132.BR ENXIO .
a01c1cbc
MK
1133For further details, see the kernel source file
1134.IR Documentation/admin-guide/kernel-parameters.txt .
e23acd79 1135.TP
03547431
MK
1136.BR PR_SET_THP_DISABLE " (since Linux 3.15)"
1137.\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
1138Set the state of the "THP disable" flag for the calling thread.
1139If
1140.I arg2
1141has a nonzero value, the flag is set, otherwise it is cleared.
1142Setting this flag provides a method
1143for disabling transparent huge pages
1144for jobs where the code cannot be modified, and using a malloc hook with
1145.BR madvise (2)
1146is not an option (i.e., statically allocated data).
1147The setting of the "THP disable" flag is inherited by a child created via
1148.BR fork (2)
1149and is preserved across
1150.BR execve (2).
1151.\"
06afe673
MK
1152.TP
1153.BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
1154Disable all performance counters attached to the calling process,
1155regardless of whether the counters were created by
1156this process or another process.
1157Performance counters created by the calling process for other
1158processes are unaffected.
66a9882e 1159For more information on performance counters, see the Linux kernel source file
06afe673
MK
1160.IR tools/perf/design.txt .
1161.IP
03547431
MK
1162Originally called
1163.BR PR_TASK_PERF_COUNTERS_DISABLE ;
1164.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
b0ea1ea3 1165renamed (retaining the same numerical value)
03547431
MK
1166in Linux 2.6.32.
1167.\"
03979794 1168.TP
03547431
MK
1169.BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
1170The converse of
1171.BR PR_TASK_PERF_EVENTS_DISABLE ;
1172enable performance counters attached to the calling process.
1173.IP
1174Originally called
1175.BR PR_TASK_PERF_COUNTERS_ENABLE ;
1176.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
1177renamed
1178.\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
1179in Linux 2.6.32.
1180.\"
1181.TP
1182.BR PR_GET_THP_DISABLE " (since Linux 3.15)"
1183Return (via the function result) the current setting of the "THP disable"
1184flag for the calling thread:
1185either 1, if the flag is set, or 0, if it is not.
1186.TP
1187.BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
1188.\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
1189Retrieve the
1190.I clear_child_tid
1191address set by
1192.BR set_tid_address (2)
1193and the
1194.BR clone (2)
1195.B CLONE_CHILD_CLEARTID
1196flag, in the location pointed to by
1197.IR "(int\ **)\ arg2" .
1198This feature is available only if the kernel is built with the
1199.BR CONFIG_CHECKPOINT_RESTORE
c7f2f9ed
MK
1200option enabled.
1201Note that since the
1202.BR prctl ()
1203system call does not have a compat implementation for
1204the AMD64 x32 and MIPS n32 ABIs,
1205and the kernel writes out a pointer using the kernel's pointer size,
1206this operation expects a user-space buffer of 8 (not 4) bytes on these ABIs.
03547431
MK
1207.TP
1208.BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
1209.\" See https://lwn.net/Articles/369549/
1210.\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
3780f8a5
MK
1211Each thread has two associated timer slack values:
1212a "default" value, and a "current" value.
1213This operation sets the "current" timer slack value for the calling thread.
1214If the nanosecond value supplied in
1215.IR arg2
1216is greater than zero, then the "current" value is set to this value.
03547431
MK
1217If
1218.I arg2
1219is less than or equal to zero,
1220.\" It seems that it's not possible to set the timer slack to zero;
1221.\" The minimum value is 1? Seems a little strange.
3780f8a5
MK
1222the "current" timer slack is reset to the
1223thread's "default" timer slack value.
efeece04 1224.IP
3780f8a5 1225The "current" timer slack is used by the kernel to group timer expirations
03547431
MK
1226for the calling thread that are close to one another;
1227as a consequence, timer expirations for the thread may be
1228up to the specified number of nanoseconds late (but will never expire early).
1229Grouping timer expirations can help reduce system power consumption
1230by minimizing CPU wake-ups.
efeece04 1231.IP
03547431
MK
1232The timer expirations affected by timer slack are those set by
1233.BR select (2),
1234.BR pselect (2),
1235.BR poll (2),
1236.BR ppoll (2),
1237.BR epoll_wait (2),
1238.BR epoll_pwait (2),
1239.BR clock_nanosleep (2),
1240.BR nanosleep (2),
1241and
1242.BR futex (2)
1243(and thus the library functions implemented via futexes, including
1244.\" List obtained by grepping for futex usage in glibc source
1245.BR pthread_cond_timedwait (3),
1246.BR pthread_mutex_timedlock (3),
1247.BR pthread_rwlock_timedrdlock (3),
1248.BR pthread_rwlock_timedwrlock (3),
1249and
1250.BR sem_timedwait (3)).
efeece04 1251.IP
03547431
MK
1252Timer slack is not applied to threads that are scheduled under
1253a real-time scheduling policy (see
1254.BR sched_setscheduler (2)).
efeece04 1255.IP
03547431 1256When a new thread is created,
3780f8a5 1257the two timer slack values are made the same as the "current" value
03547431 1258of the creating thread.
3780f8a5
MK
1259Thereafter, a thread can adjust its "current" timer slack value via
1260.BR PR_SET_TIMERSLACK .
1261The "default" value can't be changed.
03547431
MK
1262The timer slack values of
1263.IR init
1264(PID 1), the ancestor of all processes,
1265are 50,000 nanoseconds (50 microseconds).
1266The timer slack values are preserved across
1267.BR execve (2).
efeece04 1268.IP
c1f78aba
MK
1269Since Linux 4.6, the "current" timer slack value of any process
1270can be examined and changed via the file
1271.IR /proc/[pid]/timerslack_ns .
1272See
1273.BR proc (5).
e81a96ec 1274.TP
03547431
MK
1275.BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
1276Return (as the function result)
3780f8a5 1277the "current" timer slack value of the calling thread.
4bf25b89 1278.TP
d6bec36e
MK
1279.BR PR_SET_TIMING " (since Linux 2.6.0)"
1280.\" Precisely: Linux 2.6.0-test4
03547431
MK
1281Set whether to use (normal, traditional) statistical process timing or
1282accurate timestamp-based process timing, by passing
1283.B PR_TIMING_STATISTICAL
1284.\" 0
1285or
1286.B PR_TIMING_TIMESTAMP
1287.\" 1
1288to \fIarg2\fP.
1289.B PR_TIMING_TIMESTAMP
1290is not currently implemented
1291(attempting to set this mode will yield the error
1292.BR EINVAL ).
1293.\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
1294.\" and looking at the patch history, it appears
1295.\" that it never did anything.
4bf25b89 1296.TP
d6bec36e
MK
1297.BR PR_GET_TIMING " (since Linux 2.6.0)"
1298.\" Precisely: Linux 2.6.0-test4
03547431
MK
1299Return (as the function result) which process timing method is currently
1300in use.
4bf25b89 1301.TP
03547431
MK
1302.BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
1303Set the state of the flag determining whether the timestamp counter
1304can be read by the process.
1305Pass
1306.B PR_TSC_ENABLE
1307to
1308.I arg2
1309to allow it to be read, or
1310.B PR_TSC_SIGSEGV
1311to generate a
1312.B SIGSEGV
1313when the process tries to read the timestamp counter.
4bf25b89 1314.TP
03547431
MK
1315.BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
1316Return the state of the flag determining whether the timestamp counter
1317can be read,
1318in the location pointed to by
1319.IR "(int\ *) arg2" .
1320.TP
1321.B PR_SET_UNALIGN
1322(Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
0e2c6b8c
ES
1323PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22;
1324.\" sh: 94ea5e449ae834af058ef005d16a8ad44fcf13d6
1325.\" tile: 2f9ac29eec71a696cb0dcc5fb82c0f8d4dac28c9
1326sh, since Linux 2.6.34; tile, since Linux 3.12)
03547431
MK
1327Set unaligned access control bits to \fIarg2\fP.
1328Pass
1329\fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
1330or \fBPR_UNALIGN_SIGBUS\fP to generate
1331.B SIGBUS
2da72a43
MK
1332on unaligned user access.
1333Alpha also supports an additional flag with the value
1334of 4 and no corresponding named constant,
1335which instructs kernel to not fix up
0e2c6b8c 1336unaligned accesses (it is analogous to providing the
2da72a43
MK
1337.BR UAC_NOFIX
1338flag in
1339.BR SSI_NVPAIRS
1340operation of the
1341.BR setsysinfo ()
1342system call on Tru64).
03547431
MK
1343.TP
1344.B PR_GET_UNALIGN
1345(see
1346.B PR_SET_UNALIGN
1347for information on versions and architectures)
1348Return unaligned access control bits, in the location pointed to by
0e2c6b8c 1349.IR "(unsigned int\ *) arg2" .
47297adb 1350.SH RETURN VALUE
8ab8b43f
MK
1351On success,
1352.BR PR_GET_DUMPABLE ,
1353.BR PR_GET_KEEPCAPS ,
f83fe154 1354.BR PR_GET_NO_NEW_PRIVS ,
5745985f 1355.BR PR_GET_THP_DISABLE ,
8ab8b43f
MK
1356.BR PR_CAPBSET_READ ,
1357.BR PR_GET_TIMING ,
c42db321 1358.BR PR_GET_TIMERSLACK ,
8ab8b43f 1359.BR PR_GET_SECUREBITS ,
ed31c572 1360.BR PR_MCE_KILL_GET ,
0c3e75cb 1361.BR PR_CAP_AMBIENT + PR_CAP_AMBIENT_IS_SET ,
8ab8b43f
MK
1362and (if it returns)
1363.BR PR_GET_SECCOMP
2fda57bd 1364return the nonnegative values described above.
fea681da
MK
1365All other
1366.I option
1367values return 0 on success.
1368On error, \-1 is returned, and
1369.I errno
1370is set appropriately.
1371.SH ERRORS
1372.TP
0478944d
MK
1373.B EACCES
1374.I option
1375is
4ab9f1db
MK
1376.BR PR_SET_SECCOMP
1377and
1378.I arg2
1379is
1380.BR SECCOMP_MODE_FILTER ,
1381but the process does not have the
1382.BR CAP_SYS_ADMIN
1383capability or has not set the
1384.IR no_new_privs
1385attribute (see the discussion of
1386.BR PR_SET_NO_NEW_PRIVS
1387above).
1388.TP
1389.B EACCES
1390.I option
1391is
0478944d
MK
1392.BR PR_SET_MM ,
1393and
1394.I arg3
1395is
1396.BR PR_SET_MM_EXE_FILE ,
1397the file is not executable.
1398.TP
1399.B EBADF
1400.I option
1401is
1402.BR PR_SET_MM ,
1403.I arg3
1404is
1405.BR PR_SET_MM_EXE_FILE ,
1406and the file descriptor passed in
1407.I arg4
1408is not valid.
1409.TP
1410.B EBUSY
1411.I option
1412is
1413.BR PR_SET_MM ,
1414.I arg3
1415is
1416.BR PR_SET_MM_EXE_FILE ,
1417and this the second attempt to change the
1418.I /proc/pid/exe
1419symbolic link, which is prohibited.
1420.TP
8ab8b43f
MK
1421.B EFAULT
1422.I arg2
1423is an invalid address.
1424.TP
e35a0512
KC
1425.B EFAULT
1426.I option
1427is
1428.BR PR_SET_SECCOMP ,
1429.I arg2
1430is
1431.BR SECCOMP_MODE_FILTER ,
1432the system was built with
64c626f7 1433.BR CONFIG_SECCOMP_FILTER ,
e35a0512
KC
1434and
1435.I arg3
1436is an invalid address.
1437.TP
fea681da
MK
1438.B EINVAL
1439The value of
1440.I option