Received: by 10.192.165.156 with SMTP id m28csp711750imm; Thu, 19 Apr 2018 06:23:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jTYVFJHcAxe1BbUAxqQLtOAZhZP8LQlEJ2RSjJU3hJpHuFbs6L0mmKu1/Ne5Up60FPjxK X-Received: by 10.101.98.5 with SMTP id d5mr3340310pgv.416.1524144237862; Thu, 19 Apr 2018 06:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524144237; cv=none; d=google.com; s=arc-20160816; b=OS8hPSk7Gj3/HiDJSTUc22kBizaWdZ60kG4oL2xSLPPNLgCrVo42uBfBZzGRFS+QeR Mi8AmUQayg8MZls0ruhUO0F97kbheWNkuiuX015hON30Cim5k9IOZTct/bQRQV47Z0AD BkVtxNGXixt+m1dcpt8NLTlfVB+9Dog1vqB+WX2lmM/QcWiPu/d1MzH03hZQkiN1Lnyy DOyk7+axlPjyrKpm6qdiq7sC786Xc2YNOkUT4gWCAtdPQi4kXJkWDpjOe8907Fyokh2l Q9b5nTsUTXcRCopvM3Po1tEbi6FpueK5NZA2YegivEsq3/fdB2cBQWi6DWWOCPh2Yx3v 4eew== 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=XV8R+WDxlFp26cpGX8VycL3NkK6sekUViu54arRaRvs=; b=1Gg6OLsVYjY/GD6cxGE1jmXAH9BR4DFQASkFss9qe2C0CAfBcME0r+l9IaKj2w0sqG xKqBmxzFDcGbKh/Le9wvbNO4QvCaScHpEywlBXmdsJiwJQiAwlUZa6VGBb5H9ACqldeu 26JumEqi32UjP4qGFvzV6o3VEARwyY6o8gZ8eN9ii88k/DFGRDfWVFnZlkpO0P4/wJ7K gq8AAKyKRJctleBfNpd50EoTRx+R9HpSsM+dgGgBQgKqSubHfKpY6ePqNdRKDN+OZnrQ PI9wBXZ1oGU3hH+/ZY2tWqo89S12WgfdNs1fLdKs6m2EmOqyPO7kQNug1083d95h1yWT 9SEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=zlQYljks; 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 g11-v6si3278822pll.1.2018.04.19.06.23.44; Thu, 19 Apr 2018 06:23: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; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=zlQYljks; 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 S1752887AbeDSNWS (ORCPT + 99 others); Thu, 19 Apr 2018 09:22:18 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:37444 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbeDSNWP (ORCPT ); Thu, 19 Apr 2018 09:22:15 -0400 Received: by mail-lf0-f65.google.com with SMTP id b23-v6so138108lfg.4 for ; Thu, 19 Apr 2018 06:22:14 -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=XV8R+WDxlFp26cpGX8VycL3NkK6sekUViu54arRaRvs=; b=zlQYljksYgn63NESfD+qmTuOiVQNRp5GlIv806XnyX9ZPH7eiOb5xVpKv2StphkB8b qkaqIEzY/knkK85auDUuDLzLhozTHhXxFDQOdkjUIIZEmF3c3mwX8m/wZ4TuLsSP8KnM 7+w08KTKC2wxcLmcUsPdRLTXhsb7LCbW3SppAK6V6Z8cakeEv+vMjg9tB0j4AYKmYhJt tyi+T55cH59L6K7nkXKRAof5c6rJeOCmKAGphdZVhORyfKJ0+/kqpPSzEfSF+hJHJGlg 78UXKtEjS3xw9UVrpvXjob1IsTBLzJo+qf8p2LustUBfGODZEPzBdizPzCM7Hsli7pAQ HvdA== 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=XV8R+WDxlFp26cpGX8VycL3NkK6sekUViu54arRaRvs=; b=tSzH3hxm9c/ujaENcqffZq+H/y8hKBwuplVE8AjAzN301sRUvG0p5qSLOC87Jdpn+S 2ptd/g19GxlU6As6FhafilUihpHGTXJCwWAUVPBksvhxX7h+a2uyy2yI7mLL88dVoYKB w3bbJgZyqoofeevJ4nei/yrD1nGjAbfnVFTe3nAeTrNkAHrIc1hBK08n0I9/j5LW0dN0 DYIc4xOCzoMYS9qvAT/piR4ehINnDFzPJaxkQbPUAfMTMw9K4lOOStIx1p7sJ+NPpn4M 4xAKVRYmI11hiGneXRLED/QK/WoyqMzhRE4ZjYEkVyHFvGvPWumTMgNYtvvCHIAf5oGQ b7yA== X-Gm-Message-State: ALQs6tDrAZDgaaxgihsC/KPQ+ECdtTuQB1P6CkvOy/5ft2+mQdcyvIcV Jk3kQRdcyRibEOuypTMEkRnNlja2vTwnQhuoxduM X-Received: by 10.46.131.197 with SMTP id s5mr4256830ljh.72.1524144133809; Thu, 19 Apr 2018 06:22:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:a5c3:0:0:0:0:0 with HTTP; Thu, 19 Apr 2018 06:13:17 -0700 (PDT) X-Originating-IP: [108.20.156.165] In-Reply-To: <20180419124550.7uknp4oebvwoo67s@madcap2.tricolour.ca> References: <66adde01c1dda792aff99a457eea576a0b08ca98.1521179281.git.rgb@redhat.com> <20180419124550.7uknp4oebvwoo67s@madcap2.tricolour.ca> From: Paul Moore Date: Thu, 19 Apr 2018 09:13:17 -0400 Message-ID: Subject: Re: [RFC PATCH ghak32 V2 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS To: Richard Guy Briggs Cc: cgroups@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, ebiederm@xmission.com, luto@kernel.org, jlayton@redhat.com, carlos@redhat.com, dhowells@redhat.com, viro@zeniv.linux.org.uk, simo@redhat.com, Eric Paris , serge@hallyn.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 Thu, Apr 19, 2018 at 8:45 AM, Richard Guy Briggs wrote: > On 2018-04-18 22:10, Paul Moore wrote: >> On Fri, Mar 16, 2018 at 5:00 AM, Richard Guy Briggs wrote: >> > Add container ID auxiliary record(s) to NETFILTER_PKT event standalone >> > records. Iterate through all potential container IDs associated with a >> > network namespace. >> > >> > Signed-off-by: Richard Guy Briggs >> > --- >> > kernel/audit.c | 1 + >> > kernel/auditsc.c | 2 ++ >> > net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- >> > 3 files changed, 17 insertions(+), 1 deletion(-) >> > >> > diff --git a/kernel/audit.c b/kernel/audit.c >> > index 08662b4..3c77e47 100644 >> > --- a/kernel/audit.c >> > +++ b/kernel/audit.c >> > @@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context, >> > audit_log_end(ab); >> > return 0; >> > } >> > +EXPORT_SYMBOL(audit_log_container_info); >> > >> > void audit_log_key(struct audit_buffer *ab, char *key) >> > { >> > diff --git a/kernel/auditsc.c b/kernel/auditsc.c >> > index 208da962..af68d01 100644 >> > --- a/kernel/auditsc.c >> > +++ b/kernel/auditsc.c >> > @@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) >> > context->in_syscall = 1; >> > return context; >> > } >> > +EXPORT_SYMBOL(audit_alloc_local); >> > >> > inline void audit_free_context(struct audit_context *context) >> > { >> > @@ -989,6 +990,7 @@ 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, unsigned int sessionid, >> > diff --git a/net/netfilter/xt_AUDIT.c b/net/netfilter/xt_AUDIT.c >> > index c502419..edaa456 100644 >> > --- a/net/netfilter/xt_AUDIT.c >> > +++ b/net/netfilter/xt_AUDIT.c >> > @@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) >> > { >> > struct audit_buffer *ab; >> > int fam = -1; >> > + struct audit_context *context = audit_alloc_local(); >> > + struct audit_containerid *cont; >> > + int i = 0; >> > + struct net *net; >> > >> > if (audit_enabled == 0) >> > goto errout; >> >> Do I need to say it? I probably should ... the allocation should >> happen after the audit_enabled check. > > Already fixed in V3 in my tree a couple of weeks ago... ... which you never posted, at least not anywhere I've seen. Which effectively means I wasted a good chunk of time reviewing this code late last night. Awesome. > More timely review please? More patience on your part? >> > - ab = audit_log_start(NULL, GFP_ATOMIC, AUDIT_NETFILTER_PKT); >> > + ab = audit_log_start(context, GFP_ATOMIC, AUDIT_NETFILTER_PKT); >> > if (ab == NULL) >> > goto errout; >> > >> > @@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) >> > >> > audit_log_end(ab); >> > >> > + net = sock_net(NETLINK_CB(skb).sk); >> > + list_for_each_entry(cont, &net->audit_containerid, list) { >> > + char buf[14]; >> > + >> > + sprintf(buf, "net%u", i++); >> > + audit_log_container_info(context, buf, cont->id); >> > + } >> >> It seems like this could (should?) be hidden inside an audit function, >> e.g. audit_log_net_containers() or something like that. > > Perhaps... It was open-coded since at this point there are no other > users. That'll make this tidier though. If the code was all contained within a single subsystem them I would generally agree that open coding is preferable, but since we are crossing a subsystem boundary I think it would be preferable to abstract away the details into a separate function. This will probably also be necessary once you change to using the audit_net/net_generic mechanism. -- paul moore www.paul-moore.com