mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Guy Briggs <rgb@redhat.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jones Desougi <jones.desougi+netfilter@gmail.com>,
	Phil Sutter <phil@nwl.cc>, Florian Westphal <fw@strlen.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux-Audit Mailing List <linux-audit@redhat.com>,
	netfilter-devel@vger.kernel.org, twoerner@redhat.com,
	Eric Paris <eparis@parisplace.org>,
	tgraf@infradead.org, dan.carpenter@oracle.com
Subject: Re: [PATCH v2] audit: log nftables configuration change events once per table
Date: Tue, 23 Mar 2021 15:41:15 -0400	[thread overview]
Message-ID: <20210323194115.GA3112383@madcap2.tricolour.ca> (raw)
In-Reply-To: <20210322225747.GA24562@salvia>

On 2021-03-22 23:57, Pablo Neira Ayuso wrote:
> 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.

Duh, whoops!  Brain fart.  Too much muckin' in other codebases...

> > +	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)
>                 ...

This will need a bit more work since by the time this is called,
nf_tables_commit() is not prepared to accept any errors, so I'll need to
either ignore the error and continue, or allocate the table entries
before step 3.

> > +	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

- 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


      reply	other threads:[~2021-03-23 19:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 20:49 Richard Guy Briggs
2021-03-22 22:57 ` Pablo Neira Ayuso
2021-03-23 19:41   ` Richard Guy Briggs [this message]

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=20210323194115.GA3112383@madcap2.tricolour.ca \
    --to=rgb@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=eparis@parisplace.org \
    --cc=fw@strlen.de \
    --cc=jones.desougi+netfilter@gmail.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=tgraf@infradead.org \
    --cc=twoerner@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: link
Be 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

all inboxes | Powered by JetHome®