Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp1104673pxb; Fri, 13 Aug 2021 13:45:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeHXA5giW3EaQ556loeTe+IpjDz7pBrQtxDfIc5epvgZ9qb4re95vSidKyLD51/bZ7g186 X-Received: by 2002:a17:906:4948:: with SMTP id f8mr4240580ejt.187.1628887553302; Fri, 13 Aug 2021 13:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628887553; cv=none; d=google.com; s=arc-20160816; b=WggOZrPwxmU/KTvAEF4qNopCzfyoEQKiuCPRyeUBXZfi/tUgpDS0BFKsxeriOm+CA0 Pcn+aa7AwGff7fxRs1vhV/pNybmUof/yANKvapJd49D6eOjjT8CGSrylU45rydTjrU6/ tzwQ4U7Kmec8PV5B1Hs6GtFisO8BMBQU9cXT5Ixw8MVuFDFR1zfGVLPCwMZguFD0BOQl k9tTC/wNCNWnocrljTe5olSd21zusdD36+rprtyKJcY38nXXRPTKiKKcIh2RFGCy0RHZ ScooZc5DrzqvtMrXjKxRu7Uprn5qV2CRTu6cyF6yNlvZucd2jjFl/OSYBGoCh0WhAHnM jfLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iRAplBayhxWymKoWiC0WoyTJpbQvWuYgJ79F91VPsGY=; b=eeZ9kBrHahzdIOPtmqWpX2d51/0ybEcLVa8gIaBt/Lwd9vHkfopeOhF4QRANpFLS4C WO12vzHHhZkbdmhl9lFEDRXwmSJAP+riVx0JVlIllFzhpZOCNUuJAst6FP1N/eQuMz8z /vPdViWYj1rDr+GBkr6LA5TRjAy6ss36CvOU3nRmi8FQEbgROswnowLdf5OMBSwfCB0G wvomBQw/UF3Z649p63l+hEZ4nYdQuYYQDE+ORDN2g4edoEOrvyZiyxaOjHsXoamoTTyW rgbod8eIE8H1AiSsBlhrMXJcqpBC8dGpk0Sxp4EZW5Vj/IZY0VUjQLmm9s5GPLOg3bwb q+PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=AJXHxf6m; 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 e12si2434731ejk.703.2021.08.13.13.45.29; Fri, 13 Aug 2021 13:45:53 -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=AJXHxf6m; 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 S234566AbhHMUoB (ORCPT + 99 others); Fri, 13 Aug 2021 16:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233915AbhHMUn6 (ORCPT ); Fri, 13 Aug 2021 16:43:58 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39555C061756 for ; Fri, 13 Aug 2021 13:43:31 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id z11so17143983edb.11 for ; Fri, 13 Aug 2021 13:43:31 -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; bh=iRAplBayhxWymKoWiC0WoyTJpbQvWuYgJ79F91VPsGY=; b=AJXHxf6mdypCa42/YwFeu+0Ff51vNI2hZQLJOtmI36BZuel/csiDOA2aXeD2vXyi4d 6wdAaPLATieACVpkBz03DOgyyTecO6kBA7tpnJTW/LkLzIp1sfh/lF1uPjVIsPi9xL/E FzDEW8/RWzt4/ZHPAWIuS/V6U8kAIWsTC38r+MmecIj0MH979uAJtFb3YcvA+rzD1dH+ nJddGcY6JX41yknjZUr05q5UpIPjre1WgcrpR8WfsxLoPsHKk5cAXEz7tauV2QDDGvd6 U99fcfAJmKH3Ay8LkYJYjICks+rZlKX6e7Eef0N1THfeGYfNNxQ5aK7Qo3dWHqHr9eod JWqA== 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=iRAplBayhxWymKoWiC0WoyTJpbQvWuYgJ79F91VPsGY=; b=WHKyrZ7LZfk3xky4WZXU0lJA0FRctnBQxpaaekNwvqckS1PpV9R8Er2NHBe/9VG5LK WQC3pPDQQRRVv22Hy0z2mh+K8uuiC/dUrIsQKKGNKMgBE4gesRv6/j67Mmt3wnz8bw9P LfmYCyGB3Vr0pcIkvAL4ehV0ToVCaFpG0V86zBGCgRPnRGlvakYFm9OG6Jqmm3aKuIOP eSgqh38hP8DtW4ExblLL9kVfkXcWokCgpa+h7rblPY9UvjxbIKTl7ozvnIraNYR1cJGK v+uuvPW+FrvJNaR9l/76sU6u53FGavhzuCTxvdvVLuH1vJDxEFpN8A3nwfJw53dwRRy4 5isQ== X-Gm-Message-State: AOAM531wdEmSBNjknlmvKwBZYj2aUj1yahpc1G226yU63+EQSY9TzsPD PZnenDUOtsc02fLM1MVnufD6vX6ncxx8qkLvVinF X-Received: by 2002:aa7:d982:: with SMTP id u2mr5423505eds.164.1628887409671; Fri, 13 Aug 2021 13:43:29 -0700 (PDT) MIME-Version: 1.0 References: <20210722004758.12371-1-casey@schaufler-ca.com> <20210722004758.12371-23-casey@schaufler-ca.com> In-Reply-To: From: Paul Moore Date: Fri, 13 Aug 2021 16:43:18 -0400 Message-ID: Subject: Re: [PATCH v28 22/25] Audit: Add record for multiple process LSM attributes To: Casey Schaufler Cc: casey.schaufler@intel.com, James Morris , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, Stephen Smalley , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 13, 2021 at 2:48 PM Casey Schaufler wrote: > On 8/13/2021 8:31 AM, Paul Moore wrote: > > On Thu, Aug 12, 2021 at 6:38 PM Casey Schaufler wrote: > >> On 8/12/2021 1:59 PM, Paul Moore wrote: > >>> On Wed, Jul 21, 2021 at 9:12 PM Casey Schaufler wrote: > >>>> Create a new audit record type to contain the subject information > >>>> when there are multiple security modules that require such data. > > ... > > > >>> The local > >>> audit context is a hack that is made necessary by the fact that we > >>> have to audit things which happen outside the scope of an executing > >>> task, e.g. the netfilter audit hooks, it should *never* be used when > >>> there is a valid task_struct. > >> In the existing audit code a "current context" is only needed for > >> syscall events, so that's the only case where it's allocated. Would > >> you suggest that I track down the non-syscall events that include > >> subj= fields and add allocate a "current context" for them? I looked > >> into doing that, and it wouldn't be simple. > > > > This is why the "local context" was created. Prior to these stacking > > additions, and the audit container ID work, we never needed to group > > multiple audit records outside of a syscall context into a single > > audit event so passing a NULL context into audit_log_start() was > > reasonable. The local context was designed as a way to generate a > > context for use in a local function scope to group multiple records, > > however, for reasons I'll get to below I'm now wondering if the local > > context approach is really workable ... > > I haven't found a place where it didn't work. What is the concern? The concern is that use of a local context can destroy any hopes of linking with other related records, e.g. SYSCALL and PATH records, to form a single cohesive event. If the current task_struct is valid for a given function invocation then we *really* should be using current's audit_context. However, based on our discussion here it would seem that we may have some issues where current->audit_context is not being managed correctly. I'm not surprised, but I will admit to being disappointed. > > What does your audit config look like? Both the kernel command line > > and the output of 'auditctl -l' would be helpful. > > On the fedora system: > > BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.14.0-rc5stack+ > root=/dev/mapper/fedora-root ro resume=/dev/mapper/fedora-swap > rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap lsm.debug > > -a always,exit -F arch=b64 -S bpf -F key=testsuite-1628714321-EtlWIphW > > On the Ubuntu system: > > BOOT_IMAGE=/boot/vmlinuz-5.14.0-rc1stack+ > root=UUID=39c25777-d413-4c2e-948c-dfa2bf259049 ro lsm.debug > > No rules The Fedora system looks to have some audit-testsuite leftovers, but that shouldn't have an impact on what we are discussing; in both cases I would expect current->audit_context to be allocated and non-NULL. > > I'm beginning to suspect that you have the default > > we-build-audit-into-the-kernel-because-product-management-said-we-have-to-but-we-don't-actually-enable-it-at-runtime > > audit configuration that is de rigueur for many distros these days. > > Yes, but I've also fiddled about with it so as to get better event coverage. > I've run the audit-testsuite, which has got to fiddle about with the audit > configuration. Yes, it looks like my hunch was wrong. > > If that is the case, there are many cases where you would not see a > > NULL current->audit_context simply because the config never allocated > > one, see kernel/auditsc.c:audit_alloc(). > > I assume you mean that I *would* see a NULL current->audit_context > in the "event not enabled" case. Yep, typo. > > Regardless, assuming that is the case we probably need to find an > > alternative to the local context approach as it currently works. For > > reasons we already talked about, we don't want to use a local > > audit_context if there is the possibility for a proper > > current->audit_context, but we need to do *something* so that we can > > group these multiple events into a single record. > > I tried a couple things, but neither was satisfactory. > > > Since this is just occurring to me now I need a bit more time to think > > on possible solutions - all good ideas are welcome - but the first > > thing that pops into my head is that we need to augment > > audit_log_end() to potentially generated additional, associated > > records similar to what we do on syscall exit in audit_log_exit(). > > I looked into that. You need a place to save the timestamp > that doesn't disappear. That's the role the audit_context plays > now. Yes, I've spent a few hours staring at the poorly planned struct that is audit_context ;) Regardless, the obvious place for such a thing is audit_buffer; we can stash whatever we need in there. > > Of > > course the audit_log_end() changes would be much more limited than > > audit_log_exit(), just the LSM subject and audit container ID info, > > and even then we might want to limit that to cases where the ab->ctx > > value is NULL and let audit_log_exit() handle it otherwise. We may > > need to store the event type in the audit_buffer during > > audit_log_start() so that we can later use that in audit_log_end() to > > determine what additional records are needed. > > > > Regardless, let's figure out why all your current->audit_context > > values are NULL > > That's what's maddening, and why I implemented audit_alloc_for_lsm(). > They aren't all NULL. Sometimes current->audit_context is NULL, > sometimes it isn't, for the same event. I thought it might be a > question of the netlink interface being treated specially, but > that doesn't explain all the cases. Your netlink changes are exactly what made me think, "this is obviously wrong", but now I'm wondering if a previously held assumption of "current is valid and points to the calling process" in the case of the kernel servicing netlink messages sent from userspace. Or rather, perhaps that assumption is still true but something is causing current->audit_context to be NULL in that case. Friday the 13th indeed. -- paul moore www.paul-moore.com