This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
safe PTRACE_ATTACH
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Oleg Nesterov <oleg at redhat dot com>
- Cc: Roland McGrath <roland at redhat dot com>, archer at sourceware dot org
- Date: Wed, 23 Feb 2011 16:51:35 +0100
- Subject: safe PTRACE_ATTACH
- References: <20101115190537.GA15725@redhat.com><20110215204148.GA17258@host1.dyn.jankratochvil.net><20110215215438.CBD0E1806E0@magilla.sf.frob.com><20110216214423.GA22228@redhat.com><20110216220541.55E701802A2@magilla.sf.frob.com><20110217211225.GA17768@redhat.com><20110221193927.122901814AE@magilla.sf.frob.com><20110222203834.GA6977@redhat.com>
Hi Oleg,
notice: Moved thread to the Archer list.
I can confirm this problem exists.
AFAIK on recent kernels this whole "trick" (if-stopped then tkill(SIGSTOP) and
PTRACE_CONT(0)) is not needed as it now works even for `eaten-out SIGSTOP
notifications'.
But to be compatible with the older kernels (despite having this race there)
what do you suggest? Checking /proc/version seems too fragile to me.
GDB could do another ptrace test (like linux_test_for_tracesysgood etc.).
Thanks,
Jan
On Tue, 22 Feb 2011 21:38:34 +0100, Oleg Nesterov wrote:
[...]
> Btw. Jan, linux_nat_post_attach_wait() doesn't look right. It assumes
> that the first signal reported by tracee should be SIGSTOP. This is
> not true.
>
> This is what happens if gdb tries to attach to the 'T (stopped)' task,
> but the tracee gets SIGCONT after gdb does kill_lwp(pid, SIGSTOP).
>
> ptrace(PTRACE_ATTACH, 21462, 0, 0) = 0
>
> open("/proc/21462/status", O_RDONLY) = 5
> read(5, "Name:\tsleep\nState:\tT (stopped)\nTg"..., 1024) = 753
>
> pid_is_stopped()
>
> tkill(21462, SIGSTOP) = 0
>
> kill_lwp(pid, SIGSTOP) in case we dont have exit code
>
> --- Suppose that SIGCONT come here ---
>
> ptrace(PTRACE_CONT, 21462, 0, SIG_0) = 0
>
> wait4(21462, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGCONT}], 0, NULL) = 21462
>
> ptrace(PTRACE_CONT, 21462, 0x1, SIG_0) = 0
> ^^^^^^^
> this makes the tracee running, and
>
> wait4(21462,
>
> gdb hangs until it reports something else.
>
> Oleg.