CLONE_PTRACE implementation incomplete

Ulrich Drepper (drepper@cygnus.com)
14 Oct 1999 14:14:09 -0700


The implementation of the CLONE_PTRACE flag seems to be incomplete.
Currently it seems to be used only in copy_flags() in kernel/fork.c.
But what this does is not useful at all. Just look at how the
situation would be for a multi-threaded application:

(O = process tracing the application, Pn various processes)

attach to P1 -> p_pptr set to O
P1 clones -> P2 created, copy_flags() sets the ptrace flag but
p_pptr is set to P1

This means that only P1 can issue ptrace() calls from this point on.
I think copy_flags() should look somewhat like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
{
unsigned long new_flags = p->flags;

new_flags &= ~(PF_SUPERPRIV | PF_USEDFPU | PF_VFORK);
new_flags |= PF_FORKNOEXEC;
if (!(clone_flags & CLONE_PTRACE))
new_flags &= ~(PF_PTRACED|PF_TRACESYS);
else {
REMOVE_LINKS (p);
p->p_pptr = p->p_pptr->p_pptr;
SET_LINKS (p);
}
if (clone_flags & CLONE_VFORK)
new_flags |= PF_VFORK;
p->flags = new_flags;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have no idea whether this is really correct since I have no machine
handy which I can reboot. I copied this from the attach code in
arch/i386/kernel/ptrace.c.

The idea is to inherit the parent proess (i.e., the one which can
perform the ptrace() call) from the parent. This would allow the
information to be propagated down. When the initial process is
ptraced so are all children and the process which can issue the
ptrace() call is always te same. This would help making strace and
gdb and whatever other program suddenly working.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/