Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp218403ybl; Mon, 12 Aug 2019 15:00:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT/5Ilwg9tnTJMEOYFy4W/d6NyvPyMqrZtIP3nW5tL+yUY08x7KW/HHahh/gcSQQzR4O+Y X-Received: by 2002:a17:902:8205:: with SMTP id x5mr35281406pln.279.1565647243116; Mon, 12 Aug 2019 15:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565647243; cv=none; d=google.com; s=arc-20160816; b=nOgIWvg5itHt/GazFkJaQk1d7gfRIqIa5MFuVNivjBasuq+9NdB6GayyjzjWwoizo3 8I71BZHLD3BS+aLR8x6mneSFjGU9tadn3zExib+0gYvDFbEX0/Oe6A+ZTNOfdeI08/yI p/wq97RRBnb+/hD7cXQ9dS0tDU5ALxqQOPAuXRCIg55vMlabnrbGMaRKbw+Sm4BQrJTm HvHTnqbgV9+UjalXqM4HaFPxVCtUnZ1HeDxVmuhcdvy1IBq2fFqmSJnVO7L9DRBO1RL6 ocEXCpcpNeCvEPmcQXMLwgpDkhva6hClIXBEkNLt2NRDhAhnDon7Q8f+jfxtrDlWE2s9 0j9g== 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=5g7jjLU4VGzMwlr574F/Nchx2Tl+Lxpx7Ov3R6T4BKE=; b=U3rmI5D+Q3P8YB3E4zOzGRLB3cerE1QXuQfVeJZgJ1Ga2l0L67VU/pGFmR4T4zxdPS 3JtDZGYBImPwpPmk6Wu2BbgtWYh1LJhOKsQ1SWBn0VZtFAHGduSc40WulrXDsW5x731+ emcZVfUhvoNEIW1HGHzXUAkPW+72eh+VlKvMd87i9Z0kbXrVDGWSqWJjkxLpdp5wj1rJ awnXN6K+CHOOnUusQ49ncd4rzR+QZDkWgNafJHdSjctpPIdMNd2mLgcIg0g/XggQCu3B PEGPfpqMRk5s0sRgMpyTDNdS3kxh5qZI1+SRz0quHuY9lR4N6xHwDyQ/nou6yHFIEAkN bHbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i9t3qgma; 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 s198si68064443pfs.209.2019.08.12.15.00.27; Mon, 12 Aug 2019 15:00:43 -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=i9t3qgma; 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 S1727332AbfHLUQF (ORCPT + 99 others); Mon, 12 Aug 2019 16:16:05 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:39308 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbfHLUQF (ORCPT ); Mon, 12 Aug 2019 16:16:05 -0400 Received: by mail-qt1-f194.google.com with SMTP id l9so104097493qtu.6 for ; Mon, 12 Aug 2019 13:16:04 -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=5g7jjLU4VGzMwlr574F/Nchx2Tl+Lxpx7Ov3R6T4BKE=; b=i9t3qgmaJCsaeHHeK2nlpOJj47Gwd9m1UtLytdg5UDY0zjcoorUwSZzu/yRhxvQo5M iHJDjnl6Uunpv2ZEKwV3gFZqlqE2XptWcCehbcGKTyF1AHaunbVt/tFROPDUB5H4MgLQ EO8BP/vurIIEXahX3IsBfoUUNK5Ce3IuHIaRUIZAzBAalIMY3BBRQFvX3fF+LEjCo69f yeJcwAFMS/17W09iUh2XNBJdTXCsUJAeIeeSOMBbQ6yMM8p9IGzmTQTHk3HmlcT4RfMJ 2yNc5iEA73WZ8wQm/eLmQ3CyVFFFM2ZGMR2wUf29PfENq14xR38xrnntu93VRYxyZC+W 0fUg== 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=5g7jjLU4VGzMwlr574F/Nchx2Tl+Lxpx7Ov3R6T4BKE=; b=kLSmaZUOt8m6rQzEY2C43hy5UjO7K/6AfC9XBHTps3JP922d+UelDA1DQWWSJ74VDd Un8M+OyA2UwhDAlitTYRZy6NqCo0bBJz6vqTr5xH9c3iraTYzDpl/3lXsppWFYgkjrXu WO67b/w4nfol01YYnpDNLRIi4QoX1vJB6WDIB5M69R4L3Q2smd7p2C0cAWn4lpW5KXEO It09Tz2k7GeZOX910zu5hUVWtRor9JligRsHKxUvjNYZhoDY3ZwPCkGXqw/mnY2tGcLG 9WgSY7MFyUE/gYKNxl9F5W1RcWGDbw5vnE+dNzTZsdv7ITHTh5mJmz+8lWTOGdC32B4+ 65tQ== X-Gm-Message-State: APjAAAWvrFmbA2GMPp17CdKPONG2IeNhl8vmqjqaqcq92MHzhef1H3IN cN4j7c4e6T2N+uU/Frw0Eyo= X-Received: by 2002:ac8:296c:: with SMTP id z41mr5813520qtz.307.1565640963984; Mon, 12 Aug 2019 13:16:03 -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 d123sm49214177qkb.94.2019.08.12.13.16.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 13:16:01 -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 7243E40340; Mon, 12 Aug 2019 17:15:57 -0300 (-03) Date: Mon, 12 Aug 2019 17:15:57 -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: <20190812201557.GF9280@kernel.org> References: <20190812200134.GE9280@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190812200134.GE9280@kernel.org> 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 Mon, Aug 12, 2019 at 05:01:34PM -0300, Arnaldo Carvalho de Melo escreveu: > 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. So, please take a look at the tmp.perf/cap branch in my git repo: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf/cap I split the patch and made perf_cap__capable() fallback to 'return geteuid() == 0;' when libcap-devel isn't available, i.e. keep the checks made prior to your patchset. Jiri, can I keep your Acked-by? - Arnaldo