public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: ebiederm@xmission•com (Eric W. Biederman)
To: Nicolas Dichtel <nicolas.dichtel@6wind•com>
Cc: netdev@vger•kernel.org, davem@davemloft•net
Subject: Re: [PATCH net-next 1/4] netns: don't clear nsid too early on removal
Date: Thu, 02 Apr 2015 13:51:44 -0500	[thread overview]
Message-ID: <877ftus6rj.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <1427892589-4266-2-git-send-email-nicolas.dichtel@6wind.com> (Nicolas Dichtel's message of "Wed, 1 Apr 2015 14:49:46 +0200")

Nicolas Dichtel <nicolas.dichtel@6wind•com> writes:

> With the current code, ids are removed too early.
> Suppose you have an ipip interface that stands in the netns foo and its link
> part in the netns bar (so the netns bar has an nsid into the netns foo).
> Now, you remove the netns bar:
>  - the bar nsid into the netns foo is removed
>  - the netns exit method of ipip is called, thus our ipip iface is removed:
>    => a netlink message is sent in the netns foo to advertise this deletion
>    => this netlink message requests an nsid for bar, thus a new nsid is
>       allocated for bar and never removed.
>
> We must remove nsids when we are sure that nobody will refer to netns currently
> cleaned.

I missed this issue but I have grave reservations about moving this
destruction of ids later.

It should not be possible to find by any kind of lookup network
namespaces that are going through cleanup net.

There should be no network sockets and thus no in flight rtnl traffic at
the time cleanup_net is metioned so I don't see how this patch fixes
the mentioned commit.

I have a second issue with the fact that the code is unnecessarily
quadratic.  We should keep a list of the issues netns ids and just
revoke them instead of walking the whole network namespaces.

I strongly suspect that this change makes it possible to create a
network device whose bottom is in a network namespace we are destroying
after we have destroyed all of the network devices in that namespace and
otherwise cleaned up.   Beyond that I can not reason about this patch
because it opens up a huge number of races.

> Fixes: 0c7aecd4bde4 ("netns: add rtnl cmd to add and get peer netns ids")
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind•com>
> Signed-off-by: David S. Miller <davem@davemloft•net>
> (cherry picked from commit 4217291e592da0e4258b652e82e5428639d29acc)
> ---
>
> This patch comes from the net tree.
>
>  net/core/net_namespace.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index e5e96b0f6717..ce6396a75b8b 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -338,7 +338,7 @@ static LIST_HEAD(cleanup_list);  /* Must hold cleanup_list_lock to touch */
>  static void cleanup_net(struct work_struct *work)
>  {
>  	const struct pernet_operations *ops;
> -	struct net *net, *tmp;
> +	struct net *net, *tmp, *peer;
>  	struct list_head net_kill_list;
>  	LIST_HEAD(net_exit_list);
>  
> @@ -354,14 +354,6 @@ static void cleanup_net(struct work_struct *work)
>  	list_for_each_entry(net, &net_kill_list, cleanup_list) {
>  		list_del_rcu(&net->list);
>  		list_add_tail(&net->exit_list, &net_exit_list);
> -		for_each_net(tmp) {
> -			int id = __peernet2id(tmp, net, false);
> -
> -			if (id >= 0)
> -				idr_remove(&tmp->netns_ids, id);
> -		}
> -		idr_destroy(&net->netns_ids);
> -
>  	}
>  	rtnl_unlock();
>  
> @@ -387,12 +379,26 @@ static void cleanup_net(struct work_struct *work)
>  	 */
>  	rcu_barrier();
>  
> +	rtnl_lock();
>  	/* Finally it is safe to free my network namespace structure */
>  	list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) {
> +		/* Unreference net from all peers (no need to loop over
> +		 * net_exit_list because idr_destroy() will be called for each
> +		 * element of this list.
> +		 */
> +		for_each_net(peer) {
> +			int id = __peernet2id(peer, net, false);
> +
> +			if (id >= 0)
> +				idr_remove(&peer->netns_ids, id);
> +		}
> +		idr_destroy(&net->netns_ids);
> +
>  		list_del_init(&net->exit_list);
>  		put_user_ns(net->user_ns);
>  		net_drop_ns(net);
>  	}
> +	rtnl_unlock();
>  }
>  static DECLARE_WORK(net_cleanup_work, cleanup_net);

  reply	other threads:[~2015-04-02 18:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 12:49 [PATCH net-next 0/4] netns: enhance netlink interface for nsid Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 1/4] netns: don't clear nsid too early on removal Nicolas Dichtel
2015-04-02 18:51   ` Eric W. Biederman [this message]
2015-04-03  9:56     ` Nicolas Dichtel
2015-04-03 10:02       ` [PATCH net 1/2] Revert "netns: don't clear nsid too early on removal" Nicolas Dichtel
2015-04-03 10:02         ` [PATCH net 2/2] netns: don't allocate an id for dead netns Nicolas Dichtel
2015-04-03 16:36           ` David Miller
2015-04-05  8:39             ` Nicolas Dichtel
2015-04-05 20:34               ` David Miller
2015-04-07  9:36                 ` Nicolas Dichtel
2015-04-03 16:36         ` [PATCH net 1/2] Revert "netns: don't clear nsid too early on removal" David Miller
2015-04-01 12:49 ` [PATCH net-next 2/4] netns: minor cleanup in rtnl_net_getid() Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 3/4] netns: notify netns id events Nicolas Dichtel
2015-04-01 12:49 ` [PATCH net-next 4/4] netns: allow to dump netns ids Nicolas Dichtel
2015-04-01 16:54 ` [PATCH net-next 0/4] netns: enhance netlink interface for nsid Cong Wang
2015-04-02  8:52   ` Nicolas Dichtel
2015-04-07  9:51 ` [PATCH net-next v2 0/3] " Nicolas Dichtel
2015-04-07  9:51   ` [PATCH net-next v2 1/3] netns: minor cleanup in rtnl_net_getid() Nicolas Dichtel
2015-04-07  9:51   ` [PATCH net-next v2 2/3] netns: notify netns id events Nicolas Dichtel
2015-04-07  9:51   ` [PATCH net-next v2 3/3] netns: allow to dump netns ids Nicolas Dichtel
2015-04-07 21:30   ` [PATCH net-next v2 0/3] netns: enhance netlink interface for nsid David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877ftus6rj.fsf@x220.int.ebiederm.org \
    --to=ebiederm@xmission$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=nicolas.dichtel@6wind$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox