Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp217092ybl; Mon, 12 Aug 2019 14:59:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjTHuBF4ecdHpdXjnxxjt4R9hD8NMPPPk4VG9pwJTNMw+8bStxVZbV7Kv99c8x+BhLjP9w X-Received: by 2002:a65:4505:: with SMTP id n5mr28723307pgq.301.1565647152900; Mon, 12 Aug 2019 14:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565647152; cv=none; d=google.com; s=arc-20160816; b=nkmVJLoypoV7BuEX2zahQHxyUBm/t3Hag90eku1tznErsEjKDaeMM8VwbSHMZBdyyu D4i3h2/7ZFC2jbL+/u2EuvJFyfLG5tI+HqaogCJHzoRuHB2faaQ9SkD524whPEj+weqf PQeerr8MZX/DEKdQgnn+5KKQF3/25iw+PHXEbKktRiq2ETfAKJrf4PFsgKNiV+fDAH8e qbXPO7Z/ICbdsBHi2FKe1eNs/KJW+iINJAMqp/IXe4qPUm9guwJgYoKgf0jPnf3cCTHf FwUC7tROcKTa+Fuf3mn7DhyDCnbGNbgN5uOOVHUYfQhJGfrGzjZpS4prvNTXvjOtvmzW jKRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=mzJd9LfyI6OyvkYy9nxABgF/o+uPg/L4uhRhKYYKXK8=; b=Xbi7sT0C2WFlM8WHXJNye3ufHyfBfo3/WMEOl7b1BWQylz31a6XwvJRCu8tw/1fVyP WJgrCLLQq9aSSry+bqMg9qsqGPpXmXJgGGfAFcoJ/Iw30/LQZ8V6osLaC8+bvSbN+Wim eI4l8ssQ0foUD1F7meEk4isLJcN+GYRzmHW4wbDPRdLegAgaAzbGa8HS8cTBrupB25Gi BmfGijN0sdT4uMti7OR9WYvNmPoqM/ozlo/mTzjgFvcsJ1QN8rKlmpDY//c/IpX9JOf0 ac9UPy2b4l64gf9mDVIG6KTxfblY58qiENHhgRC1YlFdtunnIYDrCwDiCQyEA1K6iHCB 5vrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T+ABqL6c; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y22si57222794plp.192.2019.08.12.14.58.57; Mon, 12 Aug 2019 14:59:12 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T+ABqL6c; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727206AbfHLUBl (ORCPT + 99 others); Mon, 12 Aug 2019 16:01:41 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:41740 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbfHLUBk (ORCPT ); Mon, 12 Aug 2019 16:01:40 -0400 Received: by mail-qk1-f194.google.com with SMTP id g17so7239917qkk.8 for ; Mon, 12 Aug 2019 13:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mzJd9LfyI6OyvkYy9nxABgF/o+uPg/L4uhRhKYYKXK8=; b=T+ABqL6cQJgPOi3/KuUg8dw9+u7TLkZl7ie+BEbOpts6p3A3W9mVODE3y46Nqai7kR X/Y8oXA6FHUXaU21ggo2fHUEnuLty4utTuLosncCtowhrw421B8HtDtcDNedK5VJw8WB CQoecsb0gLNIGPdcpTDScYJ8D/QGb34a380s3+/5r482y8yLTaGd81SuOLMnBErDd0lq w2RybkThge83juCWZ0bWRj7Wn3+CMhUQWzFGmDjj7kM0pA7ENhgnqUxs39oUbhqAYfXn coZLZzzxxGqqjw+5LEXeD+qn/tpmYXrP9UTfyDJjgRRPGvPNmfqmxkeUTvKVddz/vGNA uHqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mzJd9LfyI6OyvkYy9nxABgF/o+uPg/L4uhRhKYYKXK8=; b=l6bPVhFUrxwFY6PlxOlcdO4/D1JdvFetETt1KD88HWUEIts/wkj3xWo94XAumtyoQS zf7OvNh9pVEB7YeQil8xwPpchuxwqWx1La3s6Ws6JCx4+aUFG7C9GmuOMCP6EQ2n3tAQ woWyBzTOggGVu5ehoqYC4Bj2dI8CWbk5t1SNM3RcUhBgCxC+7920vXmluc/5nOH/ViRW DYUujAYQdyEdvdPdBDiV1A7Id7g8TvOJz6LXZ6wxShNcS9QitvyVtXOAhnx2/P/c9/4s WRcoMYtlGfDv/NY4yQP/fFFEqYBA8qMOeCV+St0qZfXiEwR0f2JV6TQKt4DNf9V7gvwk jNSw== X-Gm-Message-State: APjAAAX/WE3sEPxOxtQO3TF6WpkOoBePCezcthAM/Ce1nM4hVn4h97l+ yRJXx1SA8iFz7YuOwmwI/aM= X-Received: by 2002:ae9:f801:: with SMTP id x1mr28277094qkh.242.1565640099542; Mon, 12 Aug 2019 13:01:39 -0700 (PDT) Received: from quaco.ghostprotocols.net (187-26-98-68.3g.claro.net.br. [187.26.98.68]) by smtp.gmail.com with ESMTPSA id f22sm5634753qkh.55.2019.08.12.13.01.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:01:38 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id D585740340; Mon, 12 Aug 2019 17:01:34 -0300 (-03) Date: Mon, 12 Aug 2019 17:01:34 -0300 To: Igor Lubashev Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Alexey Budankov , Peter Zijlstra , Ingo Molnar , Mathieu Poirier , Alexander Shishkin , Namhyung Kim , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, James Morris Subject: Re: [PATCH v3 2/4] perf: Use CAP_SYS_ADMIN with perf_event_paranoid checks Message-ID: <20190812200134.GE9280@kernel.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Aug 07, 2019 at 10:44:15AM -0400, Igor Lubashev escreveu: > +++ b/tools/perf/util/evsel.c > @@ -279,7 +279,7 @@ struct evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) > static bool perf_event_can_profile_kernel(void) > { > - return geteuid() == 0 || perf_event_paranoid() == -1; > + return perf_event_paranoid_check(-1); > } While looking at your changes I think the pre-existing code is wrong, i.e. the check in sys_perf_event_open(), in the kernel is: if (!attr.exclude_kernel) { if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) return -EACCES; } And: static inline bool perf_paranoid_kernel(void) { return sysctl_perf_event_paranoid > 1; } So we have to change that perf_event_paranoit_check(-1) to pass 1 instead? bool perf_event_paranoid_check(int max_level) { return perf_cap__capable(CAP_SYS_ADMIN) || perf_event_paranoid() <= max_level; } Also you defined perf_cap__capable(anything) as: #ifdef HAVE_LIBCAP_SUPPORT #include bool perf_cap__capable(cap_value_t cap); #else static inline bool perf_cap__capable(int cap __maybe_unused) { return false; } #endif /* HAVE_LIBCAP_SUPPORT */ I think we should have: #else static inline bool perf_cap__capable(int cap __maybe_unused) { return geteuid() == 0; } #endif /* HAVE_LIBCAP_SUPPORT */ Right? So I am removing the introduction of perf_cap__capable() from the first patch you sent, leaving it with _only_ the feature detection part, using that feature detection to do anything is then moved to a separate patch, after we finish this discussion about what we should fallback to when libcap-devel isn't available, i.e. we should use the previous checks, etc. - Arnaldo