Linux-Fsdevel Archive on lore.kernel.org help / color / mirror / Atom feed
From: Richard Guy Briggs <rgb@redhat.com> To: Paul Moore <paul@paul-moore.com> Cc: containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List <linux-audit@redhat.com>, linux-fsdevel@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, sgrubb@redhat.com, Ondrej Mosnacek <omosnace@redhat.com>, dhowells@redhat.com, simo@redhat.com, Eric Paris <eparis@parisplace.org>, Serge Hallyn <serge@hallyn.com>, ebiederm@xmission.com, nhorman@tuxdriver.com, Dan Walsh <dwalsh@redhat.com>, mpatel@redhat.com Subject: Re: [PATCH ghak90 V9 10/13] audit: add support for containerid to network namespaces Date: Tue, 21 Jul 2020 18:05:48 -0400 [thread overview] Message-ID: <20200721220548.oy5iwquoohevlgbi@madcap2.tricolour.ca> (raw) In-Reply-To: <CAHC9VhSRRN+Qq5dNx6Q5cG_TrXgbBMR0PNUYvf+Haf2na5wCfg@mail.gmail.com> On 2020-07-05 11:11, Paul Moore wrote: > On Sat, Jun 27, 2020 at 9:23 AM Richard Guy Briggs <rgb@redhat.com> wrote: > > > > This also adds support to qualify NETFILTER_PKT records. > > > > Audit events could happen in a network namespace outside of a task > > context due to packets received from the net that trigger an auditing > > rule prior to being associated with a running task. The network > > namespace could be in use by multiple containers by association to the > > tasks in that network namespace. We still want a way to attribute > > these events to any potential containers. Keep a list per network > > namespace to track these audit container identifiiers. > > > > Add/increment the audit container identifier on: > > - initial setting of the audit container identifier via /proc > > - clone/fork call that inherits an audit container identifier > > - unshare call that inherits an audit container identifier > > - setns call that inherits an audit container identifier > > Delete/decrement the audit container identifier on: > > - an inherited audit container identifier dropped when child set > > - process exit > > - unshare call that drops a net namespace > > - setns call that drops a net namespace > > > > Add audit container identifier auxiliary record(s) to NETFILTER_PKT > > event standalone records. Iterate through all potential audit container > > identifiers associated with a network namespace. > > > > Please see the github audit kernel issue for contid net support: > > https://github.com/linux-audit/audit-kernel/issues/92 > > Please see the github audit testsuiite issue for the test case: > > https://github.com/linux-audit/audit-testsuite/issues/64 > > Please see the github audit wiki for the feature overview: > > https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID > > Signed-off-by: Richard Guy Briggs <rgb@redhat.com> > > Acked-by: Neil Horman <nhorman@tuxdriver.com> > > Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com> > > --- > > include/linux/audit.h | 20 ++++++ > > kernel/audit.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++- > > kernel/nsproxy.c | 4 ++ > > net/netfilter/nft_log.c | 11 +++- > > net/netfilter/xt_AUDIT.c | 11 +++- > > 5 files changed, 195 insertions(+), 7 deletions(-) > > > > diff --git a/include/linux/audit.h b/include/linux/audit.h > > index c4a755ae0d61..304fbb7c3c5b 100644 > > --- a/include/linux/audit.h > > +++ b/include/linux/audit.h > > @@ -128,6 +128,13 @@ struct audit_task_info { > > > > extern struct audit_task_info init_struct_audit; > > > > +struct audit_contobj_netns { > > + struct list_head list; > > + struct audit_contobj *obj; > > + int count; > > This seems like it might be a good candidate for refcount_t, yes? I considered this before when converting the struct audit_contobj to refcount_t, but decided against it since any updates are in the context of a list traversal where it could be added to the list and so the spinlock is already held anyways. Is there a more efficent or elegant way of doing the locking around the two list traversals below (_add and _del)? I wonder about converting the count to refcount_t and only holding the spinlock for the list_add_rcu() in the _add case. And for the _del case holding the spinlock only for the list_del_rcu(). These are the only two locations items are added or deleted from the lists. Somewhat related to this is does the list order matter? Items are currently added at the end of the list which likely makes locking simpler, though the start of the list is a simple change. However, unless we understand the profile of read use of these lists for reporting contid use in audit_log_netns_contid_list() I don't think order matters significantly. It could be that reporting of a contid goes down in frequency over the lifetime of a contid that inserting them at the beginning of the list would be best. This is not a visible implementation detail so later optimization should pose no problem. > > + struct rcu_head rcu; > > +}; > > ... > > > diff --git a/kernel/audit.c b/kernel/audit.c > > index 997c34178ee8..a862721dfd9b 100644 > > --- a/kernel/audit.c > > +++ b/kernel/audit.c > > @@ -437,6 +452,136 @@ static struct sock *audit_get_sk(const struct net *net) > > return aunet->sk; > > } > > > > +void audit_netns_contid_add(struct net *net, struct audit_contobj *cont) > > +{ > > + struct audit_net *aunet; > > + struct list_head *contobj_list; > > + struct audit_contobj_netns *contns; > > + > > + if (!net) > > + return; > > + if (!cont) > > + return; > > + aunet = net_generic(net, audit_net_id); > > + if (!aunet) > > + return; > > + contobj_list = &aunet->contobj_list; > > + rcu_read_lock(); > > + spin_lock(&aunet->contobj_list_lock); > > + list_for_each_entry_rcu(contns, contobj_list, list) > > + if (contns->obj == cont) { > > + contns->count++; > > + goto out; > > + } > > + contns = kmalloc(sizeof(*contns), GFP_ATOMIC); > > + if (contns) { > > + INIT_LIST_HEAD(&contns->list); > > + contns->obj = cont; > > + contns->count = 1; > > + list_add_rcu(&contns->list, contobj_list); > > + } > > +out: > > + spin_unlock(&aunet->contobj_list_lock); > > + rcu_read_unlock(); > > +} > > + > > +void audit_netns_contid_del(struct net *net, struct audit_contobj *cont) > > +{ > > + struct audit_net *aunet; > > + struct list_head *contobj_list; > > + struct audit_contobj_netns *contns = NULL; > > + > > + if (!net) > > + return; > > + if (!cont) > > + return; > > + aunet = net_generic(net, audit_net_id); > > + if (!aunet) > > + return; > > + contobj_list = &aunet->contobj_list; > > + rcu_read_lock(); > > + spin_lock(&aunet->contobj_list_lock); > > + list_for_each_entry_rcu(contns, contobj_list, list) > > + if (contns->obj == cont) { > > + contns->count--; > > + if (contns->count < 1) { > > One could simplify this with "(--countns->count) < 1", although if it > is changed to a refcount_t (which seems like a smart thing), the > normal decrement/test would be the best choice. Agreed. > > + list_del_rcu(&contns->list); > > + kfree_rcu(contns, rcu); > > + } > > + break; > > + } > > + spin_unlock(&aunet->contobj_list_lock); > > + rcu_read_unlock(); > > +} > > paul moore - RGB -- Richard Guy Briggs <rgb@redhat.com> 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
next prev parent reply other threads:[~2020-07-21 22:06 UTC|newest] Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-27 13:20 [PATCH ghak90 V9 00/13] audit: implement container identifier Richard Guy Briggs 2020-06-27 13:20 ` [PATCH ghak90 V9 01/13] audit: collect audit task parameters Richard Guy Briggs 2020-07-05 15:09 ` Paul Moore 2020-07-07 2:50 ` Richard Guy Briggs 2020-07-08 1:42 ` Paul Moore 2020-07-13 20:29 ` Richard Guy Briggs 2020-07-14 0:44 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 02/13] audit: add container id Richard Guy Briggs 2020-07-04 13:29 ` Paul Moore 2020-07-04 13:30 ` Paul Moore 2020-07-05 15:09 ` Paul Moore 2020-07-29 20:05 ` Richard Guy Briggs 2020-08-21 19:36 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 03/13] audit: read container ID of a process Richard Guy Briggs 2020-06-27 13:20 ` [PATCH ghak90 V9 04/13] audit: log drop of contid on exit of last task Richard Guy Briggs 2020-07-05 15:10 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 05/13] audit: log container info of syscalls Richard Guy Briggs 2020-07-05 15:10 ` Paul Moore 2020-07-29 19:40 ` Richard Guy Briggs 2020-08-21 19:15 ` Paul Moore 2020-10-02 19:52 ` Richard Guy Briggs 2020-10-21 16:39 ` Richard Guy Briggs 2020-10-21 16:49 ` Steve Grubb 2020-10-21 17:53 ` Richard Guy Briggs 2020-10-23 1:21 ` Paul Moore 2020-10-23 20:40 ` Richard Guy Briggs 2020-10-28 1:35 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 06/13] audit: add contid support for signalling the audit daemon Richard Guy Briggs 2020-07-05 15:10 ` Paul Moore 2020-07-29 19:00 ` Richard Guy Briggs 2020-08-21 18:48 ` Paul Moore 2020-10-02 19:25 ` Richard Guy Briggs 2020-06-27 13:20 ` [PATCH ghak90 V9 07/13] audit: add support for non-syscall auxiliary records Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 08/13] audit: add containerid support for user records Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore 2020-07-18 0:43 ` Richard Guy Briggs 2020-08-21 18:34 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 09/13] audit: add containerid filtering Richard Guy Briggs 2020-06-27 13:20 ` [PATCH ghak90 V9 10/13] audit: add support for containerid to network namespaces Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore 2020-07-21 22:05 ` Richard Guy Briggs [this message] 2020-06-27 13:20 ` [PATCH ghak90 V9 11/13] audit: contid check descendancy and nesting Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore 2020-08-07 17:10 ` Richard Guy Briggs 2020-08-21 20:13 ` Paul Moore 2020-10-06 20:03 ` Richard Guy Briggs 2020-06-27 13:20 ` [PATCH ghak90 V9 12/13] audit: track container nesting Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore 2020-06-27 13:20 ` [PATCH ghak90 V9 13/13] audit: add capcontid to set contid outside init_user_ns Richard Guy Briggs 2020-07-05 15:11 ` Paul Moore
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200721220548.oy5iwquoohevlgbi@madcap2.tricolour.ca \ --to=rgb@redhat.com \ --cc=containers@lists.linux-foundation.org \ --cc=dhowells@redhat.com \ --cc=dwalsh@redhat.com \ --cc=ebiederm@xmission.com \ --cc=eparis@parisplace.org \ --cc=linux-api@vger.kernel.org \ --cc=linux-audit@redhat.com \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mpatel@redhat.com \ --cc=netdev@vger.kernel.org \ --cc=netfilter-devel@vger.kernel.org \ --cc=nhorman@tuxdriver.com \ --cc=omosnace@redhat.com \ --cc=paul@paul-moore.com \ --cc=serge@hallyn.com \ --cc=sgrubb@redhat.com \ --cc=simo@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).