Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5925459ybl; Tue, 14 Jan 2020 17:53:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxx1aXqWcgde/fU1FO7EOeKk3uMpVfhOVs99gzxMhTdynyRI+VqDhmfnHDzgARwQK0BEmp+ X-Received: by 2002:aca:a997:: with SMTP id s145mr3118518oie.71.1579053236921; Tue, 14 Jan 2020 17:53:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579053236; cv=none; d=google.com; s=arc-20160816; b=PZQMlVU0y0r2YxV0eIAinRNo9KrjWO/M0oqQwOAkHL/zlXRYbpQlHIanjmhaQeg7sz 0LtWSG+hz0T0zD10iOSUB76a+RbuKmfQGKZCu6FcAxlsUgArOMoPtS0IVMOUphLVRDaG bP24PTEsFXFeHdwpzrxJBXzC5FQUL+j63mlyJXOBzyN94ML8hK4MoPLmvJz1Pgk9F+85 D9PM9q1E+YdLMOkfmqQXXbmxPjP3TQR/2w10IW9v8tnYs/Z/mYSNslolR2cRzDmyi2SH gCylYKETqlOatwl6yXlWTm6bJ/+H6/SPlTaWBsElHU0hXNwf3w6lRgJwKHFRXLQPgUEZ lMrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oXKHVjTE5Nw21ta6HwRqU340V5Tey9xgPPm24w/G8F8=; b=u0Fqi4angcQqFUxnd/uOKt4HjWN45VOQLZXcGx4VzecKdNsmasc6Jk1sbZY8+oCvPZ XHUxgILlfR7TfmvxL2qqpW4pOb9fzCGut9+pNoaM95Sb/OHZEMbpF/CFI3UAP3XfStxI Pmy3RDzSW+TkJUYH9l1hb1wCWMUTW+fDF3N2wGJ9xV3wxGsd+ChDbA45h5yViPlmKuQ9 72vNGCGZj0to6Vg2HaMc5kPQHPI5TSRGNnItlogs8Nu1T8IHz8QEdtM9U0XeXGXb0DEx Ac23y1tJFpxg+OMHIPpBrnSK9jGQIl1Ar6M8nqLGbwGnyzu0KFpmNlrnwePaj3S8kqbI Zw/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uFZWzzez; 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 q17si13138182otr.219.2020.01.14.17.53.45; Tue, 14 Jan 2020 17:53:56 -0800 (PST) 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=uFZWzzez; 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 S1728913AbgAOBwZ (ORCPT + 99 others); Tue, 14 Jan 2020 20:52:25 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:33511 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728834AbgAOBwZ (ORCPT ); Tue, 14 Jan 2020 20:52:25 -0500 Received: by mail-lf1-f66.google.com with SMTP id n25so11444991lfl.0 for ; Tue, 14 Jan 2020 17:52:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oXKHVjTE5Nw21ta6HwRqU340V5Tey9xgPPm24w/G8F8=; b=uFZWzzezm1sxsihg6k6KhkykaB23jIOQIkig6kbKFlK5U6GqfHyB2fkMZN5Zk+Tj6j RNJ2GTG+s0hBPXd26F2uc70+F5P7XGfJal5n0wDC5YO9p+iDZM+rTSjag6G1aEMyxJnJ zvMZ/R/+1vKHf6qMLHL30Nnw+kJU1Bpf9UCXrIBwfG/45wDx/xlczRrCtPXxjgsXp2QN IQfphm1NiQAZRJRKZwCxPU3QZEvkrXQzu2dCKuNMQbF7tl921A2Zvp/MmOCPEfz3r98s KouGGxrLiDGmBEAahPL1BtzsBlnHHROHInGcW/7VOgUBDOql3C0P2eDD4zN/jn70e18i Kmjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oXKHVjTE5Nw21ta6HwRqU340V5Tey9xgPPm24w/G8F8=; b=BIj7bOt4wn7X6oaSTq1KamLSEnrIG5BpdohTj8UOtNAbjlurOXC/1OhOAkRSzpuTtt 9kMW538fXKJSsbJ/zIKJTjJJGfQtwiUogHCyvsRpG19K9REWu3IBpr0WkabOWiVctyph 1Jz5oxesuWVfjZH5mdg03mgBncFFsdhhQaL2QSlI9JBNF4dpFyTcNxoDFLRuPYLMbelj dV0wdX846BkxiJhUhS2m7zK/vwMcKYDaCVxJdZ9DHIi9IDkpHCtfGPW5jDR+2H1x7+FT HMdUSyxkiKgsiDC3awV21uKiXw8n4SC4nd+7yNfba5pkOlUWiU/T0AGE479XYnHUG9Xb 6hRg== X-Gm-Message-State: APjAAAXXQMi+/EIhDYkE0svENvljQzbBa8FCFDVt0GtYEEamxMDk/7Oj yXwgvR2RSEmMovsgTG3H1f7ukMsQVZdaU5FI6+4= X-Received: by 2002:ac2:4422:: with SMTP id w2mr3324584lfl.178.1579053142405; Tue, 14 Jan 2020 17:52:22 -0800 (PST) MIME-Version: 1.0 References: <20200108160713.GI2844@hirez.programming.kicks-ass.net> <20200110140234.GO2844@hirez.programming.kicks-ass.net> <20200111005213.6dfd98fb36ace098004bde0e@kernel.org> <20200110164531.GA2598@kernel.org> <20200111084735.0ff01c758bfbfd0ae2e1f24e@kernel.org> <2B79131A-3F76-47F5-AAB4-08BCA820473F@fb.com> <5e191833.1c69fb81.8bc25.a88c@mx.google.com> <158a4033-f8d6-8af7-77b0-20e62ec913b0@linux.intel.com> <20200114122506.3cf442dc189a649d4736f86e@kernel.org> <81abaa29-d1be-a888-8b2f-fdf9b7e9fde8@linux.intel.com> <257a949a-b7cc-5ff1-6f1a-34bc44b1efc5@linux.intel.com> In-Reply-To: <257a949a-b7cc-5ff1-6f1a-34bc44b1efc5@linux.intel.com> From: Alexei Starovoitov Date: Tue, 14 Jan 2020 17:52:10 -0800 Message-ID: Subject: Re: [PATCH v4 2/9] perf/core: open access for CAP_SYS_PERFMON privileged process To: Alexey Budankov Cc: Masami Hiramatsu , Arnaldo Carvalho de Melo , Song Liu , Peter Zijlstra , Ingo Molnar , "jani.nikula@linux.intel.com" , "joonas.lahtinen@linux.intel.com" , "rodrigo.vivi@intel.com" , Alexei Starovoitov , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "james.bottomley@hansenpartnership.com" , Serge Hallyn , James Morris , Will Deacon , Mark Rutland , Casey Schaufler , Robert Richter , Jiri Olsa , Andi Kleen , Stephane Eranian , Igor Lubashev , Alexander Shishkin , Namhyung Kim , linux-kernel , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 14, 2020 at 10:50 AM Alexey Budankov wrote: > > > On 14.01.2020 21:06, Alexei Starovoitov wrote: > > On Tue, Jan 14, 2020 at 1:47 AM Alexey Budankov > > wrote: > >>>> > >>>> As we talked at RFC series of CAP_SYS_TRACING last year, I just expected > >>>> to open it for enabling/disabling kprobes, not for creation. > >>>> > >>>> If we can accept user who has no admin priviledge but the CAP_SYS_PERFMON, > >>>> to shoot their foot by their own risk, I'm OK to allow it. (Even though, > >>>> it should check the max number of probes to be created by something like > >>>> ulimit) > >>>> I think nowadays we have fixed all such kernel crash problems on x86, > >>>> but not sure for other archs, especially on the devices I can not reach. > >>>> I need more help to stabilize it. > >>> > >>> I don't see how enable/disable is any safer than creation. > >>> If there are kernel bugs in kprobes the kernel will crash anyway. > >>> I think such partial CAP_SYS_PERFMON would be very confusing to the users. > >>> CAP_* is about delegation of root privileges to non-root. > >>> Delegating some of it is ok, but disallowing creation makes it useless > >>> for bpf tracing, so we would need to add another CAP later. > >>> Hence I suggest to do it right away instead of breaking > >>> sys_perf_even_open() access into two CAPs. > >>> > >> > >> Alexei, Masami, > >> > >> Thanks for your meaningful input. > >> If we know in advance that it still can crash the system in some cases and on > >> some archs, even though root fully controls delegation thru CAP_SYS_PERFMON, > >> such delegation looks premature until the crashes are avoided. So it looks like > >> access to eBPF for CAP_SYS_PERFMON privileged processes is the subject for > >> a separate patch set. > > > > perf_event_open is always dangerous. sw cannot guarantee non-bugginess of hw. > > Sure, software cannot guarantee, but known software bugs could still be fixed, > that's what I meant. > > > imo adding a cap just for pmc is pointless. > > if you add a new cap it should cover all of sys_perf_event_open syscall. > > subdividing it into sw vs hw counters, kprobe create vs enable, etc will > > be the source of ongoing confusion. nack to such cap. > > > > Well, as this patch set already covers complete perf_event_open functionality, > and also eBPF related parts too, could you please review and comment on it? > Does the patches 2/9 and 5/9 already bring all required extentions? yes. the current patches 2 and 5 look good to me. I would only change patch 1 to what Andy was proposing earlier: static inline bool perfmon_capable(void) { if (capable_noaudit(CAP_PERFMON)) return capable(CAP_PERFMON); if (capable_noaudit(CAP_SYS_ADMIN)) return capable(CAP_SYS_ADMIN); return capable(CAP_PERFMON); } I think Andy was trying to preserve the order of audit events. I'm also suggesting to drop SYS from the cap name. It doesn't add any value to the name.