* [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction
@ 2017-09-08 8:26 Sabrina Dubroca
2017-09-08 16:49 ` David Miller
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sabrina Dubroca @ 2017-09-08 8:26 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca
fib6_net_exit only frees the main and local tables. If another table was
created with fib6_alloc_table, we leak it when the netns is destroyed.
Fix this in the same way ip_fib_net_exit cleans up tables, by walking
through the whole hashtable of fib6_table's. We can get rid of the
special cases for local and main, since they're also part of the
hashtable.
Reproducer:
ip netns add x
ip -net x -6 rule add from 6003:1::/64 table 100
ip netns del x
Reported-by: Jianlin Shi <jishi@redhat.com>
Fixes: 58f09b78b730 ("[NETNS][IPV6] ip6_fib - make it per network namespace")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
net/ipv6/ip6_fib.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index a3b5c163325f..8280172c806c 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -191,6 +191,12 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
}
EXPORT_SYMBOL_GPL(rt6_free_pcpu);
+static void fib6_free_table(struct fib6_table *table)
+{
+ inetpeer_invalidate_tree(&table->tb6_peers);
+ kfree(table);
+}
+
static void fib6_link_table(struct net *net, struct fib6_table *tb)
{
unsigned int h;
@@ -2022,15 +2028,22 @@ static int __net_init fib6_net_init(struct net *net)
static void fib6_net_exit(struct net *net)
{
+ unsigned int i;
+
rt6_ifdown(net, NULL);
del_timer_sync(&net->ipv6.ip6_fib_timer);
-#ifdef CONFIG_IPV6_MULTIPLE_TABLES
- inetpeer_invalidate_tree(&net->ipv6.fib6_local_tbl->tb6_peers);
- kfree(net->ipv6.fib6_local_tbl);
-#endif
- inetpeer_invalidate_tree(&net->ipv6.fib6_main_tbl->tb6_peers);
- kfree(net->ipv6.fib6_main_tbl);
+ for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
+ struct hlist_head *head = &net->ipv6.fib_table_hash[i];
+ struct hlist_node *tmp;
+ struct fib6_table *tb;
+
+ hlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {
+ hlist_del(&tb->tb6_hlist);
+ fib6_free_table(tb);
+ }
+ }
+
kfree(net->ipv6.fib_table_hash);
kfree(net->ipv6.rt6_stats);
fib6_notifier_exit(net);
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction
2017-09-08 8:26 [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Sabrina Dubroca
@ 2017-09-08 16:49 ` David Miller
2017-09-08 17:59 ` Eric Dumazet
2017-09-08 18:24 ` [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Cong Wang
2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2017-09-08 16:49 UTC (permalink / raw)
To: sd; +Cc: netdev
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Fri, 8 Sep 2017 10:26:19 +0200
> fib6_net_exit only frees the main and local tables. If another table was
> created with fib6_alloc_table, we leak it when the netns is destroyed.
>
> Fix this in the same way ip_fib_net_exit cleans up tables, by walking
> through the whole hashtable of fib6_table's. We can get rid of the
> special cases for local and main, since they're also part of the
> hashtable.
>
> Reproducer:
> ip netns add x
> ip -net x -6 rule add from 6003:1::/64 table 100
> ip netns del x
>
> Reported-by: Jianlin Shi <jishi@redhat.com>
> Fixes: 58f09b78b730 ("[NETNS][IPV6] ip6_fib - make it per network namespace")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction
2017-09-08 8:26 [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Sabrina Dubroca
2017-09-08 16:49 ` David Miller
@ 2017-09-08 17:59 ` Eric Dumazet
2017-09-08 22:48 ` [PATCH net] ipv6: fix typo in fib6_net_exit() Eric Dumazet
2017-09-08 18:24 ` [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Cong Wang
2 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2017-09-08 17:59 UTC (permalink / raw)
To: Sabrina Dubroca; +Cc: netdev
On Fri, 2017-09-08 at 10:26 +0200, Sabrina Dubroca wrote:
> fib6_net_exit only frees the main and local tables. If another table was
> created with fib6_alloc_table, we leak it when the netns is destroyed.
>
> Fix this in the same way ip_fib_net_exit cleans up tables, by walking
> through the whole hashtable of fib6_table's. We can get rid of the
> special cases for local and main, since they're also part of the
> hashtable.
>
> Reproducer:
> ip netns add x
> ip -net x -6 rule add from 6003:1::/64 table 100
> ip netns del x
>
> Reported-by: Jianlin Shi <jishi@redhat.com>
> Fixes: 58f09b78b730 ("[NETNS][IPV6] ip6_fib - make it per network namespace")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> ---
> net/ipv6/ip6_fib.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index a3b5c163325f..8280172c806c 100644
> --- a/net/ipv6/ip6_fib.c
> +++ b/net/ipv6/ip6_fib.c
> @@ -191,6 +191,12 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
> }
> EXPORT_SYMBOL_GPL(rt6_free_pcpu);
>
> +static void fib6_free_table(struct fib6_table *table)
> +{
> + inetpeer_invalidate_tree(&table->tb6_peers);
> + kfree(table);
> +}
> +
> static void fib6_link_table(struct net *net, struct fib6_table *tb)
> {
> unsigned int h;
> @@ -2022,15 +2028,22 @@ static int __net_init fib6_net_init(struct net *net)
>
> static void fib6_net_exit(struct net *net)
> {
> + unsigned int i;
> +
> rt6_ifdown(net, NULL);
> del_timer_sync(&net->ipv6.ip6_fib_timer);
>
> -#ifdef CONFIG_IPV6_MULTIPLE_TABLES
> - inetpeer_invalidate_tree(&net->ipv6.fib6_local_tbl->tb6_peers);
> - kfree(net->ipv6.fib6_local_tbl);
> -#endif
> - inetpeer_invalidate_tree(&net->ipv6.fib6_main_tbl->tb6_peers);
> - kfree(net->ipv6.fib6_main_tbl);
> + for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
should not this be FIB6_TABLE_HASHSZ ?
> + struct hlist_head *head = &net->ipv6.fib_table_hash[i];
> + struct hlist_node *tmp;
> + struct fib6_table *tb;
> +
> + hlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {
> + hlist_del(&tb->tb6_hlist);
> + fib6_free_table(tb);
> + }
> + }
> +
> kfree(net->ipv6.fib_table_hash);
> kfree(net->ipv6.rt6_stats);
> fib6_notifier_exit(net);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction
2017-09-08 8:26 [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Sabrina Dubroca
2017-09-08 16:49 ` David Miller
2017-09-08 17:59 ` Eric Dumazet
@ 2017-09-08 18:24 ` Cong Wang
2 siblings, 0 replies; 7+ messages in thread
From: Cong Wang @ 2017-09-08 18:24 UTC (permalink / raw)
To: Sabrina Dubroca; +Cc: Linux Kernel Network Developers
On Fri, Sep 8, 2017 at 1:26 AM, Sabrina Dubroca <sd@queasysnail.net> wrote:
> fib6_net_exit only frees the main and local tables. If another table was
> created with fib6_alloc_table, we leak it when the netns is destroyed.
>
> Fix this in the same way ip_fib_net_exit cleans up tables, by walking
> through the whole hashtable of fib6_table's. We can get rid of the
> special cases for local and main, since they're also part of the
> hashtable.
>
> Reproducer:
> ip netns add x
> ip -net x -6 rule add from 6003:1::/64 table 100
> ip netns del x
>
> Reported-by: Jianlin Shi <jishi@redhat.com>
> Fixes: 58f09b78b730 ("[NETNS][IPV6] ip6_fib - make it per network namespace")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> ---
> net/ipv6/ip6_fib.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index a3b5c163325f..8280172c806c 100644
> --- a/net/ipv6/ip6_fib.c
> +++ b/net/ipv6/ip6_fib.c
> @@ -191,6 +191,12 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
> }
> EXPORT_SYMBOL_GPL(rt6_free_pcpu);
>
> +static void fib6_free_table(struct fib6_table *table)
> +{
> + inetpeer_invalidate_tree(&table->tb6_peers);
> + kfree(table);
> +}
> +
> static void fib6_link_table(struct net *net, struct fib6_table *tb)
> {
> unsigned int h;
> @@ -2022,15 +2028,22 @@ static int __net_init fib6_net_init(struct net *net)
>
> static void fib6_net_exit(struct net *net)
> {
> + unsigned int i;
> +
> rt6_ifdown(net, NULL);
> del_timer_sync(&net->ipv6.ip6_fib_timer);
>
> -#ifdef CONFIG_IPV6_MULTIPLE_TABLES
> - inetpeer_invalidate_tree(&net->ipv6.fib6_local_tbl->tb6_peers);
> - kfree(net->ipv6.fib6_local_tbl);
> -#endif
> - inetpeer_invalidate_tree(&net->ipv6.fib6_main_tbl->tb6_peers);
> - kfree(net->ipv6.fib6_main_tbl);
> + for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
> + struct hlist_head *head = &net->ipv6.fib_table_hash[i];
> + struct hlist_node *tmp;
> + struct fib6_table *tb;
> +
> + hlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {
> + hlist_del(&tb->tb6_hlist);
hlist_del_rcu() ?
> + fib6_free_table(tb);
kfree_rcu() in fib6_free_table()?
> + }
> + }
> +
> kfree(net->ipv6.fib_table_hash);
> kfree(net->ipv6.rt6_stats);
> fib6_notifier_exit(net);
> --
> 2.14.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net] ipv6: fix typo in fib6_net_exit()
2017-09-08 17:59 ` Eric Dumazet
@ 2017-09-08 22:48 ` Eric Dumazet
2017-09-08 23:09 ` David Miller
2017-09-08 23:09 ` Sabrina Dubroca
0 siblings, 2 replies; 7+ messages in thread
From: Eric Dumazet @ 2017-09-08 22:48 UTC (permalink / raw)
To: Sabrina Dubroca, David Miller; +Cc: netdev
From: Eric Dumazet <edumazet@google.com>
IPv6 FIB should use FIB6_TABLE_HASHSZ, not FIB_TABLE_HASHSZ.
Fixes: ba1cc08d9488 ("ipv6: fix memory leak with multiple tables during netns destruction")
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv6/ip6_fib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 8280172c806ca47c5ca4aef723d405a0a8d7df2a..e5308d7cbd75c4fb67861082382122d445cf5b74 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -2033,7 +2033,7 @@ static void fib6_net_exit(struct net *net)
rt6_ifdown(net, NULL);
del_timer_sync(&net->ipv6.ip6_fib_timer);
- for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
+ for (i = 0; i < FIB6_TABLE_HASHSZ; i++) {
struct hlist_head *head = &net->ipv6.fib_table_hash[i];
struct hlist_node *tmp;
struct fib6_table *tb;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net] ipv6: fix typo in fib6_net_exit()
2017-09-08 22:48 ` [PATCH net] ipv6: fix typo in fib6_net_exit() Eric Dumazet
@ 2017-09-08 23:09 ` David Miller
2017-09-08 23:09 ` Sabrina Dubroca
1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2017-09-08 23:09 UTC (permalink / raw)
To: eric.dumazet; +Cc: sd, netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 08 Sep 2017 15:48:47 -0700
> From: Eric Dumazet <edumazet@google.com>
>
> IPv6 FIB should use FIB6_TABLE_HASHSZ, not FIB_TABLE_HASHSZ.
>
> Fixes: ba1cc08d9488 ("ipv6: fix memory leak with multiple tables during netns destruction")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] ipv6: fix typo in fib6_net_exit()
2017-09-08 22:48 ` [PATCH net] ipv6: fix typo in fib6_net_exit() Eric Dumazet
2017-09-08 23:09 ` David Miller
@ 2017-09-08 23:09 ` Sabrina Dubroca
1 sibling, 0 replies; 7+ messages in thread
From: Sabrina Dubroca @ 2017-09-08 23:09 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, netdev
2017-09-08, 15:48:47 -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> IPv6 FIB should use FIB6_TABLE_HASHSZ, not FIB_TABLE_HASHSZ.
>
> Fixes: ba1cc08d9488 ("ipv6: fix memory leak with multiple tables during netns destruction")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Ouch, yes :(
Thanks for the fix.
Acked-by: Sabrina Dubroca <sd@queasysnail.net>
--
Sabrina
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-09-08 23:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-08 8:26 [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Sabrina Dubroca
2017-09-08 16:49 ` David Miller
2017-09-08 17:59 ` Eric Dumazet
2017-09-08 22:48 ` [PATCH net] ipv6: fix typo in fib6_net_exit() Eric Dumazet
2017-09-08 23:09 ` David Miller
2017-09-08 23:09 ` Sabrina Dubroca
2017-09-08 18:24 ` [PATCH net] ipv6: fix memory leak with multiple tables during netns destruction Cong Wang
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).