Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Brien Oberstein" <brienpub@gmail.com>
To: "'Arnau Valls'" <vallsfustearnau@gmail.com>,
	<netfilter-devel@vger.kernel.org>
Cc: <pablo@netfilter.org>, <fw@strlen.de>, <phil@nwl.cc>,
	<coreteam@netfilter.org>, <netdev@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: RE: [PATCH nf] netfilter: flowtable: remove hw flows before unbinding the flow block
Date: Fri, 4 Dec 2026 12:14:14 -0500	[thread overview]
Message-ID: <151801dd8412$e3a96470$aafc2d50$@gmail.com> (raw)
In-Reply-To: <20261103222243.445644-1-vallsfustearnau@gmail.com>

On Tue, 3 Nov 2026 23:22:43 +0100, Arnau Valls wrote:
> +     if (cmd == FLOW_BLOCK_UNBIND) {
> +             nf_flow_table_gc_cleanup(flowtable, dev);
> +             nf_flow_table_gc_run(flowtable);
> +             nf_flow_table_offload_flush(flowtable);
> +     }

nf_flow_table_gc_run() here can run concurrently with the flowtable's
gc worker running the same pass. Nothing serializes the two walks, and
nf_flow_offload_gc_step() frees a torn-down flow (a hardware one once
NF_FLOW_HW_DEAD is set) with flow_offload_del(), which has no guard
against the other walk doing the same to the same flow: call_rcu()
twice on its rcu_head, and its route released twice. Outside the
worker, the pass runs only on the nf_flow_table_free() path, after
cancel_delayed_work_sync() has stopped the worker, and
nf_flow_table_gc_cleanup() runs its own pass by flushing the worker.

Running the second pass on the worker avoids it:

        if (cmd == FLOW_BLOCK_UNBIND) {
                nf_flow_table_gc_cleanup(flowtable, dev);
                mod_delayed_work(system_power_efficient_wq,
                                 &flowtable->gc_work, 0);
                flush_delayed_work(&flowtable->gc_work);
                nf_flow_table_offload_flush(flowtable);
        }

Requeueing first makes the flush wait for a pass that starts after the
teardown and offload flush in nf_flow_table_gc_cleanup(), rather than
for one that may already be under way.

This is from reading the code in the nf tree; I haven't seen the double
free happen. Your patch has run on a MediaTek router here for several
weeks, and the change above for a short time so far: in a firewall
reload test with a flow offloaded, both directions are still
invalidated and bound again.


  reply	other threads:[~2026-12-04 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 22:22 [PATCH nf] netfilter: flowtable: remove hw flows before unbinding the flow block Arnau Valls
2026-12-04 17:14 ` Brien Oberstein [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-03 22:18 Arnau Valls

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='151801dd8412$e3a96470$aafc2d50$@gmail.com' \
    --to=brienpub@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=fw@strlen.de \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=stable@vger.kernel.org \
    --cc=vallsfustearnau@gmail.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