netfilter: flowtable: perform unbind callback on hook release
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: flowtable: perform unbind callback on hook release
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 performing the flow_block unbind command from the destroy path, right before the hook is released.
Fixes 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- net/netfilter/nf_tables_api.c | 80 +++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 26 deletions(-)
net/netfilter/nf_tables_api.c +54 -26
@@ -372,6 +372,23 @@ static void nft_netdev_hook_free_rcu(struct nft_hook *hook)call_rcu (&hook->rcu, __nft_netdev_hook_free_rcu); } +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 ); + } +list_del_rcu (&hook->list); +nft_netdev_hook_free_rcu (hook); +} +static void nft_netdev_hook_unlink_free_rcu (struct nft_hook *hook) {list_del_rcu (&hook->list);
@@ -8997,12 +9014,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,
@@ -9015,9 +9029,9 @@ 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);if (release_netdev) -nft_netdev_hook_unlink_free_rcu (hook); +nft_flowtable_hook_unlink_free_rcu (flowtable, hook); } }
@@ -9086,14 +9100,23 @@ 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); } -nft_netdev_hook_unlink_free_rcu (hook); +nft_flowtable_hook_unlink_free_rcu (flowtable, hook); }return err; } +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 nft_hooks_destroy (struct list_head *hook_list) {struct nft_hook *hook, *next;
@@ -9103,20 +9126,16 @@ static void nft_hooks_destroy(struct list_head *hook_list) }static void nft_flowtable_unregister_trans_hook (struct net *net, -struct nft_flowtable *flowtable,struct list_head *hook_list) { -struct nft_trans_hook *trans_hook, *next; +struct nft_trans_hook *trans_hook;struct nf_hook_ops *ops;struct nft_hook *hook; -list_for_each_entry_safe (trans_hook, next, hook_list, list) { +list_for_each_entry (trans_hook, hook_list, list) { hook = trans_hook->hook;list_for_each_entry (ops, &hook->ops_list, list) -nft_unregister_flowtable_ops (net, flowtable, ops); - -nft_netdev_hook_unlink_free_rcu (hook); -nft_trans_hook_destroy (trans_hook); +nft_unregister_flowtable_ops (net, ops); } }
@@ -9202,10 +9221,9 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,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); +nft_unregister_flowtable_ops (ctx->net, ops); } -nft_netdev_hook_unlink_free_rcu (hook); +nft_flowtable_hook_unlink_free_rcu (flowtable, hook); }return err;
@@ -9331,7 +9349,7 @@ static int nf_tables_newflowtable(struct sk_buff *skb,synchronize_rcu ();nft_trans_destroy (trans); err_flowtable_trans: -nft_hooks_destroy (&flowtable->hook_list); +nft_flowtable_hooks_destroy (flowtable, &flowtable->hook_list); err_flowtable_parse_hooks: flowtable->data.type->free (&flowtable->data); err3:
@@ -9727,7 +9745,7 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx,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);
@@ -9802,8 +9820,7 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,continue ;/* flow_offload_netdev_event() cleans up entries for us. */ -nft_unregister_flowtable_ops (dev_net (dev), - flowtable, ops); +nft_unregister_flowtable_ops (dev_net (dev), ops);list_del_rcu (&ops->list);kfree_rcu (ops, rcu);break ;
@@ -10267,8 +10284,18 @@ static void nft_commit_release(struct nft_trans *trans)break ;case NFT_MSG_DELFLOWTABLE :case NFT_MSG_DESTROYFLOWTABLE : -if (!nft_trans_flowtable_update (trans)) +if (nft_trans_flowtable_update (trans)) { +struct nft_trans_hook *trans_hook, *next; + +list_for_each_entry_safe (trans_hook, next, + &nft_trans_flowtable_hooks (trans), list) { +nft_flowtable_hook_unlink_free_rcu (nft_trans_flowtable (trans), + trans_hook->hook); +nft_trans_hook_destroy (trans_hook); + } + }else {nf_tables_flowtable_destroy (nft_trans_flowtable (trans)); + }break ; }
@@ -11205,7 +11232,6 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) &nft_trans_flowtable_hooks (trans), trans->msg_type);nft_flowtable_unregister_trans_hook (net, -nft_trans_flowtable (trans), &nft_trans_flowtable_hooks (trans)); }else {list_del_rcu (&nft_trans_flowtable (trans)->list);
@@ -11278,10 +11304,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);
Signature · 1 line
2.47.3