From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11092 invoked by alias); 23 Feb 2011 15:51:51 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 11074 invoked by uid 22791); 23 Feb 2011 15:51:49 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Wed, 23 Feb 2011 15:51:00 -0000 From: Jan Kratochvil To: Oleg Nesterov Cc: Roland McGrath , archer@sourceware.org Subject: safe PTRACE_ATTACH Message-ID: <20110223155135.GB30477@host1.dyn.jankratochvil.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110222203834.GA6977@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2011-q1/txt/msg00098.txt.bz2 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.