Re: [PATCH 11/11] ptrace: implement group stop notification forptracer

From: Oleg Nesterov
Date: Wed May 11 2011 - 16:00:25 EST


On 05/08, Tejun Heo wrote:
>
> +static void ptrace_trap_notify(struct task_struct *t)
> +{
> + WARN_ON_ONCE(!(t->ptrace & PT_SEIZED));
> + assert_spin_locked(&t->sighand->siglock);
> +
> + /*
> + * @t is being ptraced and new SEIZE behavior is in effect.
> + * Schedule sticky trap which will clear on the next GETSIGINFO.
> + */
> + t->jobctl |= JOBCTL_TRAP_NOTIFY;
> +
> + /*
> + * If @t is currently trapped for group stop or INTERRUPT
> + * (JOBCTL_TRAPPED set), it should re-trap with new exit_code
> + * indicating continuation so that the ptracer can notice the
> + * event; otherwise, use normal signal delivery wake up.
> + *
> + * The re-trapping sets JOBCTL_TRAPPING such that the transition is
> + * hidden from the ptracer.
> + *
> + * This means that if @t is trapped for other reasons than group
> + * stop or INTERRUPT, the notification trap won't be delievered
> + * until the current one is complete. This is the intended
> + * behavior.
> + */
> + if (task_is_traced(t) && (t->jobctl & JOBCTL_TRAPPED)) {
> + t->jobctl |= JOBCTL_TRAPPING;
> + signal_wake_up(t, true);

and its tracer can be inside sys_ptrace().

No, I don't think this can be right. Otherwise, why ptrace_check_attach()
calls wait_task_inactive() ? The tracee can be scheduled but only if killed,
in this case we don't care.

I know very little about this low-level (and worse, arch dependant) magic,
but even on x86 this doesn't look safe. Suppose that the tracer changes the
fpu state of the tracer and __switch_to(next_p == tracee) does
__math_state_restore() before the tracer finishes.

Or PTRACE_GETSIGINFO can fail while it shouldn't, but this is minor.


Hmm. I think we need a bit more discussion, even ignoring the implementation
details.

Oleg.

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