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