From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934852AbdKQN5p (ORCPT ); Fri, 17 Nov 2017 08:57:45 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:41576 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933420AbdKQN5e (ORCPT ); Fri, 17 Nov 2017 08:57:34 -0500 X-Google-Smtp-Source: AGs4zMZbT0DQ3yTECEpsYco4Ov/SJcqbNTew8IYVvom7kPF+SES0p8hbxCPw5nkqsfOVvoZcC7Roqw== From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Tvrtko Ursulin , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Dmitry Rogozhkin , Chris Wilson Subject: [RFC 1/2] perf/pmu: Allow PMU providers to override system-wide security settings Date: Fri, 17 Nov 2017 13:57:22 +0000 Message-Id: <20171117135723.22235-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin To allow system administrators finer-grained control over security settings, we add an optional pmu->is_privileged(pmu, event) callback which is consulted when unprivileged system-wide uncore event collection is disabled. Signed-off-by: Tvrtko Ursulin Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: linux-kernel@vger.kernel.org Cc: Dmitry Rogozhkin Cc: Chris Wilson --- include/linux/perf_event.h | 6 ++++++ kernel/events/core.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 8e22f24ded6a..a93630cad6b9 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -446,6 +446,12 @@ struct pmu { * Filter events for PMU-specific reasons. */ int (*filter_match) (struct perf_event *event); /* optional */ + + /* + * Returns true if the event needs CAP_SYS_ADMIN privilege in system- + * wide mode. + */ + bool (*is_privileged) (struct perf_event *event); /* optional */ }; /** diff --git a/kernel/events/core.c b/kernel/events/core.c index 1811dd5aa2e2..adec28c879e8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3847,6 +3847,16 @@ find_lively_task_by_vpid(pid_t vpid) return task; } +static bool cpu_is_privileged(struct pmu *pmu, struct perf_event *event) +{ + bool privileged = perf_paranoid_cpu(); + + if (privileged && pmu->is_privileged) + privileged = pmu->is_privileged(event); + + return privileged; +} + /* * Returns a matching context with refcount and pincount. */ @@ -3863,7 +3873,7 @@ find_get_context(struct pmu *pmu, struct task_struct *task, if (!task) { /* Must be root to operate on a CPU event: */ - if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) + if (cpu_is_privileged(pmu, event) && !capable(CAP_SYS_ADMIN)) return ERR_PTR(-EACCES); cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu); -- 2.14.1