From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Roland McGrath <roland@redhat.com>, archer@sourceware.org
Subject: safe PTRACE_ATTACH
Date: Wed, 23 Feb 2011 15:51:00 -0000 [thread overview]
Message-ID: <20110223155135.GB30477@host1.dyn.jankratochvil.net> (raw)
In-Reply-To: <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.
next prev parent reply other threads:[~2011-02-23 15:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-15 19:12 gdbstub initial code, v16 Oleg Nesterov
2010-11-16 20:02 ` Roland McGrath
[not found] ` <20110215204148.GA17258@host1.dyn.jankratochvil.net>
[not found] ` <20110215215438.CBD0E1806E0@magilla.sf.frob.com>
[not found] ` <20110216214423.GA22228@redhat.com>
[not found] ` <20110216220541.55E701802A2@magilla.sf.frob.com>
[not found] ` <20110217211225.GA17768@redhat.com>
[not found] ` <20110221193927.122901814AE@magilla.sf.frob.com>
[not found] ` <20110222203834.GA6977@redhat.com>
2011-02-23 15:51 ` Jan Kratochvil [this message]
2011-02-23 17:24 ` safe PTRACE_ATTACH Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110223155135.GB30477@host1.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=archer@sourceware.org \
--cc=oleg@redhat.com \
--cc=roland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).