Netdev List
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org, pabeni@redhat.com, edumazet@google.com,
	horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net 07/10] netfilter: nf_tables: skip double clone set expressions on element insert
Date: Mon, 24 Aug 2026 14:19:55 +0200	[thread overview]
Message-ID: <aow26yHSKQONZTt-@chamomile> (raw)
In-Reply-To: <20260822195228.2202729-1-kuba@kernel.org>

On Sat, Aug 22, 2026 at 12:52:28PM -0700, Jakub Kicinski wrote:
> This is an AI-generated review of your patch. The human sending this
> email has considered the AI review valid, or at least plausible.
> ---
> netfilter: nf_tables: skip double clone set expressions on element insert
> 
> This adds an override_exprs flag so that the dynset and newsetelem paths
> borrow the set's expressions instead of cloning them when userspace does
> not supply an override, and releases the expression array only when it
> really is an override.  The same flag is now used to decide whether the
> dynset expression override is dumped back to userspace.
> 
> > diff --git a/net/netfilter/nft_dynset.c b/net/netfilter/nft_dynset.c
> > index ee9d3e7b1ecf1..fa4da694e92d8 100644
> > --- a/net/netfilter/nft_dynset.c
> > +++ b/net/netfilter/nft_dynset.c
> > @@ -19,7 +19,8 @@ struct nft_dynset {
> >  	u8				sreg_key;
> >  	u8				sreg_data;
> >  	bool				invert;
> > -	bool				expr;
> > +	bool				expr:1,
> > +					override_exprs:1;
> >  	u8				num_exprs;
> >  	u64				timeout;
> >  	struct nft_expr			*expr_array[NFT_SET_EXPR_MAX];
> 
> [ ... ]
> 
> > @@ -393,7 +398,7 @@ static int nft_dynset_dump(struct sk_buff *skb,
> >  			 nf_jiffies64_to_msecs(priv->timeout),
> >  			 NFTA_DYNSET_PAD))
> >  		goto nla_put_failure;
> > -	if (priv->set->num_exprs == 0) {
> > +	if (priv->set->num_exprs == 0 || priv->override_exprs) {
> >  		if (priv->num_exprs == 1) {
> >  			if (nft_expr_dump(skb, NFTA_DYNSET_EXPR,
> >  					  priv->expr_array[0], reset))
> 
> [Severity: Medium]
> Can the message emitted by nft_dynset_dump() after this change be rejected
> by nft_dynset_init() when it is replayed?
> 
> With the widened condition, a dynset attached to a set that owns
> expressions (set->num_exprs > 0) now dumps its override.  For
> priv->num_exprs > 1 that override is emitted as an NFTA_DYNSET_EXPRESSIONS
> nest:
> 
> net/netfilter/nft_dynset.c:nft_dynset_dump() {
> 	...
> 	u32 flags = priv->invert ? NFT_DYNSET_F_INV : 0;
> 	...
> 	} else if (priv->num_exprs > 1) {
> 		struct nlattr *nest;
> 
> 		nest = nla_nest_start_noflag(skb, NFTA_DYNSET_EXPRESSIONS);
> 	...
> 	if (nla_put_be32(skb, NFTA_DYNSET_FLAGS, htonl(flags)))
> 	...
> }
> 
> The dumped NFTA_DYNSET_FLAGS is computed only from priv->invert, so
> NFT_DYNSET_F_EXPR is never set, even though priv->expr records that
> userspace passed it at creation time.  On the parse side the
> NFTA_DYNSET_EXPRESSIONS branch requires that flag:
> 
> net/netfilter/nft_dynset.c:nft_dynset_init() {
> 	...
> 	} else if (tb[NFTA_DYNSET_EXPRESSIONS]) {
> 		...
> 		if (!priv->expr)
> 			return -EINVAL;
> 	...
> }
> 
> So a rule with two override expressions on an NFT_SET_EVAL set that also
> has two set expressions (for example counter plus quota) appears to be
> dumped in a form that the kernel's own parser refuses with -EINVAL when the
> netlink message is sent back (raw netlink echo, or libnftnl parse-then-build
> restore paths).  Before this patch that configuration emitted no expression
> attributes at all, so the replay was accepted and silently fell back to the
> set's expressions.
> 
> The missing NFT_DYNSET_F_EXPR in the dump path predates this patch (it is
> already reachable for priv->set->num_exprs == 0 with more than one
> expression), but the new condition extends the asymmetry to
> override-on-eval-set rules that used to round-trip.  Should
> nft_dynset_dump() also report NFT_DYNSET_F_EXPR when priv->expr is set?

This sounds like a theotical issue:

1) Example with one single expression.

table ip x {
        set y {
                typeof ip saddr
                flags dynamic
                ct count over 2
        }
 
        chain z {
                update @y { ip saddr ct count over 3 }
        }
}

2) Example with two expressions

table ip x {
        set y {
                typeof ip saddr
                flags dynamic
                counter ct count over 2
        }
 
        chain z {
                update @y { ip saddr counter ct count over 3 }
        }
}

It works fine with userspace 'nft'.

It might be a correctness API issue to guarantee this symmetry, but we
can follow up.

  reply	other threads:[~2026-08-24 12:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 15:38 [PATCH net 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 01/10] netfilter: tproxy: use DEBUG_NET_WARN_ON_ONCE for protocol fallbacks Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 02/10] netfilter: conncount: use DEBUG_NET_WARN_ON_ONCE on reaching count limit Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 03/10] netfilter: nf_tables: move hardware offload step after building the chain blob Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 04/10] netfilter: nft_set_pipapo_avx2: add missing vzeroupper Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 05/10] netfilter: x_tables: remove pr_debug Pablo Neira Ayuso
2026-08-22 19:52   ` Jakub Kicinski
2026-08-24 12:17     ` Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 06/10] netfilter: xt_cgroup: use pr_info_ratelimited() Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 07/10] netfilter: nf_tables: skip double clone set expressions on element insert Pablo Neira Ayuso
2026-08-22 19:52   ` Jakub Kicinski
2026-08-24 12:19     ` Pablo Neira Ayuso [this message]
2026-08-21 15:38 ` [PATCH net 08/10] netfilter: nf_tables: fix device name and prefix match in hook lookup Pablo Neira Ayuso
2026-08-22 19:52   ` Jakub Kicinski
2026-08-23 17:36     ` Fernando Fernandez Mancera
2026-08-21 15:38 ` [PATCH net 09/10] netfilter: nf_tables: set on dead bit when performing early element removal Pablo Neira Ayuso
2026-08-21 15:38 ` [PATCH net 10/10] netfilter: nf_tables: remove leftover set_update_list 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=aow26yHSKQONZTt-@chamomile \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=ja@ssi.bg \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@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