Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp454951pxb; Wed, 27 Jan 2021 11:51:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjB09bds7PpHkRxFs1FJLtwX1SpaFTE5bWhzHjHOoEI/pTXsZTJW1CbC/WeFVNN0AaIClx X-Received: by 2002:a50:eb81:: with SMTP id y1mr10205213edr.176.1611776997529; Wed, 27 Jan 2021 11:49:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611776997; cv=none; d=google.com; s=arc-20160816; b=sr+vYS4UADeEAW2egDuaPN1lbHq/jpxrsgFU+hEM2ImJH67qzFnB45UUtlQqG+aGYb 9kVHVUC7VT04FR1qYE+/G6e8+Fr3V1YD7CfcsijDhGMGf+3SR1Cbj20t47ljpn8eJXuT NpuqNLV8TrZ+djDMkfLeQHDZYZPZTjUgAlfVHoiAPYIx2MyOL2j8B1IahEpHUJWWNiKL ppC/AAnA09Jk4epzGk6onSGNHujx9LW3YceF7Vy9p+Z2FoAPzNqPvZbm1HZ9gXlcjGt6 A6DVzAEWugpSJZzcvgg2xOWFqxBmnhbuIYou4Cv2K9TMbWR2tBBItJFMQG9Jpm0kHayT mfxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KGHdetCJush3K+fWXeFM7UR5m16TdWTXEUMSsFL3aak=; b=c5LcLnyfFhtcAIr0M9zSQ2pVvoWsPo0dMMWgCE1sBpLl3tbFI118GZL+IJqOqu056X 7Sp5+YF8uY8PvZFu/BDD0VXsuln8U5n803F9HnqoQW3JJc2wlFMKv7I/cIPQMkevmBlF pUSWPeIYKp+fJUTymy82tmfopjGxQX7sN+1xQylZBDsswfy1miiffSJ2yAcsWO/E0ONY hMuRyrsdoTbTh8Bw7KyaF8k0eBHDHOC0PxMNs3MRdTOEDX3TTtmbDaPuhW/b91pQIMTJ 0zxebuHg2dSnO0PJ0cEuLT2KpgnqlC4ettLcyDzWwSkS4rFXOmMYqFrwCniBARXn4sfL reMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CG9EKbSe; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o26si1232684eja.521.2021.01.27.11.49.32; Wed, 27 Jan 2021 11:49:57 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=CG9EKbSe; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392315AbhA0Blb (ORCPT + 99 others); Tue, 26 Jan 2021 20:41:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47941 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394836AbhAZSob (ORCPT ); Tue, 26 Jan 2021 13:44:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611686582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KGHdetCJush3K+fWXeFM7UR5m16TdWTXEUMSsFL3aak=; b=CG9EKbSevOmtCUjNNxmoaQfCR8z04SjMXR0RNeosaml64SrlY0sZFVDXNCtF7GQdO5e7Vj 3Ob8v0Z7BheKqIAWrACLE9M0K3iIg+vO+0nRkQ4sBdBwUJtFpNzVv2MERSxMLh+mzRiETC XcEQ8jTPG/8uwdGnWEreKKbpAYQpgEk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-5chqgj35MoeUn93n_XVp9Q-1; Tue, 26 Jan 2021 13:43:00 -0500 X-MC-Unique: 5chqgj35MoeUn93n_XVp9Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28C111005504; Tue, 26 Jan 2021 18:42:58 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.10.110.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76BE65D761; Tue, 26 Jan 2021 18:42:49 +0000 (UTC) Date: Tue, 26 Jan 2021 13:42:46 -0500 From: Richard Guy Briggs To: Casey Schaufler Cc: casey.schaufler@intel.com, jmorris@namei.org, 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, paul@paul-moore.com, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org Subject: Re: [PATCH v24 21/25] audit: add support for non-syscall auxiliary records Message-ID: <20210126184246.GM1762914@madcap2.tricolour.ca> References: <20210126164108.1958-1-casey@schaufler-ca.com> <20210126164108.1958-22-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210126164108.1958-22-casey@schaufler-ca.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-26 08:41, Casey Schaufler wrote: > Standalone audit records have the timestamp and serial number generated > on the fly and as such are unique, making them standalone. This new > function audit_alloc_local() generates a local audit context that will > be used only for a standalone record and its auxiliary record(s). The > context is discarded immediately after the local associated records are > produced. > > Signed-off-by: Richard Guy Briggs > Signed-off-by: Casey Schaufler > Cc: linux-audit@redhat.com > To: Richard Guy Briggs This has been minorly bothering me for several revisions... Is there a way for the development/authorship to be accurately reflected if/when this patch is merged before the contid patch set? > --- > include/linux/audit.h | 8 ++++++++ > kernel/audit.h | 1 + > kernel/auditsc.c | 33 ++++++++++++++++++++++++++++----- > 3 files changed, 37 insertions(+), 5 deletions(-) > > diff --git a/include/linux/audit.h b/include/linux/audit.h > index 418a485af114..97cd7471e572 100644 > --- a/include/linux/audit.h > +++ b/include/linux/audit.h > @@ -289,6 +289,8 @@ static inline int audit_signal_info(int sig, struct task_struct *t) > /* Public API */ > extern int audit_alloc(struct task_struct *task); > extern void __audit_free(struct task_struct *task); > +extern struct audit_context *audit_alloc_local(gfp_t gfpflags); > +extern void audit_free_context(struct audit_context *context); > extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1, > unsigned long a2, unsigned long a3); > extern void __audit_syscall_exit(int ret_success, long ret_value); > @@ -552,6 +554,12 @@ static inline void audit_log_nfcfg(const char *name, u8 af, > extern int audit_n_rules; > extern int audit_signals; > #else /* CONFIG_AUDITSYSCALL */ > ++static inline struct audit_context *audit_alloc_local(gfp_t gfpflags) > +{ > + return NULL; > +} > +static inline void audit_free_context(struct audit_context *context) > +{ } > static inline int audit_alloc(struct task_struct *task) > { > return 0; > diff --git a/kernel/audit.h b/kernel/audit.h > index ce41886807bb..3f2285e1c6e0 100644 > --- a/kernel/audit.h > +++ b/kernel/audit.h > @@ -99,6 +99,7 @@ struct audit_proctitle { > struct audit_context { > int dummy; /* must be the first element */ > int in_syscall; /* 1 if task is in a syscall */ > + bool local; /* local context needed */ > enum audit_state state, current_state; > unsigned int serial; /* serial number for record */ > int major; /* syscall number */ > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > index de2b2ecb3aea..479b3933d788 100644 > --- a/kernel/auditsc.c > +++ b/kernel/auditsc.c > @@ -927,11 +927,13 @@ static inline void audit_free_aux(struct audit_context *context) > } > } > > -static inline struct audit_context *audit_alloc_context(enum audit_state state) > +static inline struct audit_context *audit_alloc_context(enum audit_state state, > + gfp_t gfpflags) > { > struct audit_context *context; > > - context = kzalloc(sizeof(*context), GFP_KERNEL); > + /* We can be called in atomic context via audit_tg() */ > + context = kzalloc(sizeof(*context), gfpflags); > if (!context) > return NULL; > context->state = state; > @@ -967,7 +969,8 @@ int audit_alloc(struct task_struct *tsk) > return 0; > } > > - if (!(context = audit_alloc_context(state))) { > + context = audit_alloc_context(state, GFP_KERNEL); > + if (!context) { > kfree(key); > audit_log_lost("out of memory in audit_alloc"); > return -ENOMEM; > @@ -979,8 +982,27 @@ int audit_alloc(struct task_struct *tsk) > return 0; > } > > -static inline void audit_free_context(struct audit_context *context) > +struct audit_context *audit_alloc_local(gfp_t gfpflags) > { > + struct audit_context *context = NULL; > + > + context = audit_alloc_context(AUDIT_RECORD_CONTEXT, gfpflags); > + if (!context) { > + audit_log_lost("out of memory in audit_alloc_local"); > + goto out; > + } > + context->serial = audit_serial(); > + ktime_get_coarse_real_ts64(&context->ctime); > + context->local = true; > +out: > + return context; > +} > +EXPORT_SYMBOL(audit_alloc_local); > + > +void audit_free_context(struct audit_context *context) > +{ > + if (!context) > + return; > audit_free_module(context); > audit_free_names(context); > unroll_tree_refs(context, NULL, 0); > @@ -991,6 +1013,7 @@ static inline void audit_free_context(struct audit_context *context) > audit_proctitle_free(context); > kfree(context); > } > +EXPORT_SYMBOL(audit_free_context); > > static int audit_log_pid_context(struct audit_context *context, pid_t pid, > kuid_t auid, kuid_t uid, > @@ -2214,7 +2237,7 @@ EXPORT_SYMBOL_GPL(__audit_inode_child); > int auditsc_get_stamp(struct audit_context *ctx, > struct timespec64 *t, unsigned int *serial) > { > - if (!ctx->in_syscall) > + if (!ctx->in_syscall && !ctx->local) > return 0; > if (!ctx->serial) > ctx->serial = audit_serial(); > -- > 2.25.4 > - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635