* [PATCH nf] netfilter: flowtable: remove hw flows before unbinding the flow block
@ 2026-11-03 22:18 Arnau Valls
0 siblings, 0 replies; 3+ messages in thread
From: Arnau Valls @ 2026-11-03 22:18 UTC (permalink / raw)
To: vallsfustearnau; +Cc: stable
Since commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable
binding"), deleting a flowtable unbinds the driver callbacks at commit
time, before nf_flow_table_free() queues FLOW_CLS_DESTROY for the
remaining flows. The destroy requests find an empty cb_list and the
flows stay in hardware.
Conntrack then times the entries out while the hardware keeps forwarding
them. Once one direction ages out of the hardware table, its packets hit
the stack without a conntrack entry and get rejected. This breaks
long-lived UDP flows such as WireGuard whenever the flowtable is
recreated, for example on every firewall reload in OpenWrt.
Remove the device's flows on FLOW_BLOCK_UNBIND while the driver is still
bound, as nf_flow_table_indr_cleanup() does for indirect blocks. The gc
skips flows with pending offload work, so run one more pass and flush.
Tested on MT7981 (mtk_eth_soc PPE) with v7.4-rc1 and 6.12.74. Found and
fixed with help from an AI assistant (Claude).
Fixes: 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Cc: stable@vger.kernel.org
Link: https://github.com/openwrt/openwrt/issues/17915
Signed-off-by: Arnau Valls <vallsfustearnau@gmail.com>
---
Notes:
Reproducer: hw-offloaded UDP flow through NAT, then delete and recreate
the flowtable in one transaction (fw4 reload). Without the patch the
conntrack entry gets a timeout and the PPE entries stay bound. With it
the PPE entries are removed and the flow is offloaded again within a
second, no packet loss over six reloads.
Not tested: lockdep, other drivers, the indirect block path.
net/netfilter/nf_flow_table_offload.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e6..68654d243bae 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1279,6 +1279,15 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
if (!nf_flowtable_hw_offload(flowtable))
return nf_flow_offload_xdp_setup(flowtable, dev, cmd);
+ /* Flush this device's hw flows while the driver is still bound. The
+ * second gc pass catches flows skipped due to pending offload work.
+ */
+ if (cmd == FLOW_BLOCK_UNBIND) {
+ nf_flow_table_gc_cleanup(flowtable, dev);
+ nf_flow_table_gc_run(flowtable);
+ nf_flow_table_offload_flush(flowtable);
+ }
+
if (dev->netdev_ops->ndo_setup_tc)
err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,
&extack);
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH nf] netfilter: flowtable: remove hw flows before unbinding the flow block
@ 2026-11-03 22:22 Arnau Valls
2026-12-04 17:14 ` Brien Oberstein
0 siblings, 1 reply; 3+ messages in thread
From: Arnau Valls @ 2026-11-03 22:22 UTC (permalink / raw)
To: netfilter-devel; +Cc: pablo, fw, phil, coreteam, netdev, Arnau Valls, stable
Since commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable
binding"), deleting a flowtable unbinds the driver callbacks at commit
time, before nf_flow_table_free() queues FLOW_CLS_DESTROY for the
remaining flows. The destroy requests find an empty cb_list and the
flows stay in hardware.
Conntrack then times the entries out while the hardware keeps forwarding
them. Once one direction ages out of the hardware table, its packets hit
the stack without a conntrack entry and get rejected. This breaks
long-lived UDP flows such as WireGuard whenever the flowtable is
recreated, for example on every firewall reload in OpenWrt.
Remove the device's flows on FLOW_BLOCK_UNBIND while the driver is still
bound, as nf_flow_table_indr_cleanup() does for indirect blocks. The gc
skips flows with pending offload work, so run one more pass and flush.
Tested on MT7981 (mtk_eth_soc PPE) with v7.4-rc1 and 6.12.74. Found and
fixed with help from an AI assistant (Claude).
Fixes: 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Cc: stable@vger.kernel.org
Link: https://github.com/openwrt/openwrt/issues/17915
Signed-off-by: Arnau Valls <vallsfustearnau@gmail.com>
---
Notes:
Reproducer: hw-offloaded UDP flow through NAT, then delete and recreate
the flowtable in one transaction (fw4 reload). Without the patch the
conntrack entry gets a timeout and the PPE entries stay bound. With it
the PPE entries are removed and the flow is offloaded again within a
second, no packet loss over six reloads.
Not tested: lockdep, other drivers, the indirect block path.
net/netfilter/nf_flow_table_offload.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e6..68654d243bae 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1279,6 +1279,15 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
if (!nf_flowtable_hw_offload(flowtable))
return nf_flow_offload_xdp_setup(flowtable, dev, cmd);
+ /* Flush this device's hw flows while the driver is still bound. The
+ * second gc pass catches flows skipped due to pending offload work.
+ */
+ if (cmd == FLOW_BLOCK_UNBIND) {
+ nf_flow_table_gc_cleanup(flowtable, dev);
+ nf_flow_table_gc_run(flowtable);
+ nf_flow_table_offload_flush(flowtable);
+ }
+
if (dev->netdev_ops->ndo_setup_tc)
err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,
&extack);
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH nf] netfilter: flowtable: remove hw flows before unbinding the flow block
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
0 siblings, 0 replies; 3+ messages in thread
From: Brien Oberstein @ 2026-12-04 17:14 UTC (permalink / raw)
To: 'Arnau Valls', netfilter-devel
Cc: pablo, fw, phil, coreteam, netdev, stable
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
-- strict thread matches above, loose matches on Subject: below --
2026-11-03 22:18 Arnau Valls
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox