All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vzapolskiy@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] connector: add an event for monitoring process tracers
Date: Fri, 15 Jul 2011 20:41:59 +0300	[thread overview]
Message-ID: <CAMW3pwbr1N6Yc7K=up3mYNq2f6+_6xA4hSgh8K1hWwHPnj_d9g@mail.gmail.com> (raw)
In-Reply-To: <20110713150942.GA4850@redhat.com>

Oleg,

first of all thank you for a good review, please see my comments below.

On Wed, Jul 13, 2011 at 6:09 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> On 07/12, Vladimir Zapolskiy wrote:
>>
>> Note, a detach signal is not emitted, if a tracer process terminates
>> without explicit PTRACE_DETACH request. Such cases can be covered
>> listening to PROC_EVENT_EXIT connector events.
>
> Hmm. More and more reasons to make the implicit detach sleepable...
>
> But. There is another case. The (dead) tracee can be detached via
> do_wait(). Perhaps this falls into "covered listening to EXIT" too,
> but imho makes sense to document in the changelog. Oh, and probably
> we will add the ability to detach a zombie...
>
> I don't really understand why do you need this, but I won't argue.
>
I found that implicit ptrace detach codepath is quite mutable and
vast, and I don't want to interfere in that changes without knowing
even basic pitfalls. Somehow the sending a connector signal on
explicit detach is quite sufficient at least for the most of the proc
connector usecases I can imagine, because hopefully almost(?) all
implicit detach cases are related to tracer or tracee thread
completion, and that is supposed to be reported to userspace via
do_exit()/proc_exit_connector() path.

> As for the patch,
>
>> +void proc_ptrace_connector(struct task_struct *task)
>> +{
>> +     struct cn_msg *msg;
>> +     struct proc_event *ev;
>> +     struct timespec ts;
>> +     __u8 buffer[CN_PROC_MSG_SIZE];
>> +     struct task_struct *tracer;
>> +
>> +     if (atomic_read(&proc_event_num_listeners) < 1)
>> +             return;
>> +
>> +     msg = (struct cn_msg *)buffer;
>> +     ev = (struct proc_event *)msg->data;
>> +     get_seq(&msg->seq, &ev->cpu);
>> +     ktime_get_ts(&ts); /* get high res monotonic timestamp */
>> +     put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
>> +     ev->what = PROC_EVENT_PTRACE;
>> +     ev->event_data.ptrace.process_pid  = task->pid;
>> +     ev->event_data.ptrace.process_tgid = task->tgid;
>> +
>> +     rcu_read_lock();
>> +     tracer = tracehook_tracer_task(task);
>> +     if (tracer) {
>> +             ev->event_data.ptrace.tracer_pid  = tracer->pid;
>> +             ev->event_data.ptrace.tracer_tgid = tracer->tgid;
>> +     } else {
>> +             ev->event_data.ptrace.tracer_pid  = 0;
>> +             ev->event_data.ptrace.tracer_tgid = 0;
>> +     }
>
> This doesn't look right. The code uses tracehook_tracer_task() to
> figure out whether this task traced or not. But this is racy.
>
> ptrace_attach:
>
>        ...attach...
>
>        /* WINDOW */
>
>        proc_ptrace_connector(task);
>
> The task can exit in between, and the caller's subthread can do
> wait4() and release it. In this case proc_ptrace_connector() will
> see tracehook_tracer_task() == NULL and report "detach".
>
> The similar race in ptrace_detach() path. Another tracer can attach
> to this task before we proc_ptrace_connector().
>
> I think proc_ptrace_connector() needs the explicit "task_struct *tracer"
> argument, NULL if ptrace_detach(). Or a simple boolean, the tracer is
> current.
>
> If you think this is fine - I won't argue.
>
Fixed in the second version of the change, thanks.

>
>
> But in any case, please rediff against
>
>        git://git.kernel.org/pub/scm/linux/kernel/git/oleg/misc.git ptrace
>
> tracehook_tracer_task() was removed, and
>
>> @@ -260,6 +261,9 @@ out:
>>       if (wait_trap)
>>               wait_event(current->signal->wait_chldexit,
>>                          !(task->group_stop & GROUP_STOP_TRAPPING));
>> +     if (!retval)
>> +             proc_ptrace_connector(task);
>> +
>>       return retval;
>>  }
>
> this chunk probably should be updated.
Rebased, thanks a lot.

Vladimir

      reply	other threads:[~2011-07-15 17:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-12 20:32 [PATCH] connector: add an event for monitoring process tracers Vladimir Zapolskiy
2011-07-13 12:48 ` Evgeniy Polyakov
2011-07-13 14:53   ` David Miller
2011-07-13 15:09 ` Oleg Nesterov
2011-07-15 17:41   ` Vladimir Zapolskiy [this message]

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='CAMW3pwbr1N6Yc7K=up3mYNq2f6+_6xA4hSgh8K1hWwHPnj_d9g@mail.gmail.com' \
    --to=vzapolskiy@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=zbr@ioremap.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.