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