Re: [patch 20/24] perfmon: system calls interface

From: Oleg Nesterov
Date: Wed Nov 26 2008 - 12:02:27 EST


On 11/26, Ingo Molnar wrote:
>
> * eranian@xxxxxxxxxxxxxx <eranian@xxxxxxxxxxxxxx> wrote:
>
> > +static int pfm_task_incompatible(struct pfm_context *ctx,
> > + struct task_struct *task)
> > +{
> > + /*
> > + * cannot attach to a kernel thread
> > + */
> > + if (!task->mm) {
> > + PFM_DBG("cannot attach to kernel thread [%d]", task->pid);
> > + return -EPERM;
> > + }
> > +
> > + /*
> > + * cannot attach to a zombie task
> > + */
> > + if (task->exit_state == EXIT_ZOMBIE || task->exit_state == EXIT_DEAD) {
> > + PFM_DBG("cannot attach to zombie/dead task [%d]", task->pid);
> > + return -EBUSY;
> > + }
> > + return 0;
> > +}

I agree with Ingo these checks are pointless. Without the locks
the ->mm or ->exit_state can be changed right after the check.

And, as Ingo pointed out, you don't need this function at all,
if ptrace_check_attach() succeeds the task must have ->mm and
its ->exit_state == 0.

But, please note that the task can be SIGKILL'ed right after
ptrace_check_attach(), it can drop ->mm, it can be released.
(i don't understand the patch, perhaps this doesn't matter for
you, just in case).

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/