From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexey Budankov Subject: Re: [PATCH v2 2/7] perf/core: open access for CAP_SYS_PERFMON privileged process Date: Mon, 16 Dec 2019 20:12:02 +0300 Message-ID: References: <26101427-c0a3-db9f-39e9-9e5f4ddd009c@linux.intel.com> <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: "Lubashev, Igor" , Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar , "jani.nikula@linux.intel.com" , "joonas.lahtinen@linux.intel.com" , "rodrigo.vivi@intel.com" , Alexei Starovoitov , "james.bottomley@hansenpartnership.com" , "benh@kernel.crashing.org" , Casey Schaufler , "serge@hallyn.com" , James Morris Cc: Jiri Olsa , Andi Kleen , Stephane Eranian , Alexander Shishkin , Namhyung Kim , Jann Horn , Kees Cook , Thomas Gleixner , Tvrtko Ursulin , "linux-security-module@vger.kernel.org" , "selinux@vger.kernel.org" , linux-kernel , "linux-perf-users@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "bgregg@netflix.com" , Song Liu "bpf@vger.kernel.org" List-Id: linux-perf-users.vger.kernel.org On 16.12.2019 19:12, Lubashev, Igor wrote: > On Mon, Dec 16, 2019 at 2:15 AM, Alexey Budankov wrote: >> >> Open access to perf_events monitoring for CAP_SYS_PERFMON privileged >> processes. >> For backward compatibility reasons access to perf_events subsystem remains >> open for CAP_SYS_ADMIN privileged processes but CAP_SYS_ADMIN usage >> for secure perf_events monitoring is discouraged with respect to >> CAP_SYS_PERFMON capability. >> >> Signed-off-by: Alexey Budankov >> --- >> include/linux/perf_event.h | 9 ++++++--- >> 1 file changed, 6 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index >> 34c7c6910026..52313d2cc343 100644 >> --- a/include/linux/perf_event.h >> +++ b/include/linux/perf_event.h >> @@ -1285,7 +1285,8 @@ static inline int perf_is_paranoid(void) >> >> static inline int perf_allow_kernel(struct perf_event_attr *attr) { >> - if (sysctl_perf_event_paranoid > 1 && !capable(CAP_SYS_ADMIN)) >> + if (sysctl_perf_event_paranoid > 1 && >> + !(capable(CAP_SYS_PERFMON) || capable(CAP_SYS_ADMIN))) >> return -EACCES; >> >> return security_perf_event_open(attr, PERF_SECURITY_KERNEL); @@ >> -1293,7 +1294,8 @@ static inline int perf_allow_kernel(struct >> perf_event_attr *attr) >> >> static inline int perf_allow_cpu(struct perf_event_attr *attr) { >> - if (sysctl_perf_event_paranoid > 0 && !capable(CAP_SYS_ADMIN)) >> + if (sysctl_perf_event_paranoid > 0 && >> + !(capable(CAP_SYS_PERFMON) || capable(CAP_SYS_ADMIN))) >> return -EACCES; >> >> return security_perf_event_open(attr, PERF_SECURITY_CPU); @@ - >> 1301,7 +1303,8 @@ static inline int perf_allow_cpu(struct perf_event_attr >> *attr) >> >> static inline int perf_allow_tracepoint(struct perf_event_attr *attr) { >> - if (sysctl_perf_event_paranoid > -1 && !capable(CAP_SYS_ADMIN)) >> + if (sysctl_perf_event_paranoid > -1 && >> + !(capable(CAP_SYS_PERFMON) || capable(CAP_SYS_ADMIN))) >> return -EPERM; >> >> return security_perf_event_open(attr, PERF_SECURITY_TRACEPOINT); >> -- >> 2.20.1 > > Thanks. I like the idea of CAP_SYS_PERFMON that does not require CAP_SYS_ADMIN. It makes granting users ability to run perf a bit safer. > > I see a lot of "(capable(CAP_SYS_PERFMON) || capable(CAP_SYS_ADMIN)" constructs now. Maybe wrapping it in an " inline bool perfmon_capable()" defined somewhere (like in /include/linux/capability.h)? Sounds reasonable, thanks! ~Alexey > > - Igor >