Re: [RFC PATCH 3/6] bpf: Save the pointer to struct perf_event to map

Peter Zijlstra
2015-07-17T11:37:42Z

On Fri, Jul 17, 2015 at 06:43:33PM +0800, kaixu xia wrote:
> +static int replace_map_with_perf_event(void *value)
> +{
> + struct perf_event *event;
> + u32 fd;
> +
> + fd = *(u32 *)value;
> +
> + event = perf_event_get(fd);
> + if (IS_ERR(event))
> + return PTR_ERR(event);
> +

And userspace closes here,

> + if (atomic_long_inc_not_zero(&event->refcount))

And this goes *BOOM*

> + memcpy(value, &event, sizeof(struct perf_event *));
> + else
> + return -ENOENT;
> +
> + return 0;
> +}

Also, why do you think its OK to prod around the internals of perf_event
outside of kernel/events/ ?