[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130723163806.GA27905@redhat.com>
Date: Tue, 23 Jul 2013 18:38:06 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Mike Galbraith <bitbucket@...ine.de>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: Re: ptrace(PTRACE_ATTACH) [no intervering wait]
ptrace(PTRACE_DETACH) may leave tracee stuck
On 07/23, Oleg Nesterov wrote:
>
> On 07/23, Mike Galbraith wrote:
> >
> > I received a report that glibc:elf/pldd hangs occasionally, and indeed..
> >
> > for i in `seq 1 1000`; do taskset -c 3 pldd $$ > /dev/null 2>&1; done
> >
> > ..will do so. Rummage.....
> >
> > ptrace(PTRACE_DETACH) returns -ESRCH when the trap hasn't happened yet,
> > which happens because pldd doesn't wait() before ptrace(PTRACE_DETACH).
> >
> > pldd source:
> >
> [...snip...]
> >
> > Seems this usually works only because cycles expended between attach and
> > detach is usually enough to let trap happen so tracee can set its state
> > to TASK_TRACED as PTRACE_DETACH expects it to be.
> >
> > Is this expected behavior?
>
> Yes. PTRACE_ATTACH + PTRACE_DETACH is not correct without wait() in
> between, this is expected.
>
> PTRACE_DETACH like (almost) any other ptrace request needs the stopped
> tracee. Otherwise, say, ptrace_disable() or flush_ptrace_hw_breakpoint()
> are not safe.
I have found the source of pldd.c. It seems that it has another reason
for waitpid().
/* Stop all threads since otherwise the list of loaded modules might
change while we are reading it. */
Yes, but without waitpid() we can't know if it was actually stopped.
OTOH, in this particular case pldd.c doesn't really need PTRACE_DETACH,
it can simply exit.
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists