OSDN Git Service

(split) LDP man-pages の original/ を v3.25 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / prctl.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 1998 Andries Brouwer (aeb@cwi.nl)
4 .\" and Copyright (C) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" and Copyright Guillem Jover <guillem@hadrons.org>
6 .\"
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 .\"
27 .\" Modified Thu Nov 11 04:19:42 MET 1999, aeb: added PR_GET_PDEATHSIG
28 .\" Modified 27 Jun 02, Michael Kerrisk
29 .\"     Added PR_SET_DUMPABLE, PR_GET_DUMPABLE,
30 .\"     PR_SET_KEEPCAPS, PR_GET_KEEPCAPS
31 .\" Modified 2006-08-30 Guillem Jover <guillem@hadrons.org>
32 .\"     Updated Linux versions where the options where introduced.
33 .\"     Added PR_SET_TIMING, PR_GET_TIMING, PR_SET_NAME, PR_GET_NAME,
34 .\"     PR_SET_UNALIGN, PR_GET_UNALIGN, PR_SET_FPEMU, PR_GET_FPEMU,
35 .\"     PR_SET_FPEXC, PR_GET_FPEXC
36 .\" 2008-04-29 Serge Hallyn, Document PR_CAPBSET_READ and PR_CAPBSET_DROP
37 .\" 2008-06-13 Erik Bosman, <ejbosman@cs.vu.nl>
38 .\"     Document PR_GET_TSC and PR_SET_TSC.
39 .\" 2008-06-15 mtk, Document PR_SET_SECCOMP, PR_GET_SECCOMP
40 .\" 2009-10-03 Andi Kleen, document PR_MCE_KILL_*
41 .\"
42 .TH PRCTL 2 2010-05-13 "Linux" "Linux Programmer's Manual"
43 .SH NAME
44 prctl \- operations on a process
45 .SH SYNOPSIS
46 .nf
47 .B #include <sys/prctl.h>
48 .sp
49 .BI "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 ,
50 .BI "          unsigned long " arg4 ", unsigned long " arg5 );
51 .fi
52 .SH DESCRIPTION
53 .BR prctl ()
54 is called with a first argument describing what to do
55 (with values defined in \fI<linux/prctl.h>\fP), and further
56 arguments with a significance depending on the first one.
57 The first argument can be:
58 .TP
59 .BR PR_CAPBSET_READ " (since Linux 2.6.25)
60 Return (as the function result) 1 if the capability specified in
61 .I arg2
62 is in the calling thread's capability bounding set,
63 or 0 if it is not.
64 (The capability constants are defined in
65 .IR <linux/capability.h> .)
66 The capability bounding set dictates
67 whether the process can receive the capability through a
68 file's permitted capability set on a subsequent call to
69 .BR execve (2).
70
71 If the capability specified in
72 .I arg2
73 is not valid, then the call fails with the error
74 .BR EINVAL .
75 .TP
76 .BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
77 If the calling thread has the
78 .B CAP_SETPCAP
79 capability, then drop the capability specified by
80 .I arg2
81 from the calling thread's capability bounding set.
82 Any children of the calling thread will inherit the newly
83 reduced bounding set.
84
85 The call fails with the error:
86 .B EPERM
87 if the calling thread does not have the
88 .BR CAP_SETPCAP ;
89 .BR EINVAL
90 if
91 .I arg2
92 does not represent a valid capability; or
93 .BR EINVAL
94 if file capabilities are not enabled in the kernel,
95 in which case bounding sets are not supported.
96 .TP
97 .BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
98 Set the state of the flag determining whether core dumps are produced
99 for this process upon delivery of a signal whose default behavior is
100 to produce a core dump.
101 (Normally this flag is set for a process by default, but it is cleared
102 when a set-user-ID or set-group-ID program is executed and also by
103 various system calls that manipulate process UIDs and GIDs).
104 In kernels up to and including 2.6.12,
105 .I arg2
106 must be either 0 (process is not dumpable) or 1 (process is dumpable).
107 Between kernels 2.6.13 and 2.6.17, the value 2 was also permitted,
108 which caused any binary which normally would not be dumped
109 to be dumped readable by root only;
110 for security reasons, this feature has been removed.
111 .\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
112 .\" Subject:    Fix prctl privilege escalation (CVE-2006-2451)
113 .\" From:       Marcel Holtmann <marcel () holtmann ! org>
114 .\" Date:       2006-07-12 11:12:00
115 (See also the description of
116 .I /proc/sys/fs/suid_dumpable
117 in
118 .BR proc (5).)
119 .TP
120 .BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
121 Return (as the function result) the current state of the calling
122 process's dumpable flag.
123 .\" Since Linux 2.6.13, the dumpable flag can have the value 2,
124 .\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
125 .\" flags has a nonzero value.  This was fixed in 2.6.14.
126 .TP
127 .BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
128 Set the endian-ness of the calling process to the value given
129 in \fIarg2\fP, which should be one of the following:
130 .\" Respectively 0, 1, 2
131 .BR PR_ENDIAN_BIG ,
132 .BR PR_ENDIAN_LITTLE ,
133 or
134 .B PR_ENDIAN_PPC_LITTLE
135 (PowerPC pseudo little endian).
136 .TP
137 .BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
138 Return the endian-ness of the calling process,
139 in the location pointed to by
140 .IR "(int\ *) arg2" .
141 .TP
142 .BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
143 Set floating-point emulation control bits to \fIarg2\fP.
144 Pass \fBPR_FPEMU_NOPRINT\fP to silently emulate fp operations accesses, or
145 \fBPR_FPEMU_SIGFPE\fP to not emulate fp operations and send
146 .B SIGFPE
147 instead.
148 .TP
149 .BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
150 Return floating-point emulation control bits,
151 in the location pointed to by
152 .IR "(int\ *) arg2" .
153 .TP
154 .BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
155 Set floating-point exception mode to \fIarg2\fP.
156 Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
157 \fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
158 \fBPR_FP_EXC_OVF\fP for floating-point overflow,
159 \fBPR_FP_EXC_UND\fP for floating-point underflow,
160 \fBPR_FP_EXC_RES\fP for floating-point inexact result,
161 \fBPR_FP_EXC_INV\fP for floating-point invalid operation,
162 \fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
163 \fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
164 \fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
165 \fBPR_FP_EXC_PRECISE\fP for precise exception mode.
166 .TP
167 .BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
168 Return floating-point exception mode,
169 in the location pointed to by
170 .IR "(int\ *) arg2" .
171 .TP
172 .BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
173 Set the state of the thread's "keep capabilities" flag,
174 which determines whether the threads's permitted
175 capability set is cleared when a change is made to the threads's user IDs
176 such that the threads's real UID, effective UID, and saved set-user-ID
177 all become nonzero when at least one of them previously had the value 0.
178 By default, the permitted capability set is cleared when such a change is made;
179 setting the "keep capabilities" flag prevents it from being cleared.
180 .I arg2
181 must be either 0 (permitted capabilities are cleared)
182 or 1 (permitted capabilities are kept).
183 (A thread's
184 .I effective
185 capability set is always cleared when such a credential change is made,
186 regardless of the setting of the "keep capabilities" flag.)
187 The "keep capabilities" value will be reset to 0 on subsequent calls to
188 .BR execve (2).
189 .TP
190 .BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
191 Return (as the function result) the current state of the calling threads's
192 "keep capabilities" flag.
193 .TP
194 .BR PR_SET_NAME " (since Linux 2.6.9)"
195 Set the process name for the calling process,
196 using the value in the location pointed to by
197 .IR "(char\ *) arg2" .
198 The name can be up to 16 bytes long,
199 .\" TASK_COMM_LEN in include/linux/sched.h
200 and should be null-terminated if it contains fewer bytes.
201 .TP
202 .BR PR_GET_NAME " (since Linux 2.6.11)"
203 Return the process name for the calling process,
204 in the buffer pointed to by
205 .IR "(char\ *) arg2" .
206 The buffer should allow space for up to 16 bytes;
207 the returned string will be null-terminated if it is shorter than that.
208 .TP
209 .BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
210 Set the parent process death signal
211 of the calling process to \fIarg2\fP (either a signal value
212 in the range 1..maxsig, or 0 to clear).
213 This is the signal that the calling process will get when its
214 parent dies.
215 This value is cleared for the child of a
216 .BR fork (2).
217 .TP
218 .BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
219 Return the current value of the parent process death signal,
220 in the location pointed to by
221 .IR "(int\ *) arg2" .
222 .TP
223 .BR PR_SET_SECCOMP " (since Linux 2.6.23)"
224 .\" See http://thread.gmane.org/gmane.linux.kernel/542632
225 .\" [PATCH 0 of 2] seccomp updates
226 .\" andrea@cpushare.com
227 Set the secure computing mode for the calling thread.
228 In the current implementation,
229 .IR arg2
230 must be 1.
231 After the secure computing mode has been set to 1,
232 the only system calls that the thread is permitted to make are
233 .BR read (2),
234 .BR write (2),
235 .BR _exit (2),
236 and
237 .BR sigreturn (2).
238 Other system calls result in the delivery of a
239 .BR SIGKILL
240 signal.
241 Secure computing mode is useful for number-crunching applications
242 that may need to execute untrusted byte code,
243 perhaps obtained by reading from a pipe or socket.
244 This operation is only available
245 if the kernel is configured with CONFIG_SECCOMP enabled.
246 .TP
247 .BR PR_GET_SECCOMP " (since Linux 2.6.23)"
248 Return the secure computing mode of the calling thread.
249 Not very useful for the current implementation (mode equals 1),
250 but may be useful for other possible future modes:
251 if the caller is not in secure computing mode, this operation returns 0;
252 if the caller is in secure computing mode, then the
253 .BR prctl ()
254 call will cause a
255 .B SIGKILL
256 signal to be sent to the process.
257 This operation is only available
258 if the kernel is configured with CONFIG_SECCOMP enabled.
259 .TP
260 .BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
261 Set the "securebits" flags of the calling thread to the value supplied in
262 .IR arg2 .
263 See
264 .BR capabilities (7).
265 .TP
266 .BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
267 Return (as the function result)
268 the "securebits" flags of the calling thread.
269 See
270 .BR capabilities (7).
271 .TP
272 .BR PR_SET_TIMING " (since Linux 2.6.0-test4)"
273 Set whether to use (normal, traditional) statistical process timing or
274 accurate timestamp based process timing, by passing
275 .B PR_TIMING_STATISTICAL
276 .\" 0
277 or
278 .B PR_TIMING_TIMESTAMP
279 .\" 1
280 to \fIarg2\fP.
281 .B PR_TIMING_TIMESTAMP
282 is not currently implemented
283 (attempting to set this mode will yield the error
284 .BR EINVAL ).
285 .\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
286 .\" and looking at the patch history, it appears
287 .\" that it never did anything.
288 .TP
289 .BR PR_GET_TIMING " (since Linux 2.6.0-test4)"
290 Return (as the function result) which process timing method is currently
291 in use.
292 .TP
293 .BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
294 Set the state of the flag determining whether the timestamp counter
295 can be read by the process.
296 Pass
297 .B PR_TSC_ENABLE
298 to
299 .I arg2
300 to allow it to be read, or
301 .B PR_TSC_SIGSEGV
302 to generate a
303 .B SIGSEGV
304 when the process tries to read the timestamp counter.
305 .TP
306 .BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
307 Return the state of the flag determining whether the timestamp counter
308 can be read,
309 in the location pointed to by
310 .IR "(int\ *) arg2" .
311 .TP
312 .B PR_SET_UNALIGN
313 (Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
314 PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22)
315 Set unaligned access control bits to \fIarg2\fP.
316 Pass
317 \fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
318 or \fBPR_UNALIGN_SIGBUS\fP to generate
319 .B SIGBUS
320 on unaligned user access.
321 .TP
322 .B PR_GET_UNALIGN
323 (see
324 .B PR_SET_UNALIGN
325 for information on versions and architectures)
326 Return unaligned access control bits, in the location pointed to by
327 .IR "(int\ *) arg2" .
328 .TP
329 .BR PR_MCE_KILL " (since Linux 2.6.32)"
330 Set the machine check memory corruption kill policy for the current thread.
331 If
332 .I arg2
333 is
334 .BR PR_MCE_KILL_CLEAR ,
335 clear the thread memory corruption kill policy and use the system-wide default.
336 (The system-wide default is defined by
337 .IR /proc/sys/vm/memory_failure_early_kill ;
338 see
339 .BR proc (5).)
340 If
341 .I arg2
342 is
343 .BR PR_MCE_KILL_SET ,
344 use a thread-specific memory corruption kill policy.
345 In this case,
346 .I arg3
347 defines whether the policy is
348 .I early kill
349 .RB ( PR_MCE_KILL_EARLY ),
350 .I late kill
351 .RB ( PR_MCE_KILL_LATE ),
352 or the system-wide default
353 .RB ( PR_MCE_KILL_DEFAULT ).
354 Early kill means that the task receives a
355 .B SIGBUS
356 signal as soon as hardware memory corruption is detected inside
357 its address space.
358 In late kill mode, the process is only killed when it accesses a corrupted page.
359 See
360 .I sigaction(2)
361 for more information on the
362 .BR SIGBUS
363 signal.
364 The policy is inherited by children.
365 The remaining unused
366 .BR prctl ()
367 arguments must be zero for future compatibility.
368 .TP
369 .BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
370 Return the current per-process machine check kill policy.
371 All unused
372 .BR prctl ()
373 arguments must be zero.
374 .SH "RETURN VALUE"
375 On success,
376 .BR PR_GET_DUMPABLE ,
377 .BR PR_GET_KEEPCAPS ,
378 .BR PR_CAPBSET_READ ,
379 .BR PR_GET_TIMING ,
380 .BR PR_GET_SECUREBITS ,
381 .BR PR_MCE_KILL_GET ,
382 and (if it returns)
383 .BR PR_GET_SECCOMP
384 return the nonnegative values described above.
385 All other
386 .I option
387 values return 0 on success.
388 On error, \-1 is returned, and
389 .I errno
390 is set appropriately.
391 .SH ERRORS
392 .TP
393 .B EFAULT
394 .I arg2
395 is an invalid address.
396 .TP
397 .B EINVAL
398 The value of
399 .I option
400 is not recognized.
401 .TP
402 .B EINVAL
403 .I option
404 is
405 .BR PR_MCE_KILL
406 or
407 .BR PR_MCE_KILL_GET ,
408 and unused
409 .BR prctl ()
410 arguments were not specified as zero.
411 .TP
412 .B EINVAL
413 .I arg2
414 is not valid value for this
415 .IR option .
416 .TP
417 .B EINVAL
418 .I option
419 is
420 .BR PR_SET_SECCOMP
421 or
422 .BR PR_SET_SECCOMP ,
423 and the kernel was not configured with
424 .BR CONFIG_SECCOMP .
425 .TP
426 .B EPERM
427 .I option
428 is
429 .BR PR_SET_SECUREBITS ,
430 and the caller does not have the
431 .B CAP_SETPCAP
432 capability,
433 or tried to unset a "locked" flag,
434 or tried to set a flag whose corresponding locked flag was set
435 (see
436 .BR capabilities (7)).
437 .TP
438 .B EPERM
439 .I option
440 is
441 .BR PR_SET_KEEPCAPS ,
442 and the callers's
443 .B SECURE_KEEP_CAPS_LOCKED
444 flag is set
445 (see
446 .BR capabilities (7)).
447 .TP
448 .B EPERM
449 .I option
450 is
451 .BR PR_CAPBSET_DROP ,
452 and the caller does not have the
453 .B CAP_SETPCAP
454 capability.
455 .\" The following can't actually happen, because prctl() in
456 .\" seccomp mode will cause SIGKILL.
457 .\" .TP
458 .\" .B EPERM
459 .\" .I option
460 .\" is
461 .\" .BR PR_SET_SECCOMP ,
462 .\" and secure computing mode is already 1.
463 .SH VERSIONS
464 The
465 .BR prctl ()
466 system call was introduced in Linux 2.1.57.
467 .\" The library interface was added in glibc 2.0.6
468 .SH "CONFORMING TO"
469 This call is Linux-specific.
470 IRIX has a
471 .BR prctl ()
472 system call (also introduced in Linux 2.1.44
473 as irix_prctl on the MIPS architecture),
474 with prototype
475 .sp
476 .BI "ptrdiff_t prctl(int " option ", int " arg2 ", int " arg3 );
477 .sp
478 and options to get the maximum number of processes per user,
479 get the maximum number of processors the calling process can use,
480 find out whether a specified process is currently blocked,
481 get or set the maximum stack size, etc.
482 .SH "SEE ALSO"
483 .BR signal (2),
484 .BR core (5)