From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 865FCC2D0C3 for ; Mon, 16 Dec 2019 17:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6703B206D7 for ; Mon, 16 Dec 2019 17:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbfLPRMO (ORCPT ); Mon, 16 Dec 2019 12:12:14 -0500 Received: from mga17.intel.com ([192.55.52.151]:35213 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLPRMO (ORCPT ); Mon, 16 Dec 2019 12:12:14 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Dec 2019 09:12:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,322,1571727600"; d="scan'208";a="415144339" Received: from linux.intel.com ([10.54.29.200]) by fmsmga005.fm.intel.com with ESMTP; 16 Dec 2019 09:12:12 -0800 Received: from [10.251.95.214] (abudanko-mobl.ccr.corp.intel.com [10.251.95.214]) by linux.intel.com (Postfix) with ESMTP id 30029580342; Mon, 16 Dec 2019 09:12:03 -0800 (PST) Subject: Re: [PATCH v2 2/7] perf/core: open access for CAP_SYS_PERFMON privileged process 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" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" References: <26101427-c0a3-db9f-39e9-9e5f4ddd009c@linux.intel.com> <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> From: Alexey Budankov Organization: Intel Corp. Message-ID: Date: Mon, 16 Dec 2019 20:12:02 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@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 > 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 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7806C43603 for ; Mon, 16 Dec 2019 17:14:31 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D7E4206D7 for ; Mon, 16 Dec 2019 17:14:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D7E4206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47c7DN6PzMzDqW6 for ; Tue, 17 Dec 2019 04:14:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.intel.com (client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=alexey.budankov@linux.intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47c79t17dXzDqSB for ; Tue, 17 Dec 2019 04:12:16 +1100 (AEDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Dec 2019 09:12:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,322,1571727600"; d="scan'208";a="415144339" Received: from linux.intel.com ([10.54.29.200]) by fmsmga005.fm.intel.com with ESMTP; 16 Dec 2019 09:12:12 -0800 Received: from [10.251.95.214] (abudanko-mobl.ccr.corp.intel.com [10.251.95.214]) by linux.intel.com (Postfix) with ESMTP id 30029580342; Mon, 16 Dec 2019 09:12:03 -0800 (PST) Subject: Re: [PATCH v2 2/7] perf/core: open access for CAP_SYS_PERFMON privileged process 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 References: <26101427-c0a3-db9f-39e9-9e5f4ddd009c@linux.intel.com> <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> From: Alexey Budankov Organization: Intel Corp. Message-ID: Date: Mon, 16 Dec 2019 20:12:02 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin , Song Liu , Andi Kleen , Kees Cook , "linux-parisc@vger.kernel.org" , Jann Horn , Alexander Shishkin , "linuxppc-dev@lists.ozlabs.org" , "intel-gfx@lists.freedesktop.org" , linux-kernel , Stephane Eranian , "linux-perf-users@vger.kernel.org" , "selinux@vger.kernel.org" , "linux-security-module@vger.kernel.org" , Namhyung Kim , Thomas Gleixner , "bgregg@netflix.com" , Jiri Olsa , "bpf@vger.kernel.org" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6AC6C3F68F for ; Mon, 16 Dec 2019 17:12:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B898D206EC for ; Mon, 16 Dec 2019 17:12:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B898D206EC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F3266E840; Mon, 16 Dec 2019 17:12:15 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id DCDB96E83F for ; Mon, 16 Dec 2019 17:12:13 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Dec 2019 09:12:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,322,1571727600"; d="scan'208";a="415144339" Received: from linux.intel.com ([10.54.29.200]) by fmsmga005.fm.intel.com with ESMTP; 16 Dec 2019 09:12:12 -0800 Received: from [10.251.95.214] (abudanko-mobl.ccr.corp.intel.com [10.251.95.214]) by linux.intel.com (Postfix) with ESMTP id 30029580342; Mon, 16 Dec 2019 09:12:03 -0800 (PST) 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 References: <26101427-c0a3-db9f-39e9-9e5f4ddd009c@linux.intel.com> <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> From: Alexey Budankov Organization: Intel Corp. Message-ID: Date: Mon, 16 Dec 2019 20:12:02 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <9316a1ab21f6441eb2b421acb818a2a1@ustx2ex-dag1mb6.msg.corp.akamai.com> Content-Language: en-US Subject: Re: [Intel-gfx] [PATCH v2 2/7] perf/core: open access for CAP_SYS_PERFMON privileged process X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Song Liu , Andi Kleen , Kees Cook , "linux-parisc@vger.kernel.org" , Jann Horn , Alexander Shishkin , "linuxppc-dev@lists.ozlabs.org" , "intel-gfx@lists.freedesktop.org" , linux-kernel , Stephane Eranian , "linux-perf-users@vger.kernel.org" , "selinux@vger.kernel.org" , "linux-security-module@vger.kernel.org" , Namhyung Kim , Thomas Gleixner , "bgregg@netflix.com" , Jiri Olsa , "bpf@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 > _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx