Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b05ec5a7 authored by Rohit Gupta's avatar Rohit Gupta
Browse files

perf: Skip permission checks on kernel owned perf events



The perf event permission checks are necessary because they introduce
a security concern where one userspace task can monitor another task
and gain security related information. That concern doesn't exist for
kernel owned perf events since the kernel already has access to
everything. So, skip permission checks for kernel owned perf events.

Change-Id: I7121f5e03cf6ce8f0bfc9b5a69488efb80a97051
Signed-off-by: default avatarRohit Gupta <rohgup@codeaurora.org>
parent b06f2ad5
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -3241,16 +3241,18 @@ errout:
 * Returns a matching context with refcount and pincount.
 */
static struct perf_event_context *
find_get_context(struct pmu *pmu, struct task_struct *task, int cpu)
find_get_context(struct perf_event *event, struct task_struct *task, int cpu)
{
	struct perf_event_context *ctx, *clone_ctx = NULL;
	struct perf_cpu_context *cpuctx;
	struct pmu *pmu = event->pmu;
	unsigned long flags;
	int ctxn, err;

	if (!task) {
		/* Must be root to operate on a CPU event: */
		if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
		if (event->owner != EVENT_OWNER_KERNEL && perf_paranoid_cpu() &&
			!capable(CAP_SYS_ADMIN))
			return ERR_PTR(-EACCES);

		/*
@@ -7415,7 +7417,7 @@ SYSCALL_DEFINE5(perf_event_open,
	/*
	 * Get the target context (task or percpu):
	 */
	ctx = find_get_context(pmu, task, event->cpu);
	ctx = find_get_context(event, task, event->cpu);
	if (IS_ERR(ctx)) {
		err = PTR_ERR(ctx);
		goto err_alloc;
@@ -7584,7 +7586,7 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,

	account_event(event);

	ctx = find_get_context(event->pmu, task, cpu);
	ctx = find_get_context(event, task, cpu);
	if (IS_ERR(ctx)) {
		err = PTR_ERR(ctx);
		goto err_free;