* [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error
@ 2020-03-02 20:58 Florian Westphal
2020-03-04 1:25 ` Pablo Neira Ayuso
2020-03-05 12:10 ` Pablo Neira Ayuso
0 siblings, 2 replies; 5+ messages in thread
From: Florian Westphal @ 2020-03-02 20:58 UTC (permalink / raw)
To: netfilter-devel
Cc: syzkaller-bugs, netdev, Florian Westphal, syzbot+a2ff6fa45162a5ed4dd3
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).
Fixes: 3f0465a9ef02 ("netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables")
Reported-by: syzbot+a2ff6fa45162a5ed4dd3@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index d1318bdf49ca..bb064aa4154b 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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)
--
2.24.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error
2020-03-02 20:58 [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error Florian Westphal
@ 2020-03-04 1:25 ` Pablo Neira Ayuso
2020-03-05 12:10 ` Pablo Neira Ayuso
1 sibling, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-04 1:25 UTC (permalink / raw)
To: Florian Westphal
Cc: netfilter-devel, syzkaller-bugs, netdev, syzbot+a2ff6fa45162a5ed4dd3
On Mon, Mar 02, 2020 at 09:58:50PM +0100, Florian Westphal wrote:
> 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).
Applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error
2020-03-02 20:58 [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error Florian Westphal
2020-03-04 1:25 ` Pablo Neira Ayuso
@ 2020-03-05 12:10 ` Pablo Neira Ayuso
2020-03-05 12:28 ` Florian Westphal
2020-03-05 13:37 ` Pablo Neira Ayuso
1 sibling, 2 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-05 12:10 UTC (permalink / raw)
To: Florian Westphal
Cc: netfilter-devel, syzkaller-bugs, netdev, syzbot+a2ff6fa45162a5ed4dd3
On Mon, Mar 02, 2020 at 09:58:50PM +0100, Florian Westphal wrote:
> 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).
It seems test/shell crashes after this, looking. It works after
reverting.
> Fixes: 3f0465a9ef02 ("netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables")
> Reported-by: syzbot+a2ff6fa45162a5ed4dd3@syzkaller.appspotmail.com
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> net/netfilter/nf_tables_api.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index d1318bdf49ca..bb064aa4154b 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -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)
> --
> 2.24.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error
2020-03-05 12:10 ` Pablo Neira Ayuso
@ 2020-03-05 12:28 ` Florian Westphal
2020-03-05 13:37 ` Pablo Neira Ayuso
1 sibling, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2020-03-05 12:28 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: Florian Westphal, netfilter-devel, syzkaller-bugs, netdev,
syzbot+a2ff6fa45162a5ed4dd3
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Mon, Mar 02, 2020 at 09:58:50PM +0100, Florian Westphal wrote:
> > 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).
>
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error
2020-03-05 12:10 ` Pablo Neira Ayuso
2020-03-05 12:28 ` Florian Westphal
@ 2020-03-05 13:37 ` Pablo Neira Ayuso
1 sibling, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-05 13:37 UTC (permalink / raw)
To: Florian Westphal
Cc: netfilter-devel, syzkaller-bugs, netdev, syzbot+a2ff6fa45162a5ed4dd3
On Thu, Mar 05, 2020 at 01:10:12PM +0100, Pablo Neira Ayuso wrote:
> On Mon, Mar 02, 2020 at 09:58:50PM +0100, Florian Westphal wrote:
> > 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).
>
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-03-05 13:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-02 20:58 [PATCH nf] netfilter: nf_tables: free flowtable hooks on hook register error Florian Westphal
2020-03-04 1:25 ` Pablo Neira Ayuso
2020-03-05 12:10 ` Pablo Neira Ayuso
2020-03-05 12:28 ` Florian Westphal
2020-03-05 13:37 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).