From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1307C433C1 for ; Tue, 23 Mar 2021 01:46:44 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CA9B619A9 for ; Tue, 23 Mar 2021 01:46:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CA9B619A9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=linux-audit-bounces@redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-Tu_5ASriMDa6V-Xnd3RHmw-1; Mon, 22 Mar 2021 21:46:41 -0400 X-MC-Unique: Tu_5ASriMDa6V-Xnd3RHmw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 948D15B362; Tue, 23 Mar 2021 01:46:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C99EF50A8A; Tue, 23 Mar 2021 01:46:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E1CEC4BB7C; Tue, 23 Mar 2021 01:46:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12MMvvJJ019335 for ; Mon, 22 Mar 2021 18:57:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE15C2026D65; Mon, 22 Mar 2021 22:57:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A90A92026D60 for ; Mon, 22 Mar 2021 22:57:54 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE194100E641 for ; Mon, 22 Mar 2021 22:57:54 +0000 (UTC) Received: from mail.netfilter.org (mail.netfilter.org [217.70.188.207]) by relay.mimecast.com with ESMTP id us-mta-602-Ixquww6hNe-Fbm2FdIgvYA-1; Mon, 22 Mar 2021 18:57:52 -0400 X-MC-Unique: Ixquww6hNe-Fbm2FdIgvYA-1 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 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 In-Reply-To: <2a6d8eb6058a6961cfb6439b31dcfadcce9596a8.1616445965.git.rgb@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Mon, 22 Mar 2021 21:46:32 -0400 Cc: Jones Desougi , Phil Sutter , Florian Westphal , LKML , Linux-Audit Mailing List , netfilter-devel@vger.kernel.org, twoerner@redhat.com, Eric Paris , tgraf@infradead.org, dan.carpenter@oracle.com X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84D72C433DB for ; Mon, 22 Mar 2021 22:58:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EA78619A3 for ; Mon, 22 Mar 2021 22:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230316AbhCVW60 (ORCPT ); Mon, 22 Mar 2021 18:58:26 -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: netfilter-devel@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.