]>
Commit | Line | Data |
---|---|---|
181f997f | 1 | .\" Copyright (c) 1993 Michael Haardt <michael@moria.de> |
fea681da MK |
2 | .\" Fri Apr 2 11:32:09 MET DST 1993 |
3 | .\" | |
181f997f | 4 | .\" and changes Copyright (C) 1999 Mike Coleman (mkc@acm.org) |
fea681da | 5 | .\" -- major revision to fully document ptrace semantics per recent Linux |
c13182ef | 6 | .\" kernel (2.2.10) and glibc (2.1.2) |
fea681da MK |
7 | .\" Sun Nov 7 03:18:35 CST 1999 |
8 | .\" | |
181f997f | 9 | .\" and Copyright (c) 2011, Denys Vlasenko <vda.linux@googlemail.com> |
b0459842 | 10 | .\" and Copyright (c) 2015, 2016, Michael Kerrisk <mtk.manpages@gmail.com> |
181f997f | 11 | .\" |
1dd72f9c | 12 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) |
fea681da MK |
13 | .\" This is free documentation; you can redistribute it and/or |
14 | .\" modify it under the terms of the GNU General Public License as | |
15 | .\" published by the Free Software Foundation; either version 2 of | |
16 | .\" the License, or (at your option) any later version. | |
17 | .\" | |
18 | .\" The GNU General Public License's references to "object code" | |
19 | .\" and "executables" are to be interpreted as the output of any | |
20 | .\" document formatting or typesetting system, including | |
21 | .\" intermediate and printed output. | |
22 | .\" | |
23 | .\" This manual is distributed in the hope that it will be useful, | |
24 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | .\" GNU General Public License for more details. | |
27 | .\" | |
28 | .\" You should have received a copy of the GNU General Public | |
c715f741 MK |
29 | .\" License along with this manual; if not, see |
30 | .\" <http://www.gnu.org/licenses/>. | |
6a8d8745 | 31 | .\" %%%LICENSE_END |
fea681da MK |
32 | .\" |
33 | .\" Modified Fri Jul 23 23:47:18 1993 by Rik Faith <faith@cs.unc.edu> | |
34 | .\" Modified Fri Jan 31 16:46:30 1997 by Eric S. Raymond <esr@thyrsus.com> | |
35 | .\" Modified Thu Oct 7 17:28:49 1999 by Andries Brouwer <aeb@cwi.nl> | |
c11b1abf | 36 | .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da MK |
37 | .\" Added notes on capability requirements |
38 | .\" | |
44b35ee0 MK |
39 | .\" 2006-03-24, Chuck Ebbert <76306.1226@compuserve.com> |
40 | .\" Added PTRACE_SETOPTIONS, PTRACE_GETEVENTMSG, PTRACE_GETSIGINFO, | |
41 | .\" PTRACE_SETSIGINFO, PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP | |
42 | .\" (Thanks to Blaisorblade, Daniel Jacobowitz and others who helped.) | |
181f997f | 43 | .\" 2011-09, major update by Denys Vlasenko <vda.linux@googlemail.com> |
3b4a59c4 KC |
44 | .\" 2015-01, Kees Cook <keescook@chromium.org> |
45 | .\" Added PTRACE_O_TRACESECCOMP, PTRACE_EVENT_SECCOMP | |
44b35ee0 | 46 | .\" |
65ba6523 MK |
47 | .\" FIXME The following are undocumented: |
48 | .\" | |
02418dd0 | 49 | .\" PTRACE_GETWMMXREGS |
65ba6523 MK |
50 | .\" PTRACE_SETWMMXREGS |
51 | .\" ARM | |
52 | .\" Linux 2.6.12 | |
53 | .\" | |
54 | .\" PTRACE_SET_SYSCALL | |
55 | .\" ARM and ARM64 | |
56 | .\" Linux 2.6.16 | |
57 | .\" commit 3f471126ee53feb5e9b210ea2f525ed3bb9b7a7f | |
58 | .\" Author: Nicolas Pitre <nico@cam.org> | |
59 | .\" Date: Sat Jan 14 19:30:04 2006 +0000 | |
60 | .\" | |
61 | .\" PTRACE_GETCRUNCHREGS | |
62 | .\" PTRACE_SETCRUNCHREGS | |
63 | .\" ARM | |
64 | .\" Linux 2.6.18 | |
65 | .\" commit 3bec6ded282b331552587267d67a06ed7fd95ddd | |
66 | .\" Author: Lennert Buytenhek <buytenh@wantstofly.org> | |
67 | .\" Date: Tue Jun 27 22:56:18 2006 +0100 | |
68 | .\" | |
69 | .\" PTRACE_GETVFPREGS | |
70 | .\" PTRACE_SETVFPREGS | |
71 | .\" ARM and ARM64 | |
72 | .\" Linux 2.6.30 | |
73 | .\" commit 3d1228ead618b88e8606015cbabc49019981805d | |
74 | .\" Author: Catalin Marinas <catalin.marinas@arm.com> | |
75 | .\" Date: Wed Feb 11 13:12:56 2009 +0100 | |
76 | .\" | |
77 | .\" PTRACE_GETHBPREGS | |
78 | .\" PTRACE_SETHBPREGS | |
79 | .\" ARM and ARM64 | |
80 | .\" Linux 2.6.37 | |
81 | .\" commit 864232fa1a2f8dfe003438ef0851a56722740f3e | |
82 | .\" Author: Will Deacon <will.deacon@arm.com> | |
83 | .\" Date: Fri Sep 3 10:42:55 2010 +0100 | |
84 | .\" | |
85 | .\" PTRACE_SINGLEBLOCK | |
c7391615 | 86 | .\" Since at least Linux 2.4.0 on various architectures |
65ba6523 MK |
87 | .\" Since Linux 2.6.25 on x86 (and others?) |
88 | .\" commit 5b88abbf770a0e1975c668743100f42934f385e8 | |
89 | .\" Author: Roland McGrath <roland@redhat.com> | |
90 | .\" Date: Wed Jan 30 13:30:53 2008 +0100 | |
91 | .\" ptrace: generic PTRACE_SINGLEBLOCK | |
92 | .\" | |
93 | .\" PTRACE_GETFPXREGS | |
94 | .\" PTRACE_SETFPXREGS | |
c7391615 | 95 | .\" Since at least Linux 2.4.0 on various architectures |
65ba6523 | 96 | .\" |
65ba6523 MK |
97 | .\" PTRACE_GETFDPIC |
98 | .\" PTRACE_GETFDPIC_EXEC | |
99 | .\" PTRACE_GETFDPIC_INTERP | |
100 | .\" blackfin, c6x, frv, sh | |
101 | .\" First appearance in Linux 2.6.11 on frv | |
3b1fdaf3 | 102 | .\" |
a47c1f44 MK |
103 | .\" and others that can be found in the arch/*/include/uapi/asm/ptrace files |
104 | .\" | |
6b621d05 | 105 | .TH PTRACE 2 2020-02-09 "Linux" "Linux Programmer's Manual" |
fea681da MK |
106 | .SH NAME |
107 | ptrace \- process trace | |
108 | .SH SYNOPSIS | |
44b35ee0 | 109 | .nf |
fea681da | 110 | .B #include <sys/ptrace.h> |
68e4db0a | 111 | .PP |
44b35ee0 MK |
112 | .BI "long ptrace(enum __ptrace_request " request ", pid_t " pid ", " |
113 | .BI " void *" addr ", void *" data ); | |
114 | .fi | |
fea681da MK |
115 | .SH DESCRIPTION |
116 | The | |
e511ffb6 | 117 | .BR ptrace () |
181f997f MK |
118 | system call provides a means by which one process (the "tracer") |
119 | may observe and control the execution of another process (the "tracee"), | |
120 | and examine and change the tracee's memory and registers. | |
e63ad01d | 121 | It is primarily used to implement breakpoint debugging and system |
fea681da | 122 | call tracing. |
dd3568a1 | 123 | .PP |
8898a252 | 124 | A tracee first needs to be attached to the tracer. |
181f997f MK |
125 | Attachment and subsequent commands are per thread: |
126 | in a multithreaded process, | |
127 | every thread can be individually attached to a | |
128 | (potentially different) tracer, | |
129 | or left not attached and thus not debugged. | |
130 | Therefore, "tracee" always means "(one) thread", | |
131 | never "a (possibly multithreaded) process". | |
8b20acd1 | 132 | Ptrace commands are always sent to |
181f997f | 133 | a specific tracee using a call of the form |
efeece04 | 134 | .PP |
181f997f | 135 | ptrace(PTRACE_foo, pid, ...) |
efeece04 | 136 | .PP |
181f997f MK |
137 | where |
138 | .I pid | |
139 | is the thread ID of the corresponding Linux thread. | |
dd3568a1 | 140 | .PP |
8898a252 MK |
141 | (Note that in this page, a "multithreaded process" |
142 | means a thread group consisting of threads created using the | |
143 | .BR clone (2) | |
144 | .B CLONE_THREAD | |
145 | flag.) | |
dd3568a1 | 146 | .PP |
181f997f | 147 | A process can initiate a trace by calling |
c13182ef | 148 | .BR fork (2) |
8bd58774 MK |
149 | and having the resulting child do a |
150 | .BR PTRACE_TRACEME , | |
e63ad01d | 151 | followed (typically) by an |
4d12a715 | 152 | .BR execve (2). |
181f997f | 153 | Alternatively, one process may commence tracing another process using |
ba8f446e DV |
154 | .B PTRACE_ATTACH |
155 | or | |
156 | .BR PTRACE_SEIZE . | |
dd3568a1 | 157 | .PP |
4d12a715 | 158 | While being traced, the tracee will stop each time a signal is delivered, |
c13182ef | 159 | even if the signal is being ignored. |
181f997f | 160 | (An exception is |
8bd58774 MK |
161 | .BR SIGKILL , |
162 | which has its usual effect.) | |
181f997f MK |
163 | The tracer will be notified at its next call to |
164 | .BR waitpid (2) | |
8898a252 MK |
165 | (or one of the related "wait" system calls); that call will return a |
166 | .I status | |
167 | value containing information that indicates | |
168 | the cause of the stop in the tracee. | |
169 | While the tracee is stopped, | |
170 | the tracer can use various ptrace requests to inspect and modify the tracee. | |
4d12a715 | 171 | The tracer then causes the tracee to continue, |
e63ad01d | 172 | optionally ignoring the delivered signal |
fea681da | 173 | (or even delivering a different signal instead). |
dd3568a1 | 174 | .PP |
d39a9b98 | 175 | If the |
b16ecdae DV |
176 | .B PTRACE_O_TRACEEXEC |
177 | option is not in effect, all successful calls to | |
178 | .BR execve (2) | |
d39a9b98 | 179 | by the traced process will cause it to be sent a |
b16ecdae | 180 | .B SIGTRAP |
d39a9b98 | 181 | signal, |
b16ecdae DV |
182 | giving the parent a chance to gain control before the new program |
183 | begins execution. | |
dd3568a1 | 184 | .PP |
181f997f | 185 | When the tracer is finished tracing, it can cause the tracee to continue |
4d12a715 | 186 | executing in a normal, untraced mode via |
8bd58774 | 187 | .BR PTRACE_DETACH . |
dd3568a1 | 188 | .PP |
181f997f MK |
189 | The value of |
190 | .I request | |
191 | determines the action to be performed: | |
fea681da | 192 | .TP |
8bd58774 | 193 | .B PTRACE_TRACEME |
181f997f | 194 | Indicate that this process is to be traced by its parent. |
c13182ef MK |
195 | A process probably shouldn't make this request if its parent |
196 | isn't expecting to trace it. | |
181f997f MK |
197 | .RI ( pid , |
198 | .IR addr , | |
199 | and | |
200 | .IR data | |
201 | are ignored.) | |
a71b27f8 | 202 | .IP |
181f997f MK |
203 | The |
204 | .B PTRACE_TRACEME | |
205 | request is used only by the tracee; | |
206 | the remaining requests are used only by the tracer. | |
207 | In the following requests, | |
208 | .I pid | |
209 | specifies the thread ID of the tracee to be acted on. | |
8bd58774 | 210 | For requests other than |
ba8f446e DV |
211 | .BR PTRACE_ATTACH , |
212 | .BR PTRACE_SEIZE , | |
a797afac | 213 | .BR PTRACE_INTERRUPT , |
b16ecdae | 214 | and |
8bd58774 | 215 | .BR PTRACE_KILL , |
4d12a715 | 216 | the tracee must be stopped. |
fea681da | 217 | .TP |
8bd58774 | 218 | .BR PTRACE_PEEKTEXT ", " PTRACE_PEEKDATA |
181f997f | 219 | Read a word at the address |
0daa9e92 | 220 | .I addr |
4d12a715 | 221 | in the tracee's memory, returning the word as the result of the |
e511ffb6 | 222 | .BR ptrace () |
c13182ef | 223 | call. |
181f997f MK |
224 | Linux does not have separate text and data address spaces, |
225 | so these two requests are currently equivalent. | |
226 | .RI ( data | |
051ec121 | 227 | is ignored; but see NOTES.) |
fea681da | 228 | .TP |
428d3520 | 229 | .B PTRACE_PEEKUSER |
254255af MK |
230 | .\" PTRACE_PEEKUSR in kernel source, but glibc uses PTRACE_PEEKUSER, |
231 | .\" and that is the name that seems common on other systems. | |
181f997f | 232 | Read a word at offset |
fea681da | 233 | .I addr |
4d12a715 | 234 | in the tracee's USER area, |
8bd58774 | 235 | which holds the registers and other information about the process |
181f997f MK |
236 | (see |
237 | .IR <sys/user.h> ). | |
e63ad01d | 238 | The word is returned as the result of the |
e511ffb6 | 239 | .BR ptrace () |
c13182ef | 240 | call. |
181f997f | 241 | Typically, the offset must be word-aligned, though this might vary by |
8660aec0 MK |
242 | architecture. |
243 | See NOTES. | |
181f997f | 244 | .RI ( data |
051ec121 | 245 | is ignored; but see NOTES.) |
fea681da | 246 | .TP |
8bd58774 | 247 | .BR PTRACE_POKETEXT ", " PTRACE_POKEDATA |
181f997f | 248 | Copy the word |
0daa9e92 | 249 | .I data |
181f997f | 250 | to the address |
0daa9e92 | 251 | .I addr |
4d12a715 | 252 | in the tracee's memory. |
181f997f | 253 | As for |
d6e37473 | 254 | .BR PTRACE_PEEKTEXT |
181f997f MK |
255 | and |
256 | .BR PTRACE_PEEKDATA , | |
257 | these two requests are currently equivalent. | |
fea681da | 258 | .TP |
428d3520 | 259 | .B PTRACE_POKEUSER |
254255af MK |
260 | .\" PTRACE_POKEUSR in kernel source, but glibc uses PTRACE_POKEUSER, |
261 | .\" and that is the name that seems common on other systems. | |
181f997f | 262 | Copy the word |
0daa9e92 | 263 | .I data |
fea681da MK |
264 | to offset |
265 | .I addr | |
4d12a715 | 266 | in the tracee's USER area. |
181f997f MK |
267 | As for |
268 | .BR PTRACE_PEEKUSER , | |
269 | the offset must typically be word-aligned. | |
c13182ef | 270 | In order to maintain the integrity of the kernel, |
8bd58774 | 271 | some modifications to the USER area are disallowed. |
181f997f | 272 | .\" FIXME In the preceding sentence, which modifications are disallowed, |
7fac88a9 | 273 | .\" and when they are disallowed, how does user space discover that fact? |
fea681da | 274 | .TP |
8bd58774 | 275 | .BR PTRACE_GETREGS ", " PTRACE_GETFPREGS |
92f9c09b | 276 | Copy the tracee's general-purpose or floating-point registers, |
181f997f MK |
277 | respectively, to the address |
278 | .I data | |
279 | in the tracer. | |
280 | See | |
281 | .I <sys/user.h> | |
282 | for information on the format of this data. | |
283 | .RI ( addr | |
284 | is ignored.) | |
50fe8d53 MK |
285 | Note that SPARC systems have the meaning of |
286 | .I data | |
287 | and | |
288 | .I addr | |
289 | reversed; that is, | |
290 | .I data | |
291 | is ignored and the registers are copied to the address | |
292 | .IR addr . | |
34709982 MK |
293 | .B PTRACE_GETREGS |
294 | and | |
295 | .B PTRACE_GETFPREGS | |
296 | are not present on all architectures. | |
fea681da | 297 | .TP |
ba8f446e DV |
298 | .BR PTRACE_GETREGSET " (since Linux 2.6.34)" |
299 | Read the tracee's registers. | |
300 | .I addr | |
f04ba477 | 301 | specifies, in an architecture-dependent way, the type of registers to be read. |
ba8f446e DV |
302 | .B NT_PRSTATUS |
303 | (with numerical value 1) | |
f04ba477 MK |
304 | usually results in reading of general-purpose registers. |
305 | If the CPU has, for example, | |
ba8f446e DV |
306 | floating-point and/or vector registers, they can be retrieved by setting |
307 | .I addr | |
f04ba477 | 308 | to the corresponding |
ba8f446e DV |
309 | .B NT_foo |
310 | constant. | |
311 | .I data | |
312 | points to a | |
313 | .BR "struct iovec" , | |
f42ce0a5 | 314 | which describes the destination buffer's location and length. |
f04ba477 | 315 | On return, the kernel modifies |
ba8f446e | 316 | .B iov.len |
f04ba477 | 317 | to indicate the actual number of bytes returned. |
ba8f446e | 318 | .TP |
6beb1671 | 319 | .BR PTRACE_SETREGS ", " PTRACE_SETFPREGS |
ba8f446e | 320 | Modify the tracee's general-purpose or floating-point registers, |
181f997f MK |
321 | respectively, from the address |
322 | .I data | |
323 | in the tracer. | |
8bd58774 MK |
324 | As for |
325 | .BR PTRACE_POKEUSER , | |
a42c0c5a | 326 | some general-purpose register modifications may be disallowed. |
bea08fec | 327 | .\" FIXME . In the preceding sentence, which modifications are disallowed, |
7fac88a9 | 328 | .\" and when they are disallowed, how does user space discover that fact? |
181f997f MK |
329 | .RI ( addr |
330 | is ignored.) | |
50fe8d53 MK |
331 | Note that SPARC systems have the meaning of |
332 | .I data | |
333 | and | |
334 | .I addr | |
335 | reversed; that is, | |
336 | .I data | |
337 | is ignored and the registers are copied from the address | |
338 | .IR addr . | |
34709982 MK |
339 | .B PTRACE_SETREGS |
340 | and | |
341 | .B PTRACE_SETFPREGS | |
342 | are not present on all architectures. | |
fea681da | 343 | .TP |
ba8f446e | 344 | .BR PTRACE_SETREGSET " (since Linux 2.6.34)" |
f04ba477 MK |
345 | Modify the tracee's registers. |
346 | The meaning of | |
ba8f446e DV |
347 | .I addr |
348 | and | |
349 | .I data | |
350 | is analogous to | |
351 | .BR PTRACE_GETREGSET . | |
352 | .TP | |
ff01b232 AV |
353 | .BR PTRACE_GETSIGINFO " (since Linux 2.3.99-pre6)" |
354 | Retrieve information about the signal that caused the stop. | |
355 | Copy a | |
356 | .I siginfo_t | |
357 | structure (see | |
358 | .BR sigaction (2)) | |
359 | from the tracee to the address | |
360 | .I data | |
361 | in the tracer. | |
362 | .RI ( addr | |
363 | is ignored.) | |
364 | .TP | |
8bd58774 | 365 | .BR PTRACE_SETSIGINFO " (since Linux 2.3.99-pre6)" |
181f997f MK |
366 | Set signal information: |
367 | copy a | |
368 | .I siginfo_t | |
369 | structure from the address | |
370 | .I data | |
371 | in the tracer to the tracee. | |
372 | This will affect only signals that would normally be delivered to | |
4d12a715 | 373 | the tracee and were caught by the tracer. |
c13182ef | 374 | It may be difficult to tell |
44b35ee0 MK |
375 | these normal signals from synthetic signals generated by |
376 | .BR ptrace () | |
8660aec0 | 377 | itself. |
181f997f MK |
378 | .RI ( addr |
379 | is ignored.) | |
44b35ee0 | 380 | .TP |
7a535f54 AV |
381 | .BR PTRACE_PEEKSIGINFO " (since Linux 3.10)" |
382 | .\" commit 84c751bd4aebbaae995fe32279d3dba48327bad4 | |
383 | Retrieve | |
384 | .I siginfo_t | |
385 | structures without removing signals from a queue. | |
386 | .I addr | |
387 | points to a | |
388 | .I ptrace_peeksiginfo_args | |
83894d15 MK |
389 | structure that specifies the ordinal position from which |
390 | copying of signals should start, | |
391 | and the number of signals to copy. | |
7a535f54 | 392 | .I siginfo_t |
83894d15 MK |
393 | structures are copied into the buffer pointed to by |
394 | .IR data . | |
395 | The return value contains the number of copied signals (zero indicates | |
396 | that there is no signal corresponding to the specified ordinal position). | |
397 | Within the returned | |
7a535f54 | 398 | .I siginfo |
83894d15 MK |
399 | structures, |
400 | the | |
7a535f54 | 401 | .IR si_code |
83894d15 MK |
402 | field includes information |
403 | .RB ( __SI_CHLD , | |
404 | .BR __SI_FAULT , | |
8abd92fc | 405 | etc.) that are not otherwise exposed to user space. |
7a535f54 | 406 | .PP |
408731d4 MK |
407 | .in +4n |
408 | .EX | |
7a535f54 | 409 | struct ptrace_peeksiginfo_args { |
83894d15 MK |
410 | u64 off; /* Ordinal position in queue at which |
411 | to start copying signals */ | |
412 | u32 flags; /* PTRACE_PEEKSIGINFO_SHARED or 0 */ | |
413 | s32 nr; /* Number of signals to copy */ | |
7a535f54 | 414 | }; |
b8302363 | 415 | .EE |
a6865065 | 416 | .in |
b8854bae | 417 | .IP |
83894d15 MK |
418 | Currently, there is only one flag, |
419 | .BR PTRACE_PEEKSIGINFO_SHARED , | |
420 | for dumping signals from the process-wide signal queue. | |
421 | If this flag is not set, | |
422 | signals are read from the per-thread queue of the specified thread. | |
7a535f54 AV |
423 | .in |
424 | .PP | |
425 | .TP | |
9a36b8fc AV |
426 | .BR PTRACE_GETSIGMASK " (since Linux 3.11)" |
427 | .\" commit 29000caecbe87b6b66f144f72111f0d02fbbf0c1 | |
222475b0 MK |
428 | Place a copy of the mask of blocked signals (see |
429 | .BR sigprocmask (2)) | |
430 | in the buffer pointed to by | |
431 | .IR data , | |
432 | which should be a pointer to a buffer of type | |
433 | .IR sigset_t . | |
9a36b8fc AV |
434 | The |
435 | .I addr | |
222475b0 MK |
436 | argument contains the size of the buffer pointed to by |
437 | .IR data | |
438 | (i.e., | |
439 | .IR sizeof(sigset_t) ). | |
9a36b8fc AV |
440 | .TP |
441 | .BR PTRACE_SETSIGMASK " (since Linux 3.11)" | |
222475b0 MK |
442 | Change the mask of blocked signals (see |
443 | .BR sigprocmask (2)) | |
444 | to the value specified in the buffer pointed to by | |
445 | .IR data , | |
446 | which should be a pointer to a buffer of type | |
447 | .IR sigset_t . | |
9a36b8fc AV |
448 | The |
449 | .I addr | |
222475b0 MK |
450 | argument contains the size of the buffer pointed to by |
451 | .IR data | |
452 | (i.e., | |
453 | .IR sizeof(sigset_t) ). | |
9a36b8fc | 454 | .TP |
8bd58774 | 455 | .BR PTRACE_SETOPTIONS " (since Linux 2.4.6; see BUGS for caveats)" |
181f997f MK |
456 | Set ptrace options from |
457 | .IR data . | |
458 | .RI ( addr | |
459 | is ignored.) | |
460 | .IR data | |
461 | is interpreted as a bit mask of options, | |
462 | which are specified by the following flags: | |
cc7d99c8 | 463 | .RS |
b89e39ef MK |
464 | .TP |
465 | .BR PTRACE_O_EXITKILL " (since Linux 3.8)" | |
466 | .\" commit 992fb6e170639b0849bace8e49bf31bd37c4123 | |
14d6e62f | 467 | Send a |
b89e39ef | 468 | .B SIGKILL |
14d6e62f | 469 | signal to the tracee if the tracer exits. |
9f1b9726 | 470 | This option is useful for ptrace jailers that |
c2b54496 | 471 | want to ensure that tracees can never escape the tracer's control. |
44b35ee0 | 472 | .TP |
8bd58774 | 473 | .BR PTRACE_O_TRACECLONE " (since Linux 2.5.46)" |
4d12a715 | 474 | Stop the tracee at the next |
0bfa087b | 475 | .BR clone (2) |
181f997f MK |
476 | and automatically start tracing the newly cloned process, |
477 | which will start with a | |
29f9b8fb DV |
478 | .BR SIGSTOP , |
479 | or | |
480 | .B PTRACE_EVENT_STOP | |
481 | if | |
482 | .B PTRACE_SEIZE | |
483 | was used. | |
8898a252 MK |
484 | A |
485 | .BR waitpid (2) | |
dc85ba7c | 486 | by the tracer will return a |
8898a252 | 487 | .I status |
dc85ba7c | 488 | value such that |
efeece04 | 489 | .IP |
dc85ba7c MK |
490 | .nf |
491 | status>>8 == (SIGTRAP | (PTRACE_EVENT_CLONE<<8)) | |
492 | .fi | |
efeece04 | 493 | .IP |
181f997f | 494 | The PID of the new process can be retrieved with |
8bd58774 | 495 | .BR PTRACE_GETEVENTMSG . |
181f997f | 496 | .IP |
44b35ee0 | 497 | This option may not catch |
0bfa087b | 498 | .BR clone (2) |
c13182ef | 499 | calls in all cases. |
4d12a715 | 500 | If the tracee calls |
0bfa087b | 501 | .BR clone (2) |
8bd58774 | 502 | with the |
0daa9e92 | 503 | .B CLONE_VFORK |
8bd58774 MK |
504 | flag, |
505 | .B PTRACE_EVENT_VFORK | |
506 | will be delivered instead | |
507 | if | |
508 | .B PTRACE_O_TRACEVFORK | |
4d12a715 | 509 | is set; otherwise if the tracee calls |
0bfa087b | 510 | .BR clone (2) |
8bd58774 MK |
511 | with the exit signal set to |
512 | .BR SIGCHLD , | |
513 | .B PTRACE_EVENT_FORK | |
181f997f | 514 | will be delivered if |
8bd58774 MK |
515 | .B PTRACE_O_TRACEFORK |
516 | is set. | |
44b35ee0 | 517 | .TP |
8bd58774 | 518 | .BR PTRACE_O_TRACEEXEC " (since Linux 2.5.46)" |
4d12a715 | 519 | Stop the tracee at the next |
181f997f | 520 | .BR execve (2). |
8898a252 MK |
521 | A |
522 | .BR waitpid (2) | |
dc85ba7c | 523 | by the tracer will return a |
8898a252 | 524 | .I status |
dc85ba7c | 525 | value such that |
efeece04 | 526 | .IP |
dc85ba7c MK |
527 | .nf |
528 | status>>8 == (SIGTRAP | (PTRACE_EVENT_EXEC<<8)) | |
529 | .fi | |
efeece04 | 530 | .IP |
8f318249 MK |
531 | If the execing thread is not a thread group leader, |
532 | the thread ID is reset to thread group leader's ID before this stop. | |
b16d33ef DV |
533 | Since Linux 3.0, the former thread ID can be retrieved with |
534 | .BR PTRACE_GETEVENTMSG . | |
44b35ee0 | 535 | .TP |
8bd58774 | 536 | .BR PTRACE_O_TRACEEXIT " (since Linux 2.5.60)" |
181f997f | 537 | Stop the tracee at exit. |
8898a252 MK |
538 | A |
539 | .BR waitpid (2) | |
dc85ba7c | 540 | by the tracer will return a |
8898a252 | 541 | .I status |
dc85ba7c | 542 | value such that |
efeece04 | 543 | .IP |
dc85ba7c MK |
544 | .nf |
545 | status>>8 == (SIGTRAP | (PTRACE_EVENT_EXIT<<8)) | |
546 | .fi | |
efeece04 | 547 | .IP |
4d12a715 | 548 | The tracee's exit status can be retrieved with |
8bd58774 | 549 | .BR PTRACE_GETEVENTMSG . |
181f997f MK |
550 | .IP |
551 | The tracee is stopped early during process exit, | |
552 | when registers are still available, | |
553 | allowing the tracer to see where the exit occurred, | |
c13182ef | 554 | whereas the normal exit notification is done after the process |
e63ad01d | 555 | is finished exiting. |
181f997f MK |
556 | Even though context is available, |
557 | the tracer cannot prevent the exit from happening at this point. | |
cc7d99c8 MK |
558 | .TP |
559 | .BR PTRACE_O_TRACEFORK " (since Linux 2.5.46)" | |
560 | Stop the tracee at the next | |
561 | .BR fork (2) | |
562 | and automatically start tracing the newly forked process, | |
563 | which will start with a | |
29f9b8fb DV |
564 | .BR SIGSTOP , |
565 | or | |
566 | .B PTRACE_EVENT_STOP | |
567 | if | |
568 | .B PTRACE_SEIZE | |
569 | was used. | |
cc7d99c8 MK |
570 | A |
571 | .BR waitpid (2) | |
572 | by the tracer will return a | |
573 | .I status | |
574 | value such that | |
efeece04 | 575 | .IP |
cc7d99c8 MK |
576 | .nf |
577 | status>>8 == (SIGTRAP | (PTRACE_EVENT_FORK<<8)) | |
578 | .fi | |
efeece04 | 579 | .IP |
cc7d99c8 MK |
580 | The PID of the new process can be retrieved with |
581 | .BR PTRACE_GETEVENTMSG . | |
cc7d99c8 MK |
582 | .TP |
583 | .BR PTRACE_O_TRACESYSGOOD " (since Linux 2.4.6)" | |
584 | When delivering system call traps, set bit 7 in the signal number | |
585 | (i.e., deliver | |
586 | .IR "SIGTRAP|0x80" ). | |
587 | This makes it easy for the tracer to distinguish | |
588 | normal traps from those caused by a system call. | |
cc7d99c8 MK |
589 | .TP |
590 | .BR PTRACE_O_TRACEVFORK " (since Linux 2.5.46)" | |
591 | Stop the tracee at the next | |
592 | .BR vfork (2) | |
593 | and automatically start tracing the newly vforked process, | |
594 | which will start with a | |
29f9b8fb DV |
595 | .BR SIGSTOP , |
596 | or | |
597 | .B PTRACE_EVENT_STOP | |
598 | if | |
599 | .B PTRACE_SEIZE | |
600 | was used. | |
cc7d99c8 MK |
601 | A |
602 | .BR waitpid (2) | |
603 | by the tracer will return a | |
604 | .I status | |
605 | value such that | |
efeece04 | 606 | .IP |
cc7d99c8 MK |
607 | .nf |
608 | status>>8 == (SIGTRAP | (PTRACE_EVENT_VFORK<<8)) | |
609 | .fi | |
efeece04 | 610 | .IP |
cc7d99c8 MK |
611 | The PID of the new process can be retrieved with |
612 | .BR PTRACE_GETEVENTMSG . | |
613 | .TP | |
614 | .BR PTRACE_O_TRACEVFORKDONE " (since Linux 2.5.60)" | |
615 | Stop the tracee at the completion of the next | |
616 | .BR vfork (2). | |
617 | A | |
618 | .BR waitpid (2) | |
619 | by the tracer will return a | |
620 | .I status | |
621 | value such that | |
efeece04 | 622 | .IP |
cc7d99c8 MK |
623 | .nf |
624 | status>>8 == (SIGTRAP | (PTRACE_EVENT_VFORK_DONE<<8)) | |
625 | .fi | |
efeece04 | 626 | .IP |
cc7d99c8 MK |
627 | The PID of the new process can (since Linux 2.6.18) be retrieved with |
628 | .BR PTRACE_GETEVENTMSG . | |
3b4a59c4 KC |
629 | .TP |
630 | .BR PTRACE_O_TRACESECCOMP " (since Linux 3.5)" | |
631 | Stop the tracee when a | |
632 | .BR seccomp (2) | |
633 | .BR SECCOMP_RET_TRACE | |
81c5080b MK |
634 | rule is triggered. |
635 | A | |
3b4a59c4 KC |
636 | .BR waitpid (2) |
637 | by the tracer will return a | |
638 | .I status | |
639 | value such that | |
efeece04 | 640 | .IP |
3b4a59c4 KC |
641 | .nf |
642 | status>>8 == (SIGTRAP | (PTRACE_EVENT_SECCOMP<<8)) | |
643 | .fi | |
efeece04 | 644 | .IP |
3b4a59c4 KC |
645 | While this triggers a |
646 | .BR PTRACE_EVENT | |
ff20e9ca MK |
647 | stop, it is similar to a syscall-enter-stop. |
648 | For details, see the note on | |
649 | .B PTRACE_EVENT_SECCOMP | |
650 | below. | |
81c5080b | 651 | The seccomp event message data (from the |
3b4a59c4 | 652 | .BR SECCOMP_RET_DATA |
81c5080b | 653 | portion of the seccomp filter rule) can be retrieved with |
3b4a59c4 | 654 | .BR PTRACE_GETEVENTMSG . |
e3cfeba2 | 655 | .TP |
b4b436ad MK |
656 | .BR PTRACE_O_SUSPEND_SECCOMP " (since Linux 4.3)" |
657 | .\" commit 13c4a90119d28cfcb6b5bdd820c233b86c2b0237 | |
658 | Suspend the tracee's seccomp protections. | |
659 | This applies regardless of mode, and | |
660 | can be used when the tracee has not yet installed seccomp filters. | |
661 | That is, a valid use case is to suspend a tracee's seccomp protections | |
662 | before they are installed by the tracee, | |
663 | let the tracee install the filters, | |
664 | and then clear this flag when the filters should be resumed. | |
665 | Setting this option requires that the tracer have the | |
666 | .BR CAP_SYS_ADMIN | |
667 | capability, | |
e3cfeba2 TA |
668 | not have any seccomp protections installed, and not have |
669 | .BR PTRACE_O_SUSPEND_SECCOMP | |
670 | set on itself. | |
44b35ee0 MK |
671 | .RE |
672 | .TP | |
8bd58774 | 673 | .BR PTRACE_GETEVENTMSG " (since Linux 2.5.46)" |
c13182ef MK |
674 | Retrieve a message (as an |
675 | .IR "unsigned long" ) | |
44b35ee0 | 676 | about the ptrace event |
181f997f MK |
677 | that just happened, placing it at the address |
678 | .I data | |
679 | in the tracer. | |
8bd58774 | 680 | For |
181f997f | 681 | .BR PTRACE_EVENT_EXIT , |
4d12a715 | 682 | this is the tracee's exit status. |
8bd58774 MK |
683 | For |
684 | .BR PTRACE_EVENT_FORK , | |
181f997f MK |
685 | .BR PTRACE_EVENT_VFORK , |
686 | .BR PTRACE_EVENT_VFORK_DONE , | |
8bd58774 | 687 | and |
181f997f MK |
688 | .BR PTRACE_EVENT_CLONE , |
689 | this is the PID of the new process. | |
3b4a59c4 KC |
690 | For |
691 | .BR PTRACE_EVENT_SECCOMP , | |
692 | this is the | |
693 | .BR seccomp (2) | |
694 | filter's | |
695 | .BR SECCOMP_RET_DATA | |
696 | associated with the triggered rule. | |
36f5dd10 | 697 | .RI ( addr |
181f997f | 698 | is ignored.) |
44b35ee0 | 699 | .TP |
8bd58774 | 700 | .B PTRACE_CONT |
181f997f MK |
701 | Restart the stopped tracee process. |
702 | If | |
703 | .I data | |
704 | is nonzero, | |
705 | it is interpreted as the number of a signal to be delivered to the tracee; | |
c13182ef | 706 | otherwise, no signal is delivered. |
4d12a715 DV |
707 | Thus, for example, the tracer can control |
708 | whether a signal sent to the tracee is delivered or not. | |
181f997f MK |
709 | .RI ( addr |
710 | is ignored.) | |
fea681da | 711 | .TP |
8bd58774 | 712 | .BR PTRACE_SYSCALL ", " PTRACE_SINGLESTEP |
181f997f | 713 | Restart the stopped tracee as for |
8bd58774 | 714 | .BR PTRACE_CONT , |
181f997f MK |
715 | but arrange for the tracee to be stopped at |
716 | the next entry to or exit from a system call, | |
c13182ef | 717 | or after execution of a single instruction, respectively. |
4d12a715 DV |
718 | (The tracee will also, as usual, be stopped upon receipt of a signal.) |
719 | From the tracer's perspective, the tracee will appear to have been | |
8bd58774 MK |
720 | stopped by receipt of a |
721 | .BR SIGTRAP . | |
722 | So, for | |
723 | .BR PTRACE_SYSCALL , | |
724 | for example, the idea is to inspect | |
c13182ef | 725 | the arguments to the system call at the first stop, |
8bd58774 MK |
726 | then do another |
727 | .B PTRACE_SYSCALL | |
181f997f | 728 | and inspect the return value of the system call at the second stop. |
94cffcd7 MK |
729 | The |
730 | .I data | |
731 | argument is treated as for | |
732 | .BR PTRACE_CONT . | |
a5c725cf | 733 | .RI ( addr |
181f997f | 734 | is ignored.) |
fea681da | 735 | .TP |
c2254484 JS |
736 | .BR PTRACE_SET_SYSCALL " (since Linux 2.6.16)" |
737 | .\" commit 3f471126ee53feb5e9b210ea2f525ed3bb9b7a7f | |
cbda5fc9 MK |
738 | When in syscall-enter-stop, |
739 | change the number of the system call that is about to | |
c2254484 JS |
740 | be executed to the number specified in the |
741 | .I data | |
cbda5fc9 MK |
742 | argument. |
743 | The | |
c2254484 | 744 | .I addr |
cbda5fc9 MK |
745 | argument is ignored. |
746 | This request is currently | |
c2254484 JS |
747 | .\" As of 4.19-rc2 |
748 | supported only on arm (and arm64, though only for backwards compatibility), | |
749 | .\" commit 27aa55c5e5123fa8b8ad0156559d34d7edff58ca | |
750 | but most other architectures have other means of accomplishing this | |
751 | (usually by changing the register that the userland code passed the | |
cbda5fc9 | 752 | system call number in). |
c2254484 | 753 | .\" see change_syscall in tools/testing/selftests/seccomp/seccomp_bpf.c |
731192be | 754 | .\" and also strace's linux/*/set_scno.c files. |
c2254484 | 755 | .TP |
6beb1671 | 756 | .BR PTRACE_SYSEMU ", " PTRACE_SYSEMU_SINGLESTEP " (since Linux 2.6.14)" |
8bd58774 MK |
757 | For |
758 | .BR PTRACE_SYSEMU , | |
181f997f | 759 | continue and stop on entry to the next system call, |
ff20e9ca MK |
760 | which will not be executed. |
761 | See the documentation on syscall-stops below. | |
8bd58774 MK |
762 | For |
763 | .BR PTRACE_SYSEMU_SINGLESTEP , | |
181f997f | 764 | do the same but also singlestep if not a system call. |
c13182ef | 765 | This call is used by programs like |
4d12a715 | 766 | User Mode Linux that want to emulate all the tracee's system calls. |
94cffcd7 MK |
767 | The |
768 | .I data | |
769 | argument is treated as for | |
770 | .BR PTRACE_CONT . | |
34709982 MK |
771 | The |
772 | .I addr | |
773 | argument is ignored. | |
774 | These requests are currently | |
775 | .\" As at 3.7 | |
d2ea1bd4 | 776 | supported only on x86. |
44b35ee0 | 777 | .TP |
ba8f446e DV |
778 | .BR PTRACE_LISTEN " (since Linux 3.4)" |
779 | Restart the stopped tracee, but prevent it from executing. | |
780 | The resulting state of the tracee is similar to a process which | |
f04ba477 MK |
781 | has been stopped by a |
782 | .B SIGSTOP | |
783 | (or other stopping signal). | |
ba8f446e DV |
784 | See the "group-stop" subsection for additional information. |
785 | .B PTRACE_LISTEN | |
33a0ccb2 | 786 | works only on tracees attached by |
ba8f446e DV |
787 | .BR PTRACE_SEIZE . |
788 | .TP | |
8bd58774 | 789 | .B PTRACE_KILL |
181f997f | 790 | Send the tracee a |
8bd58774 MK |
791 | .B SIGKILL |
792 | to terminate it. | |
181f997f MK |
793 | .RI ( addr |
794 | and | |
795 | .I data | |
796 | are ignored.) | |
797 | .IP | |
798 | .I This operation is deprecated; do not use it! | |
799 | Instead, send a | |
800 | .BR SIGKILL | |
801 | directly using | |
802 | .BR kill (2) | |
803 | or | |
804 | .BR tgkill (2). | |
805 | The problem with | |
806 | .B PTRACE_KILL | |
807 | is that it requires the tracee to be in signal-delivery-stop, | |
808 | otherwise it may not work | |
809 | (i.e., may complete successfully but won't kill the tracee). | |
810 | By contrast, sending a | |
811 | .B SIGKILL | |
812 | directly has no such limitation. | |
8898a252 MK |
813 | .\" [Note from Denys Vlasenko: |
814 | .\" deprecation suggested by Oleg Nesterov. He prefers to deprecate it | |
815 | .\" instead of describing (and needing to support) PTRACE_KILL's quirks.] | |
fea681da | 816 | .TP |
ba8f446e | 817 | .BR PTRACE_INTERRUPT " (since Linux 3.4)" |
f04ba477 | 818 | Stop a tracee. |
8da59274 DV |
819 | If the tracee is running or sleeping in kernel space and |
820 | .B PTRACE_SYSCALL | |
821 | is in effect, | |
822 | the system call is interrupted and syscall-exit-stop is reported. | |
823 | (The interrupted system call is restarted when the tracee is restarted.) | |
824 | If the tracee was already stopped by a signal and | |
825 | .B PTRACE_LISTEN | |
826 | was sent to it, | |
827 | the tracee stops with | |
828 | .B PTRACE_EVENT_STOP | |
ad84c543 | 829 | and |
8da59274 | 830 | .I WSTOPSIG(status) |
ad84c543 | 831 | returns the stop signal. |
8da59274 DV |
832 | If any other ptrace-stop is generated at the same time (for example, |
833 | if a signal is sent to the tracee), this ptrace-stop happens. | |
a9deb5e0 MF |
834 | If none of the above applies (for example, if the tracee is running in user |
835 | space), it stops with | |
8da59274 DV |
836 | .B PTRACE_EVENT_STOP |
837 | with | |
838 | .I WSTOPSIG(status) | |
839 | == | |
840 | .BR SIGTRAP . | |
ba8f446e DV |
841 | .B PTRACE_INTERRUPT |
842 | only works on tracees attached by | |
843 | .BR PTRACE_SEIZE . | |
844 | .TP | |
8bd58774 | 845 | .B PTRACE_ATTACH |
181f997f | 846 | Attach to the process specified in |
fea681da | 847 | .IR pid , |
4d12a715 | 848 | making it a tracee of the calling process. |
8898a252 MK |
849 | .\" No longer true (removed by Denys Vlasenko, 2011, who remarks: |
850 | .\" "I think it isn't true in non-ancient 2.4 and in 2.6/3.x. | |
851 | .\" Basically, it's not true for any Linux in practical use. | |
4d12a715 DV |
852 | .\" ; the behavior of the tracee is as if it had done a |
853 | .\" .BR PTRACE_TRACEME . | |
854 | .\" The calling process actually becomes the parent of the tracee | |
855 | .\" process for most purposes (e.g., it will receive | |
856 | .\" notification of tracee events and appears in | |
857 | .\" .BR ps (1) | |
858 | .\" output as the tracee's parent), but a | |
859 | .\" .BR getppid (2) | |
860 | .\" by the tracee will still return the PID of the original parent. | |
861 | The tracee is sent a | |
8bd58774 MK |
862 | .BR SIGSTOP , |
863 | but will not necessarily have stopped | |
e63ad01d | 864 | by the completion of this call; use |
181f997f | 865 | .BR waitpid (2) |
8b20acd1 | 866 | to wait for the tracee to stop. |
181f997f MK |
867 | See the "Attaching and detaching" subsection for additional information. |
868 | .RI ( addr | |
869 | and | |
870 | .I data | |
871 | are ignored.) | |
efeece04 | 872 | .IP |
d4c976d8 MK |
873 | Permission to perform a |
874 | .BR PTRACE_ATTACH | |
875 | is governed by a ptrace access mode | |
876 | .B PTRACE_MODE_ATTACH_REALCREDS | |
877 | check; see below. | |
fea681da | 878 | .TP |
ba8f446e | 879 | .BR PTRACE_SEIZE " (since Linux 3.4)" |
fec74bb1 MK |
880 | .\" |
881 | .\" Noted by Dmitry Levin: | |
882 | .\" | |
883 | .\" PTRACE_SEIZE was introduced by commit v3.1-rc1~308^2~28, but | |
884 | .\" it had to be used along with a temporary flag PTRACE_SEIZE_DEVEL, | |
885 | .\" which was removed later by commit v3.4-rc1~109^2~20. | |
886 | .\" | |
887 | .\" That is, [before] v3.4 we had a test mode of PTRACE_SEIZE API, | |
888 | .\" which was not compatible with the current PTRACE_SEIZE API introduced | |
889 | .\" in Linux 3.4. | |
890 | .\" | |
ba8f446e DV |
891 | Attach to the process specified in |
892 | .IR pid , | |
893 | making it a tracee of the calling process. | |
894 | Unlike | |
895 | .BR PTRACE_ATTACH , | |
896 | .B PTRACE_SEIZE | |
f04ba477 | 897 | does not stop the process. |
28e2ca57 DV |
898 | Group-stops are reported as |
899 | .B PTRACE_EVENT_STOP | |
53cdec41 | 900 | and |
28e2ca57 | 901 | .I WSTOPSIG(status) |
53cdec41 | 902 | returns the stop signal. |
28e2ca57 DV |
903 | Automatically attached children stop with |
904 | .B PTRACE_EVENT_STOP | |
53cdec41 | 905 | and |
28e2ca57 | 906 | .I WSTOPSIG(status) |
53cdec41 | 907 | returns |
28e2ca57 DV |
908 | .B SIGTRAP |
909 | instead of having | |
910 | .B SIGSTOP | |
911 | signal delivered to them. | |
cc3407d1 | 912 | .BR execve (2) |
28e2ca57 | 913 | does not deliver an extra |
53cdec41 | 914 | .BR SIGTRAP . |
f04ba477 | 915 | Only a |
ba8f446e DV |
916 | .BR PTRACE_SEIZE d |
917 | process can accept | |
918 | .B PTRACE_INTERRUPT | |
919 | and | |
920 | .B PTRACE_LISTEN | |
921 | commands. | |
28e2ca57 DV |
922 | The "seized" behavior just described is inherited by |
923 | children that are automatically attached using | |
924 | .BR PTRACE_O_TRACEFORK , | |
925 | .BR PTRACE_O_TRACEVFORK , | |
926 | and | |
927 | .BR PTRACE_O_TRACECLONE . | |
ba8f446e DV |
928 | .I addr |
929 | must be zero. | |
930 | .I data | |
931 | contains a bit mask of ptrace options to activate immediately. | |
efeece04 | 932 | .IP |
c33e8aff MK |
933 | Permission to perform a |
934 | .BR PTRACE_SEIZE | |
935 | is governed by a ptrace access mode | |
936 | .B PTRACE_MODE_ATTACH_REALCREDS | |
937 | check; see below. | |
baf11d5c MK |
938 | .\" |
939 | .TP | |
940 | .BR PTRACE_SECCOMP_GET_FILTER " (since Linux 4.4)" | |
941 | .\" commit f8e529ed941ba2bbcbf310b575d968159ce7e895 | |
942 | This operation allows the tracer to dump the tracee's | |
943 | classic BPF filters. | |
efeece04 | 944 | .IP |
baf11d5c MK |
945 | .I addr |
946 | is an integer specifying the index of the filter to be dumped. | |
947 | The most recently installed filter has the index 0. | |
948 | If | |
949 | .I addr | |
950 | is greater than the number of installed filters, | |
951 | the operation fails with the error | |
952 | .BR ENOENT . | |
efeece04 | 953 | .IP |
baf11d5c MK |
954 | .I data |
955 | is either a pointer to a | |
956 | .IR "struct sock_filter" | |
957 | array that is large enough to store the BPF program, | |
958 | or NULL if the program is not to be stored. | |
efeece04 | 959 | .IP |
baf11d5c MK |
960 | Upon success, |
961 | the return value is the number of instructions in the BPF program. | |
962 | If | |
963 | .I data | |
964 | was NULL, then this return value can be used to correctly size the | |
965 | .IR "struct sock_filter" | |
966 | array passed in a subsequent call. | |
efeece04 | 967 | .IP |
baf11d5c | 968 | This operation fails with the error |
7b10f505 | 969 | .B EACCES |
baf11d5c MK |
970 | if the caller does not have the |
971 | .B CAP_SYS_ADMIN | |
972 | capability or if the caller is in strict or filter seccomp mode. | |
973 | If the filter referred to by | |
974 | .I addr | |
975 | is not a classic BPF filter, the operation fails with the error | |
976 | .BR EMEDIUMTYPE . | |
efeece04 | 977 | .IP |
baf11d5c MK |
978 | This operation is available if the kernel was configured with both the |
979 | .B CONFIG_SECCOMP_FILTER | |
980 | and the | |
981 | .B CONFIG_CHECKPOINT_RESTORE | |
982 | options. | |
ba8f446e | 983 | .TP |
8bd58774 | 984 | .B PTRACE_DETACH |
181f997f | 985 | Restart the stopped tracee as for |
8bd58774 | 986 | .BR PTRACE_CONT , |
181f997f MK |
987 | but first detach from it. |
988 | Under Linux, a tracee can be detached in this way regardless | |
989 | of which method was used to initiate tracing. | |
990 | .RI ( addr | |
991 | is ignored.) | |
baf11d5c | 992 | .\" |
bc8bfd8a MK |
993 | .TP |
994 | .BR PTRACE_GET_THREAD_AREA " (since Linux 2.6.0)" | |
995 | This operation performs a similar task to | |
996 | .BR get_thread_area (2). | |
997 | It reads the TLS entry in the GDT whose index is given in | |
998 | .IR addr , | |
999 | placing a copy of the entry into the | |
1000 | .IR "struct user_desc" | |
1001 | pointed to by | |
1002 | .IR data . | |
1003 | (By contrast with | |
1004 | .BR get_thread_area (2), | |
1005 | the | |
1006 | .I entry_number | |
1007 | of the | |
1008 | .IR "struct user_desc" | |
1009 | is ignored.) | |
1010 | .TP | |
1011 | .BR PTRACE_SET_THREAD_AREA " (since Linux 2.6.0)" | |
1012 | This operation performs a similar task to | |
1013 | .BR set_thread_area (2). | |
1014 | It sets the TLS entry in the GDT whose index is given in | |
1015 | .IR addr , | |
1016 | assigning it the data supplied in the | |
1017 | .IR "struct user_desc" | |
1018 | pointed to by | |
1019 | .IR data . | |
1020 | (By contrast with | |
1021 | .BR set_thread_area (2), | |
1022 | the | |
1023 | .I entry_number | |
1024 | of the | |
1025 | .IR "struct user_desc" | |
1026 | is ignored; in other words, | |
1027 | this ptrace operation can't be used to allocate a free TLS entry.) | |
fc91449c DL |
1028 | .TP |
1029 | .BR PTRACE_GET_SYSCALL_INFO " (since Linux 5.3)" | |
1030 | .\" commit 201766a20e30f982ccfe36bebfad9602c3ff574a | |
c3543fab MK |
1031 | Retrieve information about the system call that caused the stop. |
1032 | The information is placed into the buffer pointed by the | |
fc91449c DL |
1033 | .I data |
1034 | argument, which should be a pointer to a buffer of type | |
1035 | .IR "struct ptrace_syscall_info" . | |
1036 | The | |
1037 | .I addr | |
1038 | argument contains the size of the buffer pointed to | |
c3543fab | 1039 | by the |
fc91449c DL |
1040 | .I data |
1041 | argument (i.e., | |
1042 | .IR "sizeof(struct ptrace_syscall_info)" ). | |
1043 | The return value contains the number of bytes available | |
1044 | to be written by the kernel. | |
c3543fab MK |
1045 | If the size of the data to be written by the kernel exceeds the size |
1046 | specified by the | |
fc91449c | 1047 | .I addr |
c3543fab | 1048 | argument, the output data is truncated. |
a60e8f1b DL |
1049 | .IP |
1050 | The | |
1051 | .I ptrace_syscall_info | |
1052 | structure contains the following fields: | |
1053 | .IP | |
9d8f542d | 1054 | .in +2n |
a60e8f1b DL |
1055 | .EX |
1056 | struct ptrace_syscall_info { | |
9d8f542d MK |
1057 | __u8 op; /* Type of system call stop */ |
1058 | __u32 arch; /* AUDIT_ARCH_* value; see seccomp(2) */ | |
f04534d2 | 1059 | __u64 instruction_pointer; /* CPU instruction pointer */ |
9d8f542d | 1060 | __u64 stack_pointer; /* CPU stack pointer */ |
a60e8f1b | 1061 | union { |
9d8f542d MK |
1062 | struct { /* op == PTRACE_SYSCALL_INFO_ENTRY */ |
1063 | __u64 nr; /* System call number */ | |
1064 | __u64 args[6]; /* System call arguments */ | |
f04534d2 | 1065 | } entry; |
9d8f542d MK |
1066 | struct { /* op == PTRACE_SYSCALL_INFO_EXIT */ |
1067 | __s64 rval; /* System call return value */ | |
227a3682 | 1068 | __u8 is_error; /* System call error flag; |
9914d8bd MK |
1069 | Boolean: does rval contain |
1070 | an error value (\-ERRCODE) or | |
1071 | a nonerror return value? */ | |
f04534d2 | 1072 | } exit; |
9d8f542d MK |
1073 | struct { /* op == PTRACE_SYSCALL_INFO_SECCOMP */ |
1074 | __u64 nr; /* System call number */ | |
1075 | __u64 args[6]; /* System call arguments */ | |
1076 | __u32 ret_data; /* SECCOMP_RET_DATA portion | |
1077 | of SECCOMP_RET_TRACE | |
1078 | return value */ | |
f04534d2 | 1079 | } seccomp; |
a60e8f1b DL |
1080 | }; |
1081 | }; | |
1082 | .EE | |
1083 | .in | |
1084 | .IP | |
1c0955b1 | 1085 | The |
a60e8f1b DL |
1086 | .IR op , |
1087 | .IR arch , | |
1088 | .IR instruction_pointer , | |
1089 | and | |
1090 | .I stack_pointer | |
1091 | fields are defined for all kinds of ptrace system call stops. | |
1c0955b1 | 1092 | The rest of the structure is a union; one should read only those fields |
a60e8f1b DL |
1093 | that are meaningful for the kind of system call stop specified by the |
1094 | .IR op | |
1095 | field. | |
f04534d2 MK |
1096 | .IP |
1097 | The | |
1098 | .I op | |
1099 | field has one of the following values (defined in | |
1100 | .IR <linux/ptrace.h>) | |
1101 | indicating what type of stop occurred and | |
1102 | which part of the union is filled: | |
1103 | .RS | |
1104 | .TP | |
1105 | .BR PTRACE_SYSCALL_INFO_ENTRY | |
1106 | The | |
1107 | .I entry | |
1108 | component of the union contains information relating to a | |
1109 | system call entry stop. | |
1110 | .TP | |
1111 | .BR PTRACE_SYSCALL_INFO_EXIT | |
1112 | The | |
1113 | .I exit | |
1114 | component of the union contains information relating to a | |
1115 | system call exit stop. | |
1116 | .TP | |
1117 | .BR PTRACE_SYSCALL_INFO_SECCOMP | |
1118 | The | |
302c512c | 1119 | .I seccomp |
f04534d2 MK |
1120 | component of the union contains information relating to a |
1121 | .B PTRACE_EVENT_SECCOMP | |
1122 | stop. | |
1123 | .TP | |
1124 | .BR PTRACE_SYSCALL_INFO_NONE | |
1125 | No component of the union contains relevant information. | |
1126 | .RE | |
bc8bfd8a | 1127 | .\" |
4d12a715 | 1128 | .SS Death under ptrace |
181f997f MK |
1129 | When a (possibly multithreaded) process receives a killing signal |
1130 | (one whose disposition is set to | |
1131 | .B SIG_DFL | |
1132 | and whose default action is to kill the process), | |
8b20acd1 MK |
1133 | all threads exit. |
1134 | Tracees report their death to their tracer(s). | |
181f997f MK |
1135 | Notification of this event is delivered via |
1136 | .BR waitpid (2). | |
dd3568a1 | 1137 | .PP |
181f997f MK |
1138 | Note that the killing signal will first cause signal-delivery-stop |
1139 | (on one tracee only), | |
1140 | and only after it is injected by the tracer | |
1141 | (or after it was dispatched to a thread which isn't traced), | |
1142 | will death from the signal happen on | |
1143 | .I all | |
1144 | tracees within a multithreaded process. | |
1145 | (The term "signal-delivery-stop" is explained below.) | |
dd3568a1 | 1146 | .PP |
181f997f | 1147 | .B SIGKILL |
ca302d0e DV |
1148 | does not generate signal-delivery-stop and |
1149 | therefore the tracer can't suppress it. | |
181f997f MK |
1150 | .B SIGKILL |
1151 | kills even within system calls | |
1152 | (syscall-exit-stop is not generated prior to death by | |
1153 | .BR SIGKILL ). | |
1154 | The net effect is that | |
1155 | .B SIGKILL | |
1156 | always kills the process (all its threads), | |
1157 | even if some threads of the process are ptraced. | |
dd3568a1 | 1158 | .PP |
181f997f MK |
1159 | When the tracee calls |
1160 | .BR _exit (2), | |
1161 | it reports its death to its tracer. | |
4d12a715 | 1162 | Other threads are not affected. |
dd3568a1 | 1163 | .PP |
181f997f MK |
1164 | When any thread executes |
1165 | .BR exit_group (2), | |
1166 | every tracee in its thread group reports its death to its tracer. | |
dd3568a1 | 1167 | .PP |
181f997f MK |
1168 | If the |
1169 | .B PTRACE_O_TRACEEXIT | |
1170 | option is on, | |
1171 | .B PTRACE_EVENT_EXIT | |
1172 | will happen before actual death. | |
1173 | This applies to exits via | |
1174 | .BR exit (2), | |
1175 | .BR exit_group (2), | |
1176 | and signal deaths (except | |
55bd9495 MK |
1177 | .BR SIGKILL , |
1178 | depending on the kernel version; see BUGS below), | |
181f997f MK |
1179 | and when threads are torn down on |
1180 | .BR execve (2) | |
1181 | in a multithreaded process. | |
dd3568a1 | 1182 | .PP |
181f997f MK |
1183 | The tracer cannot assume that the ptrace-stopped tracee exists. |
1184 | There are many scenarios when the tracee may die while stopped (such as | |
1185 | .BR SIGKILL ). | |
d6e37473 | 1186 | Therefore, the tracer must be prepared to handle an |
181f997f MK |
1187 | .B ESRCH |
1188 | error on any ptrace operation. | |
1189 | Unfortunately, the same error is returned if the tracee | |
1190 | exists but is not ptrace-stopped | |
1191 | (for commands which require a stopped tracee), | |
1192 | or if it is not traced by the process which issued the ptrace call. | |
1193 | The tracer needs to keep track of the stopped/running state of the tracee, | |
1194 | and interpret | |
1195 | .B ESRCH | |
1196 | as "tracee died unexpectedly" only if it knows that the tracee has | |
1197 | been observed to enter ptrace-stop. | |
1198 | Note that there is no guarantee that | |
1199 | .I waitpid(WNOHANG) | |
1200 | will reliably report the tracee's death status if a | |
1201 | ptrace operation returned | |
1202 | .BR ESRCH . | |
1203 | .I waitpid(WNOHANG) | |
1204 | may return 0 instead. | |
1205 | In other words, the tracee may be "not yet fully dead", | |
1206 | but already refusing ptrace requests. | |
dd3568a1 | 1207 | .PP |
181f997f MK |
1208 | The tracer can't assume that the tracee |
1209 | .I always | |
1210 | ends its life by reporting | |
1211 | .I WIFEXITED(status) | |
1212 | or | |
8898a252 MK |
1213 | .IR WIFSIGNALED(status) ; |
1214 | there are cases where this does not occur. | |
1215 | For example, if a thread other than thread group leader does an | |
1216 | .BR execve (2), | |
1217 | it disappears; | |
1218 | its PID will never be seen again, | |
1219 | and any subsequent ptrace stops will be reported under | |
1220 | the thread group leader's PID. | |
4d12a715 DV |
1221 | .SS Stopped states |
1222 | A tracee can be in two states: running or stopped. | |
ad84c543 | 1223 | For the purposes of ptrace, a tracee which is blocked in a system call |
8da59274 DV |
1224 | (such as |
1225 | .BR read (2), | |
ad84c543 MK |
1226 | .BR pause (2), |
1227 | etc.) | |
1228 | is nevertheless considered to be running, even if the tracee is blocked | |
8da59274 DV |
1229 | for a long time. |
1230 | The state of the tracee after | |
1231 | .BR PTRACE_LISTEN | |
1232 | is somewhat of a gray area: it is not in any ptrace-stop (ptrace commands | |
ad84c543 MK |
1233 | won't work on it, and it will deliver |
1234 | .BR waitpid (2) | |
1235 | notifications), | |
8da59274 DV |
1236 | but it also may be considered "stopped" because |
1237 | it is not executing instructions (is not scheduled), and if it was | |
1238 | in group-stop before | |
1239 | .BR PTRACE_LISTEN , | |
ad84c543 MK |
1240 | it will not respond to signals until |
1241 | .B SIGCONT | |
1242 | is received. | |
dd3568a1 | 1243 | .PP |
181f997f | 1244 | There are many kinds of states when the tracee is stopped, and in ptrace |
8b20acd1 | 1245 | discussions they are often conflated. |
181f997f | 1246 | Therefore, it is important to use precise terms. |
dd3568a1 | 1247 | .PP |
181f997f MK |
1248 | In this manual page, any stopped state in which the tracee is ready |
1249 | to accept ptrace commands from the tracer is called | |
1250 | .IR ptrace-stop . | |
8b20acd1 | 1251 | Ptrace-stops can |
181f997f MK |
1252 | be further subdivided into |
1253 | .IR signal-delivery-stop , | |
1254 | .IR group-stop , | |
1255 | .IR syscall-stop , | |
20e64af8 | 1256 | .IR "PTRACE_EVENT stops" , |
181f997f MK |
1257 | and so on. |
1258 | These stopped states are described in detail below. | |
dd3568a1 | 1259 | .PP |
181f997f MK |
1260 | When the running tracee enters ptrace-stop, it notifies its tracer using |
1261 | .BR waitpid (2) | |
1262 | (or one of the other "wait" system calls). | |
1263 | Most of this manual page assumes that the tracer waits with: | |
dd3568a1 | 1264 | .PP |
181f997f | 1265 | pid = waitpid(pid_or_minus_1, &status, __WALL); |
dd3568a1 | 1266 | .PP |
181f997f MK |
1267 | Ptrace-stopped tracees are reported as returns with |
1268 | .I pid | |
1269 | greater than 0 and | |
1270 | .I WIFSTOPPED(status) | |
1271 | true. | |
8898a252 MK |
1272 | .\" Denys Vlasenko: |
1273 | .\" Do we require __WALL usage, or will just using 0 be ok? (With 0, | |
1274 | .\" I am not 100% sure there aren't ugly corner cases.) Are the | |
181f997f MK |
1275 | .\" rules different if user wants to use waitid? Will waitid require |
1276 | .\" WEXITED? | |
1277 | .\" | |
dd3568a1 | 1278 | .PP |
181f997f MK |
1279 | The |
1280 | .B __WALL | |
1281 | flag does not include the | |
1282 | .B WSTOPPED | |
1283 | and | |
1284 | .B WEXITED | |
1285 | flags, but implies their functionality. | |
dd3568a1 | 1286 | .PP |
181f997f MK |
1287 | Setting the |
1288 | .B WCONTINUED | |
1289 | flag when calling | |
1290 | .BR waitpid (2) | |
1291 | is not recommended: the "continued" state is per-process and | |
1292 | consuming it can confuse the real parent of the tracee. | |
dd3568a1 | 1293 | .PP |
181f997f MK |
1294 | Use of the |
1295 | .B WNOHANG | |
1296 | flag may cause | |
1297 | .BR waitpid (2) | |
1298 | to return 0 ("no wait results available yet") | |
1299 | even if the tracer knows there should be a notification. | |
1300 | Example: | |
408731d4 MK |
1301 | .PP |
1302 | .in +4n | |
1303 | .EX | |
1304 | errno = 0; | |
1305 | ptrace(PTRACE_CONT, pid, 0L, 0L); | |
1306 | if (errno == ESRCH) { | |
1307 | /* tracee is dead */ | |
1308 | r = waitpid(tracee, &status, __WALL | WNOHANG); | |
1309 | /* r can still be 0 here! */ | |
1310 | } | |
1311 | .EE | |
1312 | .in | |
bea08fec | 1313 | .\" FIXME . |
181f997f MK |
1314 | .\" waitid usage? WNOWAIT? |
1315 | .\" describe how wait notifications queue (or not queue) | |
dd3568a1 | 1316 | .PP |
4d12a715 | 1317 | The following kinds of ptrace-stops exist: signal-delivery-stops, |
a5c725cf DP |
1318 | group-stops, |
1319 | .B PTRACE_EVENT | |
1320 | stops, syscall-stops. | |
181f997f MK |
1321 | They all are reported by |
1322 | .BR waitpid (2) | |
1323 | with | |
1324 | .I WIFSTOPPED(status) | |
1325 | true. | |
1326 | They may be differentiated by examining the value | |
1327 | .IR status>>8 , | |
1328 | and if there is ambiguity in that value, by querying | |
1329 | .BR PTRACE_GETSIGINFO . | |
181f997f MK |
1330 | (Note: the |
1331 | .I WSTOPSIG(status) | |
dc85ba7c | 1332 | macro can't be used to perform this examination, |
8898a252 | 1333 | because it returns the value |
0ce81ab5 | 1334 | .IR "(status>>8)\ &\ 0xff" .) |
4d12a715 | 1335 | .SS Signal-delivery-stop |
181f997f MK |
1336 | When a (possibly multithreaded) process receives any signal except |
1337 | .BR SIGKILL , | |
1338 | the kernel selects an arbitrary thread which handles the signal. | |
1339 | (If the signal is generated with | |
1340 | .BR tgkill (2), | |
1341 | the target thread can be explicitly selected by the caller.) | |
1342 | If the selected thread is traced, it enters signal-delivery-stop. | |
1343 | At this point, the signal is not yet delivered to the process, | |
1344 | and can be suppressed by the tracer. | |
1345 | If the tracer doesn't suppress the signal, | |
181f997f | 1346 | it passes the signal to the tracee in the next ptrace restart request. |
8b20acd1 | 1347 | This second step of signal delivery is called |
181f997f MK |
1348 | .I "signal injection" |
1349 | in this manual page. | |
1350 | Note that if the signal is blocked, | |
1351 | signal-delivery-stop doesn't happen until the signal is unblocked, | |
1352 | with the usual exception that | |
1353 | .B SIGSTOP | |
1354 | can't be blocked. | |
dd3568a1 | 1355 | .PP |
181f997f MK |
1356 | Signal-delivery-stop is observed by the tracer as |
1357 | .BR waitpid (2) | |
1358 | returning with | |
1359 | .I WIFSTOPPED(status) | |
f098951d | 1360 | true, with the signal returned by |
181f997f | 1361 | .IR WSTOPSIG(status) . |
f098951d | 1362 | If the signal is |
181f997f MK |
1363 | .BR SIGTRAP , |
1364 | this may be a different kind of ptrace-stop; | |
1365 | see the "Syscall-stops" and "execve" sections below for details. | |
8b20acd1 | 1366 | If |
181f997f MK |
1367 | .I WSTOPSIG(status) |
1368 | returns a stopping signal, this may be a group-stop; see below. | |
4d12a715 | 1369 | .SS Signal injection and suppression |
181f997f MK |
1370 | After signal-delivery-stop is observed by the tracer, |
1371 | the tracer should restart the tracee with the call | |
dd3568a1 | 1372 | .PP |
181f997f | 1373 | ptrace(PTRACE_restart, pid, 0, sig) |
dd3568a1 | 1374 | .PP |
181f997f MK |
1375 | where |
1376 | .B PTRACE_restart | |
1377 | is one of the restarting ptrace requests. | |
1378 | If | |
1379 | .I sig | |
1380 | is 0, then a signal is not delivered. | |
1381 | Otherwise, the signal | |
1382 | .I sig | |
1383 | is delivered. | |
1384 | This operation is called | |
1385 | .I "signal injection" | |
1386 | in this manual page, to distinguish it from signal-delivery-stop. | |
dd3568a1 | 1387 | .PP |
8898a252 | 1388 | The |
181f997f MK |
1389 | .I sig |
1390 | value may be different from the | |
1391 | .I WSTOPSIG(status) | |
1392 | value: the tracer can cause a different signal to be injected. | |
dd3568a1 | 1393 | .PP |
181f997f | 1394 | Note that a suppressed signal still causes system calls to return |
8b20acd1 | 1395 | prematurely. |
15d33661 | 1396 | In this case, system calls will be restarted: the tracer will |
a17e05c5 | 1397 | observe the tracee to reexecute the interrupted system call (or |
a5c725cf | 1398 | .BR restart_syscall (2) |
177660fa | 1399 | system call for a few system calls which use a different mechanism |
f098951d DV |
1400 | for restarting) if the tracer uses |
1401 | .BR PTRACE_SYSCALL . | |
1402 | Even system calls (such as | |
a5c725cf | 1403 | .BR poll (2)) |
f098951d | 1404 | which are not restartable after signal are restarted after |
a17e05c5 | 1405 | signal is suppressed; |
177660fa | 1406 | however, kernel bugs exist which cause some system calls to fail with |
181f997f MK |
1407 | .B EINTR |
1408 | even though no observable signal is injected to the tracee. | |
dd3568a1 | 1409 | .PP |
8898a252 | 1410 | Restarting ptrace commands issued in ptrace-stops other than |
181f997f MK |
1411 | signal-delivery-stop are not guaranteed to inject a signal, even if |
1412 | .I sig | |
8b20acd1 | 1413 | is nonzero. |
181f997f MK |
1414 | No error is reported; a nonzero |
1415 | .I sig | |
1416 | may simply be ignored. | |
1417 | Ptrace users should not try to "create a new signal" this way: use | |
1418 | .BR tgkill (2) | |
1419 | instead. | |
dd3568a1 | 1420 | .PP |
8898a252 MK |
1421 | The fact that signal injection requests may be ignored |
1422 | when restarting the tracee after | |
1423 | ptrace stops that are not signal-delivery-stops | |
1424 | is a cause of confusion among ptrace users. | |
181f997f MK |
1425 | One typical scenario is that the tracer observes group-stop, |
1426 | mistakes it for signal-delivery-stop, restarts the tracee with | |
efeece04 | 1427 | .PP |
ba8f446e | 1428 | ptrace(PTRACE_restart, pid, 0, stopsig) |
efeece04 | 1429 | .PP |
181f997f MK |
1430 | with the intention of injecting |
1431 | .IR stopsig , | |
1432 | but | |
1433 | .I stopsig | |
1434 | gets ignored and the tracee continues to run. | |
dd3568a1 | 1435 | .PP |
181f997f MK |
1436 | The |
1437 | .B SIGCONT | |
1438 | signal has a side effect of waking up (all threads of) | |
1439 | a group-stopped process. | |
1440 | This side effect happens before signal-delivery-stop. | |
a5c725cf | 1441 | The tracer can't suppress this side effect (it can |
181f997f MK |
1442 | only suppress signal injection, which only causes the |
1443 | .BR SIGCONT | |
1444 | handler to not be executed in the tracee, if such a handler is installed). | |
1445 | In fact, waking up from group-stop may be followed by | |
1446 | signal-delivery-stop for signal(s) | |
1447 | .I other than | |
1448 | .BR SIGCONT , | |
1449 | if they were pending when | |
1450 | .B SIGCONT | |
1451 | was delivered. | |
1452 | In other words, | |
1453 | .B SIGCONT | |
1454 | may be not the first signal observed by the tracee after it was sent. | |
dd3568a1 | 1455 | .PP |
181f997f | 1456 | Stopping signals cause (all threads of) a process to enter group-stop. |
4d12a715 | 1457 | This side effect happens after signal injection, and therefore can be |
181f997f | 1458 | suppressed by the tracer. |
dd3568a1 | 1459 | .PP |
dc85ba7c MK |
1460 | In Linux 2.4 and earlier, the |
1461 | .B SIGSTOP | |
1462 | signal can't be injected. | |
1463 | .\" In the Linux 2.4 sources, in arch/i386/kernel/signal.c::do_signal(), | |
1464 | .\" there is: | |
d6e37473 | 1465 | .\" |
dc85ba7c MK |
1466 | .\" /* The debugger continued. Ignore SIGSTOP. */ |
1467 | .\" if (signr == SIGSTOP) | |
1468 | .\" continue; | |
dd3568a1 | 1469 | .PP |
181f997f MK |
1470 | .B PTRACE_GETSIGINFO |
1471 | can be used to retrieve a | |
1472 | .I siginfo_t | |
1473 | structure which corresponds to the delivered signal. | |
1474 | .B PTRACE_SETSIGINFO | |
1475 | may be used to modify it. | |
1476 | If | |
1477 | .B PTRACE_SETSIGINFO | |
1478 | has been used to alter | |
1479 | .IR siginfo_t , | |
1480 | the | |
1481 | .I si_signo | |
1482 | field and the | |
1483 | .I sig | |
1484 | parameter in the restarting command must match, | |
4d12a715 DV |
1485 | otherwise the result is undefined. |
1486 | .SS Group-stop | |
181f997f | 1487 | When a (possibly multithreaded) process receives a stopping signal, |
8b20acd1 MK |
1488 | all threads stop. |
1489 | If some threads are traced, they enter a group-stop. | |
181f997f MK |
1490 | Note that the stopping signal will first cause signal-delivery-stop |
1491 | (on one tracee only), and only after it is injected by the tracer | |
1492 | (or after it was dispatched to a thread which isn't traced), | |
1493 | will group-stop be initiated on | |
1494 | .I all | |
1495 | tracees within the multithreaded process. | |
1496 | As usual, every tracee reports its group-stop separately | |
1497 | to the corresponding tracer. | |
dd3568a1 | 1498 | .PP |
181f997f MK |
1499 | Group-stop is observed by the tracer as |
1500 | .BR waitpid (2) | |
1501 | returning with | |
1502 | .I WIFSTOPPED(status) | |
1503 | true, with the stopping signal available via | |
1504 | .IR WSTOPSIG(status) . | |
1505 | The same result is returned by some other classes of ptrace-stops, | |
1506 | therefore the recommended practice is to perform the call | |
dd3568a1 | 1507 | .PP |
181f997f | 1508 | ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo) |
dd3568a1 | 1509 | .PP |
181f997f MK |
1510 | The call can be avoided if the signal is not |
1511 | .BR SIGSTOP , | |
1512 | .BR SIGTSTP , | |
1513 | .BR SIGTTIN , | |
1514 | or | |
1515 | .BR SIGTTOU ; | |
1516 | only these four signals are stopping signals. | |
1517 | If the tracer sees something else, it can't be a group-stop. | |
1518 | Otherwise, the tracer needs to call | |
1519 | .BR PTRACE_GETSIGINFO . | |
1520 | If | |
1521 | .B PTRACE_GETSIGINFO | |
1522 | fails with | |
1523 | .BR EINVAL , | |
1524 | then it is definitely a group-stop. | |
1525 | (Other failure codes are possible, such as | |
1526 | .B ESRCH | |
1527 | ("no such process") if a | |
1528 | .B SIGKILL | |
1529 | killed the tracee.) | |
dd3568a1 | 1530 | .PP |
ad84c543 | 1531 | If tracee was attached using |
72906215 | 1532 | .BR PTRACE_SEIZE , |
ad84c543 | 1533 | group-stop is indicated by |
8da59274 | 1534 | .BR PTRACE_EVENT_STOP : |
ad84c543 MK |
1535 | .IR "status>>16 == PTRACE_EVENT_STOP" . |
1536 | This allows detection of group-stops | |
1537 | without requiring an extra | |
8da59274 DV |
1538 | .B PTRACE_GETSIGINFO |
1539 | call. | |
dd3568a1 | 1540 | .PP |
f04ba477 | 1541 | As of Linux 2.6.38, |
181f997f MK |
1542 | after the tracer sees the tracee ptrace-stop and until it |
1543 | restarts or kills it, the tracee will not run, | |
1544 | and will not send notifications (except | |
1545 | .B SIGKILL | |
1546 | death) to the tracer, even if the tracer enters into another | |
1547 | .BR waitpid (2) | |
8b20acd1 | 1548 | call. |
dd3568a1 | 1549 | .PP |
b8d02d56 MK |
1550 | The kernel behavior described in the previous paragraph |
1551 | causes a problem with transparent handling of stopping signals. | |
1552 | If the tracer restarts the tracee after group-stop, | |
dc85ba7c | 1553 | the stopping signal |
8898a252 | 1554 | is effectively ignored\(emthe tracee doesn't remain stopped, it runs. |
181f997f MK |
1555 | If the tracer doesn't restart the tracee before entering into the next |
1556 | .BR waitpid (2), | |
1557 | future | |
1558 | .B SIGCONT | |
b8d02d56 MK |
1559 | signals will not be reported to the tracer; |
1560 | this would cause the | |
181f997f | 1561 | .B SIGCONT |
b8d02d56 | 1562 | signals to have no effect on the tracee. |
dd3568a1 | 1563 | .PP |
f04ba477 | 1564 | Since Linux 3.4, there is a method to overcome this problem: instead of |
ba8f446e DV |
1565 | .BR PTRACE_CONT , |
1566 | a | |
1567 | .B PTRACE_LISTEN | |
1568 | command can be used to restart a tracee in a way where it does not execute, | |
f04ba477 MK |
1569 | but waits for a new event which it can report via |
1570 | .BR waitpid (2) | |
1571 | (such as when | |
ba8f446e DV |
1572 | it is restarted by a |
1573 | .BR SIGCONT ). | |
4d12a715 | 1574 | .SS PTRACE_EVENT stops |
181f997f MK |
1575 | If the tracer sets |
1576 | .B PTRACE_O_TRACE_* | |
1577 | options, the tracee will enter ptrace-stops called | |
1578 | .B PTRACE_EVENT | |
1579 | stops. | |
dd3568a1 | 1580 | .PP |
181f997f MK |
1581 | .B PTRACE_EVENT |
1582 | stops are observed by the tracer as | |
1583 | .BR waitpid (2) | |
1584 | returning with | |
1585 | .IR WIFSTOPPED(status) , | |
1586 | and | |
1587 | .I WSTOPSIG(status) | |
1588 | returns | |
302c512c DV |
1589 | .BR SIGTRAP |
1590 | (or for | |
1591 | .BR PTRACE_EVENT_STOP , | |
1592 | returns the stopping signal if tracee is in a group-stop). | |
181f997f MK |
1593 | An additional bit is set in the higher byte of the status word: |
1594 | the value | |
1595 | .I status>>8 | |
1596 | will be | |
efeece04 | 1597 | .PP |
302c512c | 1598 | ((PTRACE_EVENT_foo<<8) | SIGTRAP). |
efeece04 | 1599 | .PP |
8b20acd1 | 1600 | The following events exist: |
181f997f MK |
1601 | .TP |
1602 | .B PTRACE_EVENT_VFORK | |
1603 | Stop before return from | |
1604 | .BR vfork (2) | |
1605 | or | |
1606 | .BR clone (2) | |
1607 | with the | |
1608 | .B CLONE_VFORK | |
1609 | flag. | |
1610 | When the tracee is continued after this stop, it will wait for child to | |
1611 | exit/exec before continuing its execution | |
1612 | (in other words, the usual behavior on | |
1613 | .BR vfork (2)). | |
1614 | .TP | |
1615 | .B PTRACE_EVENT_FORK | |
1616 | Stop before return from | |
1617 | .BR fork (2) | |
1618 | or | |
1619 | .BR clone (2) | |
1620 | with the exit signal set to | |
1621 | .BR SIGCHLD . | |
1622 | .TP | |
1623 | .B PTRACE_EVENT_CLONE | |
1624 | Stop before return from | |
a5c725cf | 1625 | .BR clone (2). |
181f997f MK |
1626 | .TP |
1627 | .B PTRACE_EVENT_VFORK_DONE | |
1628 | Stop before return from | |
1629 | .BR vfork (2) | |
1630 | or | |
1631 | .BR clone (2) | |
1632 | with the | |
1633 | .B CLONE_VFORK | |
1634 | flag, | |
1635 | but after the child unblocked this tracee by exiting or execing. | |
dd3568a1 | 1636 | .PP |
181f997f MK |
1637 | For all four stops described above, |
1638 | the stop occurs in the parent (i.e., the tracee), | |
1639 | not in the newly created thread. | |
1640 | .BR PTRACE_GETEVENTMSG | |
1641 | can be used to retrieve the new thread's ID. | |
1642 | .TP | |
1643 | .B PTRACE_EVENT_EXEC | |
1644 | Stop before return from | |
1645 | .BR execve (2). | |
b16d33ef DV |
1646 | Since Linux 3.0, |
1647 | .BR PTRACE_GETEVENTMSG | |
1648 | returns the former thread ID. | |
181f997f MK |
1649 | .TP |
1650 | .B PTRACE_EVENT_EXIT | |
1651 | Stop before exit (including death from | |
1652 | .BR exit_group (2)), | |
1653 | signal death, or exit caused by | |
1654 | .BR execve (2) | |
1655 | in a multithreaded process. | |
1656 | .B PTRACE_GETEVENTMSG | |
1657 | returns the exit status. | |
8b20acd1 MK |
1658 | Registers can be examined |
1659 | (unlike when "real" exit happens). | |
181f997f MK |
1660 | The tracee is still alive; it needs to be |
1661 | .BR PTRACE_CONT ed | |
1662 | or | |
1663 | .BR PTRACE_DETACH ed | |
1664 | to finish exiting. | |
ba8f446e DV |
1665 | .TP |
1666 | .B PTRACE_EVENT_STOP | |
1667 | Stop induced by | |
1668 | .B PTRACE_INTERRUPT | |
29f9b8fb DV |
1669 | command, or group-stop, or initial ptrace-stop when a new child is attached |
1670 | (only if attached using | |
28e2ca57 | 1671 | .BR PTRACE_SEIZE ). |
3b4a59c4 KC |
1672 | .TP |
1673 | .B PTRACE_EVENT_SECCOMP | |
1674 | Stop triggered by a | |
1675 | .BR seccomp (2) | |
1676 | rule on tracee syscall entry when | |
1677 | .BR PTRACE_O_TRACESECCOMP | |
81c5080b MK |
1678 | has been set by the tracer. |
1679 | The seccomp event message data (from the | |
3b4a59c4 | 1680 | .BR SECCOMP_RET_DATA |
81c5080b | 1681 | portion of the seccomp filter rule) can be retrieved with |
ff20e9ca MK |
1682 | .BR PTRACE_GETEVENTMSG . |
1683 | The semantics of this stop are described in | |
5419141e | 1684 | detail in a separate section below. |
dd3568a1 | 1685 | .PP |
181f997f MK |
1686 | .B PTRACE_GETSIGINFO |
1687 | on | |
1688 | .B PTRACE_EVENT | |
1689 | stops returns | |
b16d33ef DV |
1690 | .B SIGTRAP |
1691 | in | |
181f997f MK |
1692 | .IR si_signo , |
1693 | with | |
1694 | .I si_code | |
1695 | set to | |
1696 | .IR "(event<<8)\ |\ SIGTRAP" . | |
4d12a715 | 1697 | .SS Syscall-stops |
181f997f | 1698 | If the tracee was restarted by |
131bcd7a KF |
1699 | .BR PTRACE_SYSCALL |
1700 | or | |
1701 | .BR PTRACE_SYSEMU , | |
181f997f | 1702 | the tracee enters |
131bcd7a KF |
1703 | syscall-enter-stop just prior to entering any system call (which |
1704 | will not be executed if the restart was using | |
ff20e9ca | 1705 | .BR PTRACE_SYSEMU , |
131bcd7a KF |
1706 | regardless of any change made to registers at this point or how the |
1707 | tracee is restarted after this stop). | |
1708 | No matter which method caused the syscall-entry-stop, | |
1709 | if the tracer restarts the tracee with | |
181f997f MK |
1710 | .BR PTRACE_SYSCALL , |
1711 | the tracee enters syscall-exit-stop when the system call is finished, | |
1712 | or if it is interrupted by a signal. | |
1713 | (That is, signal-delivery-stop never happens between syscall-enter-stop | |
1714 | and syscall-exit-stop; it happens | |
1715 | .I after | |
ff20e9ca MK |
1716 | syscall-exit-stop.). |
1717 | If the tracee is continued using any other method (including | |
1718 | .BR PTRACE_SYSEMU ), | |
1719 | no syscall-exit-stop occurs. | |
1720 | Note that all mentions | |
131bcd7a KF |
1721 | .BR PTRACE_SYSEMU |
1722 | apply equally to | |
1723 | .BR PTRACE_SYSEMU_SINGLESTEP. | |
dd3568a1 | 1724 | .PP |
0d5b85ca | 1725 | However, even if the tracee was continued using |
2bb165ec MK |
1726 | .BR PTRACE_SYSCALL , |
1727 | it is not guaranteed that the next stop will be a syscall-exit-stop. | |
181f997f MK |
1728 | Other possibilities are that the tracee may stop in a |
1729 | .B PTRACE_EVENT | |
5419141e | 1730 | stop (including seccomp stops), exit (if it entered |
181f997f MK |
1731 | .BR _exit (2) |
1732 | or | |
1733 | .BR exit_group (2)), | |
1734 | be killed by | |
1735 | .BR SIGKILL , | |
1736 | or die silently (if it is a thread group leader, the | |
1737 | .BR execve (2) | |
1738 | happened in another thread, | |
1739 | and that thread is not traced by the same tracer; | |
1740 | this situation is discussed later). | |
dd3568a1 | 1741 | .PP |
181f997f MK |
1742 | Syscall-enter-stop and syscall-exit-stop are observed by the tracer as |
1743 | .BR waitpid (2) | |
1744 | returning with | |
1745 | .I WIFSTOPPED(status) | |
1746 | true, and | |
1747 | .I WSTOPSIG(status) | |
1748 | giving | |
1749 | .BR SIGTRAP . | |
1750 | If the | |
1751 | .B PTRACE_O_TRACESYSGOOD | |
1752 | option was set by the tracer, then | |
1753 | .I WSTOPSIG(status) | |
1754 | will give the value | |
1755 | .IR "(SIGTRAP\ |\ 0x80)" . | |
dd3568a1 | 1756 | .PP |
4d12a715 | 1757 | Syscall-stops can be distinguished from signal-delivery-stop with |
181f997f MK |
1758 | .B SIGTRAP |
1759 | by querying | |
1760 | .BR PTRACE_GETSIGINFO | |
1761 | for the following cases: | |
1762 | .TP | |
1763 | .IR si_code " <= 0" | |
1764 | .B SIGTRAP | |
7fac88a9 | 1765 | was delivered as a result of a user-space action, |
8898a252 | 1766 | for example, a system call |
181f997f | 1767 | .RB ( tgkill (2), |
8898a252 | 1768 | .BR kill (2), |
181f997f | 1769 | .BR sigqueue (3), |
8898a252 MK |
1770 | etc.), |
1771 | expiration of a POSIX timer, | |
1772 | change of state on a POSIX message queue, | |
1773 | or completion of an asynchronous I/O request. | |
181f997f MK |
1774 | .TP |
1775 | .IR si_code " == SI_KERNEL (0x80)" | |
1776 | .B SIGTRAP | |
1777 | was sent by the kernel. | |
1778 | .TP | |
1779 | .IR si_code " == SIGTRAP or " si_code " == (SIGTRAP|0x80)" | |
1780 | This is a syscall-stop. | |
dd3568a1 | 1781 | .PP |
181f997f MK |
1782 | However, syscall-stops happen very often (twice per system call), |
1783 | and performing | |
1784 | .B PTRACE_GETSIGINFO | |
1785 | for every syscall-stop may be somewhat expensive. | |
dd3568a1 | 1786 | .PP |
181f997f MK |
1787 | Some architectures allow the cases to be distinguished |
1788 | by examining registers. | |
1789 | For example, on x86, | |
1790 | .I rax | |
1791 | == | |
1792 | .RB - ENOSYS | |
1793 | in syscall-enter-stop. | |
1794 | Since | |
1795 | .B SIGTRAP | |
1796 | (like any other signal) always happens | |
1797 | .I after | |
1798 | syscall-exit-stop, | |
1799 | and at this point | |
1800 | .I rax | |
1801 | almost never contains | |
1802 | .RB - ENOSYS , | |
1803 | the | |
1804 | .B SIGTRAP | |
1805 | looks like "syscall-stop which is not syscall-enter-stop"; | |
1806 | in other words, it looks like a | |
8b20acd1 | 1807 | "stray syscall-exit-stop" and can be detected this way. |
181f997f | 1808 | But such detection is fragile and is best avoided. |
dd3568a1 | 1809 | .PP |
181f997f MK |
1810 | Using the |
1811 | .B PTRACE_O_TRACESYSGOOD | |
a17e05c5 | 1812 | option is the recommended method to distinguish syscall-stops |
b8d02d56 | 1813 | from other kinds of ptrace-stops, |
181f997f | 1814 | since it is reliable and does not incur a performance penalty. |
dd3568a1 | 1815 | .PP |
181f997f MK |
1816 | Syscall-enter-stop and syscall-exit-stop are |
1817 | indistinguishable from each other by the tracer. | |
1818 | The tracer needs to keep track of the sequence of | |
4d12a715 | 1819 | ptrace-stops in order to not misinterpret syscall-enter-stop as |
8b20acd1 | 1820 | syscall-exit-stop or vice versa. |
ff20e9ca | 1821 | In general, a syscall-enter-stop is |
181f997f MK |
1822 | always followed by syscall-exit-stop, |
1823 | .B PTRACE_EVENT | |
ff20e9ca | 1824 | stop, or the tracee's death; |
181f997f | 1825 | no other kinds of ptrace-stop can occur in between. |
5419141e | 1826 | However, note that seccomp stops (see below) can cause syscall-exit-stops, |
0d5b85ca | 1827 | without preceding syscall-entry-stops. |
ff20e9ca MK |
1828 | If seccomp is in use, care needs |
1829 | to be taken not to misinterpret such stops as syscall-entry-stops. | |
dd3568a1 | 1830 | .PP |
181f997f MK |
1831 | If after syscall-enter-stop, |
1832 | the tracer uses a restarting command other than | |
1833 | .BR PTRACE_SYSCALL , | |
1834 | syscall-exit-stop is not generated. | |
dd3568a1 | 1835 | .PP |
181f997f MK |
1836 | .B PTRACE_GETSIGINFO |
1837 | on syscall-stops returns | |
1838 | .B SIGTRAP | |
1839 | in | |
1840 | .IR si_signo , | |
1841 | with | |
1842 | .I si_code | |
1843 | set to | |
1844 | .B SIGTRAP | |
1845 | or | |
1846 | .IR (SIGTRAP|0x80) . | |
ff20e9ca MK |
1847 | .\" |
1848 | .SS PTRACE_EVENT_SECCOMP stops (Linux 3.5 to 4.7) | |
5419141e KF |
1849 | The behavior of |
1850 | .BR PTRACE_EVENT_SECCOMP | |
1851 | stops and their interaction with other kinds | |
ff20e9ca MK |
1852 | of ptrace stops has changed between kernel versions. |
1853 | This documents the behavior | |
1854 | from their introduction until Linux 4.7 (inclusive). | |
1855 | The behavior in later kernel versions is documented in the next section. | |
efeece04 | 1856 | .PP |
5419141e KF |
1857 | A |
1858 | .BR PTRACE_EVENT_SECCOMP | |
1859 | stop occurs whenever a | |
1860 | .BR SECCOMP_RET_TRACE | |
ff20e9ca MK |
1861 | rule is triggered. |
1862 | This is independent of which methods was used to restart the system call. | |
1863 | Notably, seccomp still runs even if the tracee was restarted using | |
5419141e KF |
1864 | .BR PTRACE_SYSEMU |
1865 | and this system call is unconditionally skipped. | |
efeece04 | 1866 | .PP |
5419141e | 1867 | Restarts from this stop will behave as if the stop had occurred right |
ff20e9ca MK |
1868 | before the system call in question. |
1869 | In particular, both | |
5419141e KF |
1870 | .BR PTRACE_SYSCALL |
1871 | and | |
1872 | .BR PTRACE_SYSEMU | |
ff20e9ca MK |
1873 | will normally cause a subsequent syscall-entry-stop. |
1874 | However, if after the | |
5419141e | 1875 | .BR PTRACE_EVENT_SECCOMP |
ff20e9ca MK |
1876 | the system call number is negative, |
1877 | both the syscall-entry-stop and the system call itself will be skipped. | |
1878 | This means that if the system call number is negative after a | |
5419141e KF |
1879 | .BR PTRACE_EVENT_SECCOMP |
1880 | and the tracee is restarted using | |
f7111396 | 1881 | .BR PTRACE_SYSCALL , |
5419141e | 1882 | the next observed stop will be a syscall-exit-stop, |
ff20e9ca MK |
1883 | rather than the syscall-entry-stop that might have been expected. |
1884 | .\" | |
1885 | .SS PTRACE_EVENT_SECCOMP stops (since Linux 4.8) | |
1886 | Starting with Linux 4.8, | |
1887 | .\" commit 93e35efb8de45393cf61ed07f7b407629bf698ea | |
1888 | the | |
5419141e | 1889 | .BR PTRACE_EVENT_SECCOMP |
ff20e9ca MK |
1890 | stop was reordered to occur between syscall-entry-stop and |
1891 | syscall-exit-stop. | |
1892 | Note that seccomp no longer runs (and no | |
1893 | .B PTRACE_EVENT_SECCOMP | |
1894 | will be reported) if the system call is skipped due to | |
1895 | .BR PTRACE_SYSEMU . | |
efeece04 | 1896 | .PP |
ff20e9ca MK |
1897 | Functionally, a |
1898 | .B PTRACE_EVENT_SECCOMP | |
1899 | stop functions comparably | |
1900 | to a syscall-entry-stop (i.e., continuations using | |
5419141e | 1901 | .BR PTRACE_SYSCALL |
ff20e9ca MK |
1902 | will cause syscall-exit-stops, |
1903 | the system call number may be changed and any other modified registers | |
1904 | are visible to the to-be-executed system call as well). | |
1905 | Note that there may be, | |
0d5b85ca | 1906 | but need not have been a preceding syscall-entry-stop. |
efeece04 | 1907 | .PP |
5419141e KF |
1908 | After a |
1909 | .BR PTRACE_EVENT_SECCOMP | |
ff20e9ca | 1910 | stop, seccomp will be rerun, with a |
5419141e KF |
1911 | .BR SECCOMP_RET_TRACE |
1912 | rule now functioning the same as a | |
ff20e9ca MK |
1913 | .BR SECCOMP_RET_ALLOW . |
1914 | Specifically, this means that if registers are not modified during the | |
5419141e KF |
1915 | .BR PTRACE_EVENT_SECCOMP |
1916 | stop, the system call will then be allowed. | |
ff20e9ca | 1917 | .\" |
131bcd7a | 1918 | .SS PTRACE_SINGLESTEP stops |
b8d02d56 | 1919 | [Details of these kinds of stops are yet to be documented.] |
181f997f | 1920 | .\" |
bea08fec | 1921 | .\" FIXME . |
131bcd7a | 1922 | .\" document stops occurring with PTRACE_SINGLESTEP |
ff20e9ca | 1923 | .\" |
4d12a715 | 1924 | .SS Informational and restarting ptrace commands |
181f997f MK |
1925 | Most ptrace commands (all except |
1926 | .BR PTRACE_ATTACH , | |
ba8f446e | 1927 | .BR PTRACE_SEIZE , |
181f997f | 1928 | .BR PTRACE_TRACEME , |
ba8f446e | 1929 | .BR PTRACE_INTERRUPT , |
181f997f MK |
1930 | and |
1931 | .BR PTRACE_KILL ) | |
1932 | require the tracee to be in a ptrace-stop, otherwise they fail with | |
1933 | .BR ESRCH . | |
dd3568a1 | 1934 | .PP |
181f997f MK |
1935 | When the tracee is in ptrace-stop, |
1936 | the tracer can read and write data to | |
1937 | the tracee using informational commands. | |
1938 | These commands leave the tracee in ptrace-stopped state: | |
dd3568a1 | 1939 | .PP |
408731d4 MK |
1940 | .in +4n |
1941 | .EX | |
1942 | ptrace(PTRACE_PEEKTEXT/PEEKDATA/PEEKUSER, pid, addr, 0); | |
1943 | ptrace(PTRACE_POKETEXT/POKEDATA/POKEUSER, pid, addr, long_val); | |
1944 | ptrace(PTRACE_GETREGS/GETFPREGS, pid, 0, &struct); | |
1945 | ptrace(PTRACE_SETREGS/SETFPREGS, pid, 0, &struct); | |
1946 | ptrace(PTRACE_GETREGSET, pid, NT_foo, &iov); | |
1947 | ptrace(PTRACE_SETREGSET, pid, NT_foo, &iov); | |
1948 | ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo); | |
1949 | ptrace(PTRACE_SETSIGINFO, pid, 0, &siginfo); | |
1950 | ptrace(PTRACE_GETEVENTMSG, pid, 0, &long_var); | |
1951 | ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_flags); | |
1952 | .EE | |
1953 | .in | |
dd3568a1 | 1954 | .PP |
8b20acd1 | 1955 | Note that some errors are not reported. |
181f997f MK |
1956 | For example, setting signal information |
1957 | .RI ( siginfo ) | |
4d12a715 | 1958 | may have no effect in some ptrace-stops, yet the call may succeed |
181f997f MK |
1959 | (return 0 and not set |
1960 | .IR errno ); | |
1961 | querying | |
1962 | .B PTRACE_GETEVENTMSG | |
1963 | may succeed and return some random value if current ptrace-stop | |
1964 | is not documented as returning a meaningful event message. | |
dd3568a1 | 1965 | .PP |
181f997f | 1966 | The call |
efeece04 | 1967 | .PP |
181f997f | 1968 | ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_flags); |
efeece04 | 1969 | .PP |
181f997f MK |
1970 | affects one tracee. |
1971 | The tracee's current flags are replaced. | |
1972 | Flags are inherited by new tracees created and "auto-attached" via active | |
1973 | .BR PTRACE_O_TRACEFORK , | |
1974 | .BR PTRACE_O_TRACEVFORK , | |
1975 | or | |
1976 | .BR PTRACE_O_TRACECLONE | |
1977 | options. | |
dd3568a1 | 1978 | .PP |
181f997f MK |
1979 | Another group of commands makes the ptrace-stopped tracee run. |
1980 | They have the form: | |
dd3568a1 | 1981 | .PP |
8898a252 | 1982 | ptrace(cmd, pid, 0, sig); |
dd3568a1 | 1983 | .PP |
181f997f MK |
1984 | where |
1985 | .I cmd | |
1986 | is | |
1987 | .BR PTRACE_CONT , | |
ba8f446e | 1988 | .BR PTRACE_LISTEN , |
181f997f MK |
1989 | .BR PTRACE_DETACH , |
1990 | .BR PTRACE_SYSCALL , | |
1991 | .BR PTRACE_SINGLESTEP , | |
1992 | .BR PTRACE_SYSEMU , | |
1993 | or | |
a5c725cf | 1994 | .BR PTRACE_SYSEMU_SINGLESTEP . |
181f997f MK |
1995 | If the tracee is in signal-delivery-stop, |
1996 | .I sig | |
1997 | is the signal to be injected (if it is nonzero). | |
1998 | Otherwise, | |
1999 | .I sig | |
2000 | may be ignored. | |
8898a252 MK |
2001 | (When restarting a tracee from a ptrace-stop other than signal-delivery-stop, |
2002 | recommended practice is to always pass 0 in | |
a5c725cf | 2003 | .IR sig .) |
4d12a715 | 2004 | .SS Attaching and detaching |
181f997f | 2005 | A thread can be attached to the tracer using the call |
efeece04 | 2006 | .PP |
181f997f | 2007 | ptrace(PTRACE_ATTACH, pid, 0, 0); |
efeece04 | 2008 | .PP |
ba8f446e | 2009 | or |
efeece04 | 2010 | .PP |
ba8f446e | 2011 | ptrace(PTRACE_SEIZE, pid, 0, PTRACE_O_flags); |
efeece04 | 2012 | .PP |
ba8f446e DV |
2013 | .B PTRACE_ATTACH |
2014 | sends | |
181f997f MK |
2015 | .B SIGSTOP |
2016 | to this thread. | |
2017 | If the tracer wants this | |
2018 | .B SIGSTOP | |
2019 | to have no effect, it needs to suppress it. | |
2020 | Note that if other signals are concurrently sent to | |
2021 | this thread during attach, | |
2022 | the tracer may see the tracee enter signal-delivery-stop | |
2023 | with other signal(s) first! | |
2024 | The usual practice is to reinject these signals until | |
2025 | .B SIGSTOP | |
2026 | is seen, then suppress | |
2027 | .B SIGSTOP | |
2028 | injection. | |
181f997f MK |
2029 | The design bug here is that a ptrace attach and a concurrently delivered |
2030 | .B SIGSTOP | |
2031 | may race and the concurrent | |
2032 | .B SIGSTOP | |
2033 | may be lost. | |
2034 | .\" | |
3b1fdaf3 | 2035 | .\" FIXME Describe how to attach to a thread which is already group-stopped. |
dd3568a1 | 2036 | .PP |
181f997f MK |
2037 | Since attaching sends |
2038 | .B SIGSTOP | |
2039 | and the tracer usually suppresses it, this may cause a stray | |
a5c725cf | 2040 | .B EINTR |
181f997f | 2041 | return from the currently executing system call in the tracee, |
a5c725cf | 2042 | as described in the "Signal injection and suppression" section. |
dd3568a1 | 2043 | .PP |
f04ba477 | 2044 | Since Linux 3.4, |
ba8f446e DV |
2045 | .B PTRACE_SEIZE |
2046 | can be used instead of | |
2047 | .BR PTRACE_ATTACH . | |
2048 | .B PTRACE_SEIZE | |
e3948c69 MK |
2049 | does not stop the attached process. |
2050 | If you need to stop | |
ba8f446e DV |
2051 | it after attach (or at any other time) without sending it any signals, |
2052 | use | |
2053 | .B PTRACE_INTERRUPT | |
2054 | command. | |
dd3568a1 | 2055 | .PP |
181f997f | 2056 | The request |
efeece04 | 2057 | .PP |
181f997f | 2058 | ptrace(PTRACE_TRACEME, 0, 0, 0); |
efeece04 | 2059 | .PP |
181f997f MK |
2060 | turns the calling thread into a tracee. |
2061 | The thread continues to run (doesn't enter ptrace-stop). | |
2062 | A common practice is to follow the | |
2063 | .B PTRACE_TRACEME | |
2064 | with | |
efeece04 | 2065 | .PP |
181f997f | 2066 | raise(SIGSTOP); |
efeece04 | 2067 | .PP |
181f997f | 2068 | and allow the parent (which is our tracer now) to observe our |
4d12a715 | 2069 | signal-delivery-stop. |
dd3568a1 | 2070 | .PP |
d6e37473 | 2071 | If the |
181f997f MK |
2072 | .BR PTRACE_O_TRACEFORK , |
2073 | .BR PTRACE_O_TRACEVFORK , | |
2074 | or | |
2075 | .BR PTRACE_O_TRACECLONE | |
2076 | options are in effect, then children created by, respectively, | |
2077 | .BR vfork (2) | |
2078 | or | |
2079 | .BR clone (2) | |
2080 | with the | |
2081 | .B CLONE_VFORK | |
2082 | flag, | |
2083 | .BR fork (2) | |
2084 | or | |
2085 | .BR clone (2) | |
2086 | with the exit signal set to | |
2087 | .BR SIGCHLD , | |
2088 | and other kinds of | |
2089 | .BR clone (2), | |
2090 | are automatically attached to the same tracer which traced their parent. | |
2091 | .B SIGSTOP | |
2092 | is delivered to the children, causing them to enter | |
2093 | signal-delivery-stop after they exit the system call which created them. | |
dd3568a1 | 2094 | .PP |
181f997f | 2095 | Detaching of the tracee is performed by: |
efeece04 | 2096 | .PP |
181f997f | 2097 | ptrace(PTRACE_DETACH, pid, 0, sig); |
efeece04 | 2098 | .PP |
181f997f MK |
2099 | .B PTRACE_DETACH |
2100 | is a restarting operation; | |
2101 | therefore it requires the tracee to be in ptrace-stop. | |
2102 | If the tracee is in signal-delivery-stop, a signal can be injected. | |
2103 | Otherwise, the | |
2104 | .I sig | |
2105 | parameter may be silently ignored. | |
dd3568a1 | 2106 | .PP |
181f997f MK |
2107 | If the tracee is running when the tracer wants to detach it, |
2108 | the usual solution is to send | |
2109 | .B SIGSTOP | |
2110 | (using | |
2111 | .BR tgkill (2), | |
2112 | to make sure it goes to the correct thread), | |
2113 | wait for the tracee to stop in signal-delivery-stop for | |
2114 | .B SIGSTOP | |
2115 | and then detach it (suppressing | |
2116 | .B SIGSTOP | |
2117 | injection). | |
2118 | A design bug is that this can race with concurrent | |
2119 | .BR SIGSTOP s. | |
2120 | Another complication is that the tracee may enter other ptrace-stops | |
2121 | and needs to be restarted and waited for again, until | |
2122 | .B SIGSTOP | |
2123 | is seen. | |
2124 | Yet another complication is to be sure that | |
2125 | the tracee is not already ptrace-stopped, | |
2126 | because no signal delivery happens while it is\(emnot even | |
2127 | .BR SIGSTOP . | |
3b1fdaf3 MK |
2128 | .\" FIXME Describe how to detach from a group-stopped tracee so that it |
2129 | .\" doesn't run, but continues to wait for SIGCONT. | |
dd3568a1 | 2130 | .PP |
181f997f | 2131 | If the tracer dies, all tracees are automatically detached and restarted, |
8b20acd1 | 2132 | unless they were in group-stop. |
b8d02d56 MK |
2133 | Handling of restart from group-stop is currently buggy, |
2134 | but the "as planned" behavior is to leave tracee stopped and waiting for | |
181f997f MK |
2135 | .BR SIGCONT . |
2136 | If the tracee is restarted from signal-delivery-stop, | |
2137 | the pending signal is injected. | |
2138 | .SS execve(2) under ptrace | |
cb729171 | 2139 | .\" clone(2) CLONE_THREAD says: |
181f997f MK |
2140 | .\" If any of the threads in a thread group performs an execve(2), |
2141 | .\" then all threads other than the thread group leader are terminated, | |
d6e37473 | 2142 | .\" and the new program is executed in the thread group leader. |
181f997f | 2143 | .\" |
8898a252 | 2144 | When one thread in a multithreaded process calls |
181f997f MK |
2145 | .BR execve (2), |
2146 | the kernel destroys all other threads in the process, | |
2147 | .\" In kernel 3.1 sources, see fs/exec.c::de_thread() | |
2148 | and resets the thread ID of the execing thread to the | |
2149 | thread group ID (process ID). | |
181f997f MK |
2150 | (Or, to put things another way, when a multithreaded process does an |
2151 | .BR execve (2), | |
8898a252 | 2152 | at completion of the call, it appears as though the |
181f997f MK |
2153 | .BR execve (2) |
2154 | occurred in the thread group leader, regardless of which thread did the | |
2155 | .BR execve (2).) | |
181f997f MK |
2156 | This resetting of the thread ID looks very confusing to tracers: |
2157 | .IP * 3 | |
2158 | All other threads stop in | |
8898a252 | 2159 | .B PTRACE_EVENT_EXIT |
b8d02d56 | 2160 | stop, if the |
8898a252 MK |
2161 | .BR PTRACE_O_TRACEEXIT |
2162 | option was turned on. | |
181f997f MK |
2163 | Then all other threads except the thread group leader report |
2164 | death as if they exited via | |
2165 | .BR _exit (2) | |
2166 | with exit code 0. | |
b8d02d56 | 2167 | .IP * |
181f997f MK |
2168 | The execing tracee changes its thread ID while it is in the |
2169 | .BR execve (2). | |
2170 | (Remember, under ptrace, the "pid" returned from | |
2171 | .BR waitpid (2), | |
2172 | or fed into ptrace calls, is the tracee's thread ID.) | |
2173 | That is, the tracee's thread ID is reset to be the same as its process ID, | |
2174 | which is the same as the thread group leader's thread ID. | |
2175 | .IP * | |
f098951d DV |
2176 | Then a |
2177 | .B PTRACE_EVENT_EXEC | |
2178 | stop happens, if the | |
2179 | .BR PTRACE_O_TRACEEXEC | |
2180 | option was turned on. | |
2181 | .IP * | |
2182 | If the thread group leader has reported its | |
2183 | .B PTRACE_EVENT_EXIT | |
2184 | stop by this time, | |
181f997f MK |
2185 | it appears to the tracer that |
2186 | the dead thread leader "reappears from nowhere". | |
a17e05c5 | 2187 | (Note: the thread group leader does not report death via |
f098951d DV |
2188 | .I WIFEXITED(status) |
2189 | until there is at least one other live thread. | |
a17e05c5 | 2190 | This eliminates the possibility that the tracer will see |
f098951d | 2191 | it dying and then reappearing.) |
181f997f MK |
2192 | If the thread group leader was still alive, |
2193 | for the tracer this may look as if thread group leader | |
2194 | returns from a different system call than it entered, | |
2195 | or even "returned from a system call even though | |
2196 | it was not in any system call". | |
2197 | If the thread group leader was not traced | |
2198 | (or was traced by a different tracer), then during | |
2199 | .BR execve (2) | |
2200 | it will appear as if it has become a tracee of | |
2201 | the tracer of the execing tracee. | |
dd3568a1 | 2202 | .PP |
181f997f MK |
2203 | All of the above effects are the artifacts of |
2204 | the thread ID change in the tracee. | |
dd3568a1 | 2205 | .PP |
181f997f MK |
2206 | The |
2207 | .B PTRACE_O_TRACEEXEC | |
2208 | option is the recommended tool for dealing with this situation. | |
b8d02d56 | 2209 | First, it enables |
a5c725cf DP |
2210 | .BR PTRACE_EVENT_EXEC |
2211 | stop, | |
b8d02d56 | 2212 | which occurs before |
a5c725cf | 2213 | .BR execve (2) |
b8d02d56 MK |
2214 | returns. |
2215 | In this stop, the tracer can use | |
2216 | .B PTRACE_GETEVENTMSG | |
2217 | to retrieve the tracee's former thread ID. | |
94e66ffd | 2218 | (This feature was introduced in Linux 3.0.) |
b8d02d56 MK |
2219 | Second, the |
2220 | .B PTRACE_O_TRACEEXEC | |
2221 | option disables legacy | |
2222 | .B SIGTRAP | |
2223 | generation on | |
2224 | .BR execve (2). | |
dd3568a1 | 2225 | .PP |
181f997f MK |
2226 | When the tracer receives |
2227 | .B PTRACE_EVENT_EXEC | |
2228 | stop notification, | |
2229 | it is guaranteed that except this tracee and the thread group leader, | |
2230 | no other threads from the process are alive. | |
dd3568a1 | 2231 | .PP |
181f997f MK |
2232 | On receiving the |
2233 | .B PTRACE_EVENT_EXEC | |
2234 | stop notification, | |
2235 | the tracer should clean up all its internal | |
2236 | data structures describing the threads of this process, | |
2237 | and retain only one data structure\(emone which | |
2238 | describes the single still running tracee, with | |
efeece04 | 2239 | .PP |
f098951d | 2240 | thread ID == thread group ID == process ID. |
dd3568a1 | 2241 | .PP |
181f997f MK |
2242 | Example: two threads call |
2243 | .BR execve (2) | |
2244 | at the same time: | |
dd3568a1 | 2245 | .PP |
4d12a715 | 2246 | .nf |
a5c725cf | 2247 | *** we get syscall-enter-stop in thread 1: ** |
4d12a715 DV |
2248 | PID1 execve("/bin/foo", "foo" <unfinished ...> |
2249 | *** we issue PTRACE_SYSCALL for thread 1 ** | |
a5c725cf | 2250 | *** we get syscall-enter-stop in thread 2: ** |
4d12a715 DV |
2251 | PID2 execve("/bin/bar", "bar" <unfinished ...> |
2252 | *** we issue PTRACE_SYSCALL for thread 2 ** | |
2253 | *** we get PTRACE_EVENT_EXEC for PID0, we issue PTRACE_SYSCALL ** | |
2254 | *** we get syscall-exit-stop for PID0: ** | |
2255 | PID0 <... execve resumed> ) = 0 | |
2256 | .fi | |
dd3568a1 | 2257 | .PP |
181f997f MK |
2258 | If the |
2259 | .B PTRACE_O_TRACEEXEC | |
2260 | option is | |
2261 | .I not | |
28e2ca57 | 2262 | in effect for the execing tracee, |
53cdec41 | 2263 | and if the tracee was |
28e2ca57 DV |
2264 | .BR PTRACE_ATTACH ed |
2265 | rather that | |
2266 | .BR PTRACE_SEIZE d, | |
2267 | the kernel delivers an extra | |
181f997f MK |
2268 | .B SIGTRAP |
2269 | to the tracee after | |
2270 | .BR execve (2) | |
8b20acd1 MK |
2271 | returns. |
2272 | This is an ordinary signal (similar to one which can be | |
181f997f MK |
2273 | generated by |
2274 | .IR "kill -TRAP" ), | |
2275 | not a special kind of ptrace-stop. | |
2276 | Employing | |
2277 | .B PTRACE_GETSIGINFO | |
2278 | for this signal returns | |
2279 | .I si_code | |
2280 | set to 0 | |
2281 | .RI ( SI_USER ). | |
2282 | This signal may be blocked by signal mask, | |
2283 | and thus may be delivered (much) later. | |
dd3568a1 | 2284 | .PP |
181f997f MK |
2285 | Usually, the tracer (for example, |
2286 | .BR strace (1)) | |
2287 | would not want to show this extra post-execve | |
2288 | .B SIGTRAP | |
2289 | signal to the user, and would suppress its delivery to the tracee (if | |
2290 | .B SIGTRAP | |
2291 | is set to | |
2292 | .BR SIG_DFL , | |
2293 | it is a killing signal). | |
d6e37473 | 2294 | However, determining |
181f997f MK |
2295 | .I which |
2296 | .B SIGTRAP | |
2297 | to suppress is not easy. | |
2298 | Setting the | |
2299 | .B PTRACE_O_TRACEEXEC | |
28e2ca57 DV |
2300 | option or using |
2301 | .B PTRACE_SEIZE | |
2302 | and thus suppressing this extra | |
181f997f MK |
2303 | .B SIGTRAP |
2304 | is the recommended approach. | |
4d12a715 | 2305 | .SS Real parent |
181f997f MK |
2306 | The ptrace API (ab)uses the standard UNIX parent/child signaling over |
2307 | .BR waitpid (2). | |
2308 | This used to cause the real parent of the process to stop receiving | |
2309 | several kinds of | |
2310 | .BR waitpid (2) | |
2311 | notifications when the child process is traced by some other process. | |
dd3568a1 | 2312 | .PP |
181f997f MK |
2313 | Many of these bugs have been fixed, but as of Linux 2.6.38 several still |
2314 | exist; see BUGS below. | |
dd3568a1 | 2315 | .PP |
181f997f MK |
2316 | As of Linux 2.6.38, the following is believed to work correctly: |
2317 | .IP * 3 | |
dc85ba7c MK |
2318 | exit/death by signal is reported first to the tracer, then, |
2319 | when the tracer consumes the | |
181f997f MK |
2320 | .BR waitpid (2) |
2321 | result, to the real parent (to the real parent only when the | |
2322 | whole multithreaded process exits). | |
181f997f MK |
2323 | If the tracer and the real parent are the same process, |
2324 | the report is sent only once. | |
47297adb | 2325 | .SH RETURN VALUE |
051ec121 | 2326 | On success, the |
78686915 | 2327 | .B PTRACE_PEEK* |
051ec121 | 2328 | requests return the requested data (but see NOTES), |
e7a758e3 JH |
2329 | the |
2330 | .B PTRACE_SECCOMP_GET_FILTER | |
2331 | request returns the number of instructions in the BPF program, and | |
2332 | other requests return zero. | |
dd3568a1 | 2333 | .PP |
2b2581ee MK |
2334 | On error, all requests return \-1, and |
2335 | .I errno | |
2336 | is set appropriately. | |
8bd58774 | 2337 | Since the value returned by a successful |
0daa9e92 | 2338 | .B PTRACE_PEEK* |
181f997f | 2339 | request may be \-1, the caller must clear |
2b2581ee | 2340 | .I errno |
181f997f MK |
2341 | before the call, and then check it afterward |
2342 | to determine whether or not an error occurred. | |
2b2581ee MK |
2343 | .SH ERRORS |
2344 | .TP | |
2345 | .B EBUSY | |
181f997f | 2346 | (i386 only) There was an error with allocating or freeing a debug register. |
2b2581ee MK |
2347 | .TP |
2348 | .B EFAULT | |
2349 | There was an attempt to read from or write to an invalid area in | |
181f997f | 2350 | the tracer's or the tracee's memory, |
2b2581ee MK |
2351 | probably because the area wasn't mapped or accessible. |
2352 | Unfortunately, under Linux, different variations of this fault | |
2f0af33b MK |
2353 | will return |
2354 | .B EIO | |
2355 | or | |
2356 | .B EFAULT | |
2357 | more or less arbitrarily. | |
2b2581ee MK |
2358 | .TP |
2359 | .B EINVAL | |
2360 | An attempt was made to set an invalid option. | |
2361 | .TP | |
2362 | .B EIO | |
181f997f MK |
2363 | .I request |
2364 | is invalid, or an attempt was made to read from or | |
2365 | write to an invalid area in the tracer's or the tracee's memory, | |
2b2581ee MK |
2366 | or there was a word-alignment violation, |
2367 | or an invalid signal was specified during a restart request. | |
2368 | .TP | |
2369 | .B EPERM | |
2370 | The specified process cannot be traced. | |
2371 | This could be because the | |
4d12a715 | 2372 | tracer has insufficient privileges (the required capability is |
2b2581ee | 2373 | .BR CAP_SYS_PTRACE ); |
00b08db3 | 2374 | unprivileged processes cannot trace processes that they |
2b2581ee MK |
2375 | cannot send signals to or those running |
2376 | set-user-ID/set-group-ID programs, for obvious reasons. | |
181f997f MK |
2377 | Alternatively, the process may already be being traced, |
2378 | or (on kernels before 2.6.26) be | |
e8906093 | 2379 | .BR init (1) |
2b2581ee MK |
2380 | (PID 1). |
2381 | .TP | |
2382 | .B ESRCH | |
2383 | The specified process does not exist, or is not currently being traced | |
181f997f MK |
2384 | by the caller, or is not stopped |
2385 | (for requests that require a stopped tracee). | |
47297adb | 2386 | .SH CONFORMING TO |
44a2c328 | 2387 | SVr4, 4.3BSD. |
fea681da MK |
2388 | .SH NOTES |
2389 | Although arguments to | |
e511ffb6 | 2390 | .BR ptrace () |
c13182ef | 2391 | are interpreted according to the prototype given, |
5260fe08 | 2392 | glibc currently declares |
e511ffb6 | 2393 | .BR ptrace () |
181f997f MK |
2394 | as a variadic function with only the |
2395 | .I request | |
2396 | argument fixed. | |
ca302d0e DV |
2397 | It is recommended to always supply four arguments, |
2398 | even if the requested operation does not use them, | |
2399 | setting unused/ignored arguments to | |
2400 | .I 0L | |
2401 | or | |
2402 | .IR "(void\ *)\ 0". | |
dd3568a1 | 2403 | .PP |
181f997f MK |
2404 | In Linux kernels before 2.6.26, |
2405 | .\" See commit 00cd5c37afd5f431ac186dd131705048c0a11fdb | |
e8906093 | 2406 | .BR init (1), |
181f997f | 2407 | the process with PID 1, may not be traced. |
dd3568a1 | 2408 | .PP |
674f11ec JH |
2409 | A tracees parent continues to be the tracer even if that tracer calls |
2410 | .BR execve (2). | |
dd3568a1 | 2411 | .PP |
181f997f MK |
2412 | The layout of the contents of memory and the USER area are |
2413 | quite operating-system- and architecture-specific. | |
8660aec0 MK |
2414 | The offset supplied, and the data returned, |
2415 | might not entirely match with the definition of | |
2416 | .IR "struct user" . | |
2417 | .\" See http://lkml.org/lkml/2008/5/8/375 | |
dd3568a1 | 2418 | .PP |
181f997f | 2419 | The size of a "word" is determined by the operating-system variant |
3e18f289 | 2420 | (e.g., for 32-bit Linux it is 32 bits). |
dd3568a1 | 2421 | .PP |
fea681da | 2422 | This page documents the way the |
e511ffb6 | 2423 | .BR ptrace () |
c13182ef | 2424 | call works currently in Linux. |
07318a59 | 2425 | Its behavior differs significantly on other flavors of UNIX. |
e63ad01d | 2426 | In any case, use of |
e511ffb6 | 2427 | .BR ptrace () |
181f997f | 2428 | is highly specific to the operating system and architecture. |
4978c606 | 2429 | .\" |
ace93363 MK |
2430 | .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
2431 | .\" | |
2432 | .SS Ptrace access mode checking | |
2433 | Various parts of the kernel-user-space API (not just | |
bf7bc8b8 | 2434 | .BR ptrace () |
00172d8d MK |
2435 | operations), require so-called "ptrace access mode" checks, |
2436 | whose outcome determines whether an operation is permitted | |
2437 | (or, in a few cases, causes a "read" operation to return sanitized data). | |
2438 | These checks are performed in cases where one process can | |
2439 | inspect sensitive information about, | |
2440 | or in some cases modify the state of, another process. | |
2441 | The checks are based on factors such as the credentials and capabilities | |
2442 | of the two processes, | |
2443 | whether or not the "target" process is dumpable, | |
2444 | and the results of checks performed by any enabled Linux Security Module | |
2445 | (LSM)\(emfor example, SELinux, Yama, or Smack\(emand by the commoncap LSM | |
611d3ac4 | 2446 | (which is always invoked). |
efeece04 | 2447 | .PP |
be26fa86 | 2448 | Prior to Linux 2.6.27, all access checks were of a single type. |
ace93363 MK |
2449 | Since Linux 2.6.27, |
2450 | .\" commit 006ebb40d3d65338bd74abb03b945f8d60e362bd | |
2451 | two access mode levels are distinguished: | |
2452 | .TP | |
2453 | .BR PTRACE_MODE_READ | |
2454 | For "read" operations or other operations that are less dangerous, | |
2455 | such as: | |
2456 | .BR get_robust_list (2); | |
2457 | .BR kcmp (2); | |
2458 | reading | |
2459 | .IR /proc/[pid]/auxv , | |
2460 | .IR /proc/[pid]/environ , | |
2461 | or | |
2462 | .IR /proc/[pid]/stat ; | |
2463 | or | |
2464 | .BR readlink (2) | |
2465 | of a | |
2466 | .IR /proc/[pid]/ns/* | |
2467 | file. | |
2468 | .TP | |
2469 | .BR PTRACE_MODE_ATTACH | |
2470 | For "write" operations, or other operations that are more dangerous, | |
2471 | such as: ptrace attaching | |
2472 | .RB ( PTRACE_ATTACH ) | |
2473 | to another process | |
2474 | or calling | |
2475 | .BR process_vm_writev (2). | |
2476 | .RB ( PTRACE_MODE_ATTACH | |
2477 | was effectively the default before Linux 2.6.27.) | |
bcd0d82d MK |
2478 | .\" |
2479 | .\" Regarding the above description of the distinction between | |
2480 | .\" PTRACE_MODE_READ and PTRACE_MODE_ATTACH, Stephen Smalley notes: | |
2481 | .\" | |
2482 | .\" That was the intent when the distinction was introduced, but it doesn't | |
2483 | .\" appear to have been properly maintained, e.g. there is now a common | |
2484 | .\" helper lock_trace() that is used for | |
2485 | .\" /proc/pid/{stack,syscall,personality} but checks PTRACE_MODE_ATTACH, and | |
2486 | .\" PTRACE_MODE_ATTACH is also used in timerslack_ns_write/show(). Likely | |
2487 | .\" should review and make them consistent. There was also some debate | |
2488 | .\" about proper handling of /proc/pid/fd. Arguably that one might belong | |
2489 | .\" back in the _ATTACH camp. | |
2490 | .\" | |
ace93363 MK |
2491 | .PP |
2492 | Since Linux 4.5, | |
2493 | .\" commit caaee6234d05a58c5b4d05e7bf766131b810a657 | |
611d3ac4 | 2494 | the above access mode checks are combined (ORed) with |
ace93363 MK |
2495 | one of the following modifiers: |
2496 | .TP | |
2497 | .B PTRACE_MODE_FSCREDS | |
2498 | Use the caller's filesystem UID and GID (see | |
2499 | .BR credentials (7)) | |
2500 | or effective capabilities for LSM checks. | |
2501 | .TP | |
2502 | .B PTRACE_MODE_REALCREDS | |
2503 | Use the caller's real UID and GID or permitted capabilities for LSM checks. | |
2504 | This was effectively the default before Linux 4.5. | |
2505 | .PP | |
2506 | Because combining one of the credential modifiers with one of | |
2507 | the aforementioned access modes is typical, | |
2508 | some macros are defined in the kernel sources for the combinations: | |
2509 | .TP | |
2510 | .B PTRACE_MODE_READ_FSCREDS | |
2511 | Defined as | |
2512 | .BR "PTRACE_MODE_READ | PTRACE_MODE_FSCREDS" . | |
2513 | .TP | |
2514 | .B PTRACE_MODE_READ_REALCREDS | |
2515 | Defined as | |
2516 | .BR "PTRACE_MODE_READ | PTRACE_MODE_REALCREDS" . | |
2517 | .TP | |
2518 | .B PTRACE_MODE_ATTACH_FSCREDS | |
2519 | Defined as | |
2520 | .BR "PTRACE_MODE_ATTACH | PTRACE_MODE_FSCREDS" . | |
2521 | .TP | |
2522 | .B PTRACE_MODE_ATTACH_REALCREDS | |
2523 | Defined as | |
2524 | .BR "PTRACE_MODE_ATTACH | PTRACE_MODE_REALCREDS" . | |
ace93363 MK |
2525 | .PP |
2526 | One further modifier can be ORed with the access mode: | |
2527 | .TP | |
2528 | .BR PTRACE_MODE_NOAUDIT " (since Linux 3.3)" | |
2529 | .\" commit 69f594a38967f4540ce7a29b3fd214e68a8330bd | |
2530 | .\" Just for /proc/pid/stat | |
2531 | Don't audit this access mode check. | |
3cd161fe SS |
2532 | This modifier is employed for ptrace access mode checks |
2533 | (such as checks when reading | |
2534 | .IR /proc/[pid]/stat ) | |
2535 | that merely cause the output to be filtered or sanitized, | |
2536 | rather than causing an error to be returned to the caller. | |
2537 | In these cases, accessing the file is not a security violation and | |
2538 | there is no reason to generate a security audit record. | |
2539 | This modifier suppresses the generation of | |
2540 | such an audit record for the particular access check. | |
ace93363 | 2541 | .PP |
edb73684 MK |
2542 | Note that all of the |
2543 | .BR PTRACE_MODE_* | |
2544 | constants described in this subsection are kernel-internal, | |
2545 | and not visible to user space. | |
2546 | The constant names are mentioned here in order to label the various kinds of | |
2547 | ptrace access mode checks that are performed for various system calls | |
2548 | and accesses to various pseudofiles (e.g., under | |
2549 | .IR /proc ). | |
32245813 | 2550 | These names are used in other manual pages to provide a simple |
edb73684 | 2551 | shorthand for labeling the different kernel checks. |
efeece04 | 2552 | .PP |
ace93363 MK |
2553 | The algorithm employed for ptrace access mode checking determines whether |
2554 | the calling process is allowed to perform the corresponding action | |
a330bffa MK |
2555 | on the target process. |
2556 | (In the case of opening | |
2557 | .IR /proc/[pid] | |
2558 | files, the "calling process" is the one opening the file, | |
2559 | and the process with the corresponding PID is the "target process".) | |
2560 | The algorithm is as follows: | |
9edaeefb | 2561 | .IP 1. 3 |
ace93363 MK |
2562 | If the calling thread and the target thread are in the same |
2563 | thread group, access is always allowed. | |
2564 | .IP 2. | |
2565 | If the access mode specifies | |
2566 | .BR PTRACE_MODE_FSCREDS , | |
78f07865 MK |
2567 | then, for the check in the next step, |
2568 | employ the caller's filesystem UID and GID. | |
2569 | (As noted in | |
2570 | .BR credentials (7), | |
2571 | the filesystem UID and GID almost always have the same values | |
2572 | as the corresponding effective IDs.) | |
efeece04 | 2573 | .IP |
78f07865 | 2574 | Otherwise, the access mode specifies |
ace93363 | 2575 | .BR PTRACE_MODE_REALCREDS , |
78f07865 MK |
2576 | so use the caller's real UID and GID for the checks in the next step. |
2577 | (Most APIs that check the caller's UID and GID use the effective IDs. | |
2578 | For historical reasons, the | |
2579 | .BR PTRACE_MODE_REALCREDS | |
2580 | check uses the real IDs instead.) | |
ace93363 MK |
2581 | .IP 3. |
2582 | Deny access if | |
2583 | .I neither | |
2584 | of the following is true: | |
2585 | .RS | |
2586 | .IP \(bu 2 | |
2587 | The real, effective, and saved-set user IDs of the target | |
2588 | match the caller's user ID, | |
2589 | .IR and | |
2590 | the real, effective, and saved-set group IDs of the target | |
2591 | match the caller's group ID. | |
2592 | .IP \(bu | |
2593 | The caller has the | |
2594 | .B CAP_SYS_PTRACE | |
0647331a | 2595 | capability in the user namespace of the target. |
ace93363 MK |
2596 | .RE |
2597 | .IP 4. | |
2598 | Deny access if the target process "dumpable" attribute has a value other than 1 | |
2599 | .RB ( SUID_DUMP_USER ; | |
2600 | see the discussion of | |
2601 | .BR PR_SET_DUMPABLE | |
2602 | in | |
2603 | .BR prctl (2)), | |
2604 | and the caller does not have the | |
2605 | .BR CAP_SYS_PTRACE | |
2606 | capability in the user namespace of the target process. | |
2607 | .IP 5. | |
2608 | The kernel LSM | |
2609 | .IR security_ptrace_access_check () | |
2610 | interface is invoked to see if ptrace access is permitted. | |
b0459842 | 2611 | The results depend on the LSM(s). |
611d3ac4 | 2612 | The implementation of this interface in the commoncap LSM performs |
ace93363 MK |
2613 | the following steps: |
2614 | .\" (in cap_ptrace_access_check()): | |
2615 | .RS | |
2616 | .IP a) 3 | |
2617 | If the access mode includes | |
2618 | .BR PTRACE_MODE_FSCREDS , | |
2619 | then use the caller's | |
2620 | .I effective | |
2621 | capability set | |
2622 | in the following check; | |
2623 | otherwise (the access mode specifies | |
2624 | .BR PTRACE_MODE_REALCREDS , | |
2625 | so) use the caller's | |
2626 | .I permitted | |
2627 | capability set. | |
2628 | .IP b) | |
2629 | Deny access if | |
2630 | .I neither | |
2631 | of the following is true: | |
2632 | .RS | |
2633 | .IP \(bu 2 | |
0647331a | 2634 | The caller and the target process are in the same user namespace, |
173eb06c | 2635 | and the caller's capabilities are a superset of the target process's |
ace93363 MK |
2636 | .I permitted |
2637 | capabilities. | |
2638 | .IP \(bu | |
2639 | The caller has the | |
2640 | .B CAP_SYS_PTRACE | |
2641 | capability in the target process's user namespace. | |
2642 | .RE | |
2643 | .IP | |
611d3ac4 | 2644 | Note that the commoncap LSM does not distinguish between |
ace93363 MK |
2645 | .B PTRACE_MODE_READ |
2646 | and | |
2647 | .BR PTRACE_MODE_ATTACH . | |
2648 | .RE | |
2649 | .IP 6. | |
2650 | If access has not been denied by any of the preceding steps, | |
2651 | then access is allowed. | |
2652 | .\" | |
2653 | .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
2654 | .\" | |
4978c606 | 2655 | .SS /proc/sys/kernel/yama/ptrace_scope |
e5323616 MK |
2656 | On systems with the Yama Linux Security Module (LSM) installed |
2657 | (i.e., the kernel was configured with | |
2658 | .BR CONFIG_SECURITY_YAMA ), | |
2659 | the | |
4978c606 | 2660 | .I /proc/sys/kernel/yama/ptrace_scope |
94b0464c | 2661 | file (available since Linux 3.4) |
4978c606 MK |
2662 | .\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb |
2663 | can be used to restrict the ability to trace a process with | |
bf7bc8b8 | 2664 | .BR ptrace () |
4978c606 MK |
2665 | (and thus also the ability to use tools such as |
2666 | .BR strace (1) | |
2667 | and | |
2668 | .BR gdb (1)). | |
2669 | The goal of such restrictions is to prevent attack escalation whereby | |
2670 | a compromised process can ptrace-attach to other sensitive processes | |
2671 | (e.g., a GPG agent or an SSH session) owned by the user in order | |
028b5760 MK |
2672 | to gain additional credentials that may exist in memory |
2673 | and thus expand the scope of the attack. | |
efeece04 | 2674 | .PP |
e5323616 MK |
2675 | More precisely, the Yama LSM limits two types of operations: |
2676 | .IP * 3 | |
2677 | Any operation that performs a ptrace access mode | |
2678 | .BR PTRACE_MODE_ATTACH | |
2679 | check\(emfor example, | |
2680 | .BR ptrace () | |
2681 | .BR PTRACE_ATTACH . | |
2682 | (See the "Ptrace access mode checking" discussion above.) | |
efeece04 | 2683 | .IP |
e5323616 MK |
2684 | .IP * |
2685 | .BR ptrace () | |
2686 | .BR PTRACE_TRACEME . | |
2687 | .PP | |
2688 | A process that has the | |
4978c606 | 2689 | .B CAP_SYS_PTRACE |
e5323616 MK |
2690 | capability can update the |
2691 | .IR /proc/sys/kernel/yama/ptrace_scope | |
2692 | file with one of the following values: | |
4978c606 MK |
2693 | .TP |
2694 | 0 ("classic ptrace permissions") | |
e5323616 MK |
2695 | No additional restrictions on operations that perform |
2696 | .BR PTRACE_MODE_ATTACH | |
2697 | checks (beyond those imposed by the commoncap and other LSMs). | |
efeece04 | 2698 | .IP |
4978c606 MK |
2699 | The use of |
2700 | .BR PTRACE_TRACEME | |
2701 | is unchanged. | |
2702 | .TP | |
e5323616 MK |
2703 | 1 ("restricted ptrace") [default value] |
2704 | When performing an operation that requires a | |
2705 | .BR PTRACE_MODE_ATTACH | |
d5765e27 MK |
2706 | check, the calling process must either have the |
2707 | .B CAP_SYS_PTRACE | |
2708 | capability in the user namespace of the target process or | |
e48ed83a | 2709 | it must have a predefined relationship with the target process. |
4978c606 | 2710 | By default, |
e5323616 | 2711 | the predefined relationship is that the target process |
028b5760 | 2712 | must be a descendant of the caller. |
efeece04 | 2713 | .IP |
e5323616 | 2714 | A target process can employ the |
4978c606 MK |
2715 | .BR prctl (2) |
2716 | .B PR_SET_PTRACER | |
028b5760 | 2717 | operation to declare an additional PID that is allowed to perform |
e5323616 MK |
2718 | .BR PTRACE_MODE_ATTACH |
2719 | operations on the target. | |
2720 | See the kernel source file | |
6744a500 ES |
2721 | .IR Documentation/admin\-guide/LSM/Yama.rst |
2722 | .\" commit 90bb766440f2147486a2acc3e793d7b8348b0c22 | |
2723 | (or | |
4978c606 | 2724 | .IR Documentation/security/Yama.txt |
6744a500 | 2725 | before Linux 4.13) |
e5323616 | 2726 | for further details. |
efeece04 | 2727 | .IP |
4978c606 MK |
2728 | The use of |
2729 | .BR PTRACE_TRACEME | |
2730 | is unchanged. | |
2731 | .TP | |
2732 | 2 ("admin-only attach") | |
2733 | Only processes with the | |
2734 | .B CAP_SYS_PTRACE | |
d5765e27 | 2735 | capability in the user namespace of the target process may perform |
e5323616 MK |
2736 | .BR PTRACE_MODE_ATTACH |
2737 | operations or trace children that employ | |
4978c606 MK |
2738 | .BR PTRACE_TRACEME . |
2739 | .TP | |
2740 | 3 ("no attach") | |
e5323616 MK |
2741 | No process may perform |
2742 | .BR PTRACE_MODE_ATTACH | |
2743 | operations or trace children that employ | |
4978c606 | 2744 | .BR PTRACE_TRACEME . |
efeece04 | 2745 | .IP |
4978c606 | 2746 | Once this value has been written to the file, it cannot be changed. |
d5765e27 MK |
2747 | .PP |
2748 | With respect to values 1 and 2, | |
028b5760 MK |
2749 | note that creating a new user namespace effectively removes the |
2750 | protection offered by Yama. | |
2751 | This is because a process in the parent user namespace whose effective | |
2752 | UID matches the UID of the creator of a child namespace | |
2753 | has all capabilities (including | |
2754 | .BR CAP_SYS_PTRACE ) | |
2755 | when performing operations within the child user namespace | |
2756 | (and further-removed descendants of that namespace). | |
2757 | Consequently, when a process tries to use user namespaces to sandbox itself, | |
2758 | it inadvertently weakens the protections offered by the Yama LSM. | |
4978c606 | 2759 | .\" |
e5323616 MK |
2760 | .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
2761 | .\" | |
0722a578 | 2762 | .SS C library/kernel differences |
53a99749 MK |
2763 | At the system call level, the |
2764 | .BR PTRACE_PEEKTEXT , | |
2765 | .BR PTRACE_PEEKDATA , | |
2766 | and | |
2767 | .BR PTRACE_PEEKUSER | |
2768 | requests have a different API: they store the result | |
2769 | at the address specified by the | |
2770 | .I data | |
2771 | parameter, and the return value is the error flag. | |
2772 | The glibc wrapper function provides the API given in DESCRIPTION above, | |
2773 | with the result being returned via the function return value. | |
a1d5f77c | 2774 | .SH BUGS |
8bd58774 | 2775 | On hosts with 2.6 kernel headers, |
0daa9e92 | 2776 | .B PTRACE_SETOPTIONS |
181f997f MK |
2777 | is declared with a different value than the one for 2.4. |
2778 | This leads to applications compiled with 2.6 kernel | |
a1d5f77c | 2779 | headers failing when run on 2.4 kernels. |
8bd58774 | 2780 | This can be worked around by redefining |
0daa9e92 | 2781 | .B PTRACE_SETOPTIONS |
8bd58774 MK |
2782 | to |
2783 | .BR PTRACE_OLDSETOPTIONS , | |
2784 | if that is defined. | |
dd3568a1 | 2785 | .PP |
181f997f | 2786 | Group-stop notifications are sent to the tracer, but not to real parent. |
4d12a715 | 2787 | Last confirmed on 2.6.38.6. |
dd3568a1 | 2788 | .PP |
181f997f MK |
2789 | If a thread group leader is traced and exits by calling |
2790 | .BR _exit (2), | |
8898a252 MK |
2791 | .\" Note from Denys Vlasenko: |
2792 | .\" Here "exits" means any kind of death - _exit, exit_group, | |
2793 | .\" signal death. Signal death and exit_group cases are trivial, | |
2794 | .\" though: since signal death and exit_group kill all other threads | |
2795 | .\" too, "until all other threads exit" thing happens rather soon | |
2796 | .\" in these cases. Therefore, only _exit presents observably | |
2797 | .\" puzzling behavior to ptrace users: thread leader _exit's, | |
2798 | .\" but WIFEXITED isn't reported! We are trying to explain here | |
2799 | .\" why it is so. | |
181f997f MK |
2800 | a |
2801 | .B PTRACE_EVENT_EXIT | |
2802 | stop will happen for it (if requested), but the subsequent | |
2803 | .B WIFEXITED | |
2804 | notification will not be delivered until all other threads exit. | |
2805 | As explained above, if one of other threads calls | |
2806 | .BR execve (2), | |
2807 | the death of the thread group leader will | |
2808 | .I never | |
2809 | be reported. | |
2810 | If the execed thread is not traced by this tracer, | |
2811 | the tracer will never know that | |
2812 | .BR execve (2) | |
4d12a715 | 2813 | happened. |
181f997f MK |
2814 | One possible workaround is to |
2815 | .B PTRACE_DETACH | |
2816 | the thread group leader instead of restarting it in this case. | |
2817 | Last confirmed on 2.6.38.6. | |
bea08fec | 2818 | .\" FIXME . need to test/verify this scenario |
dd3568a1 | 2819 | .PP |
181f997f MK |
2820 | A |
2821 | .B SIGKILL | |
2822 | signal may still cause a | |
2823 | .B PTRACE_EVENT_EXIT | |
2824 | stop before actual signal death. | |
2825 | This may be changed in the future; | |
2826 | .B SIGKILL | |
2827 | is meant to always immediately kill tasks even under ptrace. | |
55bd9495 | 2828 | Last confirmed on Linux 3.13. |
dd3568a1 | 2829 | .PP |
a17e05c5 | 2830 | Some system calls return with |
f098951d | 2831 | .B EINTR |
a17e05c5 MK |
2832 | if a signal was sent to a tracee, but delivery was suppressed by the tracer. |
2833 | (This is very typical operation: it is usually | |
f098951d | 2834 | done by debuggers on every attach, in order to not introduce |
a17e05c5 MK |
2835 | a bogus |
2836 | .BR SIGSTOP ). | |
2837 | As of Linux 3.2.9, the following system calls are affected | |
2838 | (this list is likely incomplete): | |
f098951d | 2839 | .BR epoll_wait (2), |
a17e05c5 | 2840 | and |
f098951d | 2841 | .BR read (2) |
a17e05c5 MK |
2842 | from an |
2843 | .BR inotify (7) | |
2844 | file descriptor. | |
ca302d0e DV |
2845 | The usual symptom of this bug is that when you attach to |
2846 | a quiescent process with the command | |
efeece04 | 2847 | .PP |
408731d4 MK |
2848 | .in +4n |
2849 | .EX | |
2850 | strace \-p <process-ID> | |
2851 | .EE | |
2852 | .in | |
efeece04 | 2853 | .PP |
ca302d0e DV |
2854 | then, instead of the usual |
2855 | and expected one-line output such as | |
408731d4 MK |
2856 | .PP |
2857 | .in +4n | |
2858 | .EX | |
2859 | restart_syscall(<... resuming interrupted call ...>_ | |
2860 | .EE | |
2861 | .in | |
2862 | .PP | |
ca302d0e | 2863 | or |
408731d4 MK |
2864 | .PP |
2865 | .in +4n | |
2866 | .EX | |
2867 | select(6, [5], NULL, [5], NULL_ | |
2868 | .EE | |
2869 | .in | |
2870 | .PP | |
ca302d0e DV |
2871 | ('_' denotes the cursor position), you observe more than one line. |
2872 | For example: | |
408731d4 MK |
2873 | .PP |
2874 | .in +4n | |
2875 | .EX | |
ca302d0e DV |
2876 | clock_gettime(CLOCK_MONOTONIC, {15370, 690928118}) = 0 |
2877 | epoll_wait(4,_ | |
408731d4 MK |
2878 | .EE |
2879 | .in | |
2880 | .PP | |
ca302d0e DV |
2881 | What is not visible here is that the process was blocked in |
2882 | .BR epoll_wait (2) | |
2883 | before | |
2884 | .BR strace (1) | |
2885 | has attached to it. | |
2886 | Attaching caused | |
2887 | .BR epoll_wait (2) | |
7fac88a9 | 2888 | to return to user space with the error |
ca302d0e DV |
2889 | .BR EINTR . |
2890 | In this particular case, the program reacted to | |
2891 | .B EINTR | |
b0b1d9b5 | 2892 | by checking the current time, and then executing |
ca302d0e DV |
2893 | .BR epoll_wait (2) |
2894 | again. | |
2895 | (Programs which do not expect such "stray" | |
2896 | .BR EINTR | |
2897 | errors may behave in an unintended way upon an | |
2898 | .BR strace (1) | |
2899 | attach.) | |
c62b9453 JH |
2900 | .PP |
2901 | Contrary to the normal rules, the glibc wrapper for | |
2902 | .BR ptrace () | |
2903 | can set | |
2904 | .I errno | |
2905 | to zero. | |
47297adb | 2906 | .SH SEE ALSO |
fea681da | 2907 | .BR gdb (1), |
53506ea9 | 2908 | .BR ltrace (1), |
fea681da | 2909 | .BR strace (1), |
181f997f | 2910 | .BR clone (2), |
fea681da MK |
2911 | .BR execve (2), |
2912 | .BR fork (2), | |
181f997f | 2913 | .BR gettid (2), |
d901e325 | 2914 | .BR prctl (2), |
3b4a59c4 | 2915 | .BR seccomp (2), |
181f997f MK |
2916 | .BR sigaction (2), |
2917 | .BR tgkill (2), | |
2918 | .BR vfork (2), | |
2919 | .BR waitpid (2), | |
fea681da | 2920 | .BR exec (3), |
181f997f MK |
2921 | .BR capabilities (7), |
2922 | .BR signal (7) |