Received: by 2002:a17:90a:37e8:0:0:0:0 with SMTP id v95csp7140124pjb; Wed, 16 Oct 2019 00:42:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKerm/q3gSZfNRIjIFdi96JfqVd0F4gL+WejWAR3V9m7KmD9TKdhkiL5P7iUfjLFwJC1xs X-Received: by 2002:a50:8e53:: with SMTP id 19mr37813045edx.134.1571211771366; Wed, 16 Oct 2019 00:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211771; cv=none; d=google.com; s=arc-20160816; b=Ewv7geikvSy4sj3ymnYJyw9uGk9pYPG1q7wK3TIF65lpPHPmOggWEIGyxhQYc7192b en03QvSWg/mH8abn24TSFd0zeF1WHqVbs32fNrgD0hvgmEjCVlwOI+fe14MKfrs4Va2j OyNsPChSIpncBcty2y/t6y+8gseFkBYBAJKT2+4IXLxgLuLAeay4iXphOoOqLlWKzwlQ UtzsbzGxxxpZENEPPKA4Tnc4Ff6KbdWFYXIEOpMfzEfEYQYJQ67gLBd8YTXdT1CebJn7 wLe7cC9FmDkvDSkQ4BGtA1GQOizOEriG5KYKeQqpyBHnJXW1KS/XBJFB4w74tUMSLDlh 4qYg== 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:from:date:dkim-signature; bh=FArNhP5DErG1Ml8KyApc8sefVsVeEkXB1R/x3hburN4=; b=RdrENBiQ85Vt/qWQTcym0FtiGXkaopMQC3jIxUuu3QK7ePv1qSL7sZoNttVYBTArQK is60kt2ReWL0rr/egMtVYo6nUVvOofko+Q2KjkBPOLXbGc8OGzq4bgNP23itcCBncioj 2h2OeorjBvG45siHYCrOQNtLIQkuKaoiWvHPuthoqKbyGtgemLbg/qKz2uHds1y2AgDo F4vwldeW/hq2EbWPtWd/Fc+2cobyi/yP5IjnFzwfyc5XNpyhvTPYUqC852W+NnYJgMEg 73YpSoAz1GPY7ntzawMvs50H+PcFSM1fW9h4aE7UdICFT4l00OQYju/sFnOKau4KdzCw XDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=spCA93Ua; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14si14343980ejc.421.2019.10.16.00.42.28; Wed, 16 Oct 2019 00:42:51 -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=@joelfernandes.org header.s=google header.b=spCA93Ua; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389301AbfJPAU7 (ORCPT + 99 others); Tue, 15 Oct 2019 20:20:59 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35346 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387839AbfJPAU6 (ORCPT ); Tue, 15 Oct 2019 20:20:58 -0400 Received: by mail-pg1-f194.google.com with SMTP id p30so13155117pgl.2 for ; Tue, 15 Oct 2019 17:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FArNhP5DErG1Ml8KyApc8sefVsVeEkXB1R/x3hburN4=; b=spCA93UaswCGNF4+9dxS76ppeuge4nCJObXdAVsO+DyOAjtvUhxuUh2UED/IGfCjRH 93J+lDuNj0qTeQPUQjazdhSJGko8AmpP9WCUNFdRRKtKTeniyybLertUuZbphTNtzmt8 WYxa7hSzDwEjn+pW9BaYyoCrx6LexNpNgsGvM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FArNhP5DErG1Ml8KyApc8sefVsVeEkXB1R/x3hburN4=; b=TRjK1Pws+pNxW0++oCUg5pZUYga5Poh0xF5AqD8O6Ko9Xp5MpMt+wrcCXy0d+iI4vn mSm0tYjkIA+w/HJWbPbq7GxTTalW7ZC3wEWjBFnPdiE+9LJWOBsx42Rbq53ssfbMYnOw q+ZJmbHIAy3QS0tJIOQs4snk9LRMXqboC2HZPHvaJbyXmDggpmqSTdXU85XK+pSiTssl 6cDo4UPiXAxn6GluSqqaw+9mdPgagtLMIC1V7s4twXltaq1GwRYb6r6pUMA0ZZLf7QGU RTlcBenWO6uri8nswXkkGzIgb6yctDt/M8wLpFrXL/j2dkZEVDPhxSBGgi8zJ7eNRo45 vB7w== X-Gm-Message-State: APjAAAXd1S6DcgrfFoV+NNPyU2mz3TJXinbtoczH1ceNKK3z+44I0RWv Y164Kl1gyIN47FdBdHDYlbn9cQ== X-Received: by 2002:a17:90a:3608:: with SMTP id s8mr1480635pjb.44.1571185257717; Tue, 15 Oct 2019 17:20:57 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id l62sm24553103pfl.167.2019.10.15.17.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 17:20:56 -0700 (PDT) Date: Tue, 15 Oct 2019 20:20:55 -0400 From: Joel Fernandes To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, primiano@google.com, rsavitski@google.com, jeffv@google.com, kernel-team@android.com, James Morris , Alexei Starovoitov , Arnaldo Carvalho de Melo , bpf@vger.kernel.org, Daniel Borkmann , Ingo Molnar , Jiri Olsa , Kees Cook , linux-security-module@vger.kernel.org, Matthew Garrett , Namhyung Kim , selinux@vger.kernel.org, Song Liu , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Yonghong Song Subject: Re: [PATCH v2] perf_event: Add support for LSM and SELinux checks Message-ID: <20191016002055.GA176924@google.com> References: <20191014170308.70668-1-joel@joelfernandes.org> <20191015083008.GC2311@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191015083008.GC2311@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 15, 2019 at 10:30:08AM +0200, Peter Zijlstra wrote: > On Mon, Oct 14, 2019 at 01:03:08PM -0400, Joel Fernandes (Google) wrote: > > In current mainline, the degree of access to perf_event_open(2) system > > call depends on the perf_event_paranoid sysctl. This has a number of > > limitations: > > > > 1. The sysctl is only a single value. Many types of accesses are controlled > > based on the single value thus making the control very limited and > > coarse grained. > > 2. The sysctl is global, so if the sysctl is changed, then that means > > all processes get access to perf_event_open(2) opening the door to > > security issues. > > > > This patch adds LSM and SELinux access checking which will be used in > > Android to access perf_event_open(2) for the purposes of attaching BPF > > programs to tracepoints, perf profiling and other operations from > > userspace. These operations are intended for production systems. > > > > 5 new LSM hooks are added: > > 1. perf_event_open: This controls access during the perf_event_open(2) > > syscall itself. The hook is called from all the places that the > > perf_event_paranoid sysctl is checked to keep it consistent with the > > systctl. The hook gets passed a 'type' argument which controls CPU, > > kernel and tracepoint accesses (in this context, CPU, kernel and > > tracepoint have the same semantics as the perf_event_paranoid sysctl). > > Additionally, I added an 'open' type which is similar to > > perf_event_paranoid sysctl == 3 patch carried in Android and several other > > distros but was rejected in mainline [1] in 2016. > > > > 2. perf_event_alloc: This allocates a new security object for the event > > which stores the current SID within the event. It will be useful when > > the perf event's FD is passed through IPC to another process which may > > try to read the FD. Appropriate security checks will limit access. > > > > 3. perf_event_free: Called when the event is closed. > > > > 4. perf_event_read: Called from the read(2) and mmap(2) syscalls for the event. > > > > 5. perf_event_write: Called from the ioctl(2) syscalls for the event. > > > > [1] https://lwn.net/Articles/696240/ > > > > Since Peter had suggest LSM hooks in 2016 [1], I am adding his > > Suggested-by tag below. > > Thanks, I've queued the patch! Thanks! > > To use this patch, we set the perf_event_paranoid sysctl to -1 and then > > apply selinux checking as appropriate (default deny everything, and then > > add policy rules to give access to domains that need it). In the future > > we can remove the perf_event_paranoid sysctl altogether. > > This I'm not sure about; the sysctl is only redundant when you actually > use a security thingy, not everyone is. I always find them things to be > mightily unfriendly. Right. I was just stating the above for the folks who use the security controls. thanks, - Joel