Re: [RFC PATCH 15/17] perf: Allow controlled non-root access to detached events
From: Peter Zijlstra
Date: Tue Oct 03 2017 - 10:53:17 EST
On Tue, Sep 05, 2017 at 04:30:24PM +0300, Alexander Shishkin wrote:
> @@ -5587,7 +5587,13 @@ static int perf_open(struct inode *inode, struct file *file)
> if (!atomic_long_inc_not_zero(&event->refcount))
> return -ENOENT;
>
> - ret = simple_open(inode, file);
> + /* event's user is stable while we're holding the reference */
> + if (event->rb->mmap_user != current_user() &&
> + !capable(CAP_SYS_ADMIN))
> + ret = -EACCES;
> +
> + if (!ret)
> + ret = simple_open(inode, file);
> if (ret)
> put_event(event);
>
> @@ -11530,6 +11537,18 @@ static int perf_instance_unlink(const char *name)
> if (!event)
> return -EINVAL;
>
> + if (!atomic_long_inc_not_zero(&event->refcount))
> + return 0;
> +
> + /* event's user is stable while we're holding the reference */
> + if (event->rb->mmap_user != current_user() &&
> + !capable(CAP_SYS_ADMIN))
> + ret = -EACCES;
> + put_event(event);
> +
> + if (ret)
> + return ret;
> +
> if (!(event->attach_state & PERF_ATTACH_CONTEXT))
> return -EBUSY;
>
Why aren't we using regular file permissions for this?