Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp260403ybp; Thu, 10 Oct 2019 17:42:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpDJIA2USjtiUjEqS1u6Mmr/yn4NbEyOU8xgj/Eocd/jxcOk1CTLb4KO8VydjBdbJvl2wg X-Received: by 2002:a17:906:19cf:: with SMTP id h15mr11439151ejd.184.1570754521136; Thu, 10 Oct 2019 17:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570754521; cv=none; d=google.com; s=arc-20160816; b=F8cTJY0M+Ql14ItIu+zfL3tR787jvp0ekgd/L0QV3Kzqivnshp8mUz/R2iNkoR/7mK sGKHugXbyqB3aBDNfM/sFRI4tYT5cgx2Bw0IN/+mZb1qHjjYD8WC/wQDjfbXFTyJLmxk czfKYiLA8vaq3yQJk3r4aoMT6S55UdxEPpgtiXDFIaaqojs2YagjD72d+xcXMeLwT8hB TIGrtC0vmgIGtnIeM0qopTtUy6Sc0Ilr1frH6sels/wNMF/zBR4wPNjEjHz5hC6T7bum Tg8G8cx8rxO8dEgj+ZnhWCQmSntilVbM4ts08prCQTNOaygLFZyKd07HEHXvSUfAXaBN nlUA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=QkzZR9OEPJLaUXXIdfh6gF0s61TBZnR/lxZWV3PihuE=; b=C94M3Yxevy4A1DmGMinYSO3uKa+eMf8+S6qs7YWfrbMh1iTV+jM6euQqrbpk6Cc5gB r0b+zeUziOQJQDSPjHx6fzqhDelMZwCEPOlYLzovMESAjqx3emLB1VvhSjOSErPpsCC6 +YSI9/4PlajQYfrca1hvskoPJPyaaZgcLksfKSfrHoj7B1AsrYTpU5HO6EPYSJEBaGCt lWU3DkkQYkNWj0iFps5TgeIroKnt9MLLxNx8GhNEpO782wFS2TH8JRM+GOLG5lkwrvZ2 dswAhZhS3g0yOCWuJYJrtZ6ajet/6hixBsjx6IasiD32zukrISpZK+9d+INJHUdnhdqB tgcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=UTddWIBi; 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 h13si4784965edh.242.2019.10.10.17.41.37; Thu, 10 Oct 2019 17:42:01 -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=UTddWIBi; 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 S1727988AbfJKAkF (ORCPT + 99 others); Thu, 10 Oct 2019 20:40:05 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:42013 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbfJKAkE (ORCPT ); Thu, 10 Oct 2019 20:40:04 -0400 Received: by mail-lf1-f67.google.com with SMTP id c195so5723411lfg.9 for ; Thu, 10 Oct 2019 17:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QkzZR9OEPJLaUXXIdfh6gF0s61TBZnR/lxZWV3PihuE=; b=UTddWIBiR1GAGxR+mVYGM2xyl/RvsIwM/NAHHgw54XYygmhj3i5UVV2I4PEAPeMN6C gUnZcpxsnn/VIoSqeuT29NvcCnTBtQZZYIzezV5nhl7h4g7PLvfzBM9JLlGRzxCT3t2Z V27bVV3SutbKjSG6fE1eHwplxGQDRN6z39JCyjIWMYGA/+VseS+1Fy34mOJ9AHdVA5AH 3C1Tm5Nh052pq5kI5hNpRdfIZf13CWV/RwRTcOz8sqXffvjbRwBESlTXGOtLlGBMADel MFiIkKsyURq0OHNdEEPAgujRar/g74XGku51ImEHY3XnH6J7Re0MG9K7AQuvm1WQxIJG lrQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QkzZR9OEPJLaUXXIdfh6gF0s61TBZnR/lxZWV3PihuE=; b=CeHyebolQIRYZh4r2nOs4GEXkFlXMeElazbRM4slfGS/QDrR8uqvSktdijzof0aH5j Q4YvQO7alVNKciy8x6AKmZvm99zZKGHlIHWR14T4I4yJpSxt1sdbKNhmnwg65IZGe5Ia IkxsCb2tvrFcnclcSHgANIrXxFGthL/VLtIeb/p7RPtXr0MY2x4VNOpB1525+zfhoKa8 OcJEwO6rXhBJirrRmNCb5GpTgxsr1tql8GAUF8sElAF8Xs9RM979ZzS4JEIIqU1OebpO myOZ/dSIFSVzG13WE4RbOQks+00WgqG78Giy+vxwrvD8IBWZsF57WbwsiLFOBqODviwB ovZQ== X-Gm-Message-State: APjAAAU0thMuXzeHWHzE/CTwuThRYrIjaGh/V09fxIzfBJH47q1RK40d yVgz+jCpdKRiRwZ5ZlpFzpcqvYotWqpl7tTLvc8S X-Received: by 2002:a19:c7cf:: with SMTP id x198mr7323383lff.158.1570754401856; Thu, 10 Oct 2019 17:40:01 -0700 (PDT) MIME-Version: 1.0 References: <18f14bfbffc30c53c2b1dd06694b69ef286f3b72.1568834524.git.rgb@redhat.com> In-Reply-To: <18f14bfbffc30c53c2b1dd06694b69ef286f3b72.1568834524.git.rgb@redhat.com> From: Paul Moore Date: Thu, 10 Oct 2019 20:39:50 -0400 Message-ID: Subject: Re: [PATCH ghak90 V7 13/21] audit: NETFILTER_PKT: record each container ID associated with a netNS To: Richard Guy Briggs Cc: containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, Eric Paris , Serge Hallyn , ebiederm@xmission.com, nhorman@tuxdriver.com, Dan Walsh , mpatel@redhat.com 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 Wed, Sep 18, 2019 at 9:26 PM Richard Guy Briggs wrote: > 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. > > Signed-off-by: Richard Guy Briggs > Acked-by: Neil Horman > Reviewed-by: Ondrej Mosnacek > --- > include/linux/audit.h | 5 +++++ > kernel/audit.c | 39 +++++++++++++++++++++++++++++++++++++++ > net/netfilter/nft_log.c | 11 +++++++++-- > net/netfilter/xt_AUDIT.c | 11 +++++++++-- > 4 files changed, 62 insertions(+), 4 deletions(-) This should be squashed together with patch 12/21; neither patch makes sense by themselves. > diff --git a/include/linux/audit.h b/include/linux/audit.h > index 73e3ab38e3e0..dcd92f964120 100644 > --- a/include/linux/audit.h > +++ b/include/linux/audit.h > @@ -241,6 +241,8 @@ static inline u64 audit_get_contid(struct task_struct *tsk) > extern void audit_netns_contid_del(struct net *net, u64 contid); > extern void audit_switch_task_namespaces(struct nsproxy *ns, > struct task_struct *p); > +extern void audit_log_netns_contid_list(struct net *net, > + struct audit_context *context); > > extern u32 audit_enabled; > > @@ -328,6 +330,9 @@ static inline void audit_netns_contid_del(struct net *net, u64 contid) > static inline void audit_switch_task_namespaces(struct nsproxy *ns, > struct task_struct *p) > { } > +static inline void audit_log_netns_contid_list(struct net *net, > + struct audit_context *context) > +{ } > > #define audit_enabled AUDIT_OFF > > diff --git a/kernel/audit.c b/kernel/audit.c > index e0c27bc39925..9ce7a1ec7a92 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -450,6 +450,45 @@ void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p) > audit_netns_contid_add(new->net_ns, contid); > } > > +/** > + * audit_log_netns_contid_list - List contids for the given network namespace > + * @net: the network namespace of interest > + * @context: the audit context to use > + * > + * Description: > + * Issues a CONTAINER_ID record with a CSV list of contids associated > + * with a network namespace to accompany a NETFILTER_PKT record. > + */ > +void audit_log_netns_contid_list(struct net *net, struct audit_context *context) > +{ > + struct audit_buffer *ab = NULL; > + struct audit_contid *cont; > + struct audit_net *aunet; > + > + /* Generate AUDIT_CONTAINER_ID record with container ID CSV list */ > + rcu_read_lock(); > + aunet = net_generic(net, audit_net_id); > + if (!aunet) > + goto out; > + list_for_each_entry_rcu(cont, &aunet->contid_list, list) { > + if (!ab) { > + ab = audit_log_start(context, GFP_ATOMIC, > + AUDIT_CONTAINER_ID); > + if (!ab) { > + audit_log_lost("out of memory in audit_log_netns_contid_list"); > + goto out; > + } > + audit_log_format(ab, "contid="); > + } else > + audit_log_format(ab, ","); > + audit_log_format(ab, "%llu", cont->id); > + } > + audit_log_end(ab); > +out: > + rcu_read_unlock(); > +} > +EXPORT_SYMBOL(audit_log_netns_contid_list); > + > void audit_panic(const char *message) > { > switch (audit_failure) { > diff --git a/net/netfilter/nft_log.c b/net/netfilter/nft_log.c > index fe4831f2258f..98d1e7e1a83c 100644 > --- a/net/netfilter/nft_log.c > +++ b/net/netfilter/nft_log.c > @@ -66,13 +66,16 @@ static void nft_log_eval_audit(const struct nft_pktinfo *pkt) > struct sk_buff *skb = pkt->skb; > struct audit_buffer *ab; > int fam = -1; > + struct audit_context *context; > + struct net *net; > > if (!audit_enabled) > return; > > - ab = audit_log_start(NULL, GFP_ATOMIC, AUDIT_NETFILTER_PKT); > + context = audit_alloc_local(GFP_ATOMIC); > + ab = audit_log_start(context, GFP_ATOMIC, AUDIT_NETFILTER_PKT); > if (!ab) > - return; > + goto errout; > > audit_log_format(ab, "mark=%#x", skb->mark); > > @@ -99,6 +102,10 @@ static void nft_log_eval_audit(const struct nft_pktinfo *pkt) > audit_log_format(ab, " saddr=? daddr=? proto=-1"); > > audit_log_end(ab); > + net = xt_net(&pkt->xt); > + audit_log_netns_contid_list(net, context); > +errout: > + audit_free_context(context); > } > > static void nft_log_eval(const struct nft_expr *expr, > diff --git a/net/netfilter/xt_AUDIT.c b/net/netfilter/xt_AUDIT.c > index 9cdc16b0d0d8..ecf868a1abde 100644 > --- a/net/netfilter/xt_AUDIT.c > +++ b/net/netfilter/xt_AUDIT.c > @@ -68,10 +68,13 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) > { > struct audit_buffer *ab; > int fam = -1; > + struct audit_context *context; > + struct net *net; > > if (audit_enabled == AUDIT_OFF) > - goto errout; > - ab = audit_log_start(NULL, GFP_ATOMIC, AUDIT_NETFILTER_PKT); > + goto out; > + context = audit_alloc_local(GFP_ATOMIC); > + ab = audit_log_start(context, GFP_ATOMIC, AUDIT_NETFILTER_PKT); > if (ab == NULL) > goto errout; > > @@ -101,7 +104,11 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) > > audit_log_end(ab); > > + net = xt_net(par); > + audit_log_netns_contid_list(net, context); > errout: > + audit_free_context(context); > +out: > return XT_CONTINUE; > } > -- paul moore www.paul-moore.com