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