Skip to content

Commit 70479ea

Browse files
qsngregkh
authored andcommitted
ipv6: fix memory leak with multiple tables during netns destruction
[ Upstream commit ba1cc08d9488c94cb8d94f545305688b72a2a300 ] 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: 58f09b7 ("[NETNS][IPV6] ip6_fib - make it per network namespace") Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9b5e5d8 commit 70479ea

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

net/ipv6/ip6_fib.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ static void rt6_release(struct rt6_info *rt)
203203
}
204204
}
205205

206+
static void fib6_free_table(struct fib6_table *table)
207+
{
208+
inetpeer_invalidate_tree(&table->tb6_peers);
209+
kfree(table);
210+
}
211+
206212
static void fib6_link_table(struct net *net, struct fib6_table *tb)
207213
{
208214
unsigned int h;
@@ -1885,15 +1891,22 @@ static int __net_init fib6_net_init(struct net *net)
18851891

18861892
static void fib6_net_exit(struct net *net)
18871893
{
1894+
unsigned int i;
1895+
18881896
rt6_ifdown(net, NULL);
18891897
del_timer_sync(&net->ipv6.ip6_fib_timer);
18901898

1891-
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
1892-
inetpeer_invalidate_tree(&net->ipv6.fib6_local_tbl->tb6_peers);
1893-
kfree(net->ipv6.fib6_local_tbl);
1894-
#endif
1895-
inetpeer_invalidate_tree(&net->ipv6.fib6_main_tbl->tb6_peers);
1896-
kfree(net->ipv6.fib6_main_tbl);
1899+
for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
1900+
struct hlist_head *head = &net->ipv6.fib_table_hash[i];
1901+
struct hlist_node *tmp;
1902+
struct fib6_table *tb;
1903+
1904+
hlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {
1905+
hlist_del(&tb->tb6_hlist);
1906+
fib6_free_table(tb);
1907+
}
1908+
}
1909+
18971910
kfree(net->ipv6.fib_table_hash);
18981911
kfree(net->ipv6.rt6_stats);
18991912
}

0 commit comments

Comments
 (0)