[Devel] [PATCH RH7] net: Bring clearness to ve_netns deassignment

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 26 19:36:45 MSK 2020


ve_netns is cleared in two places and this looks strange.
ve_drop_context() puts net right before it clears ve_netns,
so the probability of that cleanup_net() will be first is
very small. So, let's just reorder lines in ve_drop_context(),
and the situation (ve->ve_netns == net) in cleanup_net()
will become impossible.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 kernel/ve/ve.c           |    4 +++-
 net/core/net_namespace.c |    2 --
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index b423a9676679..f88452d0396d 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -462,8 +462,10 @@ static void ve_grab_context(struct ve_struct *ve)
 static void ve_drop_context(struct ve_struct *ve)
 {
 	struct nsproxy *ve_ns = ve->ve_ns;
-	put_net(ve->ve_netns);
+	struct net *net = ve->ve_netns;
+
 	ve->ve_netns = NULL;
+	put_net(net);
 
 	/* Allows to dereference init_cred and init_task if ve_ns is set */
 	rcu_assign_pointer(ve->ve_ns, NULL);
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 3348f7c550e1..69893c8ae6a0 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -499,8 +499,6 @@ static void cleanup_net(struct work_struct *work)
 		struct ve_struct *ve = net->owner_ve;
 
 		atomic_inc(&ve->netns_avail_nr);
-		if (ve->ve_netns == net)
-			ve->ve_netns = NULL;
 		put_ve(ve);
 	}
 




More information about the Devel mailing list