Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2198819ybh; Fri, 24 Jul 2020 06:57:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu9wTbJb812q1HXAZxQHkEB78I//UFb65ffNfQYeCG3RaZRhc7KaaSavW+eABMJS8TVD4l X-Received: by 2002:a17:907:72cc:: with SMTP id du12mr9202727ejc.357.1595599072587; Fri, 24 Jul 2020 06:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595599072; cv=none; d=google.com; s=arc-20160816; b=nWFOXZCSivS3HPobe0G7xMi7MsTqaEVCsED5dko5O6SKNxDJuUSWlIgI4LPrnEEswO gq1bbi2GVauqOf+98wBs7jAf4s/v+rWyv1CKoEAFIXVOlzDzUrQldRR8uSdPv3eQ8ZrB pemKAR6L+FPMYCzsPGUfzQFludna5+wDWl83RfK5Sp1hhksr0vWmF7hBxAA9qVctDiSx 27pkXIypoBI3Aug7cQRMVMtCntwaALuQSrms8kOYz1nE7PS7X1HFiwzocXjirW79JXAJ VwZHbR7hFpAomGlSj8yGO/OZvw6EvK2uhwNdGAKgTbsFwnv1XoDR5cP/9tejWiRtWetj NE3A== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2+QY4UUobhGBvSSFOCx6nVkPgfj8aj4xZ1WgLjYrTQs=; b=rUx4WIVYIZWqcb/EmUvgxHA1fSthz1tRKviJRX94xxlWfn26+N1C8UtPjVxn1xp6PR 6GXkl3ZiN/hQSNGjJGzMAZanmjIAjWBj0husFdbEnt/EkhZeKmIp7FKuAGeY5qzVGhE6 jILIYu23bO9JwuQpoKP0GT7QfqCO3HiCQfxy0LQ8LLER/H12tsgaghOPmY9DpIWu+wg/ 2PiDysuBjwyPEDsdxk0aMfmbL102M/8cK/N5tLz1eexo0mvoYEvX+pLwUwuDruezVTYo 8K8jqbRgCnizWhqWkAW1UbjUSKJfKMi1L+CoNvZ9x5cHbdVVTXuteaEfu3A8rWFyuWR+ jRLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=yw8HskBN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be28si547076edb.373.2020.07.24.06.57.30; Fri, 24 Jul 2020 06:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=yw8HskBN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726366AbgGXNzO (ORCPT + 99 others); Fri, 24 Jul 2020 09:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbgGXNzO (ORCPT ); Fri, 24 Jul 2020 09:55:14 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC5DDC0619E4 for ; Fri, 24 Jul 2020 06:55:13 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id a21so10049737ejj.10 for ; Fri, 24 Jul 2020 06:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=2+QY4UUobhGBvSSFOCx6nVkPgfj8aj4xZ1WgLjYrTQs=; b=yw8HskBNj5wOQJSaAsDDosZQzeLjims7JWWXKdcziXgfxwCTExxUhYTruFid5xgh8T 7SxjC/csP73hxZuLXPZm34Iz8fw6WG7hjiR5uvQzZKsedkAWqQhR+ppw0+mjKSlibCYF vxQS8PsSkoA0cfWG41Gs+CWBr7oLDXmQkbUmN3a/xKyXcVL9pyRrd520M5f6KtYB67CY lBLeCvPY4BOFokvNqbHqorLtD2L9SEy7WyEXA2aSIQGpsDUJYj/R0KTDCovBALQhllG4 F+Qj79J1hh/g2J5y/nc5fO0Egqqn3x2nb86zlya0t64gGFhwzm/DpC5VN787S3p6hRdL utMg== 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:content-transfer-encoding; bh=2+QY4UUobhGBvSSFOCx6nVkPgfj8aj4xZ1WgLjYrTQs=; b=DS1gHyRE43DPCWO2Me5DTuP+sOY13/fL0/9epQh50CxwSrckTxVREnzqVujvt6uZXp OQbrEZlJoBWayZmH+y89ty9oXOQMinXO8kTXcP+8vWrtCEA+asdRG50hSNURW0exjjpi JX4RdEN08bVh6bBSFXVzNRAMmKqDbOT4OEd2wRkOZbCTBRmvAyn65lnakIuqL5Ul0ZFu BuQLIHxAnn/0Gf/pWs+iRwP7omWI+9Mf1DhS1CRgJxmcwJgZKEpIuvTwMriHLn7P+g7w aVKQ4b6qh+HQZ1QuK+yIPgPgXTvOBFMEfPh+9ULcRcvO1dEursqs4aYVyTFvGV6xoIEW Iylg== X-Gm-Message-State: AOAM531LunBHYgmGjpVzqxWAx+sVhMIyOdUZ5jOrnslTBNgtNQzCvwTd i3xqzFlcJgOirTlW/U0WdbbP/6DftJjQ3kPUvZYPN7s= X-Received: by 2002:a17:906:1911:: with SMTP id a17mr1088054eje.431.1595598912508; Fri, 24 Jul 2020 06:55:12 -0700 (PDT) MIME-Version: 1.0 References: <20200724091520.880211-1-tweek@google.com> In-Reply-To: From: Paul Moore Date: Fri, 24 Jul 2020 09:54:59 -0400 Message-ID: Subject: Re: [PATCH] selinux: add tracepoint on denials To: Stephen Smalley Cc: =?UTF-8?Q?Thi=C3=A9baud_Weksteen?= , Nick Kralevich , Joel Fernandes , Eric Paris , Steven Rostedt , Ingo Molnar , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , linux-kernel , SElinux list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 24, 2020 at 9:32 AM Stephen Smalley wrote: > On Fri, Jul 24, 2020 at 5:15 AM Thi=C3=A9baud Weksteen = wrote: > > The audit data currently captures which process and which target > > is responsible for a denial. There is no data on where exactly in the > > process that call occurred. Debugging can be made easier by being able = to > > reconstruct the unified kernel and userland stack traces [1]. Add a > > tracepoint on the SELinux denials which can then be used by userland > > (i.e. perf). > > > > Although this patch could manually be added by each OS developer to > > trouble shoot a denial, adding it to the kernel streamlines the > > developers workflow. > > > > [1] https://source.android.com/devices/tech/debug/native_stack_dump > > > > Signed-off-by: Thi=C3=A9baud Weksteen > > Signed-off-by: Joel Fernandes > > --- > > MAINTAINERS | 1 + > > include/trace/events/selinux.h | 35 ++++++++++++++++++++++++++++++++++ > > security/selinux/avc.c | 6 ++++++ > > 3 files changed, 42 insertions(+) > > create mode 100644 include/trace/events/selinux.h > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index e64cdde81851..6b6cd5e13537 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -15358,6 +15358,7 @@ T: git git://git.kernel.org/pub/scm/linux/= kernel/git/pcmoore/selinux.git > > F: Documentation/ABI/obsolete/sysfs-selinux-checkreqprot > > F: Documentation/ABI/obsolete/sysfs-selinux-disable > > F: Documentation/admin-guide/LSM/SELinux.rst > > +F: include/trace/events/selinux.h > > F: include/uapi/linux/selinux_netlink.h > > F: scripts/selinux/ > > F: security/selinux/ > > diff --git a/include/trace/events/selinux.h b/include/trace/events/seli= nux.h > > new file mode 100644 > > index 000000000000..e247187a8135 > > --- /dev/null > > +++ b/include/trace/events/selinux.h > > @@ -0,0 +1,35 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#undef TRACE_SYSTEM > > +#define TRACE_SYSTEM selinux > > + > > +#if !defined(_TRACE_SELINUX_H) || defined(TRACE_HEADER_MULTI_READ) > > +#define _TRACE_SELINUX_H > > + > > +#include > > +#include > > + > > +TRACE_EVENT(selinux_denied, > > + > > + TP_PROTO(int cls, int av), > > + > > + TP_ARGS(cls, av), > > + > > + TP_STRUCT__entry( > > + __field(int, cls) > > + __field(int, av) > > + ), > > + > > + TP_fast_assign( > > + __entry->cls =3D cls; > > + __entry->av =3D av; > > + ), > > + > > + TP_printk("denied %d %d", > > + __entry->cls, > > + __entry->av) > > +); > > I would think you would want to log av as %x for easier interpretation > especially when there are multiple permissions being checked at once > (which can happen). Also both cls and av would properly be unsigned > values. Only other question I have is whether it would be beneficial > to include other information here to help uniquely identify/correlate > the denial with the avc: message and whether any decoding of the > class, av, or other information could/should be done here versus in > some userland helper. It does seem like at the very least it would be nice to see the av as hex values instead of integers, e.g. "%x" in the TP_printk() call. Considering this patch is about making dev's lives easier, I tend to agree with Stephen questioning if you should go a step further and convert both the class and av values into string representations. --=20 paul moore www.paul-moore.com