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