Commit 5acab914 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso
Browse files

netfilter: nf_tables: unbind callbacks from flowtable destroy path



Callback unbinding needs to be done after nf_flow_table_free(),
otherwise entries are not removed from the hardware.

Update nft_unregister_flowtable_net_hooks() to call
nf_unregister_net_hook() instead since the commit/abort paths do not
deal with the callback unbinding anymore.

Add a comment to nft_flowtable_event() to clarify that
flow_offload_netdev_event() already removes the entries before the
callback unbinding.

Fixes: 8bb69f3b ("netfilter: nf_tables: add flowtable offload control plane")
Fixes ff4bf2f4 ("netfilter: nf_tables: add nft_unregister_flowtable_hook()")
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Acked-by: default avatarwenxu <wenxu@ucloud.cn>
parent 73327d47
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -5984,6 +5984,7 @@ nft_flowtable_type_get(struct net *net, u8 family)
	return ERR_PTR(-ENOENT);
	return ERR_PTR(-ENOENT);
}
}


/* Only called from error and netdev event paths. */
static void nft_unregister_flowtable_hook(struct net *net,
static void nft_unregister_flowtable_hook(struct net *net,
					  struct nft_flowtable *flowtable,
					  struct nft_flowtable *flowtable,
					  struct nft_hook *hook)
					  struct nft_hook *hook)
@@ -5999,7 +6000,7 @@ static void nft_unregister_flowtable_net_hooks(struct net *net,
	struct nft_hook *hook;
	struct nft_hook *hook;


	list_for_each_entry(hook, &flowtable->hook_list, list)
	list_for_each_entry(hook, &flowtable->hook_list, list)
		nft_unregister_flowtable_hook(net, flowtable, hook);
		nf_unregister_net_hook(net, &hook->ops);
}
}


static int nft_register_flowtable_net_hooks(struct net *net,
static int nft_register_flowtable_net_hooks(struct net *net,
@@ -6448,12 +6449,14 @@ static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
{
{
	struct nft_hook *hook, *next;
	struct nft_hook *hook, *next;


	flowtable->data.type->free(&flowtable->data);
	list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) {
	list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) {
		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
					    FLOW_BLOCK_UNBIND);
		list_del_rcu(&hook->list);
		list_del_rcu(&hook->list);
		kfree(hook);
		kfree(hook);
	}
	}
	kfree(flowtable->name);
	kfree(flowtable->name);
	flowtable->data.type->free(&flowtable->data);
	module_put(flowtable->data.type->owner);
	module_put(flowtable->data.type->owner);
	kfree(flowtable);
	kfree(flowtable);
}
}
@@ -6497,6 +6500,7 @@ static void nft_flowtable_event(unsigned long event, struct net_device *dev,
		if (hook->ops.dev != dev)
		if (hook->ops.dev != dev)
			continue;
			continue;


		/* flow_offload_netdev_event() cleans up entries for us. */
		nft_unregister_flowtable_hook(dev_net(dev), flowtable, hook);
		nft_unregister_flowtable_hook(dev_net(dev), flowtable, hook);
		list_del_rcu(&hook->list);
		list_del_rcu(&hook->list);
		kfree_rcu(hook, rcu);
		kfree_rcu(hook, rcu);