From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92BE0C2BB55 for ; Tue, 7 Apr 2020 17:23:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A0BC20719 for ; Tue, 7 Apr 2020 17:23:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AISqMdEd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726669AbgDGRXp (ORCPT ); Tue, 7 Apr 2020 13:23:45 -0400 Received: from mail-qk1-f175.google.com ([209.85.222.175]:43015 "EHLO mail-qk1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbgDGRXp (ORCPT ); Tue, 7 Apr 2020 13:23:45 -0400 Received: by mail-qk1-f175.google.com with SMTP id 13so137941qko.10; Tue, 07 Apr 2020 10:23:44 -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; bh=K+MMhgwbQedUfosyD2Cw+pAjWD5r/4ySukc35JXfHtQ=; b=AISqMdEd8PmC6p044QKzmqRvTEknmQL37J3YiXyuydqqLA9II7+ikNL1/d1tev4diw 4quCsK0SbFHe16ewvETijwjSegnewllWpsYE9/RmuzbJzWeof90cD8xTKghvASkb5YCH dRKhp4Rea3pGc0yerTbItjCt5X7Q8nHrSdPObogOtuRJj1IWe5klvpHR/WnB/7mbgXra voptzu1KNaqfjBPeOBjpm5QxutfUDr8T9uglWizgQ6zcyAGPT2NqX77iU7bjsLV8ATIV g/ERhpCiQDGEaTqr22AW+xneH6DFGgLRiqvNdYmUHEv4QCOZCr7VYviX87oE7r/2kDCY WuDA== 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; bh=K+MMhgwbQedUfosyD2Cw+pAjWD5r/4ySukc35JXfHtQ=; b=LuX7QPV7b5FuRkuH4V4jH96qruJE8eVNWyap3qt0UFGZmjngmzOZVTKeKPW4wnT97x adCKBQXNeMPhp6T5m+4vLyvBxTkeoyAGssjPQIondu1kEFvV7Wdru/RG90m7bpV5dqRt 9bqgF/+gY1aOV7olcmyAa6XFpugNXLePsW+yQgkq6rieff0ScI1fUuXwRDdyhIvPK5kl zBPJofjeKEZm+z0heIIrFUVSImPhs1iXYqoQdq4zVP1YVcSl/O5oFGHBGlxBSfPZlqWX QSKapXg4x0ygbbPNzkDZNodBaBL1JdAIQffzLaVN90dV2Mdy6EV/wqPdI0iahEpK5h9B SfEg== X-Gm-Message-State: AGi0Pub9nqPDtu/LrsIvhmIaQzaaP7bFmsvfwFwAU+qM3wIZQGhqLnDQ xae0A59xh01MemnOfhbkv+0= X-Google-Smtp-Source: APiQypKsro8wjK4xTL2iHaRs1nV2makOkwiSA9zQ+y+DTWaEm6VBA1HeGxqxnp89G+j6RhEQBYILJg== X-Received: by 2002:a37:6213:: with SMTP id w19mr3134388qkb.447.1586280222882; Tue, 07 Apr 2020 10:23:42 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id l7sm16781124qkb.47.2020.04.07.10.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 10:23:42 -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 1678C409A3; Tue, 7 Apr 2020 14:23:40 -0300 (-03) Date: Tue, 7 Apr 2020 14:23:40 -0300 To: Arnaldo Carvalho de Melo Cc: Alexey Budankov , Peter Zijlstra , Alexei Starovoitov , Ingo Molnar , James Morris , Namhyung Kim , Serge Hallyn , Jiri Olsa , Song Liu , Andi Kleen , Stephane Eranian , Igor Lubashev , Thomas Gleixner , linux-kernel , "linux-security-module@vger.kernel.org" , "selinux@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "linux-doc@vger.kernel.org" , linux-man@vger.kernel.org Subject: Re: [PATCH v8 00/12] Introduce CAP_PERFMON to secure system performance monitoring and observability Message-ID: <20200407172340.GF12003@kernel.org> References: <20200407143014.GD11186@kernel.org> <20200407143551.GF11186@kernel.org> <10cc74ee-8587-8cdb-f85f-5724b370a2ce@linux.intel.com> <20200407163654.GB12003@kernel.org> <20200407165643.GD12003@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200407165643.GD12003@kernel.org> X-Url: http://acmel.wordpress.com Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Em Tue, Apr 07, 2020 at 01:56:43PM -0300, Arnaldo Carvalho de Melo escreveu: > > But then, even with that attr.exclude_kernel set to 1 we _still_ get > kernel samples, which looks like another bug, now trying with strace, > which leads us to another rabbit hole: > > [perf@five ~]$ strace -e perf_event_open -o /tmp/out.put perf top --stdio > Error: > You may not have permission to collect system-wide stats. > > Consider tweaking /proc/sys/kernel/perf_event_paranoid, > which controls use of the performance events system by > unprivileged users (without CAP_PERFMON or CAP_SYS_ADMIN). > > The current value is 2: > > -1: Allow use of (almost) all events by all users > Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK > >= 0: Disallow ftrace function tracepoint by users without CAP_PERFMON or CAP_SYS_ADMIN > Disallow raw tracepoint access by users without CAP_SYS_PERFMON or CAP_SYS_ADMIN > >= 1: Disallow CPU event access by users without CAP_PERFMON or CAP_SYS_ADMIN > >= 2: Disallow kernel profiling by users without CAP_PERFMON or CAP_SYS_ADMIN > > To make this setting permanent, edit /etc/sysctl.conf too, e.g.: > > kernel.perf_event_paranoid = -1 > > [perf@five ~]$ > > If I remove that strace -e ... from the front, 'perf top' is back > working as a non-cap_sys_admin user, just with cap_perfmon. > So I couldn't figure it out so far why is that exclude_kernel is being set to 1, as perf-top when no event is passed defaults to this to find out what to use as a default event: perf_evlist__add_default(top.evlist) perf_evsel__new_cycles(true); struct perf_event_attr attr = { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES, .exclude_kernel = !perf_event_can_profile_kernel(), }; perf_event_paranoid_check(1); return perf_cap__capable(CAP_SYS_ADMIN) || perf_cap__capable(CAP_PERFMON) || perf_event_paranoid() <= max_level; And then that second condition should hold true, it returns true, and then .exclude_kernel should be set to !true -> zero.o Now the wallclock says I need to stop being a programmer and turn into a daycare provider for Pedro, cya! - Arnaldo