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.