Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp538643ybb; Fri, 3 Apr 2020 07:30:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJy7ZkqZtRHH0aEdBojurjO3Z5y2b9Yqm94Gm7jGrBFWI5avPIH6K6sDf0JUDUIyu4D9Q2R X-Received: by 2002:a9d:5ad:: with SMTP id 42mr6983789otd.231.1585924216738; Fri, 03 Apr 2020 07:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585924216; cv=none; d=google.com; s=arc-20160816; b=pGAsYqpCCAiQNZk1W+tfBOhDqxqSPJgYyh8ttXJjQ/gPN92ntD5x0rpw8R5WNbyhXK POtryww99g4BSllhWurL+VOsIirKuWxssqnL/r84tY1sw1/ksAC9DKf1U2/gnKnEetU1 mqSmk2isagFQF5sZlGSbgAUb32WCGsSw61NgokJhW1uvxhCbvPSSwXO+iCvu+Jlj+K2o vnpeiHtaZbPMfXG2pJ9ZhP21peyfIEv3N3pxFxwDjCjJMWruoLZzBx0B7z56K+d6h6ov YSbf3OMgkAdLStIvqlf2L0uYOvbGF81tfca2VcPCy/Va31R+MluBgcXv9BaNLVTJ3WDT yYDQ== 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:references:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=1dm+GH2p2lkXCFdMP8ADg4jm2PWAUtnxiQP02aDyzMc=; b=CZcUZ0Ve9/n+uzOfoCj0GlMgwjfuZhyybmiFkJaALB7pIiNtDxweQfVGyxWE/KWO4A CN4iV4Jy1Z/UnJXEZrbNtA+LxWY2jmZlXaVwoGrJE46NQGdZOe2X5s9pFTTDJIcc+uxY z3YJD8MyNVwbjDSIsbaWggtT+jGQZRvxolz0NYbrm0/8/ZaAXLRz6cHAQPR50ghghlsn fJM7PWLAnPVljC+lC1++dTtzaS4O5YFSw1LrJxZzKpeT4WMncNHLr1SIqFKuvvJbF3I8 9pt9yeTL9KtEbRByMw3v5abspjTy8BknlFurTIzx6cSvruR8ts+WccANHFqgI3ZWzz8x D/DQ== 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 f12si4122590otc.147.2020.04.03.07.30.03; Fri, 03 Apr 2020 07:30:16 -0700 (PDT) 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 S2403850AbgDCO3I (ORCPT + 99 others); Fri, 3 Apr 2020 10:29:08 -0400 Received: from mga03.intel.com ([134.134.136.65]:15121 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727431AbgDCO3H (ORCPT ); Fri, 3 Apr 2020 10:29:07 -0400 IronPort-SDR: lxkOUMurYjhN0Y7l5fVYl8hVuGT7Tv2y6Nn6e4HkS3v4sbjKM6Ci8b80w1fz1QH1XtBSKc0NP4 oGfjxiJUY8qw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 07:29:03 -0700 IronPort-SDR: QYYCSMTHxnMmHUYdTN6qK8Da/qeXWJtpW9hr4z2CR28Woc6Zx24PddrIMX5hFpFjSByE1cBk6A Lpx/dB5rmG0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,340,1580803200"; d="scan'208";a="329180493" Received: from linux.intel.com ([10.54.29.200]) by orsmga001.jf.intel.com with ESMTP; 03 Apr 2020 07:29:03 -0700 Received: from [10.249.254.224] (abudanko-mobl.ccr.corp.intel.com [10.249.254.224]) by linux.intel.com (Postfix) with ESMTP id C813E58077B; Fri, 3 Apr 2020 07:29:00 -0700 (PDT) Subject: Re: [PATCH v4 2/9] perf/core: open access for CAP_SYS_PERFMON privileged process From: Alexey Budankov To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , James Morris , Jiri Olsa , Andi Kleen , Alexander Shishkin , Namhyung Kim , linux-kernel References: <20200108160713.GI2844@hirez.programming.kicks-ass.net> <4e528ce4-a937-358b-47b6-7d7085ab4eaa@linux.intel.com> Organization: Intel Corp. Message-ID: <930384c0-e852-a7bf-cd61-829cb9993234@linux.intel.com> Date: Fri, 3 Apr 2020 17:28:59 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <4e528ce4-a937-358b-47b6-7d7085ab4eaa@linux.intel.com> 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 01.04.2020 23:49, Alexey Budankov wrote: > Hi Peter, > > 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. >> >>> @@ -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. > > Could this have you explicit Reviewed-by or Acked-by tag > so the changes could be driven into the kernel? > Latest v7 is here: > https://lore.kernel.org/lkml/c8de937a-0b3a-7147-f5ef-69f467e87a13@linux.intel.com/ Posted v8 with all acquired tags so far: https://lore.kernel.org/lkml/f96f8f8a-e65c-3f36-dc85-fc3f5191e8c5@linux.intel.com/ Thanks, Alexey