Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp9631imm; Thu, 10 May 2018 14:27:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpg4zisilzu8iY4/cr1bGVhOvMMNrKjMz22AMfaRpNB/DnW1PiFHfWLynphaX1u9vEyqZjT X-Received: by 2002:a63:6fc9:: with SMTP id k192-v6mr2350526pgc.143.1525987677723; Thu, 10 May 2018 14:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525987677; cv=none; d=google.com; s=arc-20160816; b=AtMUMnlYYd6CVnGRerL+1aYhokQ70ZNXB9WNPJdAR/dpF9l76GFVofV7UAFkNyYuDg IdP55eAWHFqW7o3Kn1WgsBxYVsHiLoZHLAsC/tPa6BoZL9maAqD19Is29L7U5VJfhxFt x/dZLpJmTA/XjYFEaygF6fS++VBBabbKUZg1K/f+cs7C58vW9fWRRvJVtqEJ2VLN9gXM PeY29t7JuTL5d/1kyZJnAQ823it1aHhn2E5alaSgUKiKz99Nm0J0hydyWxZSj2mHIza0 5+ukVd9S9ZNzWf7WnAwexbgcphKRvgcWdz73vZhBr3ANp4x+SJYEABhYeHLhJazaw3pL qZNQ== 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:arc-authentication-results; bh=lVW+A9VoTqm3GW+E0OrQikFHT52BnuukDIltDMax8AU=; b=oTJhWZhD4IGFwodzW8h5UG/R8mcYdHpwy4paCtARCguWSF17OOD/IHwzrZxZ69wBpT m4lKMHYzAoHrBDcFM0jMt9iI83yEFve9A/6VdUOScl1b3HiZkaverWEZQRyS+UN6bKKH /kqIcazuHlSasq9JCoqB8fD3f9sScjak54CHoBGjrIL3DvAHt+gGYF2ZjEkgpas3lvDd 4BZFQuwHHC2YfEnQPXC+OJvDjn9HQUDUJ3fGV5V1Aca2pYvK5GwdxGYWkHdSb+s07ACo QtWDaI6m6gvqlCSEUq7xSfqdH1vlqFVSj/QhS09xe2Be8Y6HTYsH2ANnDBM8Az9G1cB9 1qVQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5-v6si1554055plp.108.2018.05.10.14.27.41; Thu, 10 May 2018 14:27:57 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752527AbeEJV1X (ORCPT + 99 others); Thu, 10 May 2018 17:27:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34140 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752104AbeEJV1U (ORCPT ); Thu, 10 May 2018 17:27:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39DAD8185343; Thu, 10 May 2018 21:27:19 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-12.rdu2.redhat.com [10.10.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FD072026DEF; Thu, 10 May 2018 21:27:16 +0000 (UTC) Date: Thu, 10 May 2018 17:26:57 -0400 From: Richard Guy Briggs To: Paul Moore Cc: Linux-Audit Mailing List , LKML , Linux NetDev Upstream Mailing List , Netfilter Devel List , Linux Security Module list , Integrity Measurement Architecture , SElinux list , Eric Paris , Steve Grubb , Ingo Molnar , David Howells Subject: Re: [PATCH ghak81 RFC V1 5/5] audit: collect audit task parameters Message-ID: <20180510212657.qnwm3jeqjjke77yz@madcap2.tricolour.ca> References: <5b0e0eef72b5137830f9f6c67908e5252dbf48f5.1525466167.git.rgb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171027 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 21:27:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 21:27:19 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rgb@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-09 11:46, Paul Moore wrote: > On Fri, May 4, 2018 at 4:54 PM, Richard Guy Briggs wrote: > > The audit-related parameters in struct task_struct should ideally be > > collected together and accessed through a standard audit API. > > > > Collect the existing loginuid, sessionid and audit_context together in a > > new struct audit_task_info pointer called "audit" in struct task_struct. > > > > Use kmem_cache to manage this pool of memory. > > Un-inline audit_free() to be able to always recover that memory. > > > > See: https://github.com/linux-audit/audit-kernel/issues/81 > > > > Signed-off-by: Richard Guy Briggs > > --- > > MAINTAINERS | 2 +- > > include/linux/audit.h | 8 ++++---- > > include/linux/audit_task.h | 31 +++++++++++++++++++++++++++++++ > > include/linux/sched.h | 6 ++---- > > init/init_task.c | 8 ++++++-- > > kernel/auditsc.c | 4 ++-- > > 6 files changed, 46 insertions(+), 13 deletions(-) > > create mode 100644 include/linux/audit_task.h > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index 0a1410d..8c7992d 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -2510,7 +2510,7 @@ L: linux-audit@redhat.com (moderated for non-subscribers) > > W: https://github.com/linux-audit > > T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit.git > > S: Supported > > -F: include/linux/audit.h > > +F: include/linux/audit*.h > > F: include/uapi/linux/audit.h > > F: kernel/audit* > > > > diff --git a/include/linux/audit.h b/include/linux/audit.h > > index dba0d45..1324969 100644 > > --- a/include/linux/audit.h > > +++ b/include/linux/audit.h > > @@ -237,11 +237,11 @@ extern void __audit_inode_child(struct inode *parent, > > > > static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx) > > { > > - task->audit_context = ctx; > > + task->audit.ctx = ctx; > > } > > static inline struct audit_context *audit_context(struct task_struct *task) > > { > > - return task->audit_context; > > + return task->audit.ctx; > > } > > static inline bool audit_dummy_context(void) > > { > > @@ -330,12 +330,12 @@ extern int auditsc_get_stamp(struct audit_context *ctx, > > > > static inline kuid_t audit_get_loginuid(struct task_struct *tsk) > > { > > - return tsk->loginuid; > > + return tsk->audit.loginuid; > > } > > > > static inline unsigned int audit_get_sessionid(struct task_struct *tsk) > > { > > - return tsk->sessionid; > > + return tsk->audit.sessionid; > > } > > > > extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp); > > diff --git a/include/linux/audit_task.h b/include/linux/audit_task.h > > new file mode 100644 > > index 0000000..d4b3a20 > > --- /dev/null > > +++ b/include/linux/audit_task.h > > @@ -0,0 +1,31 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* audit_task.h -- definition of audit_task_info structure > > + * > > + * Copyright 2018 Red Hat Inc., Raleigh, North Carolina. > > + * All Rights Reserved. > > + * > > + * This program is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU General Public License as published by > > + * the Free Software Foundation; either version 2 of the License, or > > + * (at your option) any later version. > > + * > > + * This program is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > + * GNU General Public License for more details. > > + * > > + * Written by Richard Guy Briggs > > + * > > + */ > > + > > +#ifndef _LINUX_AUDIT_TASK_H_ > > +#define _LINUX_AUDIT_TASK_H_ > > + > > +struct audit_context; > > +struct audit_task_info { > > + kuid_t loginuid; > > + unsigned int sessionid; > > + struct audit_context *ctx; > > +}; > > + > > +#endif > > diff --git a/include/linux/sched.h b/include/linux/sched.h > > index b3d697f..b58eca0 100644 > > --- a/include/linux/sched.h > > +++ b/include/linux/sched.h > > @@ -27,9 +27,9 @@ > > #include > > #include > > #include > > +#include > > > > /* task_struct member predeclarations (sorted alphabetically): */ > > -struct audit_context; > > struct backing_dev_info; > > struct bio_list; > > struct blk_plug; > > @@ -832,10 +832,8 @@ struct task_struct { > > > > struct callback_head *task_works; > > > > - struct audit_context *audit_context; > > #ifdef CONFIG_AUDITSYSCALL > > - kuid_t loginuid; > > - unsigned int sessionid; > > + struct audit_task_info audit; > > #endif > > Considering that the audit_context pointer is now in the > audit_task_info struct, should the audit_task_info struct be placed > outside the CONFIG_AUDITSYSCALL protections? Or rather, shouldn't the > CONFIG_AUDITSYSCALL protections be moved inside audit_task_info or > removed entirely? Well, I wondered about that anyways. audit_context is only meaningful in CONFIG_AUDIT_SYSCALL, and loginuid and sessionid were already there, so the whole thing should be inside, but given that CONFIG_AUDIT_SYSCALL is forced on when CONFIG_AUDIT is set I don't see that it matters. Perhaps CONFIG_AUDIT_SYSCALL should be ripped out completely and the code flattenned to the CONFIG_AUDIT case. I see your point though, moving CONFIG_AUDIT_SYSCALL protections to within the audit_task_info struct definition makes more sense than this above. > > diff --git a/init/init_task.c b/init/init_task.c > > index c788f91..d33260d 100644 > > --- a/init/init_task.c > > +++ b/init/init_task.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -118,8 +119,11 @@ struct task_struct init_task > > .thread_group = LIST_HEAD_INIT(init_task.thread_group), > > .thread_node = LIST_HEAD_INIT(init_signals.thread_head), > > #ifdef CONFIG_AUDITSYSCALL > > - .loginuid = INVALID_UID, > > - .sessionid = AUDIT_SID_UNSET, > > + .audit = { > > + .loginuid = INVALID_UID, > > + .sessionid = AUDIT_SID_UNSET, > > + .ctx = NULL, > > + }, > > #endif > > #ifdef CONFIG_PERF_EVENTS > > .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex), > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index f294e4a..b5d8bff 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -2068,8 +2068,8 @@ int audit_set_loginuid(kuid_t loginuid) > > sessionid = (unsigned int)atomic_inc_return(&session_id); > > } > > > > - task->sessionid = sessionid; > > - task->loginuid = loginuid; > > + task->audit.sessionid = sessionid; > > + task->audit.loginuid = loginuid; > > out: > > audit_log_set_loginuid(oldloginuid, loginuid, oldsessionid, sessionid, rc); > > return rc; > > -- > > 1.8.3.1 > > -- > paul moore > www.paul-moore.com - 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