Re: [RFC PATCH] perf_counter: dynamically allocate tasks'perf_counter_context struct

From: Paul Mackerras
Date: Wed May 20 2009 - 21:10:41 EST


Peter Zijlstra writes:

> This seems to be the only site where we use ->perf_counter_mutex,
> couldn't we simply write this as:
>
> if (cmpxchg(&task->perf_counter_ctx, NULL, ctx) != NULL)
> kfree(ctx);
>
> and get rid of the mutex?

Yes, that should work, with an smp_wmb() before the cmpxchg.

> If, in find_get_context() we exclude PF_EXITING tasks under ctx->mutex,
> and ensure we take ctx->mutex in perf_counter_exit_task() we should be
> good.

It's the fact that we also call perf_counter_exit_task when doing an
exec of a setuid program that concerns me. In that case the task
isn't exiting and its pid is still accessible, so it is quite possible
that some other task could be attaching counters to us. Certainly
root could; I don't know whether we change uid before doing the
dumpable check or not, so it's possible a non-privileged process would
be refused.

Paul.
--
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/