[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211207005142.1688204-14-eric.dumazet@gmail.com>
Date: Mon, 6 Dec 2021 16:51:38 -0800
From: Eric Dumazet <eric.dumazet@...il.com>
To: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: netdev <netdev@...r.kernel.org>,
Eric Dumazet <edumazet@...gle.com>,
Eric Dumazet <eric.dumazet@...il.com>
Subject: [PATCH net-next 13/17] net: add netns refcount tracker to struct nsproxy
From: Eric Dumazet <edumazet@...gle.com>
Signed-off-by: Eric Dumazet <edumazet@...gle.com>
---
include/linux/nsproxy.h | 2 ++
kernel/nsproxy.c | 5 +++--
net/core/net_namespace.c | 4 ++--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index cdb171efc7cb052dd4844ae182206939627c68e8..eed7768daf428cfede70f438ecd366af23da85f2 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -4,6 +4,7 @@
#include <linux/spinlock.h>
#include <linux/sched.h>
+#include <net/net_trackers.h>
struct mnt_namespace;
struct uts_namespace;
@@ -35,6 +36,7 @@ struct nsproxy {
struct mnt_namespace *mnt_ns;
struct pid_namespace *pid_ns_for_children;
struct net *net_ns;
+ netns_tracker ns_tracker;
struct time_namespace *time_ns;
struct time_namespace *time_ns_for_children;
struct cgroup_namespace *cgroup_ns;
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index eec72ca962e249c94266192b77a3c1f92ec8e889..8b50e8153bc8957b47e2fce860aacce4e9f56616 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -112,6 +112,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
err = PTR_ERR(new_nsp->net_ns);
goto out_net;
}
+ netns_tracker_alloc(new_nsp->net_ns, &new_nsp->ns_tracker, GFP_KERNEL);
new_nsp->time_ns_for_children = copy_time_ns(flags, user_ns,
tsk->nsproxy->time_ns_for_children);
@@ -124,7 +125,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
return new_nsp;
out_time:
- put_net(new_nsp->net_ns);
+ put_net_track(new_nsp->net_ns, &new_nsp->ns_tracker);
out_net:
put_cgroup_ns(new_nsp->cgroup_ns);
out_cgroup:
@@ -200,7 +201,7 @@ void free_nsproxy(struct nsproxy *ns)
if (ns->time_ns_for_children)
put_time_ns(ns->time_ns_for_children);
put_cgroup_ns(ns->cgroup_ns);
- put_net(ns->net_ns);
+ put_net_track(ns->net_ns, &ns->ns_tracker);
kmem_cache_free(nsproxy_cachep, ns);
}
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 3ea5321430ee21af687510917da9b9aea5154e12..962062ad8cc4697ff6791aea7c48aea0b5db94a5 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1355,8 +1355,8 @@ static int netns_install(struct nsset *nsset, struct ns_common *ns)
!ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN))
return -EPERM;
- put_net(nsproxy->net_ns);
- nsproxy->net_ns = get_net(net);
+ put_net_track(nsproxy->net_ns, &nsproxy->ns_tracker);
+ nsproxy->net_ns = get_net_track(net, &nsproxy->ns_tracker, GFP_KERNEL);
return 0;
}
--
2.34.1.400.ga245620fadb-goog
Powered by blists - more mailing lists