Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6073210ybl; Tue, 14 Jan 2020 21:17:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwDfwb3UTcA/TkGn7HyZgmKDc0kCfvyasNOlWnsat29yV57N2r6tFMBftKaGBRbipE4KOoP X-Received: by 2002:a54:4e08:: with SMTP id a8mr20386074oiy.77.1579065441854; Tue, 14 Jan 2020 21:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579065441; cv=none; d=google.com; s=arc-20160816; b=PixlmuKjkfed2ZEVTgMFWs3ImD0TwCGO7k+8us2gsKOL29E0bxcBKjbClE8lFZvwoX ysWjgpehNrvnqlgWE0695hQ8kq5hlqpegLl8t95JMqkMeelnNEIKNdRTHDS/W7eGq9pT BCY3+6u6sNvWuaVFcFSmUAVcHWGpsParGzK3nelMt1MOxx01KYm3/plPpQKRwPub8D8G q3o3z4jkYxc77fPgGqfR+qrGP3QYwNoHbWWaJcwBDS6a9g8ABGdpz7EFR64GZ7nc+T8y HQCA4WWeZcOyeFysQayiEV1p39l5ndp9IjxArt+++q8sYjI5Yhpgt5AHNPLYE7DH84wx TDcQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=+QAQi6TtVCDQNeNxb9hTn5dAlD49rVWxL1dN/4tdTDY=; b=ooJl4LGUebjuwCtjnsICl7uVICLoNDZc1fvPSwhdvP5dgweWIf+j8RTMpAmrshvJRY kDERSnF8AoFniDaIlp9Q0oTbXFylQIXC/zyMfuh3fOHDwQ8l+bzYQAuTA5z9MJ/3PIdB p3c6bpkDWEY/Hho0TxWs0kDNyZIWWgp0v44eooqQOeVGxPLqi8/VYu2Rw5qyxKgwbKjB 93NZGd7yPXgQbuBIdrfLtj0na9SLXo5yK4e0+hQCtpN+xRcSNIoIDYHGRokGdArsH0+D WYHDuNLBWdBvhzERQITCoJ5C+taaol36eZQOyuXTR4pUX2EC4VlLPBoEbicIsCE+Tifa uW6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si9938454otr.293.2020.01.14.21.17.09; Tue, 14 Jan 2020 21:17:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726483AbgAOFPV (ORCPT + 99 others); Wed, 15 Jan 2020 00:15:21 -0500 Received: from mga12.intel.com ([192.55.52.136]:60301 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbgAOFPV (ORCPT ); Wed, 15 Jan 2020 00:15:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 21:15:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,321,1574150400"; d="scan'208";a="248284425" Received: from linux.intel.com ([10.54.29.200]) by fmsmga004.fm.intel.com with ESMTP; 14 Jan 2020 21:15:19 -0800 Received: from [10.252.24.8] (abudanko-mobl.ccr.corp.intel.com [10.252.24.8]) by linux.intel.com (Postfix) with ESMTP id 6688E5802B0; Tue, 14 Jan 2020 21:15:12 -0800 (PST) Subject: Re: [PATCH v4 2/9] perf/core: open access for CAP_SYS_PERFMON privileged process To: Alexei Starovoitov 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 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> From: Alexey Budankov Organization: Intel Corp. Message-ID: <40881285-ce6c-e6f1-1272-feb86eef0973@linux.intel.com> Date: Wed, 15 Jan 2020 08:15:10 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15.01.2020 4:52, Alexei Starovoitov wrote: > 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. Thanks. I appreciate your cooperation. > I would only change patch 1 to what Andy was proposing earlier: Could you please share the link to the proposal to get more details? In this patch set discussion there was only this [1] on more generic naming of PERFMON cap from Andi Kleen. > > 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); > } Yes, this makes sense and adds up. > 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. Agreed, CAP_PERFMON sounds more generic, as it actually is. Gratefully, Alexey [1] https://lore.kernel.org/lkml/20191211203648.GA862919@tassilo.jf.intel.com/