Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp943643ybl; Wed, 8 Jan 2020 08:23:41 -0800 (PST) X-Google-Smtp-Source: APXvYqz6+tLRBDDkSgBuaP8VxEDU3BJWmlLQfjabW9VJx/4HmxjRQDnI/6NidoLot13ZeqYAkJzd X-Received: by 2002:aca:3cd7:: with SMTP id j206mr3819506oia.142.1578500620962; Wed, 08 Jan 2020 08:23:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578500620; cv=none; d=google.com; s=arc-20160816; b=tMwi6Wv6rHp5Cx0irFnatziqN5uuxCr6BOIRgEL37zVHCK4EGZE9N2BstZztc8ltbw OC2Vh2vDejVtTjl8xOV8heAxN8QPWWa8z5XFWYLWGPlDHHRsi/XVysPc22e/BRI0qiBJ gPbO8hTKgKQ0Sk+L7pBGRQTTqtcyukexGOkq71A/mzXvzX5XGaSs5Cz0B+v2g/jurssz C+4apBA8vFdxM3PkcEGqrTyHmd6z1rw2G2Uqxp01JCstiulVXq/IHwBoSsDDhZ5LABgB rOvIRiSHiJaF3RA+64k/NcqOnsiLH5aFCE9AxSfiNRVF7mQ1/iw2w0XVTQwso082RZTS DCBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vTWY1coa2Uglbk+2ijUNU4PAcTKo3OAi9shtTNMi0Rk=; b=LvOKzEOcRa2ASvwexaH4qBpCUrFutq1xqKGhkiVU9Efp4I9QXUmrC0yOUle0jNlcYk mkYj1JSuk6PvprqaktOcs29T4XUtIuNrZohDvMIh8toIDOw9izCePTp16MaxqLM+ZUMc g7lJBVyOYVfBDNqQhliIQcZA01BKyhlkr7oHTa7KrBIdDd8rq59K6n9FizM3GOgowWlI leJFGATogOTvBkXVJdE7+yUf99bfUFVRmGWJak6uoU8HN3/YirO8moldI/scCys/G6dh imE5CnGIv/pJW3bykR8Jln+u15UQyRAVV05SrE38fWL/KSTABXvPb7Y0pSsrn35TE7qD lDzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gqbvtODk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si1953919oiv.13.2020.01.08.08.23.28; Wed, 08 Jan 2020 08:23:40 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gqbvtODk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729021AbgAHQHu (ORCPT + 99 others); Wed, 8 Jan 2020 11:07:50 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:58506 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727421AbgAHQHt (ORCPT ); Wed, 8 Jan 2020 11:07:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vTWY1coa2Uglbk+2ijUNU4PAcTKo3OAi9shtTNMi0Rk=; b=gqbvtODkaNnvdu0BtI1I+oz9W A/2kAzeM+Of8bAddV33sSuyFB5xF+Iq5ljJRIvioI+k+R95x57awB/8d2/OaCxPEWI73HH3ggqw/b sRuPnU/M3cuEf3KHzciBaTOkOpg9la+z/euW56512nmDwFzNGDIve2Ho4jXCQShNWbCSAJw0jVzgp W73rwpfbOnlx/JXYvxqZG+ueOUqg0TTsDyxTW539J3TnC4nfAFSqo8UjcEPXCvaV8lYoYsU9cKROX c5nXwgc0c5to6F7JUcDXFL8eRwzCCSZ1nK2sOxQ5uehPgx5U+VprgiM8abXXvQlwSBJdkTRyrU3JI mPuHTmEYQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ipDrb-0002aV-JF; Wed, 08 Jan 2020 16:07:19 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0BFB530018B; Wed, 8 Jan 2020 17:05:40 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 08A5520B79C82; Wed, 8 Jan 2020 17:07:14 +0100 (CET) Date: Wed, 8 Jan 2020 17:07:13 +0100 From: Peter Zijlstra To: Alexey Budankov 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 Subject: Re: [PATCH v4 2/9] perf/core: open access for CAP_SYS_PERFMON privileged process Message-ID: <20200108160713.GI2844@hirez.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.