public inbox for netfilter-devel@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf] nf_tables: nft_dynset: fix possible stateful expression memleak in error path
Date: Thu, 12 Mar 2026 12:56:31 +0100	[thread overview]
Message-ID: <abKp7-ES9haxX3S-@strlen.de> (raw)
In-Reply-To: <abKkj6BaaD0xZp9B@chamomile>

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Thu, Mar 12, 2026 at 12:02:37PM +0100, Florian Westphal wrote:
> > Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > > If cloning the second stateful expression in the element via GFP_ATOMIC
> > > fails, then the first stateful expression remains in place without being
> > > released.
> > > 
> > >    unreferenced object (percpu) 0x607b97e9cab8 (size 16):
> > >      comm "softirq", pid 0, jiffies 4294931867
> > >      hex dump (first 16 bytes on cpu 3):
> > >        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> > >      backtrace (crc 0):
> > >        pcpu_alloc_noprof+0x453/0xd80
> > >        nft_counter_clone+0x9c/0x190 [nf_tables]
> > >        nft_expr_clone+0x8f/0x1b0 [nf_tables]
> > >        nft_dynset_new+0x2cb/0x5f0 [nf_tables]
> > >        nft_rhash_update+0x236/0x11c0 [nf_tables]
> > >        nft_dynset_eval+0x11f/0x670 [nf_tables]
> > >        nft_do_chain+0x253/0x1700 [nf_tables]
> > >        nft_do_chain_ipv4+0x18d/0x270 [nf_tables]
> > >        nf_hook_slow+0xaa/0x1e0
> > >        ip_local_deliver+0x209/0x330
> > > 
> > > Pass NULL to nft_set_elem_expr_destroy() given stateful expressions do
> > > not require context at this stage.
> > 
> > static void nft_connlimit_do_destroy(const struct nft_ctx *ctx,
> >                                      struct nft_connlimit *priv)
> > {
> >         nf_ct_netns_put(ctx->net, ctx->family);
> >         nf_conncount_cache_free(priv->list);
> >         kfree(priv->list);
> > }
> > 
> > I think minimal fake context could work though, the clone wasn't
> > exposed to other cpus yet.
> > 
> > Other than this patch looks correct to me.
> 
> It is following this path:
>
> static void nft_connlimit_destroy_clone(const struct nft_ctx *ctx,
>                                         const struct nft_expr *expr)
> {
>         struct nft_connlimit *priv = nft_expr_priv(expr);
>  
>         nf_conncount_cache_free(priv->list);
>         kfree(priv->list);
> }

Oh, I see -- you are right, this follows the destroy_expr special case.

> But I will post a v2 setting nft_ctx anyway.

Thanks, I find it hard to assert correctness otherwise.

      reply	other threads:[~2026-03-12 11:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 10:11 [PATCH nf] nf_tables: nft_dynset: fix possible stateful expression memleak in error path Pablo Neira Ayuso
2026-03-12 11:02 ` Florian Westphal
2026-03-12 11:33   ` Pablo Neira Ayuso
2026-03-12 11:56     ` Florian Westphal [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=abKp7-ES9haxX3S-@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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