1PRCTL(2) Linux Programmer's Manual PRCTL(2)
2
3
4
6 prctl - operations on a process or thread
7
9 #include <sys/prctl.h>
10
11 int prctl(int option, unsigned long arg2, unsigned long arg3,
12 unsigned long arg4, unsigned long arg5);
13
15 prctl() manipulates various aspects of the behavior of the calling
16 thread or process.
17
18 Note that careless use of some prctl() operations can confuse the user-
19 space run-time environment, so these operations should be used with
20 care.
21
22 prctl() is called with a first argument describing what to do (with
23 values defined in <linux/prctl.h>), and further arguments with a sig‐
24 nificance depending on the first one. The first argument can be:
25
26 PR_CAP_AMBIENT (since Linux 4.3)
27 Reads or changes the ambient capability set of the calling
28 thread, according to the value of arg2, which must be one of the
29 following:
30
31 PR_CAP_AMBIENT_RAISE
32 The capability specified in arg3 is added to the ambient
33 set. The specified capability must already be present in
34 both the permitted and the inheritable sets of the
35 process. This operation is not permitted if the
36 SECBIT_NO_CAP_AMBIENT_RAISE securebit is set.
37
38 PR_CAP_AMBIENT_LOWER
39 The capability specified in arg3 is removed from the
40 ambient set.
41
42 PR_CAP_AMBIENT_IS_SET
43 The prctl() call returns 1 if the capability in arg3 is
44 in the ambient set and 0 if it is not.
45
46 PR_CAP_AMBIENT_CLEAR_ALL
47 All capabilities will be removed from the ambient set.
48 This operation requires setting arg3 to zero.
49
50 In all of the above operations, arg4 and arg5 must be specified
51 as 0.
52
53 Higher-level interfaces layered on top of the above operations
54 are provided in the libcap(3) library in the form of
55 cap_get_ambient(3), cap_set_ambient(3), and cap_reset_ambi‐
56 ent(3).
57
58 PR_CAPBSET_READ (since Linux 2.6.25)
59 Return (as the function result) 1 if the capability specified in
60 arg2 is in the calling thread's capability bounding set, or 0 if
61 it is not. (The capability constants are defined in
62 <linux/capability.h>.) The capability bounding set dictates
63 whether the process can receive the capability through a file's
64 permitted capability set on a subsequent call to execve(2).
65
66 If the capability specified in arg2 is not valid, then the call
67 fails with the error EINVAL.
68
69 A higher-level interface layered on top of this operation is
70 provided in the libcap(3) library in the form of
71 cap_get_bound(3).
72
73 PR_CAPBSET_DROP (since Linux 2.6.25)
74 If the calling thread has the CAP_SETPCAP capability within its
75 user namespace, then drop the capability specified by arg2 from
76 the calling thread's capability bounding set. Any children of
77 the calling thread will inherit the newly reduced bounding set.
78
79 The call fails with the error: EPERM if the calling thread does
80 not have the CAP_SETPCAP; EINVAL if arg2 does not represent a
81 valid capability; or EINVAL if file capabilities are not enabled
82 in the kernel, in which case bounding sets are not supported.
83
84 A higher-level interface layered on top of this operation is
85 provided in the libcap(3) library in the form of
86 cap_drop_bound(3).
87
88 PR_SET_CHILD_SUBREAPER (since Linux 3.4)
89 If arg2 is nonzero, set the "child subreaper" attribute of the
90 calling process; if arg2 is zero, unset the attribute.
91
92 A subreaper fulfills the role of init(1) for its descendant pro‐
93 cesses. When a process becomes orphaned (i.e., its immediate
94 parent terminates), then that process will be reparented to the
95 nearest still living ancestor subreaper. Subsequently, calls to
96 getppid(2) in the orphaned process will now return the PID of
97 the subreaper process, and when the orphan terminates, it is the
98 subreaper process that will receive a SIGCHLD signal and will be
99 able to wait(2) on the process to discover its termination sta‐
100 tus.
101
102 The setting of the "child subreaper" attribute is not inherited
103 by children created by fork(2) and clone(2). The setting is
104 preserved across execve(2).
105
106 Establishing a subreaper process is useful in session management
107 frameworks where a hierarchical group of processes is managed by
108 a subreaper process that needs to be informed when one of the
109 processes—for example, a double-forked daemon—terminates (per‐
110 haps so that it can restart that process). Some init(1) frame‐
111 works (e.g., systemd(1)) employ a subreaper process for similar
112 reasons.
113
114 PR_GET_CHILD_SUBREAPER (since Linux 3.4)
115 Return the "child subreaper" setting of the caller, in the loca‐
116 tion pointed to by (int *) arg2.
117
118 PR_SET_DUMPABLE (since Linux 2.3.20)
119 Set the state of the "dumpable" attribute, which determines
120 whether core dumps are produced for the calling process upon
121 delivery of a signal whose default behavior is to produce a core
122 dump.
123
124 In kernels up to and including 2.6.12, arg2 must be either 0
125 (SUID_DUMP_DISABLE, process is not dumpable) or 1
126 (SUID_DUMP_USER, process is dumpable). Between kernels 2.6.13
127 and 2.6.17, the value 2 was also permitted, which caused any
128 binary which normally would not be dumped to be dumped readable
129 by root only; for security reasons, this feature has been
130 removed. (See also the description of /proc/sys/fs/
131 suid_dumpable in proc(5).)
132
133 Normally, the "dumpable" attribute is set to 1. However, it is
134 reset to the current value contained in the file /proc/sys/fs/
135 suid_dumpable (which by default has the value 0), in the follow‐
136 ing circumstances:
137
138 * The process's effective user or group ID is changed.
139
140 * The process's filesystem user or group ID is changed (see
141 credentials(7)).
142
143 * The process executes (execve(2)) a set-user-ID or set-group-
144 ID program, resulting in a change of either the effective
145 user ID or the effective group ID.
146
147 * The process executes (execve(2)) a program that has file
148 capabilities (see capabilities(7)), but only if the permitted
149 capabilities gained exceed those already permitted for the
150 process.
151
152 Processes that are not dumpable can not be attached via
153 ptrace(2) PTRACE_ATTACH; see ptrace(2) for further details.
154
155 If a process is not dumpable, the ownership of files in the
156 process's /proc/[pid] directory is affected as described in
157 proc(5).
158
159 PR_GET_DUMPABLE (since Linux 2.3.20)
160 Return (as the function result) the current state of the calling
161 process's dumpable attribute.
162
163 PR_SET_ENDIAN (since Linux 2.6.18, PowerPC only)
164 Set the endian-ness of the calling process to the value given in
165 arg2, which should be one of the following: PR_ENDIAN_BIG,
166 PR_ENDIAN_LITTLE, or PR_ENDIAN_PPC_LITTLE (PowerPC pseudo little
167 endian).
168
169 PR_GET_ENDIAN (since Linux 2.6.18, PowerPC only)
170 Return the endian-ness of the calling process, in the location
171 pointed to by (int *) arg2.
172
173 PR_SET_FP_MODE (since Linux 4.0, only on MIPS)
174 On the MIPS architecture, user-space code can be built using an
175 ABI which permits linking with code that has more restrictive
176 floating-point (FP) requirements. For example, user-space code
177 may be built to target the O32 FPXX ABI and linked with code
178 built for either one of the more restrictive FP32 or FP64 ABIs.
179 When more restrictive code is linked in, the overall requirement
180 for the process is to use the more restrictive floating-point
181 mode.
182
183 Because the kernel has no means of knowing in advance which mode
184 the process should be executed in, and because these restric‐
185 tions can change over the lifetime of the process, the
186 PR_SET_FP_MODE operation is provided to allow control of the
187 floating-point mode from user space.
188
189 The (unsigned int) arg2 argument is a bit mask describing the
190 floating-point mode used:
191
192 PR_FP_MODE_FR
193 When this bit is unset (so called FR=0 or FR0 mode), the
194 32 floating-point registers are 32 bits wide, and 64-bit
195 registers are represented as a pair of registers (even-
196 and odd- numbered, with the even-numbered register con‐
197 taining the lower 32 bits, and the odd-numbered register
198 containing the higher 32 bits).
199
200 When this bit is set (on supported hardware), the 32
201 floating-point registers are 64 bits wide (so called FR=1
202 or FR1 mode). Note that modern MIPS implementations
203 (MIPS R6 and newer) support FR=1 mode only.
204
205 Applications that use the O32 FP32 ABI can operate only
206 when this bit is unset (FR=0; or they can be used with
207 FRE enabled, see below). Applications that use the O32
208 FP64 ABI (and the O32 FP64A ABI, which exists to provide
209 the ability to operate with existing FP32 code; see
210 below) can operate only when this bit is set (FR=1).
211 Applications that use the O32 FPXX ABI can operate with
212 either FR=0 or FR=1.
213
214 PR_FP_MODE_FRE
215 Enable emulation of 32-bit floating-point mode. When
216 this mode is enabled, it emulates 32-bit floating-point
217 operations by raising a reserved-instruction exception on
218 every instruction that uses 32-bit formats and the kernel
219 then handles the instruction in software. (The problem
220 lies in the discrepancy of handling odd-numbered regis‐
221 ters which are the high 32 bits of 64-bit registers with
222 even numbers in FR=0 mode and the lower 32-bit parts of
223 odd-numbered 64-bit registers in FR=1 mode.) Enabling
224 this bit is necessary when code with the O32 FP32 ABI
225 should operate with code with compatible the O32 FPXX or
226 O32 FP64A ABIs (which require FR=1 FPU mode) or when it
227 is executed on newer hardware (MIPS R6 onwards) which
228 lacks FR=0 mode support when a binary with the FP32 ABI
229 is used.
230
231 Note that this mode makes sense only when the FPU is in
232 64-bit mode (FR=1).
233
234 Note that the use of emulation inherently has a signifi‐
235 cant performance hit and should be avoided if possible.
236
237 In the N32/N64 ABI, 64-bit floating-point mode is always used,
238 so FPU emulation is not required and the FPU always operates in
239 FR=1 mode.
240
241 This option is mainly intended for use by the dynamic linker
242 (ld.so(8)).
243
244 The arguments arg3, arg4, and arg5 are ignored.
245
246 PR_GET_FP_MODE (since Linux 4.0, only on MIPS)
247 Return (as the function result) the current floating-point mode
248 (see the description of PR_SET_FP_MODE for details).
249
250 On success, the call returns a bit mask which represents the
251 current floating-point mode.
252
253 The arguments arg2, arg3, arg4, and arg5 are ignored.
254
255 PR_SET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
256 Set floating-point emulation control bits to arg2. Pass
257 PR_FPEMU_NOPRINT to silently emulate floating-point operation
258 accesses, or PR_FPEMU_SIGFPE to not emulate floating-point oper‐
259 ations and send SIGFPE instead.
260
261 PR_GET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
262 Return floating-point emulation control bits, in the location
263 pointed to by (int *) arg2.
264
265 PR_SET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
266 Set floating-point exception mode to arg2. Pass
267 PR_FP_EXC_SW_ENABLE to use FPEXC for FP exception enables,
268 PR_FP_EXC_DIV for floating-point divide by zero, PR_FP_EXC_OVF
269 for floating-point overflow, PR_FP_EXC_UND for floating-point
270 underflow, PR_FP_EXC_RES for floating-point inexact result,
271 PR_FP_EXC_INV for floating-point invalid operation,
272 PR_FP_EXC_DISABLED for FP exceptions disabled, PR_FP_EXC_NONRE‐
273 COV for async nonrecoverable exception mode, PR_FP_EXC_ASYNC for
274 async recoverable exception mode, PR_FP_EXC_PRECISE for precise
275 exception mode.
276
277 PR_GET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
278 Return floating-point exception mode, in the location pointed to
279 by (int *) arg2.
280
281 PR_SET_IO_FLUSHER (since Linux 5.6)
282 If a user process is involved in the block layer or filesystem
283 I/O path, and can allocate memory while processing I/O requests
284 it must set arg2 to 1. This will put the process in the
285 IO_FLUSHER state, which allows it special treatment to make
286 progress when allocating memory. If arg2 is 0, the process will
287 clear the IO_FLUSHER state, and the default behavior will be
288 used.
289
290 The calling process must have the CAP_SYS_RESOURCE capability.
291
292 arg3, arg4, and arg5 must be zero.
293
294 The IO_FLUSHER state is inherited by a child process created via
295 fork(2) and is preserved across execve(2).
296
297 Examples of IO_FLUSHER applications are FUSE daemons, SCSI
298 device emulation daemons, and daemons that perform error han‐
299 dling like multipath path recovery applications.
300
301 PR_GET_IO_FLUSHER (Since Linux 5.6)
302 Return (as the function result) the IO_FLUSHER state of the
303 caller. A value of 1 indicates that the caller is in the
304 IO_FLUSHER state; 0 indicates that the caller is not in the
305 IO_FLUSHER state.
306
307 The calling process must have the CAP_SYS_RESOURCE capability.
308
309 arg2, arg3, arg4, and arg5 must be zero.
310
311 PR_SET_KEEPCAPS (since Linux 2.2.18)
312 Set the state of the calling thread's "keep capabilities" flag.
313 The effect of this flag is described in capabilities(7). arg2
314 must be either 0 (clear the flag) or 1 (set the flag). The
315 "keep capabilities" value will be reset to 0 on subsequent calls
316 to execve(2).
317
318 PR_GET_KEEPCAPS (since Linux 2.2.18)
319 Return (as the function result) the current state of the calling
320 thread's "keep capabilities" flag. See capabilities(7) for a
321 description of this flag.
322
323 PR_MCE_KILL (since Linux 2.6.32)
324 Set the machine check memory corruption kill policy for the
325 calling thread. If arg2 is PR_MCE_KILL_CLEAR, clear the thread
326 memory corruption kill policy and use the system-wide default.
327 (The system-wide default is defined by /proc/sys/vm/memory_fail‐
328 ure_early_kill; see proc(5).) If arg2 is PR_MCE_KILL_SET, use a
329 thread-specific memory corruption kill policy. In this case,
330 arg3 defines whether the policy is early kill
331 (PR_MCE_KILL_EARLY), late kill (PR_MCE_KILL_LATE), or the sys‐
332 tem-wide default (PR_MCE_KILL_DEFAULT). Early kill means that
333 the thread receives a SIGBUS signal as soon as hardware memory
334 corruption is detected inside its address space. In late kill
335 mode, the process is killed only when it accesses a corrupted
336 page. See sigaction(2) for more information on the SIGBUS sig‐
337 nal. The policy is inherited by children. The remaining unused
338 prctl() arguments must be zero for future compatibility.
339
340 PR_MCE_KILL_GET (since Linux 2.6.32)
341 Return (as the function result) the current per-process machine
342 check kill policy. All unused prctl() arguments must be zero.
343
344 PR_SET_MM (since Linux 3.3)
345 Modify certain kernel memory map descriptor fields of the call‐
346 ing process. Usually these fields are set by the kernel and
347 dynamic loader (see ld.so(8) for more information) and a regular
348 application should not use this feature. However, there are
349 cases, such as self-modifying programs, where a program might
350 find it useful to change its own memory map.
351
352 The calling process must have the CAP_SYS_RESOURCE capability.
353 The value in arg2 is one of the options below, while arg3 pro‐
354 vides a new value for the option. The arg4 and arg5 arguments
355 must be zero if unused.
356
357 Before Linux 3.10, this feature is available only if the kernel
358 is built with the CONFIG_CHECKPOINT_RESTORE option enabled.
359
360 PR_SET_MM_START_CODE
361 Set the address above which the program text can run.
362 The corresponding memory area must be readable and exe‐
363 cutable, but not writable or shareable (see mprotect(2)
364 and mmap(2) for more information).
365
366 PR_SET_MM_END_CODE
367 Set the address below which the program text can run.
368 The corresponding memory area must be readable and exe‐
369 cutable, but not writable or shareable.
370
371 PR_SET_MM_START_DATA
372 Set the address above which initialized and uninitialized
373 (bss) data are placed. The corresponding memory area
374 must be readable and writable, but not executable or
375 shareable.
376
377 PR_SET_MM_END_DATA
378 Set the address below which initialized and uninitialized
379 (bss) data are placed. The corresponding memory area
380 must be readable and writable, but not executable or
381 shareable.
382
383 PR_SET_MM_START_STACK
384 Set the start address of the stack. The corresponding
385 memory area must be readable and writable.
386
387 PR_SET_MM_START_BRK
388 Set the address above which the program heap can be
389 expanded with brk(2) call. The address must be greater
390 than the ending address of the current program data seg‐
391 ment. In addition, the combined size of the resulting
392 heap and the size of the data segment can't exceed the
393 RLIMIT_DATA resource limit (see setrlimit(2)).
394
395 PR_SET_MM_BRK
396 Set the current brk(2) value. The requirements for the
397 address are the same as for the PR_SET_MM_START_BRK
398 option.
399
400 The following options are available since Linux 3.5.
401
402 PR_SET_MM_ARG_START
403 Set the address above which the program command line is
404 placed.
405
406 PR_SET_MM_ARG_END
407 Set the address below which the program command line is
408 placed.
409
410 PR_SET_MM_ENV_START
411 Set the address above which the program environment is
412 placed.
413
414 PR_SET_MM_ENV_END
415 Set the address below which the program environment is
416 placed.
417
418 The address passed with PR_SET_MM_ARG_START,
419 PR_SET_MM_ARG_END, PR_SET_MM_ENV_START, and
420 PR_SET_MM_ENV_END should belong to a process stack area.
421 Thus, the corresponding memory area must be readable,
422 writable, and (depending on the kernel configuration)
423 have the MAP_GROWSDOWN attribute set (see mmap(2)).
424
425 PR_SET_MM_AUXV
426 Set a new auxiliary vector. The arg3 argument should
427 provide the address of the vector. The arg4 is the size
428 of the vector.
429
430 PR_SET_MM_EXE_FILE
431 Supersede the /proc/pid/exe symbolic link with a new one
432 pointing to a new executable file identified by the file
433 descriptor provided in arg3 argument. The file descrip‐
434 tor should be obtained with a regular open(2) call.
435
436 To change the symbolic link, one needs to unmap all
437 existing executable memory areas, including those created
438 by the kernel itself (for example the kernel usually cre‐
439 ates at least one executable memory area for the ELF
440 .text section).
441
442 In Linux 4.9 and earlier, the PR_SET_MM_EXE_FILE opera‐
443 tion can be performed only once in a process's lifetime;
444 attempting to perform the operation a second time results
445 in the error EPERM. This restriction was enforced for
446 security reasons that were subsequently deemed specious,
447 and the restriction was removed in Linux 4.10 because
448 some user-space applications needed to perform this oper‐
449 ation more than once.
450
451 The following options are available since Linux 3.18.
452
453 PR_SET_MM_MAP
454 Provides one-shot access to all the addresses by passing
455 in a struct prctl_mm_map (as defined in <linux/prctl.h>).
456 The arg4 argument should provide the size of the struct.
457
458 This feature is available only if the kernel is built
459 with the CONFIG_CHECKPOINT_RESTORE option enabled.
460
461 PR_SET_MM_MAP_SIZE
462 Returns the size of the struct prctl_mm_map the kernel
463 expects. This allows user space to find a compatible
464 struct. The arg4 argument should be a pointer to an
465 unsigned int.
466
467 This feature is available only if the kernel is built
468 with the CONFIG_CHECKPOINT_RESTORE option enabled.
469
470 PR_MPX_ENABLE_MANAGEMENT, PR_MPX_DISABLE_MANAGEMENT (since Linux 3.19,
471 removed in Linux 5.4; only on x86)
472 Enable or disable kernel management of Memory Protection eXten‐
473 sions (MPX) bounds tables. The arg2, arg3, arg4, and arg5 argu‐
474 ments must be zero.
475
476 MPX is a hardware-assisted mechanism for performing bounds
477 checking on pointers. It consists of a set of registers storing
478 bounds information and a set of special instruction prefixes
479 that tell the CPU on which instructions it should do bounds
480 enforcement. There is a limited number of these registers and
481 when there are more pointers than registers, their contents must
482 be "spilled" into a set of tables. These tables are called
483 "bounds tables" and the MPX prctl() operations control whether
484 the kernel manages their allocation and freeing.
485
486 When management is enabled, the kernel will take over allocation
487 and freeing of the bounds tables. It does this by trapping the
488 #BR exceptions that result at first use of missing bounds tables
489 and instead of delivering the exception to user space, it allo‐
490 cates the table and populates the bounds directory with the
491 location of the new table. For freeing, the kernel checks to
492 see if bounds tables are present for memory which is not allo‐
493 cated, and frees them if so.
494
495 Before enabling MPX management using PR_MPX_ENABLE_MANAGEMENT,
496 the application must first have allocated a user-space buffer
497 for the bounds directory and placed the location of that direc‐
498 tory in the bndcfgu register.
499
500 These calls fail if the CPU or kernel does not support MPX.
501 Kernel support for MPX is enabled via the CONFIG_X86_INTEL_MPX
502 configuration option. You can check whether the CPU supports
503 MPX by looking for the mpx CPUID bit, like with the following
504 command:
505
506 cat /proc/cpuinfo | grep ' mpx '
507
508 A thread may not switch in or out of long (64-bit) mode while
509 MPX is enabled.
510
511 All threads in a process are affected by these calls.
512
513 The child of a fork(2) inherits the state of MPX management.
514 During execve(2), MPX management is reset to a state as if
515 PR_MPX_DISABLE_MANAGEMENT had been called.
516
517 For further information on Intel MPX, see the kernel source file
518 Documentation/x86/intel_mpx.txt.
519
520 Due to a lack of toolchain support, PR_MPX_ENABLE_MANAGEMENT and
521 PR_MPX_DISABLE_MANAGEMENT are not supported in Linux 5.4 and
522 later.
523
524 PR_SET_NAME (since Linux 2.6.9)
525 Set the name of the calling thread, using the value in the loca‐
526 tion pointed to by (char *) arg2. The name can be up to 16
527 bytes long, including the terminating null byte. (If the length
528 of the string, including the terminating null byte, exceeds 16
529 bytes, the string is silently truncated.) This is the same
530 attribute that can be set via pthread_setname_np(3) and
531 retrieved using pthread_getname_np(3). The attribute is like‐
532 wise accessible via /proc/self/task/[tid]/comm (see proc(5)),
533 where [tid] is the thread ID of the calling thread, as returned
534 by gettid(2).
535
536 PR_GET_NAME (since Linux 2.6.11)
537 Return the name of the calling thread, in the buffer pointed to
538 by (char *) arg2. The buffer should allow space for up to 16
539 bytes; the returned string will be null-terminated.
540
541 PR_SET_NO_NEW_PRIVS (since Linux 3.5)
542 Set the calling thread's no_new_privs attribute to the value in
543 arg2. With no_new_privs set to 1, execve(2) promises not to
544 grant privileges to do anything that could not have been done
545 without the execve(2) call (for example, rendering the set-user-
546 ID and set-group-ID mode bits, and file capabilities non-func‐
547 tional). Once set, the no_new_privs attribute cannot be unset.
548 The setting of this attribute is inherited by children created
549 by fork(2) and clone(2), and preserved across execve(2).
550
551 Since Linux 4.10, the value of a thread's no_new_privs attribute
552 can be viewed via the NoNewPrivs field in the /proc/[pid]/status
553 file.
554
555 For more information, see the kernel source file Documenta‐
556 tion/userspace-api/no_new_privs.rst (or Documenta‐
557 tion/prctl/no_new_privs.txt before Linux 4.13). See also sec‐
558 comp(2).
559
560 PR_GET_NO_NEW_PRIVS (since Linux 3.5)
561 Return (as the function result) the value of the no_new_privs
562 attribute for the calling thread. A value of 0 indicates the
563 regular execve(2) behavior. A value of 1 indicates execve(2)
564 will operate in the privilege-restricting mode described above.
565
566 PR_PAC_RESET_KEYS (since Linux 5.0, only on arm64)
567 Securely reset the thread's pointer authentication keys to fresh
568 random values generated by the kernel.
569
570 The set of keys to be reset is specified by arg2, which must be
571 a logical OR of zero or more of the following:
572
573 PR_PAC_APIAKEY
574 instruction authentication key A
575
576 PR_PAC_APIBKEY
577 instruction authentication key B
578
579 PR_PAC_APDAKEY
580 data authentication key A
581
582 PR_PAC_APDBKEY
583 data authentication key B
584
585 PR_PAC_APGAKEY
586 generic authentication “A” key.
587
588 (Yes folks, there really is no generic B key.)
589
590 As a special case, if arg2 is zero, then all the keys are reset.
591 Since new keys could be added in future, this is the recommended
592 way to completely wipe the existing keys when establishing a
593 clean execution context. Note that there is no need to use
594 PR_PAC_RESET_KEYS in preparation for calling execve(2), since
595 execve(2) resets all the pointer authentication keys.
596
597 The remaining arguments arg3, arg4, and arg5 must all be zero.
598
599 If the arguments are invalid, and in particular if arg2 contains
600 set bits that are unrecognized or that correspond to a key not
601 available on this platform, then the call fails with error EIN‐
602 VAL.
603
604 Warning: Because the compiler or run-time environment may be
605 using some or all of the keys, a successful may crash the call‐
606 ing process. The conditions for using it safely are complex and
607 system-dependent. Don't use it unless you know what you are
608 doing.
609
610 For more information, see the kernel source file Documenta‐
611 tion/arm64/pointer-authentication.rst (or Documenta‐
612 tion/arm64/pointer-authentication.txt before Linux 5.3).
613 PR_PAC_RESET_KEYS
614
615 PR_SET_PDEATHSIG (since Linux 2.1.57)
616 Set the parent-death signal of the calling process to arg2
617 (either a signal value in the range 1..NSIG-1, or 0 to clear).
618 This is the signal that the calling process will get when its
619 parent dies.
620
621 Warning: the "parent" in this case is considered to be the
622 thread that created this process. In other words, the signal
623 will be sent when that thread terminates (via, for example,
624 pthread_exit(3)), rather than after all of the threads in the
625 parent process terminate.
626
627 The parent-death signal is sent upon subsequent termination of
628 the parent thread and also upon termination of each subreaper
629 process (see the description of PR_SET_CHILD_SUBREAPER above) to
630 which the caller is subsequently reparented. If the parent
631 thread and all ancestor subreapers have already terminated by
632 the time of the PR_SET_PDEATHSIG operation, then no parent-death
633 signal is sent to the caller.
634
635 The parent-death signal is process-directed (see signal(7)) and,
636 if the child installs a handler using the sigaction(2) SA_SIG‐
637 INFO flag, the si_pid field of the siginfo_t argument of the
638 handler contains the PID of the terminating parent process.
639
640 The parent-death signal setting is cleared for the child of a
641 fork(2). It is also (since Linux 2.4.36 / 2.6.23) cleared when
642 executing a set-user-ID or set-group-ID binary, or a binary that
643 has associated capabilities (see capabilities(7)); otherwise,
644 this value is preserved across execve(2).
645
646 PR_GET_PDEATHSIG (since Linux 2.3.15)
647 Return the current value of the parent process death signal, in
648 the location pointed to by (int *) arg2.
649
650 PR_SET_PTRACER (since Linux 3.4)
651 This is meaningful only when the Yama LSM is enabled and in mode
652 1 ("restricted ptrace", visible via /proc/sys/ker‐
653 nel/yama/ptrace_scope). When a "ptracer process ID" is passed
654 in arg2, the caller is declaring that the ptracer process can
655 ptrace(2) the calling process as if it were a direct process
656 ancestor. Each PR_SET_PTRACER operation replaces the previous
657 "ptracer process ID". Employing PR_SET_PTRACER with arg2 set to
658 0 clears the caller's "ptracer process ID". If arg2 is
659 PR_SET_PTRACER_ANY, the ptrace restrictions introduced by Yama
660 are effectively disabled for the calling process.
661
662 For further information, see the kernel source file Documenta‐
663 tion/admin-guide/LSM/Yama.rst (or Documentation/secu‐
664 rity/Yama.txt before Linux 4.13).
665
666 PR_SET_SECCOMP (since Linux 2.6.23)
667 Set the secure computing (seccomp) mode for the calling thread,
668 to limit the available system calls. The more recent seccomp(2)
669 system call provides a superset of the functionality of
670 PR_SET_SECCOMP.
671
672 The seccomp mode is selected via arg2. (The seccomp constants
673 are defined in <linux/seccomp.h>.)
674
675 With arg2 set to SECCOMP_MODE_STRICT, the only system calls that
676 the thread is permitted to make are read(2), write(2), _exit(2)
677 (but not exit_group(2)), and sigreturn(2). Other system calls
678 result in the delivery of a SIGKILL signal. Strict secure com‐
679 puting mode is useful for number-crunching applications that may
680 need to execute untrusted byte code, perhaps obtained by reading
681 from a pipe or socket. This operation is available only if the
682 kernel is configured with CONFIG_SECCOMP enabled.
683
684 With arg2 set to SECCOMP_MODE_FILTER (since Linux 3.5), the sys‐
685 tem calls allowed are defined by a pointer to a Berkeley Packet
686 Filter passed in arg3. This argument is a pointer to struct
687 sock_fprog; it can be designed to filter arbitrary system calls
688 and system call arguments. This mode is available only if the
689 kernel is configured with CONFIG_SECCOMP_FILTER enabled.
690
691 If SECCOMP_MODE_FILTER filters permit fork(2), then the seccomp
692 mode is inherited by children created by fork(2); if execve(2)
693 is permitted, then the seccomp mode is preserved across
694 execve(2). If the filters permit prctl() calls, then additional
695 filters can be added; they are run in order until the first non-
696 allow result is seen.
697
698 For further information, see the kernel source file Documenta‐
699 tion/userspace-api/seccomp_filter.rst (or Documenta‐
700 tion/prctl/seccomp_filter.txt before Linux 4.13).
701
702 PR_GET_SECCOMP (since Linux 2.6.23)
703 Return (as the function result) the secure computing mode of the
704 calling thread. If the caller is not in secure computing mode,
705 this operation returns 0; if the caller is in strict secure com‐
706 puting mode, then the prctl() call will cause a SIGKILL signal
707 to be sent to the process. If the caller is in filter mode, and
708 this system call is allowed by the seccomp filters, it returns
709 2; otherwise, the process is killed with a SIGKILL signal. This
710 operation is available only if the kernel is configured with
711 CONFIG_SECCOMP enabled.
712
713 Since Linux 3.8, the Seccomp field of the /proc/[pid]/status
714 file provides a method of obtaining the same information, with‐
715 out the risk that the process is killed; see proc(5).
716
717 PR_SET_SECUREBITS (since Linux 2.6.26)
718 Set the "securebits" flags of the calling thread to the value
719 supplied in arg2. See capabilities(7).
720
721 PR_GET_SECUREBITS (since Linux 2.6.26)
722 Return (as the function result) the "securebits" flags of the
723 calling thread. See capabilities(7).
724
725 PR_GET_SPECULATION_CTRL (since Linux 4.17)
726 Return (as the function result) the state of the speculation
727 misfeature specified in arg2. Currently, the only permitted
728 value for this argument is PR_SPEC_STORE_BYPASS (otherwise the
729 call fails with the error ENODEV).
730
731 The return value uses bits 0-3 with the following meaning:
732
733 PR_SPEC_PRCTL
734 Mitigation can be controlled per thread by PR_SET_SPECU‐
735 LATION_CTRL.
736
737 PR_SPEC_ENABLE
738 The speculation feature is enabled, mitigation is dis‐
739 abled.
740
741 PR_SPEC_DISABLE
742 The speculation feature is disabled, mitigation is
743 enabled.
744
745 PR_SPEC_FORCE_DISABLE
746 Same as PR_SPEC_DISABLE but cannot be undone.
747
748 PR_SPEC_DISABLE_NOEXEC (since Linux 5.1)
749 Same as PR_SPEC_DISABLE, but the state will be cleared on
750 execve(2).
751
752 If all bits are 0, then the CPU is not affected by the specula‐
753 tion misfeature.
754
755 If PR_SPEC_PRCTL is set, then per-thread control of the mitiga‐
756 tion is available. If not set, prctl() for the speculation mis‐
757 feature will fail.
758
759 The arg3, arg4, and arg5 arguments must be specified as 0; oth‐
760 erwise the call fails with the error EINVAL.
761
762 PR_SET_SPECULATION_CTRL (since Linux 4.17)
763 Sets the state of the speculation misfeature specified in arg2.
764 The speculation-misfeature settings are per-thread attributes.
765
766 Currently, arg2 must be one of:
767
768 PR_SPEC_STORE_BYPASS
769 Set the state of the speculative store bypass misfeature.
770
771 PR_SPEC_INDIRECT_BRANCH (since Linux 4.20)
772 Set the state of the indirect branch speculation misfea‐
773 ture.
774
775 If arg2 does not have one of the above values, then the call
776 fails with the error ENODEV.
777
778 The arg3 argument is used to hand in the control value, which is
779 one of the following:
780
781 PR_SPEC_ENABLE
782 The speculation feature is enabled, mitigation is dis‐
783 abled.
784
785 PR_SPEC_DISABLE
786 The speculation feature is disabled, mitigation is
787 enabled.
788
789 PR_SPEC_FORCE_DISABLE
790 Same as PR_SPEC_DISABLE, but cannot be undone. A subse‐
791 quent prctl(arg2, PR_SPEC_ENABLE) with the same value for
792 arg2 will fail with the error EPERM.
793
794 PR_SPEC_DISABLE_NOEXEC (since Linux 5.1)
795 Same as PR_SPEC_DISABLE, but the state will be cleared on
796 execve(2). Currently only supported for arg2 equal to
797 PR_SPEC_STORE_BYPASS.
798
799 Any unsupported value in arg3 will result in the call failing
800 with the error ERANGE.
801
802 The arg4 and arg5 arguments must be specified as 0; otherwise
803 the call fails with the error EINVAL.
804
805 The speculation feature can also be controlled by the
806 spec_store_bypass_disable boot parameter. This parameter may
807 enforce a read-only policy which will result in the prctl() call
808 failing with the error ENXIO. For further details, see the ker‐
809 nel source file Documentation/admin-guide/kernel-parameters.txt.
810
811 PR_TASK_PERF_EVENTS_DISABLE (since Linux 2.6.31)
812 Disable all performance counters attached to the calling
813 process, regardless of whether the counters were created by this
814 process or another process. Performance counters created by the
815 calling process for other processes are unaffected. For more
816 information on performance counters, see the Linux kernel source
817 file tools/perf/design.txt.
818
819 Originally called PR_TASK_PERF_COUNTERS_DISABLE; renamed
820 (retaining the same numerical value) in Linux 2.6.32.
821
822 PR_TASK_PERF_EVENTS_ENABLE (since Linux 2.6.31)
823 The converse of PR_TASK_PERF_EVENTS_DISABLE; enable performance
824 counters attached to the calling process.
825
826 Originally called PR_TASK_PERF_COUNTERS_ENABLE; renamed in Linux
827 2.6.32.
828
829 PR_SET_THP_DISABLE (since Linux 3.15)
830 Set the state of the "THP disable" flag for the calling thread.
831 If arg2 has a nonzero value, the flag is set, otherwise it is
832 cleared. Setting this flag provides a method for disabling
833 transparent huge pages for jobs where the code cannot be modi‐
834 fied, and using a malloc hook with madvise(2) is not an option
835 (i.e., statically allocated data). The setting of the "THP dis‐
836 able" flag is inherited by a child created via fork(2) and is
837 preserved across execve(2).
838
839 PR_GET_THP_DISABLE (since Linux 3.15)
840 Return (as the function result) the current setting of the "THP
841 disable" flag for the calling thread: either 1, if the flag is
842 set, or 0, if it is not.
843
844 PR_GET_TID_ADDRESS (since Linux 3.5)
845 Return the clear_child_tid address set by set_tid_address(2) and
846 the clone(2) CLONE_CHILD_CLEARTID flag, in the location pointed
847 to by (int **) arg2. This feature is available only if the ker‐
848 nel is built with the CONFIG_CHECKPOINT_RESTORE option enabled.
849 Note that since the prctl() system call does not have a compat
850 implementation for the AMD64 x32 and MIPS n32 ABIs, and the ker‐
851 nel writes out a pointer using the kernel's pointer size, this
852 operation expects a user-space buffer of 8 (not 4) bytes on
853 these ABIs.
854
855 PR_SET_TIMERSLACK (since Linux 2.6.28)
856 Each thread has two associated timer slack values: a "default"
857 value, and a "current" value. This operation sets the "current"
858 timer slack value for the calling thread. arg2 is an unsigned
859 long value, then maximum "current" value is ULONG_MAX and the
860 minimum "current" value is 1. If the nanosecond value supplied
861 in arg2 is greater than zero, then the "current" value is set to
862 this value. If arg2 is equal to zero, the "current" timer slack
863 is reset to the thread's "default" timer slack value.
864
865 The "current" timer slack is used by the kernel to group timer
866 expirations for the calling thread that are close to one
867 another; as a consequence, timer expirations for the thread may
868 be up to the specified number of nanoseconds late (but will
869 never expire early). Grouping timer expirations can help reduce
870 system power consumption by minimizing CPU wake-ups.
871
872 The timer expirations affected by timer slack are those set by
873 select(2), pselect(2), poll(2), ppoll(2), epoll_wait(2),
874 epoll_pwait(2), clock_nanosleep(2), nanosleep(2), and futex(2)
875 (and thus the library functions implemented via futexes, includ‐
876 ing pthread_cond_timedwait(3), pthread_mutex_timedlock(3),
877 pthread_rwlock_timedrdlock(3), pthread_rwlock_timedwrlock(3),
878 and sem_timedwait(3)).
879
880 Timer slack is not applied to threads that are scheduled under a
881 real-time scheduling policy (see sched_setscheduler(2)).
882
883 When a new thread is created, the two timer slack values are
884 made the same as the "current" value of the creating thread.
885 Thereafter, a thread can adjust its "current" timer slack value
886 via PR_SET_TIMERSLACK. The "default" value can't be changed.
887 The timer slack values of init (PID 1), the ancestor of all pro‐
888 cesses, are 50,000 nanoseconds (50 microseconds). The timer
889 slack value is inherited by a child created via fork(2), and is
890 preserved across execve(2).
891
892 Since Linux 4.6, the "current" timer slack value of any process
893 can be examined and changed via the file /proc/[pid]/timer‐
894 slack_ns. See proc(5).
895
896 PR_GET_TIMERSLACK (since Linux 2.6.28)
897 Return (as the function result) the "current" timer slack value
898 of the calling thread.
899
900 PR_SET_TIMING (since Linux 2.6.0)
901 Set whether to use (normal, traditional) statistical process
902 timing or accurate timestamp-based process timing, by passing
903 PR_TIMING_STATISTICAL or PR_TIMING_TIMESTAMP to arg2. PR_TIM‐
904 ING_TIMESTAMP is not currently implemented (attempting to set
905 this mode will yield the error EINVAL).
906
907 PR_GET_TIMING (since Linux 2.6.0)
908 Return (as the function result) which process timing method is
909 currently in use.
910
911 PR_SET_TSC (since Linux 2.6.26, x86 only)
912 Set the state of the flag determining whether the timestamp
913 counter can be read by the process. Pass PR_TSC_ENABLE to arg2
914 to allow it to be read, or PR_TSC_SIGSEGV to generate a SIGSEGV
915 when the process tries to read the timestamp counter.
916
917 PR_GET_TSC (since Linux 2.6.26, x86 only)
918 Return the state of the flag determining whether the timestamp
919 counter can be read, in the location pointed to by (int *) arg2.
920
921 PR_SET_UNALIGN
922 (Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
923 PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22; sh,
924 since Linux 2.6.34; tile, since Linux 3.12) Set unaligned access
925 control bits to arg2. Pass PR_UNALIGN_NOPRINT to silently fix
926 up unaligned user accesses, or PR_UNALIGN_SIGBUS to generate
927 SIGBUS on unaligned user access. Alpha also supports an addi‐
928 tional flag with the value of 4 and no corresponding named con‐
929 stant, which instructs kernel to not fix up unaligned accesses
930 (it is analogous to providing the UAC_NOFIX flag in SSI_NVPAIRS
931 operation of the setsysinfo() system call on Tru64).
932
933 PR_GET_UNALIGN
934 (See PR_SET_UNALIGN for information on versions and architec‐
935 tures.) Return unaligned access control bits, in the location
936 pointed to by (unsigned int *) arg2.
937
939 On success, PR_CAP_AMBIENT+PR_CAP_AMBIENT_IS_SET, PR_CAPBSET_READ,
940 PR_GET_DUMPABLE, PR_GET_FP_MODE, PR_GET_IO_FLUSHER, PR_GET_KEEPCAPS,
941 PR_MCE_KILL_GET, PR_GET_NO_NEW_PRIVS, PR_GET_SECUREBITS, PR_GET_SPECU‐
942 LATION_CTRL, PR_GET_THP_DISABLE, PR_GET_TIMING, PR_GET_TIMERSLACK, and
943 (if it returns) PR_GET_SECCOMP return the nonnegative values described
944 above. All other option values return 0 on success. On error, -1 is
945 returned, and errno is set appropriately.
946
948 EACCES option is PR_SET_SECCOMP and arg2 is SECCOMP_MODE_FILTER, but
949 the process does not have the CAP_SYS_ADMIN capability or has
950 not set the no_new_privs attribute (see the discussion of
951 PR_SET_NO_NEW_PRIVS above).
952
953 EACCES option is PR_SET_MM, and arg3 is PR_SET_MM_EXE_FILE, the file is
954 not executable.
955
956 EBADF option is PR_SET_MM, arg3 is PR_SET_MM_EXE_FILE, and the file
957 descriptor passed in arg4 is not valid.
958
959 EBUSY option is PR_SET_MM, arg3 is PR_SET_MM_EXE_FILE, and this the
960 second attempt to change the /proc/pid/exe symbolic link, which
961 is prohibited.
962
963 EFAULT arg2 is an invalid address.
964
965 EFAULT option is PR_SET_SECCOMP, arg2 is SECCOMP_MODE_FILTER, the sys‐
966 tem was built with CONFIG_SECCOMP_FILTER, and arg3 is an invalid
967 address.
968
969 EINVAL The value of option is not recognized, or not supported on this
970 system.
971
972 EINVAL option is PR_MCE_KILL or PR_MCE_KILL_GET or PR_SET_MM, and
973 unused prctl() arguments were not specified as zero.
974
975 EINVAL arg2 is not valid value for this option.
976
977 EINVAL option is PR_SET_SECCOMP or PR_GET_SECCOMP, and the kernel was
978 not configured with CONFIG_SECCOMP.
979
980 EINVAL option is PR_SET_SECCOMP, arg2 is SECCOMP_MODE_FILTER, and the
981 kernel was not configured with CONFIG_SECCOMP_FILTER.
982
983 EINVAL option is PR_SET_MM, and one of the following is true
984
985 * arg4 or arg5 is nonzero;
986
987 * arg3 is greater than TASK_SIZE (the limit on the size of the
988 user address space for this architecture);
989
990 * arg2 is PR_SET_MM_START_CODE, PR_SET_MM_END_CODE,
991 PR_SET_MM_START_DATA, PR_SET_MM_END_DATA, or
992 PR_SET_MM_START_STACK, and the permissions of the correspond‐
993 ing memory area are not as required;
994
995 * arg2 is PR_SET_MM_START_BRK or PR_SET_MM_BRK, and arg3 is
996 less than or equal to the end of the data segment or speci‐
997 fies a value that would cause the RLIMIT_DATA resource limit
998 to be exceeded.
999
1000 EINVAL option is PR_SET_PTRACER and arg2 is not 0, PR_SET_PTRACER_ANY,
1001 or the PID of an existing process.
1002
1003 EINVAL option is PR_SET_PDEATHSIG and arg2 is not a valid signal num‐
1004 ber.
1005
1006 EINVAL option is PR_SET_DUMPABLE and arg2 is neither SUID_DUMP_DISABLE
1007 nor SUID_DUMP_USER.
1008
1009 EINVAL option is PR_SET_TIMING and arg2 is not PR_TIMING_STATISTICAL.
1010
1011 EINVAL option is PR_SET_NO_NEW_PRIVS and arg2 is not equal to 1 or
1012 arg3, arg4, or arg5 is nonzero.
1013
1014 EINVAL option is PR_GET_NO_NEW_PRIVS and arg2, arg3, arg4, or arg5 is
1015 nonzero.
1016
1017 EINVAL option is PR_SET_THP_DISABLE and arg3, arg4, or arg5 is nonzero.
1018
1019 EINVAL option is PR_GET_THP_DISABLE and arg2, arg3, arg4, or arg5 is
1020 nonzero.
1021
1022 EINVAL option is PR_CAP_AMBIENT and an unused argument (arg4, arg5, or,
1023 in the case of PR_CAP_AMBIENT_CLEAR_ALL, arg3) is nonzero; or
1024 arg2 has an invalid value; or arg2 is PR_CAP_AMBIENT_LOWER,
1025 PR_CAP_AMBIENT_RAISE, or PR_CAP_AMBIENT_IS_SET and arg3 does not
1026 specify a valid capability.
1027
1028 EINVAL option was PR_GET_SPECULATION_CTRL or PR_SET_SPECULATION_CTRL
1029 and unused arguments to prctl() are not 0. EINVAL option is
1030 PR_PAC_RESET_KEYS and the arguments are invalid or unsupported.
1031 See the description of PR_PAC_RESET_KEYS above for details.
1032
1033 ENODEV option was PR_SET_SPECULATION_CTRL the kernel or CPU does not
1034 support the requested speculation misfeature.
1035
1036 ENXIO option was PR_MPX_ENABLE_MANAGEMENT or PR_MPX_DISABLE_MANAGEMENT
1037 and the kernel or the CPU does not support MPX management.
1038 Check that the kernel and processor have MPX support.
1039
1040 ENXIO option was PR_SET_SPECULATION_CTRL implies that the control of
1041 the selected speculation misfeature is not possible. See
1042 PR_GET_SPECULATION_CTRL for the bit fields to determine which
1043 option is available.
1044
1045 EOPNOTSUPP
1046 option is PR_SET_FP_MODE and arg2 has an invalid or unsupported
1047 value.
1048
1049 EPERM option is PR_SET_SECUREBITS, and the caller does not have the
1050 CAP_SETPCAP capability, or tried to unset a "locked" flag, or
1051 tried to set a flag whose corresponding locked flag was set (see
1052 capabilities(7)).
1053
1054 EPERM option is PR_SET_SPECULATION_CTRL wherein the speculation was
1055 disabled with PR_SPEC_FORCE_DISABLE and caller tried to enable
1056 it again.
1057
1058 EPERM option is PR_SET_KEEPCAPS, and the caller's
1059 SECBIT_KEEP_CAPS_LOCKED flag is set (see capabilities(7)).
1060
1061 EPERM option is PR_CAPBSET_DROP, and the caller does not have the
1062 CAP_SETPCAP capability.
1063
1064 EPERM option is PR_SET_MM, and the caller does not have the
1065 CAP_SYS_RESOURCE capability.
1066
1067 EPERM option is PR_CAP_AMBIENT and arg2 is PR_CAP_AMBIENT_RAISE, but
1068 either the capability specified in arg3 is not present in the
1069 process's permitted and inheritable capability sets, or the
1070 PR_CAP_AMBIENT_LOWER securebit has been set.
1071
1072 ERANGE option was PR_SET_SPECULATION_CTRL and arg3 is not
1073 PR_SPEC_ENABLE, PR_SPEC_DISABLE, PR_SPEC_FORCE_DISABLE, nor
1074 PR_SPEC_DISABLE_NOEXEC.
1075
1077 The prctl() system call was introduced in Linux 2.1.57.
1078
1080 This call is Linux-specific. IRIX has a prctl() system call (also
1081 introduced in Linux 2.1.44 as irix_prctl on the MIPS architecture),
1082 with prototype
1083
1084 ptrdiff_t prctl(int option, int arg2, int arg3);
1085
1086 and options to get the maximum number of processes per user, get the
1087 maximum number of processors the calling process can use, find out
1088 whether a specified process is currently blocked, get or set the maxi‐
1089 mum stack size, and so on.
1090
1092 signal(2), core(5)
1093
1095 This page is part of release 5.07 of the Linux man-pages project. A
1096 description of the project, information about reporting bugs, and the
1097 latest version of this page, can be found at
1098 https://www.kernel.org/doc/man-pages/.
1099
1100
1101
1102Linux 2020-04-11 PRCTL(2)