This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

safe PTRACE_ATTACH


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]