diff mbox

[net,2/2] netns: don't allocate an id for dead netns

Message ID 1428055357-15289-2-git-send-email-nicolas.dichtel@6wind.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Nicolas Dichtel April 3, 2015, 10:02 a.m. UTC
First, let's explain the problem.
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 built 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.

This patch adds a check in peernet2id() so that an id cannot be allocated for
a netns which is currently destroyed.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/core/net_namespace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

David Miller April 3, 2015, 4:36 p.m. UTC | #1
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri,  3 Apr 2015 12:02:37 +0200

> First, let's explain the problem.
> 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 built 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.
> 
> This patch adds a check in peernet2id() so that an id cannot be allocated for
> a netns which is currently destroyed.
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicolas Dichtel April 5, 2015, 8:39 a.m. UTC | #2
Le 03/04/2015 18:36, David Miller a écrit :
> From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Date: Fri,  3 Apr 2015 12:02:37 +0200
>
>> First, let's explain the problem.
>> 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 built 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.
>>
>> This patch adds a check in peernet2id() so that an id cannot be allocated for
>> a netns which is currently destroyed.
>>
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>
> Applied.
>
I don't see these patches in your tree, maybe you forget to push them on
kernel.org?
My other series will conflict with these patches, is it possible to merge
net into net-next after them?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller April 5, 2015, 8:34 p.m. UTC | #3
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Sun, 05 Apr 2015 10:39:53 +0200

> I don't see these patches in your tree, maybe you forget to push
> them on kernel.org?

Indeed, I did, pushed out now.  Sorry about that.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicolas Dichtel April 7, 2015, 9:36 a.m. UTC | #4
Le 05/04/2015 22:34, David Miller a écrit :
> From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Date: Sun, 05 Apr 2015 10:39:53 +0200
>
>> I don't see these patches in your tree, maybe you forget to push
>> them on kernel.org?
>
> Indeed, I did, pushed out now.  Sorry about that.
>
No problem, thank you.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index cb5290b8c428..70d3450588b2 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -198,8 +198,10 @@  static int __peernet2id(struct net *net, struct net *peer, bool alloc)
  */
 int peernet2id(struct net *net, struct net *peer)
 {
-	int id = __peernet2id(net, peer, true);
+	bool alloc = atomic_read(&peer->count) == 0 ? false : true;
+	int id;
 
+	id = __peernet2id(net, peer, alloc);
 	return id >= 0 ? id : NETNSA_NSID_NOT_ASSIGNED;
 }
 EXPORT_SYMBOL(peernet2id);