Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1960022ybl; Thu, 9 Jan 2020 04:39:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyBiSm3snV6Z78/8pAWskq61P3o8dRkewq39kMaHEK20QyGwVSeNte6TNXMsSLc8RX+2QWR X-Received: by 2002:a9d:674f:: with SMTP id w15mr8365838otm.243.1578573578849; Thu, 09 Jan 2020 04:39:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578573578; cv=none; d=google.com; s=arc-20160816; b=E6qO9neR+Uq2zoIjlCe+STYrTwl2+G++6GARHAd9QPLJkYC3Rptiz1Q+kGyS6oil4V /Fbc4FfFuLEkseGACuQ1vkuehqn8omDwUxEuoDCXqG7AIVtY4PeryrD7kddcSC6fMajE wh8aO4FrYhN8UIRXFXYVHB3QDn5rk1rELlRJ3l0Jv/tvHXF+5hyejzZfwpvs8SmWX8to DJtVy/jtLA+jO0Y+AFyjUa3nqfVHO+x2FjIkadd8lFy5nDtMd/dyqmeHvoMmM0bJLcDh dvgPOaOtxAEeq5Ef2yn8HgFXpFbGLiGVerdmotghMTkeUvcXztECfEsn80AO8cPeelZ/ xfcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=oBFTXRcTZ3utAeV8/WrjIBKKbVN1IiWvp5coMWobEwg=; b=fYOvLu9Mj1qPkhy2KHsETyB/oysiJphCZqlRaUI13cNFEphnzVS7epYE71SA627p5n B9zroywcPtyXXbTANCAqihuwA2BPYZ3jTj3DfJ3xPL/7xwoWjJtQhIa7o8X/cfzgmuul jcW34nFGMvGRPL8mtTcnJHfddBOBDxpFpRG2YSBxMAg33ZojSRVm7L2AaqYFNkEqEnwj QNQ6V4Qi7Q11CkGzm+JRPv7r9drYmrzR1Fmlo5qK/BnaFL2v6ahrUQZ2NuadmsbKhKQa s79G1JSZC+T+lfDKRwX6sQgyj+Q2a/eYhVWNYD7cBBeQ8ACe+K7R/xNrWq8VFRhvnSPZ YJ3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g16si3780132otj.79.2020.01.09.04.39.25; Thu, 09 Jan 2020 04:39:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726616AbgAILhB (ORCPT + 99 others); Thu, 9 Jan 2020 06:37:01 -0500 Received: from mga01.intel.com ([192.55.52.88]:55961 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725997AbgAILhA (ORCPT ); Thu, 9 Jan 2020 06:37:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2020 03:37:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,413,1571727600"; d="scan'208";a="216275607" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP; 09 Jan 2020 03:36:59 -0800 Received: from [10.125.253.127] (abudanko-mobl.ccr.corp.intel.com [10.125.253.127]) by linux.intel.com (Postfix) with ESMTP id 2707C58043A; Thu, 9 Jan 2020 03:36:50 -0800 (PST) Subject: Re: [PATCH v4 2/9] perf/core: open access for CAP_SYS_PERFMON privileged process To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , "jani.nikula@linux.intel.com" , "joonas.lahtinen@linux.intel.com" , "rodrigo.vivi@intel.com" , Alexei Starovoitov , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "james.bottomley@hansenpartnership.com" , Serge Hallyn , James Morris , Will Deacon , Mark Rutland , Casey Schaufler , Robert Richter , Jiri Olsa , Andi Kleen , Stephane Eranian , Igor Lubashev , Alexander Shishkin , Namhyung Kim , Kees Cook , Jann Horn , Thomas Gleixner , Tvrtko Ursulin , Lionel Landwerlin , Song Liu , linux-kernel , "linux-security-module@vger.kernel.org" , "selinux@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "bpf@vger.kernel.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-perf-users@vger.kernel.org" , linux-arm-kernel@lists.infradead.org, oprofile-list@lists.sf.net References: <20200108160713.GI2844@hirez.programming.kicks-ass.net> From: Alexey Budankov Organization: Intel Corp. Message-ID: Date: Thu, 9 Jan 2020 14:36:50 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200108160713.GI2844@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08.01.2020 19:07, Peter Zijlstra wrote: > On Wed, Dec 18, 2019 at 12:25:35PM +0300, 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 | 6 +++--- >> kernel/events/core.c | 6 +++--- >> 2 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h >> index 34c7c6910026..f46acd69425f 100644 >> --- a/include/linux/perf_event.h >> +++ b/include/linux/perf_event.h >> @@ -1285,7 +1285,7 @@ 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 && !perfmon_capable()) >> return -EACCES; >> >> return security_perf_event_open(attr, PERF_SECURITY_KERNEL); >> @@ -1293,7 +1293,7 @@ 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 && !perfmon_capable()) >> return -EACCES; >> >> return security_perf_event_open(attr, PERF_SECURITY_CPU); >> @@ -1301,7 +1301,7 @@ 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 && !perfmon_capable()) >> return -EPERM; >> >> return security_perf_event_open(attr, PERF_SECURITY_TRACEPOINT); > > These are OK I suppose. > >> diff --git a/kernel/events/core.c b/kernel/events/core.c >> index 059ee7116008..d9db414f2197 100644 >> --- a/kernel/events/core.c >> +++ b/kernel/events/core.c >> @@ -9056,7 +9056,7 @@ static int perf_kprobe_event_init(struct perf_event *event) >> if (event->attr.type != perf_kprobe.type) >> return -ENOENT; >> >> - if (!capable(CAP_SYS_ADMIN)) >> + if (!perfmon_capable()) >> return -EACCES; >> >> /* > > This one only allows attaching to already extant kprobes, right? It does > not allow creation of kprobes. This unblocks creation of local trace kprobes and uprobes by CAP_SYS_PERFMON privileged process, exactly the same as for CAP_SYS_ADMIN privileged process. > >> @@ -9116,7 +9116,7 @@ static int perf_uprobe_event_init(struct perf_event *event) >> if (event->attr.type != perf_uprobe.type) >> return -ENOENT; >> >> - if (!capable(CAP_SYS_ADMIN)) >> + if (!perfmon_capable()) >> return -EACCES; >> >> /* > > Idem, I presume. > >> @@ -11157,7 +11157,7 @@ SYSCALL_DEFINE5(perf_event_open, >> } >> >> if (attr.namespaces) { >> - if (!capable(CAP_SYS_ADMIN)) >> + if (!perfmon_capable()) >> return -EACCES; >> } > > And given we basically make the entire kernel observable with this CAP, > busting namespaces shoulnd't be a problem either. > > So yeah, I suppose that works. >