Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1514391ybz; Thu, 30 Apr 2020 00:17:52 -0700 (PDT) X-Google-Smtp-Source: APiQypKADsBmLL24rHWWdDiT62NOkQUfwGCg0gQ8sEOQLThOYY74ScilRjKg43JuYqSQCRXR/+Vk X-Received: by 2002:a05:6402:1a46:: with SMTP id bf6mr1384272edb.44.1588231072756; Thu, 30 Apr 2020 00:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588231072; cv=none; d=google.com; s=arc-20160816; b=GKT1qPpDuLIXa3pPfZYQZJjQxAgn9vh1XWQYe40U2NEP0nm6X3WDZxQbFLbeclvQBm 6YDom9VGCuKOkwRgE4xqGpd3gFsXa4TSqxPMrZtkmCA57llE5syf9DFbK+4Qw+SjHxxa BSofhdH+cHdhH+G0jMapKnCMjdcUoWSpUcG9QA0eHCQ78T7//Veb7mH88OpzD/uEWSxK SDiK2p4kiIpC/wvJxXLPeMtvO0C0pXcmyZdQxfYFufnJ8PAcBVUVVVazMZSpsa4QLMKg g6THa0jHKuzE9m8Z80emCnLDSu3TmBHSCLuclcffcXP2Oa4hm2nIKSzasFBMN6UHsyYC kumg== 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=2ZMGs1e5En/G8HFAbrBT3h5wP5pOyWQA+nXi9l41zZE=; b=S6+VRE8D9W0od4KxR+EUeeXbmz687xs+wSpLwVVjIMrseETLQyPIwagah/GrePB7fi 145fBymGH8k5dFR5/Bh+iMqNg6iTgvZYi1s6YAvu5UQNhzK2IqrH817v52etcu6Y27Zw lmHMnbUkF2pcAJGx9Y+TdkiHTaRNgjknbVkRg6P9r8pBuAEmepLZ3zkpDVjoLuWa+xCT XY/gQFRfzTxSsjzeTPCB98HQanuC/PdR9ZvIAjXgbMSVsrTbUHbYchOP8xQXJAyyNAk0 +4u56t6okU578nbR1NktqPpAvEeVhGn8Mr36O8iALkLpdQ2ky7ydeYWEQfT2AkuHDqrB SoEg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o24si4693794edr.456.2020.04.30.00.17.28; Thu, 30 Apr 2020 00:17:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726684AbgD3HQE (ORCPT + 99 others); Thu, 30 Apr 2020 03:16:04 -0400 Received: from mga11.intel.com ([192.55.52.93]:28453 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgD3HQE (ORCPT ); Thu, 30 Apr 2020 03:16:04 -0400 IronPort-SDR: 9xMGMNaUYrczB0xGHi7ocA5dickWwud1WKeUCb9VS4+Yw7ag3Vk6n/RNXXGoWXeGffGzXf6Njk 32AQBHw9APtQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2020 00:16:03 -0700 IronPort-SDR: fUD0gyVvzpYJBfzFPfp1dgMiGx+PpiFKZUmUCEeVOlrroMQyYvNrWRkNwADKEXKq4R/Jo0uUsz wK5j7ZOygVAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="405307891" Received: from linux.intel.com ([10.54.29.200]) by orsmga004.jf.intel.com with ESMTP; 30 Apr 2020 00:16:01 -0700 Received: from [10.249.229.126] (abudanko-mobl.ccr.corp.intel.com [10.249.229.126]) by linux.intel.com (Postfix) with ESMTP id 526905805EB; Thu, 30 Apr 2020 00:15:58 -0700 (PDT) Subject: [PATCH v3 2/3] perf tool: make Perf tool aware of SELinux access control From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel , "selinux@vger.kernel.org" , "linux-security-module@vger.kernel.org" References: <0fffd9e2-1f22-a0c2-c2e3-cb7f4bb89d66@linux.intel.com> Organization: Intel Corp. Message-ID: <819338ce-d160-4a2f-f1aa-d756a2e7c6fc@linux.intel.com> Date: Thu, 30 Apr 2020 10:15:57 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <0fffd9e2-1f22-a0c2-c2e3-cb7f4bb89d66@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 Implement selinux sysfs check to see the system is in enforcing mode and print warning message with pointer to check audit logs. Signed-off-by: Alexey Budankov --- tools/perf/util/cloexec.c | 4 ++-- tools/perf/util/evsel.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c index a12872f2856a..9c8ec816261b 100644 --- a/tools/perf/util/cloexec.c +++ b/tools/perf/util/cloexec.c @@ -65,7 +65,7 @@ static int perf_flag_probe(void) return 1; } - WARN_ONCE(err != EINVAL && err != EBUSY, + WARN_ONCE(err != EINVAL && err != EBUSY && err != EACCES, "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", err, str_error_r(err, sbuf, sizeof(sbuf))); @@ -83,7 +83,7 @@ static int perf_flag_probe(void) if (fd >= 0) close(fd); - if (WARN_ONCE(fd < 0 && err != EBUSY, + if (WARN_ONCE(fd < 0 && err != EBUSY && err != EACCES, "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", err, str_error_r(err, sbuf, sizeof(sbuf)))) return -1; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9fa92649adb4..bf437c059c2b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2514,32 +2514,41 @@ int perf_evsel__open_strerror(struct evsel *evsel, struct target *target, int err, char *msg, size_t size) { char sbuf[STRERR_BUFSIZE]; - int printed = 0; + int printed = 0, enforced = 0; switch (err) { case EPERM: case EACCES: + printed += scnprintf(msg + printed, size - printed, + "Access to performance monitoring and observability operations is limited.\n"); + + if (!sysfs__read_int("fs/selinux/enforce", &enforced)) { + if (enforced) { + printed += scnprintf(msg + printed, size - printed, + "Enforced MAC policy settings (SELinux) can limit access to performance\n" + "monitoring and observability operations. Inspect system audit records for\n" + "more perf_event access control information and adjusting the policy.\n"); + } + } + if (err == EPERM) - printed = scnprintf(msg, size, + printed += scnprintf(msg, size, "No permission to enable %s event.\n\n", perf_evsel__name(evsel)); return scnprintf(msg + printed, size - printed, - "You may not have permission to collect %sstats.\n\n" - "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n" - "which controls use of the performance events system by\n" - "unprivileged users (without CAP_PERFMON or CAP_SYS_ADMIN).\n\n" - "The current value is %d:\n\n" + "Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open\n" + "access to performance monitoring and observability operations for users\n" + "without CAP_PERFMON or CAP_SYS_ADMIN Linux capability.\n" + "perf_event_paranoid setting is %d:\n" " -1: Allow use of (almost) all events by all users\n" " Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n" - ">= 0: Disallow ftrace function tracepoint by users without CAP_PERFMON or CAP_SYS_ADMIN\n" - " Disallow raw tracepoint access by users without CAP_SYS_PERFMON or CAP_SYS_ADMIN\n" - ">= 1: Disallow CPU event access by users without CAP_PERFMON or CAP_SYS_ADMIN\n" - ">= 2: Disallow kernel profiling by users without CAP_PERFMON or CAP_SYS_ADMIN\n\n" - "To make this setting permanent, edit /etc/sysctl.conf too, e.g.:\n\n" - " kernel.perf_event_paranoid = -1\n" , - target->system_wide ? "system-wide " : "", - perf_event_paranoid()); + ">= 0: Disallow raw and ftrace function tracepoint access\n" + ">= 1: Disallow CPU event access\n" + ">= 2: Disallow kernel profiling\n" + "To make the adjusted perf_event_paranoid setting permanent preserve it\n" + "in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = )", + perf_event_paranoid()); case ENOENT: return scnprintf(msg, size, "The %s event is not supported.", perf_evsel__name(evsel)); -- 2.24.1