Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3537703ybz; Mon, 20 Apr 2020 04:55:32 -0700 (PDT) X-Google-Smtp-Source: APiQypLcybh5nhIU0X7ly3mZzwu69T4nvN2uY5lZmy/Lizb2jVtg/NagblXFBaW3f1luJhHUivgh X-Received: by 2002:a17:906:35d0:: with SMTP id p16mr15338893ejb.77.1587383732775; Mon, 20 Apr 2020 04:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383732; cv=none; d=google.com; s=arc-20160816; b=MLye2/N0IVWR+dkrF95/UxvVS5Ar46TP6OhOuBMjKDDnnxFzQFtuM388OynqFH7juu 4sHHNMsgUaWsDVS2dRbLHcGBEwf6WdGh5o2fXe/wJdqedEyjnBKDxrqD+8tgbOwHsw5f hvkruzwdItzXmtDddPcwSes4ubqLHbbYyATMpyrHQLgq6hrqzRiZRDOkIl29/ppm4qcf XQDrPsg+apKxlGLj7lVwtnV7TFP1UVcOo2+cm0TDStxJo9x4INLUcsE7dtqlskdYm4rU nkuhuQbY1zdkYDhjb35ShAQm7N0mKuZtWYFgYqe9XaTAhWRPkso8/793AmeWc+VHGikh R/Gg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e3C1VIV35F7zNlpxy6uvd5/MylQWaHfxo/Phv7nL1mQ=; b=PqL/EbePKxeyHICA7hRxzYYoR1Dx+MwlyuMBYh4fTAsQ6y9AuimJxBJ8cyVexDjhx/ A8PFzaHW9pYAhF/M2gvwAYEOqTkejl/JFHcTDQ+NsgoMEWljgLm4DjlzFm73u5noWyeU Z1EK9JdnDtCqMivV0/o1Uo9cdKLlJlOWatb1Afio8tdjkxV3h2jKPiTrw4V5HNwEuklk svug+9JMxBhxTQ0OsJ0U2KyB4eS+EcjPq9UOSo5iQAZkgZ/xoUEwhqseQpBTIPKXr2rt zOhtV37bf7Zk1YtDLfupvIP9xh7gzYFqpNhX52N4B5Jxk/BpouO9UDsUWYVM/JSjgKnJ aX7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CrCekbuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si404113ejt.479.2020.04.20.04.55.10; Mon, 20 Apr 2020 04:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CrCekbuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbgDTLxz (ORCPT + 99 others); Mon, 20 Apr 2020 07:53:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgDTLxy (ORCPT ); Mon, 20 Apr 2020 07:53:54 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE2F3206D4; Mon, 20 Apr 2020 11:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383634; bh=PWjy/B+21HQPLawk/uU7/6+PxUTYrdc8ItS1u38jg7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CrCekbuQzUEiHVCs3rvwQlRQOhBIgD9Yfij35aayQghq4Xtruet5C9dhhuUzK2CZ+ d3YqNFRVpyou2eNrp2a0PY1TfH0jRdom/Gyv95KZ7+O+sTqBVmuMoifnhQAwhz/O6I +thbwzrPtr5UJVdSyP4QNQlXSsrKp0pn1W1d7T0o= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Alexey Budankov , James Morris , Arnaldo Carvalho de Melo , Alexei Starovoitov , Andi Kleen , Igor Lubashev , Jiri Olsa , linux-man@vger.kernel.org, Peter Zijlstra , Serge Hallyn , Song Liu , Stephane Eranian , intel-gfx@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH 06/60] perf/core: Open access to the core for CAP_PERFMON privileged process Date: Mon, 20 Apr 2020 08:52:22 -0300 Message-Id: <20200420115316.18781-7-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Budankov Open access to monitoring of kernel code, CPUs, tracepoints and namespaces data for a CAP_PERFMON privileged process. Providing the access under CAP_PERFMON capability singly, without the rest of CAP_SYS_ADMIN credentials, excludes chances to misuse the credentials and makes operation more secure. CAP_PERFMON implements the principle of least privilege for performance monitoring and observability operations (POSIX IEEE 1003.1e 2.2.2.39 principle of least privilege: A security design principle that states that a process or program be granted only those privileges (e.g., capabilities) necessary to accomplish its legitimate function, and only for the time that such privileges are actually required) For backward compatibility reasons the 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_PERFMON capability. Signed-off-by: Alexey Budankov Reviewed-by: James Morris Tested-by: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andi Kleen Cc: Igor Lubashev Cc: Jiri Olsa Cc: linux-man@vger.kernel.org Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Serge Hallyn Cc: Song Liu Cc: Stephane Eranian Cc: Thomas Gleixner Cc: intel-gfx@lists.freedesktop.org Cc: linux-doc@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: selinux@vger.kernel.org Link: http://lore.kernel.org/lkml/471acaef-bb8a-5ce2-923f-90606b78eef9@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- include/linux/perf_event.h | 6 +++--- kernel/events/core.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 9c3e7619c929..87e21681759c 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1305,7 +1305,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); @@ -1313,7 +1313,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); @@ -1321,7 +1321,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); diff --git a/kernel/events/core.c b/kernel/events/core.c index bc9b98a9af9a..74025b7b83a0 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11504,7 +11504,7 @@ SYSCALL_DEFINE5(perf_event_open, } if (attr.namespaces) { - if (!capable(CAP_SYS_ADMIN)) + if (!perfmon_capable()) return -EACCES; } -- 2.21.1