diff options
-rw-r--r-- | net/core/net_namespace.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index cb5290b8c428..5221f975a4cc 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
@@ -349,7 +349,7 @@ static LIST_HEAD(cleanup_list); /* Must hold cleanup_list_lock to touch */ | |||
349 | static void cleanup_net(struct work_struct *work) | 349 | static void cleanup_net(struct work_struct *work) |
350 | { | 350 | { |
351 | const struct pernet_operations *ops; | 351 | const struct pernet_operations *ops; |
352 | struct net *net, *tmp; | 352 | struct net *net, *tmp, *peer; |
353 | struct list_head net_kill_list; | 353 | struct list_head net_kill_list; |
354 | LIST_HEAD(net_exit_list); | 354 | LIST_HEAD(net_exit_list); |
355 | 355 | ||
@@ -365,14 +365,6 @@ static void cleanup_net(struct work_struct *work) | |||
365 | list_for_each_entry(net, &net_kill_list, cleanup_list) { | 365 | list_for_each_entry(net, &net_kill_list, cleanup_list) { |
366 | list_del_rcu(&net->list); | 366 | list_del_rcu(&net->list); |
367 | list_add_tail(&net->exit_list, &net_exit_list); | 367 | list_add_tail(&net->exit_list, &net_exit_list); |
368 | for_each_net(tmp) { | ||
369 | int id = __peernet2id(tmp, net, false); | ||
370 | |||
371 | if (id >= 0) | ||
372 | idr_remove(&tmp->netns_ids, id); | ||
373 | } | ||
374 | idr_destroy(&net->netns_ids); | ||
375 | |||
376 | } | 368 | } |
377 | rtnl_unlock(); | 369 | rtnl_unlock(); |
378 | 370 | ||
@@ -398,12 +390,26 @@ static void cleanup_net(struct work_struct *work) | |||
398 | */ | 390 | */ |
399 | rcu_barrier(); | 391 | rcu_barrier(); |
400 | 392 | ||
393 | rtnl_lock(); | ||
401 | /* Finally it is safe to free my network namespace structure */ | 394 | /* Finally it is safe to free my network namespace structure */ |
402 | list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { | 395 | list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { |
396 | /* Unreference net from all peers (no need to loop over | ||
397 | * net_exit_list because idr_destroy() will be called for each | ||
398 | * element of this list. | ||
399 | */ | ||
400 | for_each_net(peer) { | ||
401 | int id = __peernet2id(peer, net, false); | ||
402 | |||
403 | if (id >= 0) | ||
404 | idr_remove(&peer->netns_ids, id); | ||
405 | } | ||
406 | idr_destroy(&net->netns_ids); | ||
407 | |||
403 | list_del_init(&net->exit_list); | 408 | list_del_init(&net->exit_list); |
404 | put_user_ns(net->user_ns); | 409 | put_user_ns(net->user_ns); |
405 | net_drop_ns(net); | 410 | net_drop_ns(net); |
406 | } | 411 | } |
412 | rtnl_unlock(); | ||
407 | } | 413 | } |
408 | static DECLARE_WORK(net_cleanup_work, cleanup_net); | 414 | static DECLARE_WORK(net_cleanup_work, cleanup_net); |
409 | 415 | ||