Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3537852ybz; Mon, 20 Apr 2020 04:55:46 -0700 (PDT) X-Google-Smtp-Source: APiQypLZaJzdqaOCmIqGWJIbbm8CR8tEsCjdYCIaCSP43aunDXo39Gq3e81C2qwHupDg4IKrfwBn X-Received: by 2002:a05:6402:31b6:: with SMTP id dj22mr14201960edb.258.1587383746023; Mon, 20 Apr 2020 04:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383746; cv=none; d=google.com; s=arc-20160816; b=P9OBujHOQjGCgEVYmYi0pJX9l/Af/1v2ZL5ob7dxp7NqKtCW3NJuBDKeIzDN6Br5fs c5KJDpQaSakpEYattOgp6LUSbyR/h7TPVUpRKi2UjO3BY7RlFa7xF396AMdVs6Puo6Ig ZlEqdkkaLNHb7/4O1FVHMMO0in3BeL5KnvxHNWkKF2tKUqLA1TxQto0BpqA5wMr//6sT Km2sCnKueuejkwLxSjoagvRA2YHc0MSoinoXfRJkVGrH3yWzedU60bc5PKKipD82aBkI opdNQPDJVcmXzFVXYvxCP7WW0lAAPqQrfrq9sCe2Gb+6VHDCxtQ/Srs3EA5/SX/p8XVY mthQ== 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=2nF6Q3mWLQso3hiDUSK9MdJFeoJFE7TPBB5PDuqjUL8=; b=dqzSSicbGHUAn9/XHtQlsqS6b+nm9iLErs3OXEH0ee/uJ8b1x+6JzyHiLnQdlbJmT1 TvIYXbGga9oEfHQ7H0lnmUXnp5hnI7ILrgIY1Ix8YhneCEPzv0w9s78uCUqEVQVXM0pB NpFboLns4n4BXNeafR+YT44pvG+C2w1nlOx/EOOEFHlZIjPbf+O88dUznECoJcRkq9a0 t2hyP5CcZy2K3HudXx/vRybQADYANKzVnVg6+egCB7TKejiUNQ9VEcRDq8mVWeW91fLs gLm1t3RTtVKI6u6vzzwPpGwwqbLt080Qx5CMA6i0mvSR8beqUX00CISzjhCXScrHuRuI a7/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cuxBGSfR; 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 cc27si446457edb.544.2020.04.20.04.55.23; Mon, 20 Apr 2020 04:55:46 -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=cuxBGSfR; 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 S1726668AbgDTLyB (ORCPT + 99 others); Mon, 20 Apr 2020 07:54:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:37386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgDTLyA (ORCPT ); Mon, 20 Apr 2020 07:54:00 -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 87015214AF; Mon, 20 Apr 2020 11:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383639; bh=+xEoiGPexvXw2sKFmZsWTCkSb2u7zsmlJFePteV0FYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cuxBGSfRM4mRwroR4FIXEnNSGjpXChR/18QORf1aWO5Ws3tHERNUr2V8I9rGMPfTV 9Qg0223aE3K1su8NJ0dtffFB+M/XgJ4IJPHFvutrKex5xDUZOQ9S4Ed61HkCr7WdfY OrYbuTChIvtETvHspP58GF4PXceYL9cN2mv2ihrY= 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 , 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, linux-man@vger.kernel.org Subject: [PATCH 07/60] perf/core: open access to probes for CAP_PERFMON privileged process Date: Mon, 20 Apr 2020 08:52:23 -0300 Message-Id: <20200420115316.18781-8-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 via kprobes and uprobes and eBPF tracing for 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. perf kprobes and uprobes are used by ftrace and eBPF. perf probe uses ftrace to define new kprobe events, and those events are treated as tracepoint events. eBPF defines new probes via perf_event_open interface and then the probes are used in eBPF tracing. 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 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: 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 Cc: linux-man@vger.kernel.org Link: http://lore.kernel.org/lkml/3c129d9a-ba8a-3483-ecc5-ad6c8e7c203f@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- kernel/events/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 74025b7b83a0..52951e9e8e1b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9397,7 +9397,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; /* @@ -9457,7 +9457,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; /* -- 2.21.1