On Wed, Jun 11, 2014 at 06:41:48PM +0300, Alexander Shishkin wrote:
> +static bool exclusive_event_ok(struct perf_event *event,
> +                           struct perf_event_context *ctx)
> +{
> +     struct perf_event *iter_event;
> +
> +     if (!(event->pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE))
> +             return true;
> +
> +     list_for_each_entry(iter_event, &ctx->event_list, event_entry) {
> +             if (exclusive_event_match(iter_event, event))
> +                     return false;
> +     }

This list iteration needs either rcu or ctx->lock or ctx->mutex, and the
two callsites below don't have either afaict.

> +
> +     return true;
> +}
> +
>  /**
>   * sys_perf_event_open - open a performance event, associate it to a task/cpu
>   *
> @@ -7261,6 +7287,11 @@ SYSCALL_DEFINE5(perf_event_open,
>               goto err_alloc;
>       }
>  
> +     if (!exclusive_event_ok(event, ctx)) {
> +             err = -EBUSY;
> +             goto err_context;
> +     }
> +
>       if (task) {
>               put_task_struct(task);
>               task = NULL;
> @@ -7427,6 +7458,13 @@ perf_event_create_kernel_counter(struct 
> perf_event_attr *attr, int cpu,
>               goto err_free;
>       }
>  
> +     if (!exclusive_event_ok(event, ctx)) {
> +             perf_unpin_context(ctx);
> +             put_ctx(ctx);
> +             err = -EBUSY;
> +             goto err_free;
> +     }
> +
>       WARN_ON_ONCE(ctx->parent_ctx);
>       mutex_lock(&ctx->mutex);
>       perf_install_in_context(ctx, event, cpu);
> -- 
> 2.0.0
> 

Attachment: pgpTEFSX3FEZZ.pgp
Description: PGP signature

Reply via email to