Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp454170pxb; Wed, 27 Jan 2021 11:50:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJykABV04uDLwXbliRarK4R0GZt9L1hO9nSa2gLYGaqKqzdUSK32QO3SHDVcGu+nD9YQsiuj X-Received: by 2002:a17:906:eca7:: with SMTP id qh7mr8067377ejb.437.1611777032495; Wed, 27 Jan 2021 11:50:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611777032; cv=none; d=google.com; s=arc-20160816; b=hmQ5UNNe4aWTU61Q0tM5ywiI+OY3E7MuIlrvmOoE8F2dzvXvNcLAxrSIdj1O2M8C4x q6VbSHx/0EfOmf87CguYbHwoDoHVXhJeMxE9YTBDaibFowVWrk+/sUXhm9ut1xv/glUn jVDvLudm5j4WGmiIBx0XK5c+QGjwsGsw+OLO7KSsI2pzDvB8fUr8DmPPwQi7ohuP2wVF Yxs1CikK+QtYnITuMfQTWUr4FCop/CUnQLWro9BV44fyg6qNHstKfrMtrHb6i/PFqVPz xDzp1gK3Wz9+1lT04oDSehqP91DA5oPF94P0e2wO3PcFRJslqcaj/Kb3bxURFfP/U2Kp SRGw== 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=m/u93bfQxIYyXQ08UiKaRmMGUT9o1Hv+NSbQL83syII=; b=aS9DW54i5Sx3MeH1unYnqscQ0ny4XrNatifClEcdZbCt0fiN+I7lpvlk5uLoMIdkpr /Js70csVqGU3y94GpFyiQNLm/KRRDcmmFiIsw4vm5JGbgA+N9AvfSAWXz27N3yNuti7I 69CnBq119Dz63bABqw8dDlZN/c0OpLvRMtDrabWO8WMOHTVf1rtZMVWhGtqZBWU5VkNU sVgEeUfinjvq3geEtYrRxqaFWg2KCLPKsW2vhcF5XGJmKpiavajlfDusBla1+SDF2300 tXCRQPzKHhzzJ1ERDwqh+RZVU47G+8k5hwdfRXxrrDhJjUkBfPFYPCDhWjnJmuatzIXW Xitw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CibOJRqs; 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 hp6si1228548ejc.532.2021.01.27.11.50.03; Wed, 27 Jan 2021 11:50:32 -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=CibOJRqs; 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 S235345AbhA0DQl (ORCPT + 99 others); Tue, 26 Jan 2021 22:16:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44899 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731124AbhAZUZE (ORCPT ); Tue, 26 Jan 2021 15:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611692616; 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=m/u93bfQxIYyXQ08UiKaRmMGUT9o1Hv+NSbQL83syII=; b=CibOJRqsVbnH4uyH3jxLVnzTnp4ecYhwKHuReP0VUpPdSBKcvsXum52hXBJ9F+OZ++RMc8 q3wYws0VQsGOabBWVHcrGkJfR5lDAHYH87sNa3C5NttxbuwrGd0LNLlfeGx3IyxSQgkxMx 9fIFI9+IsyduOxVGziR5rlwcXeqlZkk= 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-314-NwaC3_pbMYK5Ly5YxcYgBQ-1; Tue, 26 Jan 2021 15:23:33 -0500 X-MC-Unique: NwaC3_pbMYK5Ly5YxcYgBQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29C52100747E; Tue, 26 Jan 2021 20:23:01 +0000 (UTC) Received: from madcap2.tricolour.ca (unknown [10.10.110.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A0C35D9C2; Tue, 26 Jan 2021 20:22:47 +0000 (UTC) Date: Tue, 26 Jan 2021 15:22:45 -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: <20210126202245.GN1762914@madcap2.tricolour.ca> References: <20210126164108.1958-1-casey@schaufler-ca.com> <20210126164108.1958-22-casey@schaufler-ca.com> <20210126184246.GM1762914@madcap2.tricolour.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-26 10:58, Casey Schaufler wrote: > On 1/26/2021 10:42 AM, Richard Guy Briggs wrote: > > 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? > > I don't know the right way to do that because I had to pull > some of what was in the original patch out. Any way you would > like it done is fine with me. Other than diff context, it appears to be identical to the patch in the v9 contid patchset (with one tiny cut/paste below, I don't know how it compiles...). There are minor updates to bring it up to v11. > >> --- > >> 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) This extra "+" that ends up at the beginning of the line looks unintentional and I'd have expected the compiler to complain. > >> +{ > >> + 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 - 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