From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nf-next PATCH v3 1/3] netfilter: nf_tables: Audit log dump reset after the fact
Date: Wed, 25 Oct 2023 22:57:25 +0200 [thread overview]
Message-ID: <ZTmBNTDHKhwKGgdo@calendula> (raw)
In-Reply-To: <ZTl+jIRe0ODMtI5F@calendula>
On Wed, Oct 25, 2023 at 10:46:08PM +0200, Pablo Neira Ayuso wrote:
> On Wed, Oct 25, 2023 at 10:08:26PM +0200, Phil Sutter wrote:
> > In theory, dumpreset may fail and invalidate the preceeding log message.
> > Fix this and use the occasion to prepare for object reset locking, which
> > benefits from a few unrelated changes:
> >
> > * Add an early call to nfnetlink_unicast if not resetting which
> > effectively skips the audit logging but also unindents it.
> > * Extract the table's name from the netlink attribute (which is verified
> > via earlier table lookup) to not rely upon validity of the looked up
> > table pointer.
> > * Do not use local variable family, it will vanish.
> >
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > net/netfilter/nf_tables_api.c | 28 +++++++++++++---------------
> > 1 file changed, 13 insertions(+), 15 deletions(-)
> >
> > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> > index 3c1fd8283bf4..d0f7274b7ffe 100644
> > --- a/net/netfilter/nf_tables_api.c
> > +++ b/net/netfilter/nf_tables_api.c
> > @@ -7767,6 +7767,7 @@ static int nf_tables_dump_obj_done(struct netlink_callback *cb)
> > static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
> > const struct nlattr * const nla[])
> > {
> > + const struct nftables_pernet *nft_net = nft_pernet(info->net);
> > struct netlink_ext_ack *extack = info->extack;
> > u8 genmask = nft_genmask_cur(info->net);
> > u8 family = info->nfmsg->nfgen_family;
> > @@ -7776,6 +7777,7 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
> > struct sk_buff *skb2;
> > bool reset = false;
> > u32 objtype;
> > + char *buf;
> > int err;
> >
> > if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
> > @@ -7814,27 +7816,23 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
> > if (NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_GETOBJ_RESET)
> > reset = true;
> >
> > - if (reset) {
> > - const struct nftables_pernet *nft_net;
> > - char *buf;
> > -
> > - nft_net = nft_pernet(net);
> > - buf = kasprintf(GFP_ATOMIC, "%s:%u", table->name, nft_net->base_seq);
> > -
> > - audit_log_nfcfg(buf,
> > - family,
> > - 1,
> > - AUDIT_NFT_OP_OBJ_RESET,
> > - GFP_ATOMIC);
> > - kfree(buf);
> > - }
> > -
> > err = nf_tables_fill_obj_info(skb2, net, NETLINK_CB(skb).portid,
> > info->nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
> > family, table, obj, reset);
> > if (err < 0)
> > goto err_fill_obj_info;
> >
> > + if (!reset)
> > + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
>
> More simple with?
>
> if (reset) {
> buf = kasprintf(GFP_ATOMIC, "%.*s:%u",
> nla_len(nla[NFTA_OBJ_TABLE]),
> (char *)nla_data(nla[NFTA_OBJ_TABLE]),
> nft_net->base_seq);
> audit_log_nfcfg(buf, info->nfmsg->nfgen_family,
> 1, AUDIT_NFT_OP_OBJ_RESET, GFP_ATOMIC);
> kfree(buf);
> }
>
> return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
>
> single call to nfnetlink_unicast().
Oh I see. It goes away in patch 3/3.
- if (!reset)
- return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
next prev parent reply other threads:[~2023-10-25 20:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 20:08 [nf-next PATCH v3 0/3] Add locking for NFT_MSG_GETOBJ_RESET requests Phil Sutter
2023-10-25 20:08 ` [nf-next PATCH v3 1/3] netfilter: nf_tables: Audit log dump reset after the fact Phil Sutter
2023-10-25 20:46 ` Pablo Neira Ayuso
2023-10-25 20:57 ` Pablo Neira Ayuso [this message]
2023-10-25 20:08 ` [nf-next PATCH v3 2/3] netfilter: nf_tables: Introduce nf_tables_getobj_single Phil Sutter
2023-10-25 20:08 ` [nf-next PATCH v3 3/3] netfilter: nf_tables: Add locking for NFT_MSG_GETOBJ_RESET requests Phil Sutter
2023-10-25 21:00 ` Pablo Neira Ayuso
2023-10-26 8:15 ` Pablo Neira Ayuso
2023-10-26 8:26 ` Pablo Neira Ayuso
2023-10-26 8:55 ` Pablo Neira Ayuso
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=ZTmBNTDHKhwKGgdo@calendula \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.