Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3537985ybz; Mon, 20 Apr 2020 04:55:56 -0700 (PDT) X-Google-Smtp-Source: APiQypIW5zpozopWuyTHmM4lJkMiHHQ6wI7DfHZ+0Dq2XVgK2hZ5H7IZWXHxMYoEl+igydMrl9so X-Received: by 2002:aa7:c606:: with SMTP id h6mr4859959edq.265.1587383756556; Mon, 20 Apr 2020 04:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383756; cv=none; d=google.com; s=arc-20160816; b=cltse2CJm35RpawG6IlKGIOPbXp3LUuVzW++PSCCz4/SJ49kSnn6oeyuhBX6pd7sOK 2/eKBx0bLLucTAsDSGpGSfjYqz08NgL+2mBMGbFcQ+1WH33sVYbqAO6JbrCYT7LcOxkS tACPPaCYkyriydrbIOtS2lypM9lXUXJ/e081rkEAu7jE2DIXnScwCiWvul3Vh1sH6qN7 irzEJxxMThzA7dCULh9QvhgEVnwkvMLyQw5yjFJaBlxSjidDBVXsFGOKWW+G2Hp8BljD Mk90mc/YNM+eJRi7tkhZFbUBKTV3K1Jq3DXrmw5a6jnUAhZhlGkrQJMGWMcMhaAvQrE0 N/cQ== 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=fIddB8o2OTHJ1VIEMFydvigg29lpIf10LE+fZGswO5A=; b=soh2hTFMMMSpPRIcBgXwy2qkrJAvZw4nP8df0o3unO6e8d3zB4tluqsyMz7HVT1Qo/ uz35AMBroJ9xc8TVdsFJD70HBuLfLdfEDcpy9P/lhJNBr4yNl25e0ue2Qj/4mdwbSlPJ 0jOCspX1NQLR9LnRC3P9E0l9nMRIQJW6tBV4hcYNORnViEtBvD6OLwlkISoh2la7CMNn IcCQAipGlyV4n7q9GeuBZkqdZLWMPnj842l9umSdgwKi7JksIcw4oTBpMqN86Cvc/m2s hHk0QN1MSfWOLZpkbtQrK/+chD9QRTmYdsoRZ69R8hWq8wFVzyu8MUcClzo35YZi16Ga 6WMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rNdaTZCI; 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 b18si419255ejb.281.2020.04.20.04.55.33; Mon, 20 Apr 2020 04:55:56 -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=rNdaTZCI; 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 S1726711AbgDTLyP (ORCPT + 99 others); Mon, 20 Apr 2020 07:54:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgDTLyL (ORCPT ); Mon, 20 Apr 2020 07:54:11 -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 A42EA206D4; Mon, 20 Apr 2020 11:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383651; bh=KcU35D57021g0uqwoqjTd5rmvJznq2uTIrvtUOTNjoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNdaTZCIqUpvS2/vtJgLe1A/O/b62vWFcdSB0uWWp514bDGzm+/OnU23mIyftpmFn c2KI+6Qr0SEbpUkGpBtgl8oH4TunkeFPTGDCnWwHuO5DQlrpqfVJ9hQXTCeAAY/KAG 3+kQQupT+ZflY0kILRangxmd174cJvhZC+CKjCGg= 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 , Lionel Landwerlin , 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-man@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 09/60] drm/i915/perf: Open access for CAP_PERFMON privileged process Date: Mon, 20 Apr 2020 08:52:25 -0300 Message-Id: <20200420115316.18781-10-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 i915_perf monitoring 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. 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 i915_events subsystem remains open for CAP_SYS_ADMIN privileged processes but CAP_SYS_ADMIN usage for secure i915_events monitoring is discouraged with respect to CAP_PERFMON capability. Signed-off-by: Alexey Budankov Reviewed-by: James Morris Acked-by: Lionel Landwerlin 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-man@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: selinux@vger.kernel.org Link: http://lore.kernel.org/lkml/e3e3292f-f765-ea98-e59c-fbe2db93fd34@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- drivers/gpu/drm/i915/i915_perf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index 551be589d6f4..5fb174931231 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -3433,10 +3433,10 @@ i915_perf_open_ioctl_locked(struct i915_perf *perf, /* Similar to perf's kernel.perf_paranoid_cpu sysctl option * we check a dev.i915.perf_stream_paranoid sysctl option * to determine if it's ok to access system wide OA counters - * without CAP_SYS_ADMIN privileges. + * without CAP_PERFMON or CAP_SYS_ADMIN privileges. */ if (privileged_op && - i915_perf_stream_paranoid && !capable(CAP_SYS_ADMIN)) { + i915_perf_stream_paranoid && !perfmon_capable()) { DRM_DEBUG("Insufficient privileges to open i915 perf stream\n"); ret = -EACCES; goto err_ctx; @@ -3629,9 +3629,8 @@ static int read_properties_unlocked(struct i915_perf *perf, } else oa_freq_hz = 0; - if (oa_freq_hz > i915_oa_max_sample_rate && - !capable(CAP_SYS_ADMIN)) { - DRM_DEBUG("OA exponent would exceed the max sampling frequency (sysctl dev.i915.oa_max_sample_rate) %uHz without root privileges\n", + if (oa_freq_hz > i915_oa_max_sample_rate && !perfmon_capable()) { + DRM_DEBUG("OA exponent would exceed the max sampling frequency (sysctl dev.i915.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n", i915_oa_max_sample_rate); return -EACCES; } @@ -4052,7 +4051,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, return -EINVAL; } - if (i915_perf_stream_paranoid && !capable(CAP_SYS_ADMIN)) { + if (i915_perf_stream_paranoid && !perfmon_capable()) { DRM_DEBUG("Insufficient privileges to add i915 OA config\n"); return -EACCES; } @@ -4199,7 +4198,7 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; } - if (i915_perf_stream_paranoid && !capable(CAP_SYS_ADMIN)) { + if (i915_perf_stream_paranoid && !perfmon_capable()) { DRM_DEBUG("Insufficient privileges to remove i915 OA config\n"); return -EACCES; } -- 2.21.1