netfilter: nf_tables: free flowtable hooks on hook register error
Subsystems (3)
Florian Westphal
maintainerPATCH 1/1 netfilter: nf_tables: free flowtable hooks on hook register error
If hook registration fails, the hooks allocated via nft_netdev_hook_alloc need to be freed.
We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
--- net/netfilter/nf_tables_api.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +6 -1
@@ -6300,8 +6300,13 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, goto err4; err =nft_register_flowtable_net_hooks (ctx.net, table, flowtable); -if (err <0 ) +if (err <0 ) { +list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) { +list_del_rcu (&hook->list); +kfree_rcu (hook, rcu); + } goto err4; + } err =nft_trans_flowtable_add (&ctx,NFT_MSG_NEWFLOWTABLE , flowtable);if (err <0 )
Signature · 1 line
2.24.1
Quoted 6 lines · Florian Westphal
If hook registration fails, the hooks allocated via
nft_netdev_hook_allocneed to be freed.We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
Applied, thanks.
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
If hook registration fails, the hooks allocated via
nft_netdev_hook_allocneed to be freed.We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
It seems test/shell crashes after this, looking. It works after reverting.
Quoted 29 lines
Fixes 3f0465a9ef02 ("netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables")Reported-by [email protected]Signed-off-by Florian Westphal <[email protected]>--- net/netfilter/nf_tables_api.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/netfilter/nf_tables_api.c +6
-1@@ -6300,8 +6300,13 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, goto err4; err =nft_register_flowtable_net_hooks (ctx.net, table, flowtable); -if (err <0 ) +if (err <0 ) { +list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) { +list_del_rcu (&hook->list); +kfree_rcu (hook, rcu); + } goto err4; + } err =nft_trans_flowtable_add (&ctx,NFT_MSG_NEWFLOWTABLE , flowtable);if (err <0 )Signature · 1 line
2.24.1
Florian Westphal
maintainerQuoted 10 lines · Pablo Neira Ayuso
Quoted 6 lines · Florian Westphal
If hook registration fails, the hooks allocated via
nft_netdev_hook_allocneed to be freed.We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
It seems test/shell crashes after this, looking. It works after reverting.
Sorry about that. Let me know if you want me to look into this.
Pablo Neira Ayuso
maintainerQuoted 10 lines · Pablo Neira Ayuso
Quoted 6 lines · Florian Westphal
If hook registration fails, the hooks allocated via
nft_netdev_hook_allocneed to be freed.We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
It seems test/shell crashes after this, looking. It works after reverting.
Actually, no problem problem is not related to this patch. Sorry for the noise.