Received: by 10.192.165.148 with SMTP id m20csp60317imm; Wed, 9 May 2018 08:47:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoV0sOJ0FG7+RSPtOlI+mNpItraM5OoQMwKWCd1tiO5TtZ7VhWF1kVnBxLwCQjtb9l0e3dU X-Received: by 2002:a65:4083:: with SMTP id t3-v6mr36343395pgp.129.1525880859477; Wed, 09 May 2018 08:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525880859; cv=none; d=google.com; s=arc-20160816; b=BP1/Nfuiybd+Z6LsvkZ+X+xpnctpWO1Irkw9GVid9vA8XPDTqA470+X6LfqVdJHSKg n4jBRYCM2KX3W33x+pawPCMZLW/exWV3zbOm8XcdqPaXoVhj9rcjBuNKqGJM7X62sdo8 U1VPpHPm8Sg/5R/GAyieDHUjigQip4ltUcvLv42x9hji1KSEt2QiktYWQDsWEpudsbLj nSlNidtJxVV77idqwekmUXO1RhTjci/CmrEJ5Bz0pRzpxUS/f92KE9Ngtwm9qiYASyLP qsyxFzql9oLupV/auJ0rP18xtXk8GGb8RJpwgUu5v+i2kDDapaHt/5HCZXZlByBMhJ4J 6r2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=RnFJbsw06uYbzeCg7k8DBirHzIWPgHI3g3Csvir2LKw=; b=K0nzplRSxBWOY/ICpUJ6tgCjFIKQ2VgJXGyMmJqh0SW+fx/1LcTl6eUhIQkLJmM0jZ ABaRO53Zgq7QiJpt2QvQQju2Y8/9GV+8A6VMKxsIc6wVueIJGv0H9EaCIbed+487ZOLB NH63N8l1QaFS4r3XGfWJcstnvyowIHDafRl/8soJCpNM2b54QNhUi8xcoY4oHpt47PWL prPbjQCpSpZjYvnf2sce4QDTZZbwL7sRnJwksDlEz5wen6mDq0VyrozJBsXM9RB5FrPM JuCTXmkbJCm8hEbgqYl/K93HVRxgyYb8aXCLFciBJI6C6Mq6wQCIaVVActku1DOybADj tqHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=OJ9w3lW5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s61-v6si483107plb.271.2018.05.09.08.47.25; Wed, 09 May 2018 08:47:39 -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; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=OJ9w3lW5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965205AbeEIPrC (ORCPT + 99 others); Wed, 9 May 2018 11:47:02 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:41374 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965188AbeEIPq5 (ORCPT ); Wed, 9 May 2018 11:46:57 -0400 Received: by mail-lf0-f66.google.com with SMTP id o123-v6so51627312lfe.8 for ; Wed, 09 May 2018 08:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=RnFJbsw06uYbzeCg7k8DBirHzIWPgHI3g3Csvir2LKw=; b=OJ9w3lW5Xfp/kWFrMrVC7Rrnu7MP6Aiu22BYkKeuBBVO0CrvssMaxYn/xgl6VriLzM 7fXHvEyDIFfkyV2WYDVNhiQ7uxHMB3wlb5F3iVDUNRN0DxYkGJcvSLI+Yw5zb7VYtGNf 3OOcc+Kfg7lwxTshb4yfQ7vpD0eAWlUuAxw4iXPt3k0ZqrIMJ4yWOTgR6b2IYrRB6Qsg nt2yfVSioxMnTMkvzMSdAIau2wcR0vyFKnnzQhcho99jEF+uRJsyYUQ1WH1kNvo1yXkS lO2RuZ7wK4D9wdUUn0q7Zpl29zWstqMZlOPoFE6avL00HEjBFQ5ANaIQI4VjnL1QWTXn PRYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=RnFJbsw06uYbzeCg7k8DBirHzIWPgHI3g3Csvir2LKw=; b=LHfptc0nY8/aDpy5QZa4Um+K98DAYcqAnCZxFwvs1c2+Q5Mwh/t3uemyxJPL3q3kNG 9Vp0VtqMTyoT6nQdNHXEkUFO7m6FmNwdYY4hHNYCHL1o7jGlcgCfSobMK4yKSGjZ1Y9d VsF0sRpO4ZyDmxYZxYqYYdyIk+DDA4JInPEqNnatmPfAEY5eE0F5sDKga223MS2z2nEl fyJ+mkGP918cw0tB717/GSh6mDpBG9H07ppBUE74eVkK9JMOlXsJVoGnnQv3tEgxP+XI pM0v6uu/kuqgv/St0+cVFiYPpk7milevBwkpJRj8cx2kC+4tYcrn6TiVmg4RerlDBN0n oXtw== X-Gm-Message-State: ALKqPwcv7/WD4oOY6p/zIeDnU8YV2T7HJHUDtes4vn6immAeiRtAY0fg bNgz1ngMHHUtOwcHmNyeD2hLSDuY3YcW34tQ3+9n X-Received: by 2002:a2e:c41:: with SMTP id o1-v6mr244764ljd.87.1525880815097; Wed, 09 May 2018 08:46:55 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:a947:0:0:0:0:0 with HTTP; Wed, 9 May 2018 08:46:54 -0700 (PDT) X-Originating-IP: [68.177.129.184] In-Reply-To: <5b0e0eef72b5137830f9f6c67908e5252dbf48f5.1525466167.git.rgb@redhat.com> References: <5b0e0eef72b5137830f9f6c67908e5252dbf48f5.1525466167.git.rgb@redhat.com> From: Paul Moore Date: Wed, 9 May 2018 11:46:54 -0400 Message-ID: Subject: Re: [PATCH ghak81 RFC V1 5/5] audit: collect audit task parameters To: Richard Guy Briggs 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > 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