From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Zach Loafman <zml@zml.net>
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de, phil@nwl.cc
Subject: Re: [PATCH] netfilter: nft_dynset: check extension template errors
Date: Thu, 26 Nov 2026 01:46:28 +0100 [thread overview]
Message-ID: <aweBZHiTptFcPUI8@chamomile> (raw)
In-Reply-To: <20261126001556.69645-1-zml@zml.net>
On Wed, Nov 25, 2026 at 04:15:56PM -0800, Zach Loafman wrote:
> nft_dynset_init() currently adds expressions before timeout metadata and
> ignores all nft_set_ext_add_length() errors.
>
> For a map with 64-byte keys, 64-byte values and two packet-limit
Hm. What 64-byte key and 64-byte value do you have in mind in a real
world scenario?
> expressions, the template is 264 bytes long before timeout is added. The
> timeout start therefore cannot be represented in the extension's u8
> offset and nft_set_ext_add_length() returns -EINVAL.
>
> Ignoring this error
> leaves the timeout offset unset, so packet-created elements do not expire
> automatically.
>
> Add timeout before expressions, as the control-plane element constructor
> does. This places timeout at offset 144 and expressions at offset 160; the
> resulting 280-byte total remains valid because only individual extension
> starts and lengths are u8. Propagate errors from every template builder so
> layouts rejected by those builders fail construction and use the existing
> expression unwind.
That's funny way to fix this issue.
> With a 30-second default set timeout, a raw nfnetlink reproducer creates
> the rule and inserts elements on both the unpatched and patched kernels.
> The unpatched element dump lacks EXPIRATION; the patched dump includes it.
> The missing extension also prevents the element from expiring during
> normal set expiration and garbage collection.
This all sounds as a theoretical issue found by LLM. This does not
sound as nf.git material.
LLM can just fix stuff right with oneliners, anything else is simply
crap.
> This fixes incorrect element lifetime and resource retention. No
> memory-safety primitive has been identified.
>
> Fixes: 48b0ae046ee9 ("netfilter: nftables: netlink support for several set element expressions")
> Signed-off-by: Zach Loafman <zml@zml.net>
>
> ---
> net/netfilter/nft_dynset.c | 33 +++++++++++++++++++++++----------
> 1 file changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/net/netfilter/nft_dynset.c b/net/netfilter/nft_dynset.c
> index fa4da694e92d..8fc2ec2212f4 100644
> --- a/net/netfilter/nft_dynset.c
> +++ b/net/netfilter/nft_dynset.c
> @@ -120,7 +120,7 @@ void nft_dynset_eval(const struct nft_expr *expr,
> regs->verdict.code = NFT_BREAK;
> }
>
> -static void nft_dynset_ext_add_expr(struct nft_dynset *priv)
> +static int nft_dynset_ext_add_expr(struct nft_dynset *priv)
> {
> u8 size = 0;
> int i;
> @@ -128,8 +128,8 @@ static void nft_dynset_ext_add_expr(struct nft_dynset *priv)
> for (i = 0; i < priv->num_exprs; i++)
> size += priv->expr_array[i]->ops->size;
>
> - nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_EXPRESSIONS,
> - sizeof(struct nft_set_elem_expr) + size);
> + return nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_EXPRESSIONS,
> + sizeof(struct nft_set_elem_expr) + size);
> }
>
> static struct nft_expr *
> @@ -317,16 +317,29 @@ static int nft_dynset_init(const struct nft_ctx *ctx,
> }
>
> nft_set_ext_prepare(&priv->tmpl);
> - nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_KEY, set->klen);
> - if (set->flags & NFT_SET_MAP)
> - nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_DATA, set->dlen);
> + err = nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_KEY, set->klen);
> + if (err < 0)
> + goto err_expr_free;
>
> - if (priv->num_exprs)
> - nft_dynset_ext_add_expr(priv);
> + if (set->flags & NFT_SET_MAP) {
> + err = nft_set_ext_add_length(&priv->tmpl, NFT_SET_EXT_DATA,
> + set->dlen);
> + if (err < 0)
> + goto err_expr_free;
> + }
>
> if (set->flags & NFT_SET_TIMEOUT &&
> - (timeout || READ_ONCE(set->timeout)))
> - nft_set_ext_add(&priv->tmpl, NFT_SET_EXT_TIMEOUT);
> + (timeout || READ_ONCE(set->timeout))) {
> + err = nft_set_ext_add(&priv->tmpl, NFT_SET_EXT_TIMEOUT);
> + if (err < 0)
> + goto err_expr_free;
> + }
> +
> + if (priv->num_exprs) {
> + err = nft_dynset_ext_add_expr(priv);
> + if (err < 0)
> + goto err_expr_free;
> + }
>
> priv->timeout = timeout;
>
> --
> 2.52.0
prev parent reply other threads:[~2026-11-26 0:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:15 [PATCH] netfilter: nft_dynset: check extension template errors Zach Loafman
2026-11-26 0:46 ` Pablo Neira Ayuso [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=aweBZHiTptFcPUI8@chamomile \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=zml@zml.net \
/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