]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/prctl.2
prctl.2: Note that arg4 and arg5 must be zero for CAP_AMBIENT
[thirdparty/man-pages.git] / man2 / prctl.2
CommitLineData
fea681da 1.\" Copyright (C) 1998 Andries Brouwer (aeb@cwi.nl)
73d3ac53 2.\" and Copyright (C) 2002, 2006, 2008, 2012, 2013 Michael Kerrisk <mtk.manpages@gmail.com>
af5f9508 3.\" and Copyright Guillem Jover <guillem@hadrons.org>
3cd5e983 4.\" and Copyright (C) 2014 Dave Hansen / Intel
fea681da 5.\"
93015253 6.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
7.\" Permission is granted to make and distribute verbatim copies of this
8.\" manual provided the copyright notice and this permission notice are
9.\" preserved on all copies.
10.\"
11.\" Permission is granted to copy and distribute modified versions of this
12.\" manual under the conditions for verbatim copying, provided that the
13.\" entire resulting derived work is distributed under the terms of a
14.\" permission notice identical to this one.
c13182ef 15.\"
fea681da
MK
16.\" Since the Linux kernel and libraries are constantly changing, this
17.\" manual page may be incorrect or out-of-date. The author(s) assume no
18.\" responsibility for errors or omissions, or for damages resulting from
19.\" the use of the information contained herein. The author(s) may not
20.\" have taken the same level of care in the production of this manual,
21.\" which is licensed free of charge, as they might when working
22.\" professionally.
c13182ef 23.\"
fea681da
MK
24.\" Formatted or processed versions of this manual, if unaccompanied by
25.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 26.\" %%%LICENSE_END
fea681da
MK
27.\"
28.\" Modified Thu Nov 11 04:19:42 MET 1999, aeb: added PR_GET_PDEATHSIG
29.\" Modified 27 Jun 02, Michael Kerrisk
c13182ef 30.\" Added PR_SET_DUMPABLE, PR_GET_DUMPABLE,
fea681da 31.\" PR_SET_KEEPCAPS, PR_GET_KEEPCAPS
e87fdd92
MK
32.\" Modified 2006-08-30 Guillem Jover <guillem@hadrons.org>
33.\" Updated Linux versions where the options where introduced.
34.\" Added PR_SET_TIMING, PR_GET_TIMING, PR_SET_NAME, PR_GET_NAME,
35.\" PR_SET_UNALIGN, PR_GET_UNALIGN, PR_SET_FPEMU, PR_GET_FPEMU,
36.\" PR_SET_FPEXC, PR_GET_FPEXC
8ab8b43f
MK
37.\" 2008-04-29 Serge Hallyn, Document PR_CAPBSET_READ and PR_CAPBSET_DROP
38.\" 2008-06-13 Erik Bosman, <ejbosman@cs.vu.nl>
39.\" Document PR_GET_TSC and PR_SET_TSC.
40.\" 2008-06-15 mtk, Document PR_SET_SECCOMP, PR_GET_SECCOMP
bc02b3ea 41.\" 2009-10-03 Andi Kleen, document PR_MCE_KILL
06afe673 42.\" 2012-04 Cyrill Gorcunov, Document PR_SET_MM
bc02b3ea
MK
43.\" 2012-04-25 Michael Kerrisk, Document PR_TASK_PERF_EVENTS_DISABLE and
44.\" PR_TASK_PERF_EVENTS_ENABLE
34447828 45.\" 2012-09-20 Kees Cook, update PR_SET_SECCOMP for mode 2
f83fe154 46.\" 2012-09-20 Kees Cook, document PR_SET_NO_NEW_PRIVS, PR_GET_NO_NEW_PRIVS
934487a0
MK
47.\" 2012-10-25 Michael Kerrisk, Document PR_SET_TIMERSLACK and
48.\" PR_GET_TIMERSLACK
491b2e75 49.\" 2013-01-10 Kees Cook, document PR_SET_PTRACER
73d3ac53 50.\" 2012-02-04 Michael kerrisk, document PR_{SET,GET}_CHILD_SUBREAPER
03979794 51.\" 2014-11-10 Dave Hansen, document PR_MPX_{EN,DIS}ABLE_MANAGEMENT
fea681da 52.\"
e14baeeb 53.\"
67d2c687 54.TH PRCTL 2 2015-05-07 "Linux" "Linux Programmer's Manual"
fea681da
MK
55.SH NAME
56prctl \- operations on a process
57.SH SYNOPSIS
521bf584 58.nf
fea681da
MK
59.B #include <sys/prctl.h>
60.sp
521bf584
MK
61.BI "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 ,
62.BI " unsigned long " arg4 ", unsigned long " arg5 );
63.fi
fea681da 64.SH DESCRIPTION
e511ffb6 65.BR prctl ()
fea681da 66is called with a first argument describing what to do
1a329b56 67(with values defined in \fI<linux/prctl.h>\fP), and further
c4bb193f 68arguments with a significance depending on the first one.
fea681da 69The first argument can be:
03547431
MK
70.\"
71.TP
72.BR PR_CAP_AMBIENT " (since Linux 4.3)"
73.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
74Reads or changes the ambient capability set, according to the value of
75.IR arg2 ,
76which must be one of the following:
77.RS
78.\"
79.TP
80.B PR_CAP_AMBIENT_RAISE
81The capability specified in
82.I arg3
83is added to the ambient set.
84The specified capability must already be present in
85both the permitted and the inheritable sets of the process.
86This operation is not permitted if the
87.B SECBIT_NO_CAP_AMBIENT_RAISE
88securebit is set.
89.TP
90.B PR_CAP_AMBIENT_LOWER
91The capability specified in
92.I arg3
93is removed from the ambient set.
94.TP
95.B PR_CAP_AMBIENT_IS_SET
96The
97.BR prctl (2)
98call returns 1 if the capability in
99.I arg3
100is in the ambient set and 0 if it is not.
101.TP
102.BR PR_CAP_AMBIENT_CLEAR_ALL
103All capabilities will be removed from the ambient set.
104This operation requires setting
105.I arg3
106to zero.
107.RE
269e3b97
MK
108.IP
109In all of the above operations,
110.I arg4
111and
112.I arg5
113must be specified as 0.
fea681da 114.TP
2e781e20 115.BR PR_CAPBSET_READ " (since Linux 2.6.25)"
8ab8b43f
MK
116Return (as the function result) 1 if the capability specified in
117.I arg2
118is in the calling thread's capability bounding set,
119or 0 if it is not.
120(The capability constants are defined in
121.IR <linux/capability.h> .)
122The capability bounding set dictates
123whether the process can receive the capability through a
2914a14d 124file's permitted capability set on a subsequent call to
8ab8b43f
MK
125.BR execve (2).
126
127If the capability specified in
128.I arg2
129is not valid, then the call fails with the error
130.BR EINVAL .
131.TP
132.BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
133If the calling thread has the
134.B CAP_SETPCAP
135capability, then drop the capability specified by
136.I arg2
137from the calling thread's capability bounding set.
138Any children of the calling thread will inherit the newly
139reduced bounding set.
140
141The call fails with the error:
142.B EPERM
2914a14d 143if the calling thread does not have the
8ab8b43f
MK
144.BR CAP_SETPCAP ;
145.BR EINVAL
146if
147.I arg2
148does not represent a valid capability; or
149.BR EINVAL
150if file capabilities are not enabled in the kernel,
151in which case bounding sets are not supported.
73d3ac53
MK
152.TP
153.BR PR_SET_CHILD_SUBREAPER " (since Linux 3.4)"
154.\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b
155If
156.I arg2
157is nonzero,
158set the "child subreaper" attribute of the calling process;
159if
160.I arg2
161is zero, unset the attribute.
36127c0e 162When a process is marked as a child subreaper,
73d3ac53
MK
163all of the children that it creates, and their descendants,
164will be marked as having a subreaper.
165In effect, a subreaper fulfills the role of
166.BR init (1)
167for its descendant processes.
168Upon termination of a process
169that is orphaned (i.e., its immediate parent has already terminated)
170and marked as having a subreaper,
171the nearest still living ancestor subreaper
172will receive a
173.BR SIGCHLD
174signal and be able to
175.BR wait (2)
176on the process to discover its termination status.
73d3ac53
MK
177.TP
178.BR PR_GET_CHILD_SUBREAPER " (since Linux 3.4)"
179Return the "child subreaper" setting of the caller,
180in the location pointed to by
181.IR "(int\ *) arg2" .
8ab8b43f 182.TP
88989295 183.BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
2d7fc98d
MK
184Set the state of the "dumpable" flag,
185which determines whether core dumps are produced for the calling process
186upon delivery of a signal whose default behavior is to produce a core dump.
4a3713a4 187
88989295 188In kernels up to and including 2.6.12,
8ab8b43f 189.I arg2
8aad30d7
MK
190must be either 0
191.RB ( SUID_DUMP_DISABLE ,
192process is not dumpable) or 1
193.RB ( SUID_DUMP_USER ,
194process is dumpable).
0de51ed1
MK
195Between kernels 2.6.13 and 2.6.17,
196.\" commit abf75a5033d4da7b8a7e92321d74021d1fcfb502
197the value 2 was also permitted,
88989295
MK
198which caused any binary which normally would not be dumped
199to be dumped readable by root only;
200for security reasons, this feature has been removed.
201.\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
202.\" Subject: Fix prctl privilege escalation (CVE-2006-2451)
203.\" From: Marcel Holtmann <marcel () holtmann ! org>
204.\" Date: 2006-07-12 11:12:00
205(See also the description of
2d7fc98d 206.I /proc/sys/fs/\:suid_dumpable
88989295
MK
207in
208.BR proc (5).)
4a3713a4 209
2d7fc98d
MK
210Normally, this flag is set to 1.
211However, it is reset to the current value contained in the file
212.IR /proc/sys/fs/\:suid_dumpable
213(which by default has the value 0),
214if any of the following attributes of the process
215are changed by the operations listed below:
216.\" See kernel/cred.c::commit_creds() (Linux 3.18 sources)
217.RS
218.IP * 3
219The effective user or group ID is changed.
220.IP *
221The filesystem user or group ID is changed (see
222.BR credentials (7)).
223.IP *
224The process's set of permitted capabilities (see
225.BR capabilities (7))
226is changed such that its new set of capabilities is
227not a subset of its previous set of capabilities.
228.RE
229.IP
230The operations that may trigger changes to the dumpable flag include:
231.\" Look for uses of commit_creds() in the kernel source code
232.RS
233.IP * 3
234execution
235.RB ( execve (2))
236of a set-user-ID or set-group-ID program,
237or a program that has capabilities (see
238.BR capabilities (7));
239.IP *
240.BR capset (2);
241and
242.IP *
243system calls that change process credentials
244.RB ( setuid (2)
245.BR setgid (2),
246.BR setresuid (2),
247.BR setresgid (2),
248.BR setgroups (2),
249and so on).
5d28ea3e 250.\" Also certain namespace operations;
2d7fc98d
MK
251.RE
252.IP
cadcf1b1 253Processes that are not dumpable can not be attached via
6fdbc779 254.BR ptrace (2)
cadcf1b1 255.BR PTRACE_ATTACH .
64536a1b 256.TP
88989295
MK
257.BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
258Return (as the function result) the current state of the calling
259process's dumpable flag.
260.\" Since Linux 2.6.13, the dumpable flag can have the value 2,
261.\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
c7094399 262.\" flags has a nonzero value. This was fixed in 2.6.14.
64536a1b 263.TP
8ab8b43f 264.BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
c13182ef 265Set the endian-ness of the calling process to the value given
64536a1b 266in \fIarg2\fP, which should be one of the following:
8ab8b43f 267.\" Respectively 0, 1, 2
64536a1b
MK
268.BR PR_ENDIAN_BIG ,
269.BR PR_ENDIAN_LITTLE ,
270or
0daa9e92 271.B PR_ENDIAN_PPC_LITTLE
64536a1b 272(PowerPC pseudo little endian).
e87fdd92 273.TP
8ab8b43f
MK
274.BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
275Return the endian-ness of the calling process,
276in the location pointed to by
277.IR "(int\ *) arg2" .
278.TP
8ab8b43f 279.BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
e87fdd92 280Set floating-point emulation control bits to \fIarg2\fP.
7626d2ce
MK
281Pass
282.B PR_FPEMU_NOPRINT
283to silently emulate floating-point operation accesses, or
284.B PR_FPEMU_SIGFPE
285to not emulate floating-point operations and send
8bd58774
MK
286.B SIGFPE
287instead.
e87fdd92 288.TP
8ab8b43f
MK
289.BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
290Return floating-point emulation control bits,
291in the location pointed to by
292.IR "(int\ *) arg2" .
e87fdd92 293.TP
8ab8b43f 294.BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
1c44bd5b
MK
295Set floating-point exception mode to \fIarg2\fP.
296Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
c45bd688
MK
297\fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
298\fBPR_FP_EXC_OVF\fP for floating-point overflow,
299\fBPR_FP_EXC_UND\fP for floating-point underflow,
300\fBPR_FP_EXC_RES\fP for floating-point inexact result,
301\fBPR_FP_EXC_INV\fP for floating-point invalid operation,
e87fdd92 302\fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
b28f6e56 303\fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
e87fdd92
MK
304\fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
305\fBPR_FP_EXC_PRECISE\fP for precise exception mode.
306.TP
8ab8b43f
MK
307.BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
308Return floating-point exception mode,
309in the location pointed to by
310.IR "(int\ *) arg2" .
311.TP
88989295
MK
312.BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
313Set the state of the thread's "keep capabilities" flag,
028cb080
MK
314which determines whether the threads's permitted
315capability set is cleared when a change is made to the threads's user IDs
88989295 316such that the threads's real UID, effective UID, and saved set-user-ID
c7094399 317all become nonzero when at least one of them previously had the value 0.
028cb080
MK
318By default, the permitted capability set is cleared when such a change is made;
319setting the "keep capabilities" flag prevents it from being cleared.
88989295 320.I arg2
028cb080
MK
321must be either 0 (permitted capabilities are cleared)
322or 1 (permitted capabilities are kept).
323(A thread's
324.I effective
325capability set is always cleared when such a credential change is made,
326regardless of the setting of the "keep capabilities" flag.)
327The "keep capabilities" value will be reset to 0 on subsequent calls to
88989295
MK
328.BR execve (2).
329.TP
330.BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
331Return (as the function result) the current state of the calling threads's
332"keep capabilities" flag.
333.TP
03547431
MK
334.BR PR_MCE_KILL " (since Linux 2.6.32)"
335Set the machine check memory corruption kill policy for the current thread.
336If
337.I arg2
338is
339.BR PR_MCE_KILL_CLEAR ,
340clear the thread memory corruption kill policy and use the system-wide default.
341(The system-wide default is defined by
342.IR /proc/sys/vm/memory_failure_early_kill ;
343see
344.BR proc (5).)
345If
346.I arg2
347is
348.BR PR_MCE_KILL_SET ,
349use a thread-specific memory corruption kill policy.
350In this case,
351.I arg3
352defines whether the policy is
353.I early kill
354.RB ( PR_MCE_KILL_EARLY ),
355.I late kill
356.RB ( PR_MCE_KILL_LATE ),
357or the system-wide default
358.RB ( PR_MCE_KILL_DEFAULT ).
359Early kill means that the thread receives a
360.B SIGBUS
361signal as soon as hardware memory corruption is detected inside
362its address space.
363In late kill mode, the process is killed only when it accesses a corrupted page.
364See
365.BR sigaction (2)
366for more information on the
367.BR SIGBUS
368signal.
369The policy is inherited by children.
370The remaining unused
371.BR prctl ()
372arguments must be zero for future compatibility.
88989295 373.TP
03547431
MK
374.BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
375Return the current per-process machine check kill policy.
376All unused
377.BR prctl ()
378arguments must be zero.
88989295 379.TP
03547431
MK
380.BR PR_SET_MM " (since Linux 3.3)"
381.\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
382Modify certain kernel memory map descriptor fields
383of the calling process.
384Usually these fields are set by the kernel and dynamic loader (see
385.BR ld.so (8)
386for more information) and a regular application should not use this feature.
387However, there are cases, such as self-modifying programs,
388where a program might find it useful to change its own memory map.
389This feature is available only if the kernel is built with the
390.BR CONFIG_CHECKPOINT_RESTORE
391option enabled.
392The calling process must have the
393.BR CAP_SYS_RESOURCE
394capability.
395The value in
396.I arg2
397is one of the options below, while
398.I arg3
399provides a new value for the option.
400.RS
401.TP
402.BR PR_SET_MM_START_CODE
403Set the address above which the program text can run.
404The corresponding memory area must be readable and executable,
405but not writable or sharable (see
406.BR mprotect (2)
0fcc276f 407and
03547431
MK
408.BR mmap (2)
409for more information).
f83fe154 410.TP
03547431
MK
411.BR PR_SET_MM_END_CODE
412Set the address below which the program text can run.
413The corresponding memory area must be readable and executable,
414but not writable or sharable.
f83fe154 415.TP
03547431
MK
416.BR PR_SET_MM_START_DATA
417Set the address above which initialized and
418uninitialized (bss) data are placed.
419The corresponding memory area must be readable and writable,
420but not executable or sharable.
88989295 421.TP
03547431
MK
422.B PR_SET_MM_END_DATA
423Set the address below which initialized and
424uninitialized (bss) data are placed.
425The corresponding memory area must be readable and writable,
426but not executable or sharable.
88989295 427.TP
03547431
MK
428.BR PR_SET_MM_START_STACK
429Set the start address of the stack.
430The corresponding memory area must be readable and writable.
491b2e75 431.TP
03547431
MK
432.BR PR_SET_MM_START_BRK
433Set the address above which the program heap can be expanded with
434.BR brk (2)
435call.
436The address must be greater than the ending address of
437the current program data segment.
438In addition, the combined size of the resulting heap and
439the size of the data segment can't exceed the
440.BR RLIMIT_DATA
441resource limit (see
442.BR setrlimit (2)).
443.TP
444.BR PR_SET_MM_BRK
445Set the current
446.BR brk (2)
447value.
448The requirements for the address are the same as for the
449.BR PR_SET_MM_START_BRK
450option.
451.P
452The following options are available since Linux 3.5.
453.\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
454.TP
455.BR PR_SET_MM_ARG_START
456Set the address above which the program command line is placed.
457.TP
458.BR PR_SET_MM_ARG_END
459Set the address below which the program command line is placed.
460.TP
461.BR PR_SET_MM_ENV_START
462Set the address above which the program environment is placed.
463.TP
464.BR PR_SET_MM_ENV_END
465Set the address below which the program environment is placed.
466.IP
467The address passed with
468.BR PR_SET_MM_ARG_START ,
469.BR PR_SET_MM_ARG_END ,
470.BR PR_SET_MM_ENV_START ,
471and
472.BR PR_SET_MM_ENV_END
473should belong to a process stack area.
474Thus, the corresponding memory area must be readable, writable, and
475(depending on the kernel configuration) have the
476.BR MAP_GROWSDOWN
477attribute set (see
478.BR mmap (2)).
479.TP
480.BR PR_SET_MM_AUXV
481Set a new auxiliary vector.
482The
483.I arg3
484argument should provide the address of the vector.
485The
486.I arg4
487is the size of the vector.
488.TP
489.BR PR_SET_MM_EXE_FILE
490.\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
491Supersede the
492.IR /proc/pid/exe
493symbolic link with a new one pointing to a new executable file
494identified by the file descriptor provided in
495.I arg3
496argument.
497The file descriptor should be obtained with a regular
498.BR open (2)
499call.
500.IP
501To change the symbolic link, one needs to unmap all existing
502executable memory areas, including those created by the kernel itself
503(for example the kernel usually creates at least one executable
504memory area for the ELF
505.IR \.text
506section).
507.IP
508The second limitation is that such transitions can be done only once
509in a process life time.
510Any further attempts will be rejected.
511This should help system administrators monitor unusual
512symbolic-link transitions over all processes running on a system.
513.RE
514.TP
515.BR PR_MPX_ENABLE_MANAGEMENT ", " PR_MPX_DISABLE_MANAGEMENT " (since Linux 3.19) "
516.\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c
517.\" See also http://lwn.net/Articles/582712/
518.\" See also https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
519Enable or disable kernel management of Memory Protection eXtensions (MPX)
520bounds tables.
521The
522.IR arg2 ,
523.IR arg3 ,
524.IR arg4 ,
525and
526.IR arg5
527.\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88
528arguments must be zero.
529
530MPX is a hardware-assisted mechanism for performing bounds checking on
531pointers.
532It consists of a set of registers storing bounds information
533and a set of special instruction prefixes that tell the CPU on which
534instructions it should do bounds enforcement.
535There is a limited number of these registers and
536when there are more pointers than registers,
537their contents must be "spilled" into a set of tables.
538These tables are called "bounds tables" and the MPX
539.BR prctl ()
540operations control
541whether the kernel manages their allocation and freeing.
542
543When management is enabled, the kernel will take over allocation
544and freeing of the bounds tables.
545It does this by trapping the #BR exceptions that result
546at first use of missing bounds tables and
547instead of delivering the exception to user space,
548it allocates the table and populates the bounds directory
549with the location of the new table.
550For freeing, the kernel checks to see if bounds tables are
551present for memory which is not allocated, and frees them if so.
552
553Before enabling MPX management using
554.BR PR_MPX_ENABLE_MANAGEMENT ,
555the application must first have allocated a user-space buffer for
556the bounds directory and placed the location of that directory in the
557.I bndcfgu
558register.
559
560These calls will fail if the CPU or kernel does not support MPX.
561Kernel support for MPX is enabled via the
562.BR CONFIG_X86_INTEL_MPX
563configuration option.
564You can check whether the CPU supports MPX by looking for the 'mpx'
565CPUID bit, like with the following command:
566
567 cat /proc/cpuinfo | grep ' mpx '
568
569A thread may not switch in or out of long (64-bit) mode while MPX is
570enabled.
571
572All threads in a process are affected by these calls.
573
574The child of a
575.BR fork (2)
576inherits the state of MPX management.
577During
578.BR execve (2),
579MPX management is reset to a state as if
580.BR PR_MPX_DISABLE_MANAGEMENT
581had been called.
582
583For further information on Intel MPX, see the kernel source file
584.IR Documentation/x86/intel_mpx.txt .
585.TP
586.BR PR_SET_NAME " (since Linux 2.6.9)"
587Set the name of the calling thread,
588using the value in the location pointed to by
589.IR "(char\ *) arg2" .
590The name can be up to 16 bytes long,
591.\" TASK_COMM_LEN in include/linux/sched.h
592including the terminating null byte.
593(If the length of the string, including the terminating null byte,
594exceeds 16 bytes, the string is silently truncated.)
595This is the same attribute that can be set via
596.BR pthread_setname_np (3)
597and retrieved using
598.BR pthread_getname_np (3).
599The attribute is likewise accessible via
600.IR /proc/self/task/[tid]/comm ,
601where
602.I tid
603is the name of the calling thread.
604.TP
605.BR PR_GET_NAME " (since Linux 2.6.11)"
606Return the name of the calling thread,
607in the buffer pointed to by
608.IR "(char\ *) arg2" .
609The buffer should allow space for up to 16 bytes;
610the returned string will be null-terminated.
611.TP
612.BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
613Set the calling process's
614.I no_new_privs
615bit to the value in
616.IR arg2 .
617With
618.I no_new_privs
619set to 1,
620.BR execve (2)
621promises not to grant privileges to do anything
622that could not have been done without the
623.BR execve (2)
624call (for example,
625rendering the set-user-ID and set-group-ID mode bits,
626and file capabilities non-functional).
627Once set, this bit cannot be unset.
628The setting of this bit is inherited by children created by
629.BR fork (2)
630and
631.BR clone (2),
632and preserved across
633.BR execve (2).
634
635For more information, see the kernel source file
636.IR Documentation/prctl/no_new_privs.txt .
637.TP
638.BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
639Return (as the function result) the value of the
640.I no_new_privs
641bit for the current process.
642A value of 0 indicates the regular
643.BR execve (2)
644behavior.
645A value of 1 indicates
646.BR execve (2)
647will operate in the privilege-restricting mode described above.
648.TP
649.BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
650Set the parent death signal
651of the calling process to \fIarg2\fP (either a signal value
652in the range 1..maxsig, or 0 to clear).
653This is the signal that the calling process will get when its
654parent dies.
655This value is cleared for the child of a
656.BR fork (2)
657and (since Linux 2.4.36 / 2.6.23)
658when executing a set-user-ID or set-group-ID binary,
659or a binary that has associated capabilities (see
660.BR capabilities (7)).
661This value is preserved across
662.BR execve (2).
663
664.IR Warning :
665.\" https://bugzilla.kernel.org/show_bug.cgi?id=43300
666the "parent" in this case is considered to be the
667.I thread
668that created this process.
669In other words, the signal will be sent when that thread terminates
670(via, for example,
671.BR pthread_exit (3)),
672rather than after all of the threads in the parent process terminate.
673.TP
674.BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
675Return the current value of the parent process death signal,
676in the location pointed to by
677.IR "(int\ *) arg2" .
678.TP
679.BR PR_SET_PTRACER " (since Linux 3.4)"
680.\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
681.\" commit bf06189e4d14641c0148bea16e9dd24943862215
682This is meaningful only when the Yama LSM is enabled and in mode 1
683("restricted ptrace", visible via
684.IR /proc/sys/kernel/yama/ptrace_scope ).
685When a "ptracer process ID" is passed in \fIarg2\fP,
686the caller is declaring that the ptracer process can
687.BR ptrace (2)
688the calling process as if it were a direct process ancestor.
689Each
690.B PR_SET_PTRACER
691operation replaces the previous "ptracer process ID".
692Employing
693.B PR_SET_PTRACER
694with
695.I arg2
696set to 0 clears the caller's "ptracer process ID".
697If
698.I arg2
699is
700.BR PR_SET_PTRACER_ANY ,
701the ptrace restrictions introduced by Yama are effectively disabled for the
702calling process.
703
704For further information, see the kernel source file
705.IR Documentation/security/Yama.txt .
706.TP
707.BR PR_SET_SECCOMP " (since Linux 2.6.23)"
708.\" See http://thread.gmane.org/gmane.linux.kernel/542632
709.\" [PATCH 0 of 2] seccomp updates
710.\" andrea@cpushare.com
711Set the secure computing (seccomp) mode for the calling thread, to limit
712the available system calls.
713The more recent
714.BR seccomp (2)
715system call provides a superset of the functionality of
716.BR PR_SET_SECCOMP .
717
718The seccomp mode is selected via
719.IR arg2 .
720(The seccomp constants are defined in
721.IR <linux/seccomp.h> .)
34447828
KC
722
723With
8ab8b43f 724.IR arg2
34447828 725set to
b1248a9d 726.BR SECCOMP_MODE_STRICT ,
8ab8b43f
MK
727the only system calls that the thread is permitted to make are
728.BR read (2),
729.BR write (2),
85fbef74
MK
730.BR _exit (2)
731(but not
732.BR exit_group (2)),
fea681da 733and
8ab8b43f
MK
734.BR sigreturn (2).
735Other system calls result in the delivery of a
736.BR SIGKILL
737signal.
34447828 738Strict secure computing mode is useful for number-crunching applications
8ab8b43f
MK
739that may need to execute untrusted byte code,
740perhaps obtained by reading from a pipe or socket.
33a0ccb2 741This operation is available only
d6ef3d57
MK
742if the kernel is configured with
743.B CONFIG_SECCOMP
744enabled.
34447828
KC
745
746With
747.IR arg2
748set to
b1248a9d 749.BR SECCOMP_MODE_FILTER " (since Linux 3.5),"
6239dfb2
MK
750the system calls allowed are defined by a pointer
751to a Berkeley Packet Filter passed in
752.IR arg3 .
753This argument is a pointer to
754.IR "struct sock_fprog" ;
755it can be designed to filter
d6ef3d57 756arbitrary system calls and system call arguments.
33a0ccb2 757This mode is available only if the kernel is configured with
d6ef3d57
MK
758.B CONFIG_SECCOMP_FILTER
759enabled.
34447828 760
1733db35
MK
761If
762.BR SECCOMP_MODE_FILTER
763filters permit
764.BR fork (2),
990e3887 765then the seccomp mode is inherited by children created by
1733db35
MK
766.BR fork (2);
767if
768.BR execve (2)
fa1d2749 769is permitted, then the seccomp mode is preserved across
1733db35
MK
770.BR execve (2).
771If the filters permit
a26ec136 772.BR prctl ()
1733db35
MK
773calls, then additional filters can be added;
774they are run in order until the first non-allow result is seen.
775
6239dfb2
MK
776For further information, see the kernel source file
777.IR Documentation/prctl/seccomp_filter.txt .
8ab8b43f
MK
778.TP
779.BR PR_GET_SECCOMP " (since Linux 2.6.23)"
5e91816c
MK
780Return (as the function result)
781the secure computing mode of the calling thread.
34447828
KC
782If the caller is not in secure computing mode, this operation returns 0;
783if the caller is in strict secure computing mode, then the
8ab8b43f
MK
784.BR prctl ()
785call will cause a
786.B SIGKILL
787signal to be sent to the process.
d6ef3d57 788If the caller is in filter mode, and this system call is allowed by the
8eeb062d
MK
789seccomp filters, it returns 2; otherwise, the process is killed with a
790.BR SIGKILL
791signal.
33a0ccb2 792This operation is available only
d6ef3d57
MK
793if the kernel is configured with
794.B CONFIG_SECCOMP
795enabled.
787843e7
MK
796
797Since Linux 3.8, the
798.IR Seccomp
799field of the
800.IR /proc/[pid]/status
801file provides a method of obtaining the same information,
802without the risk that the process is killed; see
803.BR proc (5).
88989295
MK
804.TP
805.BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
806Set the "securebits" flags of the calling thread to the value supplied in
03547431
MK
807.IR arg2 .
808See
809.BR capabilities (7).
88989295 810.TP
03547431
MK
811.BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
812Return (as the function result)
813the "securebits" flags of the calling thread.
814See
815.BR capabilities (7).
816.TP
817.BR PR_SET_THP_DISABLE " (since Linux 3.15)"
818.\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
819Set the state of the "THP disable" flag for the calling thread.
820If
821.I arg2
822has a nonzero value, the flag is set, otherwise it is cleared.
823Setting this flag provides a method
824for disabling transparent huge pages
825for jobs where the code cannot be modified, and using a malloc hook with
826.BR madvise (2)
827is not an option (i.e., statically allocated data).
828The setting of the "THP disable" flag is inherited by a child created via
829.BR fork (2)
830and is preserved across
831.BR execve (2).
832.\"
06afe673
MK
833.TP
834.BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
835Disable all performance counters attached to the calling process,
836regardless of whether the counters were created by
837this process or another process.
838Performance counters created by the calling process for other
839processes are unaffected.
66a9882e 840For more information on performance counters, see the Linux kernel source file
06afe673
MK
841.IR tools/perf/design.txt .
842.IP
03547431
MK
843Originally called
844.BR PR_TASK_PERF_COUNTERS_DISABLE ;
845.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
846renamed (with same numerical value)
847in Linux 2.6.32.
848.\"
03979794 849.TP
03547431
MK
850.BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
851The converse of
852.BR PR_TASK_PERF_EVENTS_DISABLE ;
853enable performance counters attached to the calling process.
854.IP
855Originally called
856.BR PR_TASK_PERF_COUNTERS_ENABLE ;
857.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
858renamed
859.\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
860in Linux 2.6.32.
861.\"
862.TP
863.BR PR_GET_THP_DISABLE " (since Linux 3.15)"
864Return (via the function result) the current setting of the "THP disable"
865flag for the calling thread:
866either 1, if the flag is set, or 0, if it is not.
867.TP
868.BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
869.\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
870Retrieve the
871.I clear_child_tid
872address set by
873.BR set_tid_address (2)
874and the
875.BR clone (2)
876.B CLONE_CHILD_CLEARTID
877flag, in the location pointed to by
878.IR "(int\ **)\ arg2" .
879This feature is available only if the kernel is built with the
880.BR CONFIG_CHECKPOINT_RESTORE
881option enabled.
882.TP
883.BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
884.\" See https://lwn.net/Articles/369549/
885.\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
886Set the current timer slack for the calling thread to the nanosecond value
887supplied in
888.IR arg2 .
889If
890.I arg2
891is less than or equal to zero,
892.\" It seems that it's not possible to set the timer slack to zero;
893.\" The minimum value is 1? Seems a little strange.
894reset the current timer slack to the thread's default timer slack value.
895The timer slack is used by the kernel to group timer expirations
896for the calling thread that are close to one another;
897as a consequence, timer expirations for the thread may be
898up to the specified number of nanoseconds late (but will never expire early).
899Grouping timer expirations can help reduce system power consumption
900by minimizing CPU wake-ups.
03979794 901
03547431
MK
902The timer expirations affected by timer slack are those set by
903.BR select (2),
904.BR pselect (2),
905.BR poll (2),
906.BR ppoll (2),
907.BR epoll_wait (2),
908.BR epoll_pwait (2),
909.BR clock_nanosleep (2),
910.BR nanosleep (2),
911and
912.BR futex (2)
913(and thus the library functions implemented via futexes, including
914.\" List obtained by grepping for futex usage in glibc source
915.BR pthread_cond_timedwait (3),
916.BR pthread_mutex_timedlock (3),
917.BR pthread_rwlock_timedrdlock (3),
918.BR pthread_rwlock_timedwrlock (3),
919and
920.BR sem_timedwait (3)).
03979794 921
03547431
MK
922Timer slack is not applied to threads that are scheduled under
923a real-time scheduling policy (see
924.BR sched_setscheduler (2)).
03979794 925
03547431
MK
926Each thread has two associated timer slack values:
927a "default" value, and a "current" value.
928The current value is the one that governs grouping
929of timer expirations.
930When a new thread is created,
931the two timer slack values are made the same as the current value
932of the creating thread.
933Thereafter, a thread can adjust its current timer slack value via
934.BR PR_SET_TIMERSLACK
935(the default value can't be changed).
936The timer slack values of
937.IR init
938(PID 1), the ancestor of all processes,
939are 50,000 nanoseconds (50 microseconds).
940The timer slack values are preserved across
941.BR execve (2).
e81a96ec 942.TP
03547431
MK
943.BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
944Return (as the function result)
945the current timer slack value of the calling thread.
4bf25b89 946.TP
03547431
MK
947.BR PR_SET_TIMING " (since Linux 2.6.0-test4)"
948Set whether to use (normal, traditional) statistical process timing or
949accurate timestamp-based process timing, by passing
950.B PR_TIMING_STATISTICAL
951.\" 0
952or
953.B PR_TIMING_TIMESTAMP
954.\" 1
955to \fIarg2\fP.
956.B PR_TIMING_TIMESTAMP
957is not currently implemented
958(attempting to set this mode will yield the error
959.BR EINVAL ).
960.\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
961.\" and looking at the patch history, it appears
962.\" that it never did anything.
4bf25b89 963.TP
03547431
MK
964.BR PR_GET_TIMING " (since Linux 2.6.0-test4)"
965Return (as the function result) which process timing method is currently
966in use.
4bf25b89 967.TP
03547431
MK
968.BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
969Set the state of the flag determining whether the timestamp counter
970can be read by the process.
971Pass
972.B PR_TSC_ENABLE
973to
974.I arg2
975to allow it to be read, or
976.B PR_TSC_SIGSEGV
977to generate a
978.B SIGSEGV
979when the process tries to read the timestamp counter.
4bf25b89 980.TP
03547431
MK
981.BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
982Return the state of the flag determining whether the timestamp counter
983can be read,
984in the location pointed to by
985.IR "(int\ *) arg2" .
986.TP
987.B PR_SET_UNALIGN
988(Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
989PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22)
990Set unaligned access control bits to \fIarg2\fP.
991Pass
992\fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
993or \fBPR_UNALIGN_SIGBUS\fP to generate
994.B SIGBUS
995on unaligned user access.
996.TP
997.B PR_GET_UNALIGN
998(see
999.B PR_SET_UNALIGN
1000for information on versions and architectures)
1001Return unaligned access control bits, in the location pointed to by
1002.IR "(int\ *) arg2" .
47297adb 1003.SH RETURN VALUE
8ab8b43f
MK
1004On success,
1005.BR PR_GET_DUMPABLE ,
1006.BR PR_GET_KEEPCAPS ,
f83fe154 1007.BR PR_GET_NO_NEW_PRIVS ,
5745985f 1008.BR PR_GET_THP_DISABLE ,
8ab8b43f
MK
1009.BR PR_CAPBSET_READ ,
1010.BR PR_GET_TIMING ,
c42db321 1011.BR PR_GET_TIMERSLACK ,
8ab8b43f 1012.BR PR_GET_SECUREBITS ,
ed31c572 1013.BR PR_MCE_KILL_GET ,
0c3e75cb 1014.BR PR_CAP_AMBIENT + PR_CAP_AMBIENT_IS_SET ,
8ab8b43f
MK
1015and (if it returns)
1016.BR PR_GET_SECCOMP
2fda57bd 1017return the nonnegative values described above.
fea681da
MK
1018All other
1019.I option
1020values return 0 on success.
1021On error, \-1 is returned, and
1022.I errno
1023is set appropriately.
1024.SH ERRORS
1025.TP
0478944d
MK
1026.B EACCES
1027.I option
1028is
1029.BR PR_SET_MM ,
1030and
1031.I arg3
1032is
1033.BR PR_SET_MM_EXE_FILE ,
1034the file is not executable.
1035.TP
1036.B EBADF
1037.I option
1038is
1039.BR PR_SET_MM ,
1040.I arg3
1041is
1042.BR PR_SET_MM_EXE_FILE ,
1043and the file descriptor passed in
1044.I arg4
1045is not valid.
1046.TP
1047.B EBUSY
1048.I option
1049is
1050.BR PR_SET_MM ,
1051.I arg3
1052is
1053.BR PR_SET_MM_EXE_FILE ,
1054and this the second attempt to change the
1055.I /proc/pid/exe
1056symbolic link, which is prohibited.
1057.TP
8ab8b43f
MK
1058.B EFAULT
1059.I arg2
1060is an invalid address.
1061.TP
e35a0512
KC
1062.B EFAULT
1063.I option
1064is
1065.BR PR_SET_SECCOMP ,
1066.I arg2
1067is
1068.BR SECCOMP_MODE_FILTER ,
1069the system was built with
64c626f7 1070.BR CONFIG_SECCOMP_FILTER ,
e35a0512
KC
1071and
1072.I arg3
1073is an invalid address.
1074.TP
fea681da
MK
1075.B EINVAL
1076The value of
1077.I option