From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org,
pabeni@redhat.com, edumazet@kernel.org, horms@kernel.org,
fw@strlen.de, ja@ssi.bg
Subject: [PATCH net 12/14] netfilter: nf_tables: unbind flowtable on hook release
Date: Sun, 29 Nov 2026 01:07:22 +0100 [thread overview]
Message-ID: <20261129000724.797425-13-pablo@netfilter.org> (raw)
In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org>
Commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable
binding") breaks hardware offload by unbinding the flow_block too early,
this results in leaving entries in the hardware. Any pending offload
work will be ignored because there is no flow_block anymore in place.
This patch restores the strategy followed by commit 5acab91458ce
("netfilter: nf_tables: unbind callbacks from flowtable destroy path")
by unregistering the hook first, then unbind the flow_block from the
error and destroy paths, right before the hook is released.
Fixes: 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 65 +++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 18 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index c19cf6d8cd0b..0189375e4063 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -380,6 +380,22 @@ static void nft_netdev_hook_unlink_free_rcu(struct nft_hook *hook)
nft_netdev_hook_free_rcu(hook);
}
+static void nft_flowtable_hook_unlink_free_rcu(struct nft_flowtable *flowtable,
+ struct nft_hook *hook)
+{
+ struct nf_hook_ops *ops;
+
+ /* This unbind command needs to come this late, otherwise offload
+ * worker finds no flow_block and entries are not cleaned up from
+ * hardware.
+ */
+ list_for_each_entry(ops, &hook->ops_list, list) {
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
+ }
+ nft_netdev_hook_unlink_free_rcu(hook);
+}
+
static void nft_trans_hook_destroy(struct nft_trans_hook *trans_hook)
{
list_del(&trans_hook->list);
@@ -9026,12 +9042,9 @@ nft_flowtable_type_get(struct net *net, u8 family)
/* Only called from error and netdev event paths. */
static void nft_unregister_flowtable_ops(struct net *net,
- struct nft_flowtable *flowtable,
struct nf_hook_ops *ops)
{
nf_unregister_net_hook(net, ops);
- flowtable->data.type->setup(&flowtable->data, ops->dev,
- FLOW_BLOCK_UNBIND);
}
static void __nft_unregister_flowtable_net_hooks(struct net *net,
@@ -9043,7 +9056,7 @@ static void __nft_unregister_flowtable_net_hooks(struct net *net,
list_for_each_entry_safe(hook, next, hook_list, list) {
list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
hook->flags |= NFT_HOOK_UNREGISTERED;
}
@@ -9114,7 +9127,9 @@ static int nft_register_flowtable_net_hooks(struct net *net,
if (i-- <= 0)
break;
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
}
nft_netdev_hook_unlink_free_rcu(hook);
}
@@ -9141,9 +9156,9 @@ static void nft_flowtable_unregister_trans_hook(struct net *net,
list_for_each_entry_safe(trans_hook, next, hook_list, list) {
hook = trans_hook->hook;
list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
- nft_netdev_hook_unlink_free_rcu(hook);
+ nft_flowtable_hook_unlink_free_rcu(flowtable, trans_hook->hook);
nft_trans_hook_destroy(trans_hook);
}
}
@@ -9229,9 +9244,11 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
err_flowtable_update_hook:
list_for_each_entry_safe(hook, next, &flowtable_hook.list, list) {
if (unregister) {
- list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(ctx->net,
- flowtable, ops);
+ list_for_each_entry(ops, &hook->ops_list, list) {
+ nft_unregister_flowtable_ops(ctx->net, ops);
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
+ }
}
nft_netdev_hook_unlink_free_rcu(hook);
}
@@ -9752,10 +9769,19 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx,
nfnetlink_set_err(ctx->net, ctx->portid, NFNLGRP_NFTABLES, -ENOBUFS);
}
+static void nft_flowtable_hooks_destroy(struct nft_flowtable *flowtable,
+ struct list_head *hook_list)
+{
+ struct nft_hook *hook, *next;
+
+ list_for_each_entry_safe(hook, next, hook_list, list)
+ nft_flowtable_hook_unlink_free_rcu(flowtable, hook);
+}
+
static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
{
flowtable->data.type->free(&flowtable->data);
- nft_hooks_destroy(&flowtable->hook_list);
+ nft_flowtable_hooks_destroy(flowtable, &flowtable->hook_list);
kfree(flowtable->name);
module_put(flowtable->data.type->owner);
kfree(flowtable);
@@ -9830,10 +9856,11 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
continue;
/* flow_offload_netdev_event() cleans up entries for us. */
- if (!(hook->flags & NFT_HOOK_UNREGISTERED)) {
- nft_unregister_flowtable_ops(dev_net(dev),
- flowtable, ops);
- }
+ if (!(hook->flags & NFT_HOOK_UNREGISTERED))
+ nft_unregister_flowtable_ops(dev_net(dev), ops);
+
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
list_del_rcu(&ops->list);
kfree_rcu(ops, rcu);
break;
@@ -11311,10 +11338,12 @@ static void nf_tables_abort_release(struct nft_trans *trans)
nft_obj_destroy(&ctx, nft_trans_obj(trans));
break;
case NFT_MSG_NEWFLOWTABLE:
- if (nft_trans_flowtable_update(trans))
- nft_hooks_destroy(&nft_trans_flowtable_hooks(trans));
- else
+ if (nft_trans_flowtable_update(trans)) {
+ nft_flowtable_hooks_destroy(nft_trans_flowtable(trans),
+ &nft_trans_flowtable_hooks(trans));
+ } else {
nf_tables_flowtable_destroy(nft_trans_flowtable(trans));
+ }
break;
}
kfree(trans);
--
2.47.3
next prev parent reply other threads:[~2026-11-29 0:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
2026-11-29 0:14 ` netdev-bot+sinfo
2026-11-29 0:16 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 02/14] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 03/14] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 04/14] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 05/14] netfilter: conntrack: attach generated TCP resets as ESTABLISHED Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 06/14] netfilter: nf_conntrack: limit expectation master chain depth Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 07/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 08/14] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 09/14] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 10/14] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 11/14] netfilter: nf_tables: add NFT_HOOK_UNREGISTERED and use it Pablo Neira Ayuso
2026-11-29 0:07 ` Pablo Neira Ayuso [this message]
2026-11-29 0:07 ` [PATCH net 13/14] netfilter: nf_tables: flush destroy work from flowtable netdev event handler Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 14/14] netfilter: ipv6: stop the conntrack fragment search at AH Pablo Neira Ayuso
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=20261129000724.797425-13-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.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