Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1876421ybl; Thu, 5 Dec 2019 08:22:41 -0800 (PST) X-Google-Smtp-Source: APXvYqz4tbbPbnF2R+xHR09ep/FS63JW+paEdTMEELJ71gBTHp7BoPYfwAko4hHaUvWOvwDOoYOx X-Received: by 2002:a9d:6d10:: with SMTP id o16mr7527906otp.28.1575562961191; Thu, 05 Dec 2019 08:22:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575562961; cv=none; d=google.com; s=arc-20160816; b=DYxDRPtdkuobGJKyWPxFqfRqs4WKhHg10Sj+gvqKEGnm4rgja02N32hUrcW2j49Ody 3tWHOvDDbLxuqZlHXHen3YUVyw/UT7JdH886UvJ8WyECnYwwJTOSB+j9fiazXlRCTeG4 7o952+fCeM7OXO5ZDr8Z/gHPI3kGFVR+Yk3K6P58zVQ1GqHYL9tK0eHp0ka3zrs0z6KM gaUFdaobCFfFsyFDqrBD73VaNUvfIDUNmkdLTUtf8qlnFxEgpJm+Dgm8WGpmuzU9rOxr +TEudOqFan/48lk5iTIpy2vsDw/j5kIupg9PtB5tinsOrPzISI3YXhNgcpmcT0L9ApaZ 2VFQ== 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; bh=XLqspGY/vUu+0iXrw6P79xpCN7n6UWF64LX6bQYGLxs=; b=vLdptRlke4SFFIGb8YLj2pmg/lNCj8UM04ci+u9Us4lDp2WIucZE63i/sK/mnRrtmy ItWpVOKR08a7JfqKvq2ozK1I0Gi4XqrAARohvmdruAiDRIQukRN99dxFhWGbTWZB+qCu tr/dPMzjrXFRRJlq+XWBjSOs9rCJ5HYCOlu6pWYEcq+CwZdGjvYspYfXUyaqXtgnimP3 mFVv2iK7PGkovDqpZtIhkfTX0TBZ5xF+22rZbaiGLcbRqMuBfDXiyRvlPL6Al7VedKxx BlvFAtXIiYG9Vz7beO08znuFIMcnrtVJPSEw1TWfhrUL/DRr6vAn6TaefzBIFNP42QVs OfoQ== 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 i185si4362504oia.187.2019.12.05.08.22.27; Thu, 05 Dec 2019 08:22:41 -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 S1729598AbfLEQVi (ORCPT + 99 others); Thu, 5 Dec 2019 11:21:38 -0500 Received: from mga12.intel.com ([192.55.52.136]:62139 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726589AbfLEQVi (ORCPT ); Thu, 5 Dec 2019 11:21:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2019 08:21:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,281,1571727600"; d="scan'208";a="201816551" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP; 05 Dec 2019 08:21:36 -0800 Received: from [10.125.252.254] (abudanko-mobl.ccr.corp.intel.com [10.125.252.254]) by linux.intel.com (Postfix) with ESMTP id 2D8155804A0; Thu, 5 Dec 2019 08:21:32 -0800 (PST) Subject: [PATCH v1 2/3] perf/core: apply CAP_SYS_PERFMON to CPUs and kernel monitoring From: Alexey Budankov To: Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar Cc: Jiri Olsa , Andi Kleen , elena.reshetova@intel.com, Alexander Shishkin , Jann Horn , Kees Cook , Stephane Eranian , Namhyung Kim , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kernel References: <283f09a5-33bd-eac3-bdfd-83d775045bf9@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Thu, 5 Dec 2019 19:21:32 +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: <283f09a5-33bd-eac3-bdfd-83d775045bf9@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 Enable CAP_SYS_PERFMON privileged process with secure performance monitoring of available online CPUs, when executing code in kernel and user modes. For backward compatibility reasons performance monitoring functionality of perf_events subsystem remains available under CAP_SYS_ADMIN but its usage for secure performance monitoring use cases is discouraged with respect to the introduced CAP_SYS_PERFMON capability. Signed-off-by: Alexey Budankov --- include/linux/perf_event.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 34c7c6910026..e8dc8411de9a 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); -- 2.20.1