linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ptrace.2: BUGS (missing WIFEXITED notification)
@ 2015-05-12 14:31 Vegard Nossum
       [not found] ` <55520EAC.2010003-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Vegard Nossum @ 2015-05-12 14:31 UTC (permalink / raw)
  To: Michael Kerrisk
  Cc: Quentin Casasnovas, Denys Vlasenko,
	linux-man-u79uwXL29TY76Z2rM5mHXA

[resend with Cc: linux-man]

Hi again :-)

We hit another edge case in the ptrace() interface and after several
hours of chasing it down, we found that it was already described in the
"BUGS" section:

"If a thread group leader is traced and exits by calling _exit(2), a
PTRACE_EVENT_EXIT stop will happen for it (if requested), but the
subsequent WIFEXITED notification will not be delivered until all other
threads exit. As explained above, if one of other threads calls
execve(2), the death of the thread group leader will never be reported.
If the execed thread is not traced by this tracer, the tracer will never
know that execve(2) happened. One possible workaround is to
PTRACE_DETACH the thread group leader instead of restarting it in this
case. Last confirmed on 2.6.38.6."

I wanted to write that we've also noticed the same thing not only for
_exit() but also for terminating signals, however we also came across
this bit in the manual source:

.\" Note from Denys Vlasenko:
.\" Here "exits" means any kind of death - _exit, exit_group,
.\" signal death. Signal death and exit_group cases are trivial,
.\" though: since signal death and exit_group kill all other threads
.\" too, "until all other threads exit" thing happens rather soon
.\" in these cases. Therefore, only _exit presents observably
.\" puzzling behavior to ptrace users: thread leader _exit's,
.\" but WIFEXITED isn't reported! We are trying to explain here
.\" why it is so.

There is a difference, however -- this behaviour can also be observed
for the other types of death if you are currently tracing the other
threads too!

In other words, when multiple threads are being traced and the group
leader exits, waitpid() on this group leader will hang indefinitely
(because the other threads won't exit until we wait for and CONT/DETACH
them, and we don't receive the exit notification for the group leader
until the other threads have really exited).

To me, this means that not only _exit() but also other types of death
present "observably puzzling behavior to ptrace users".

I'd propose the following changes:

1) include some (if not all) of Denys's explanation in the actual text:

-If a thread group leader is traced and exits by calling _exit(2)...
+If a thread group leader is traced and exits for any reason (_exit,
exit_group, signal death, etc.), ...

2) include the bits about tracing other threads:

+If the other threads in the thread group are being traced, they will
not exit until they have been either waited for and restarted or
detached, thereby blocking the exit notification (WIFEXITED) of the
group leader to wait()/waitpid().

3) there's a typo in the original text:

-one of other threads
+one of the other threads

Feel free to rephrase any of the above.

Thoughts? We can also provide more details, including a reproducer, or
clarification if needed.

(PS: Please also credit Quentin Casasnovas with the report as we've both
spent more than a few hours tracking this down!)


Vegard
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-08-12 19:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-12 14:31 ptrace.2: BUGS (missing WIFEXITED notification) Vegard Nossum
     [not found] ` <55520EAC.2010003-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-05-14 13:44   ` Michael Kerrisk (man-pages)
     [not found]     ` <5554A6B0.2090409-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-14 13:52       ` Denys Vlasenko
     [not found]         ` <5554A8A4.7060404-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-14 16:28           ` Quentin Casasnovas
     [not found]             ` <20150514162807.GA13385-Cuu6V/XUcleLI2c71l+0mdkmqwFzkYv6@public.gmane.org>
2015-05-14 16:39               ` Denys Vlasenko
     [not found]                 ` <5554CFDF.6070602-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-14 16:50                   ` Quentin Casasnovas
     [not found]                     ` <20150514165031.GB13385-Cuu6V/XUcleLI2c71l+0mdkmqwFzkYv6@public.gmane.org>
2015-05-14 17:06                       ` Denys Vlasenko
     [not found]                         ` <5554D5F8.8050305-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-14 17:41                           ` Quentin Casasnovas
2015-05-15 10:12                   ` Vegard Nossum
     [not found]                     ` <5555C69A.3070509-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-05-15 12:05                       ` Michael Kerrisk (man-pages)
     [not found]                         ` <CAKgNAkixHtPEdmwuVhic8k2gz8ooLmW1rJ3760oWGUC07K-5hg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-18  6:49                           ` Michael Kerrisk (man-pages)
     [not found]                             ` <55826A17.8000804-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-12 14:50                               ` Vegard Nossum
     [not found]                                 ` <57ADE23B.8050905-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-08-12 16:15                                   ` Denys Vlasenko
     [not found]                                     ` <864524d3-6a7f-9555-b4a4-eb4816c4da18-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-08-12 18:37                                       ` Vegard Nossum
     [not found]                                         ` <57AE1750.50303-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-08-12 19:11                                           ` Denys Vlasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).