Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3804326pxf; Mon, 22 Mar 2021 16:02:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzggrRQwO5CC89eFIg5zt7MpF9D3rNa8q7V+1uhOV6qaXsd9r5dM/iAZl7yw7HUaqe/K+Wv X-Received: by 2002:a17:907:2b03:: with SMTP id gc3mr2015662ejc.448.1616454125362; Mon, 22 Mar 2021 16:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616454125; cv=none; d=google.com; s=arc-20160816; b=dDNZ98sjpGcFAQFFOgPrcsw5jN2CW6r90MzXdmD4AANEvZFce12ANTlFmZiJouCpCj I19tHDpXMHgc2S/YJJIxPUD6C7M1QeInJibUWNMAVWdXDr1dXewxpjg2X8ton8zD8g6Q j7xI6RirkvxYwajm9ve/CjJ4bJUgo3TDF7emDe6/rXIdI1LWuGPrTeTH1zmFLp0KP5K6 gxujIwnYYfrp1fPo6dP0bxNhL1VNYsW8LzuGkyB8XncA/Qh+y7cLHOLC7vOEhlT9u0Tj nnYkYJAKLa/gaQ1+68/WNNCzpBZwLbtisR2SuAXNF3wXqbwlFxEJMIFxC83jX2pDJx4J y5DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=V9/aNIq9OC/jRap3pas4+uqbYaWWXgIvepnvCFi4Xec=; b=L9uYTv7x8vTC2wXoT8xY4DjsReUoO1F8lXvT0EYNdaJhYyeN/3ZSTBHVrlDWmu4rBR d4ECpESJpq92KPDqA4pVTj2+6dDafKtOehh+DuSZmt7sqeUrF0M2e5YPh1yNdqvpMg3k Qs8+mSRmDYYnL1xKYdyUHgCW+4YcqkrsGNySIjYOQrU4HjQ5wTT74/qCVxxRuYwxi7Yu lsxW50FwexHyotgvA72OJ1MqkRvzfxXa/UWSwWwjaCUN7iDtF4d8mqgL1SlhZ7X7Vjek /5SbNLLNN43vhl78oVm+dJcPVOlXOIf0xwt6mstDtVbkNM5clrupakJ9MQG3rAFEnlXC zacg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si12139276ejy.263.2021.03.22.16.01.39; Mon, 22 Mar 2021 16:02:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbhCVW61 (ORCPT + 99 others); Mon, 22 Mar 2021 18:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbhCVW5y (ORCPT ); Mon, 22 Mar 2021 18:57:54 -0400 Received: from mail.netfilter.org (mail.netfilter.org [IPv6:2001:4b98:dc0:41:216:3eff:fe8c:2bda]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E7FDC061574; Mon, 22 Mar 2021 15:57:52 -0700 (PDT) Received: from us.es (unknown [90.77.255.23]) by mail.netfilter.org (Postfix) with ESMTPSA id 6D803630C2; Mon, 22 Mar 2021 23:57:43 +0100 (CET) Date: Mon, 22 Mar 2021 23:57:47 +0100 From: Pablo Neira Ayuso To: Richard Guy Briggs Cc: Linux-Audit Mailing List , LKML , netfilter-devel@vger.kernel.org, Paul Moore , Eric Paris , Steve Grubb , Florian Westphal , Phil Sutter , twoerner@redhat.com, tgraf@infradead.org, dan.carpenter@oracle.com, Jones Desougi Subject: Re: [PATCH v2] audit: log nftables configuration change events once per table Message-ID: <20210322225747.GA24562@salvia> References: <2a6d8eb6058a6961cfb6439b31dcfadcce9596a8.1616445965.git.rgb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2a6d8eb6058a6961cfb6439b31dcfadcce9596a8.1616445965.git.rgb@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 22, 2021 at 04:49:04PM -0400, Richard Guy Briggs wrote: > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > index c1eb5cdb3033..42ba44890523 100644 > --- a/net/netfilter/nf_tables_api.c > +++ b/net/netfilter/nf_tables_api.c [...] > @@ -8006,12 +7938,47 @@ static void nft_commit_notify(struct net *net, u32 portid) > WARN_ON_ONCE(!list_empty(&net->nft.notify_list)); > } > > +void nf_tables_commit_audit_collect(struct list_head *adl, > + struct nft_trans *trans) { nitpick: curly brace starts in the line. > + struct nft_audit_data *adp; > + > + list_for_each_entry(adp, adl, list) { > + if (adp->table == trans->ctx.table) > + goto found; > + } > + adp = kzalloc(sizeof(*adp), GFP_KERNEL); if (!adp) ... > + adp->table = trans->ctx.table; > + INIT_LIST_HEAD(&adp->list); > + list_add(&adp->list, adl); > +found: > + adp->entries++; > + if (!adp->op || adp->op > trans->msg_type) > + adp->op = trans->msg_type; > +} > + > +#define AUNFTABLENAMELEN (NFT_TABLE_MAXNAMELEN + 22) > + > +void nf_tables_commit_audit_log(struct list_head *adl, u32 generation) { ^ same thing here > + struct nft_audit_data *adp, *adn; > + char aubuf[AUNFTABLENAMELEN]; > + > + list_for_each_entry_safe(adp, adn, adl, list) { > + snprintf(aubuf, AUNFTABLENAMELEN, "%s:%u", adp->table->name, > + generation); > + audit_log_nfcfg(aubuf, adp->table->family, adp->entries, > + nft2audit_op[adp->op], GFP_KERNEL); > + list_del(&adp->list); > + kfree(adp); > + } > +} > + > static int nf_tables_commit(struct net *net, struct sk_buff *skb) > { > struct nft_trans *trans, *next; > struct nft_trans_elem *te; > struct nft_chain *chain; > struct nft_table *table; > + LIST_HEAD(adl); > int err; > > if (list_empty(&net->nft.commit_list)) { > @@ -8206,12 +8173,15 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) > } > break; > } > + nf_tables_commit_audit_collect(&adl, trans); > } > > nft_commit_notify(net, NETLINK_CB(skb).portid); > nf_tables_gen_notify(net, skb, NFT_MSG_NEWGEN); > nf_tables_commit_release(net); > > + nf_tables_commit_audit_log(&adl, net->nft.base_seq); > + This looks more self-contained and nicer, thanks.