[Devel] [PATCH RH7 14/32] switch the rest of proc_ns_operations to working with &...->ns

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon Jun 8 20:05:44 MSK 2020


From: Al Viro <viro at zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>

(cherry picked from VZ8 commit 3c0411846118a578de3a979faf2da3ab5fb81179)

https://jira.sw.ru/browse/PSBM-102357

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 ipc/namespace.c         | 15 +++++++++------
 kernel/pid_namespace.c  | 14 +++++++++-----
 kernel/user_namespace.c | 14 +++++++++-----
 kernel/utsname.c        | 15 +++++++++------
 4 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/ipc/namespace.c b/ipc/namespace.c
index a9e2f64d56ea..6781d622549e 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -151,6 +151,11 @@ void put_ipc_ns(struct ipc_namespace *ns)
 	}
 }
 
+static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
+{
+	return container_of(ns, struct ipc_namespace, ns);
+}
+
 static void *ipcns_get(struct task_struct *task)
 {
 	struct ipc_namespace *ns = NULL;
@@ -162,17 +167,17 @@ static void *ipcns_get(struct task_struct *task)
 		ns = get_ipc_ns(nsproxy->ipc_ns);
 	task_unlock(task);
 
-	return ns;
+	return ns ? &ns->ns : NULL;
 }
 
 static void ipcns_put(void *ns)
 {
-	return put_ipc_ns(ns);
+	return put_ipc_ns(to_ipc_ns(ns));
 }
 
 static int ipcns_install(struct nsproxy *nsproxy, void *new)
 {
-	struct ipc_namespace *ns = new;
+	struct ipc_namespace *ns = to_ipc_ns(new);
 	if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
 	    !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
 		return -EPERM;
@@ -186,9 +191,7 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new)
 
 static unsigned int ipcns_inum(void *vp)
 {
-	struct ipc_namespace *ns = vp;
-
-	return ns->ns.inum;
+	return ((struct ns_common *)vp)->inum;
 }
 
 const struct proc_ns_operations ipcns_operations = {
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index d50a926eee00..2c478203cba3 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -342,6 +342,11 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
 	return 0;
 }
 
+static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
+{
+	return container_of(ns, struct pid_namespace, ns);
+}
+
 static void *pidns_get(struct task_struct *task)
 {
 	struct pid_namespace *ns;
@@ -352,18 +357,18 @@ static void *pidns_get(struct task_struct *task)
 		get_pid_ns(ns);
 	rcu_read_unlock();
 
-	return ns;
+	return ns ? &ns->ns : NULL;
 }
 
 static void pidns_put(void *ns)
 {
-	put_pid_ns(ns);
+	put_pid_ns(to_pid_ns(ns));
 }
 
 static int pidns_install(struct nsproxy *nsproxy, void *ns)
 {
 	struct pid_namespace *active = task_active_pid_ns(current);
-	struct pid_namespace *ancestor, *new = ns;
+	struct pid_namespace *ancestor, *new = to_pid_ns(ns);
 
 	if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) ||
 	    !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
@@ -393,8 +398,7 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
 
 static unsigned int pidns_inum(void *ns)
 {
-	struct pid_namespace *pid_ns = ns;
-	return pid_ns->ns.inum;
+	return ((struct ns_common *)ns)->inum;
 }
 
 const struct proc_ns_operations pidns_operations = {
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 7f433288ddae..c39871e61559 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -1026,6 +1026,11 @@ bool current_in_userns(const struct user_namespace *target_ns)
 }
 EXPORT_SYMBOL(current_in_userns);
 
+static inline struct user_namespace *to_user_ns(struct ns_common *ns)
+{
+	return container_of(ns, struct user_namespace, ns);
+}
+
 static void *userns_get(struct task_struct *task)
 {
 	struct user_namespace *user_ns;
@@ -1034,17 +1039,17 @@ static void *userns_get(struct task_struct *task)
 	user_ns = get_user_ns(__task_cred(task)->user_ns);
 	rcu_read_unlock();
 
-	return user_ns;
+	return user_ns ? &user_ns->ns : NULL;
 }
 
 static void userns_put(void *ns)
 {
-	put_user_ns(ns);
+	put_user_ns(to_user_ns(ns));
 }
 
 static int userns_install(struct nsproxy *nsproxy, void *ns)
 {
-	struct user_namespace *user_ns = ns;
+	struct user_namespace *user_ns = to_user_ns(ns);
 	struct cred *cred;
 
 	/* Don't allow gaining capabilities by reentering
@@ -1075,8 +1080,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
 
 static unsigned int userns_inum(void *ns)
 {
-	struct user_namespace *user_ns = ns;
-	return user_ns->ns.inum;
+	return ((struct ns_common *)ns)->inum;
 }
 
 const struct proc_ns_operations userns_operations = {
diff --git a/kernel/utsname.c b/kernel/utsname.c
index c4d9fbd98303..d8c062d2ab28 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -142,6 +142,11 @@ void free_uts_ns(struct kref *kref)
 	kfree(ns);
 }
 
+static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
+{
+	return container_of(ns, struct uts_namespace, ns);
+}
+
 static void *utsns_get(struct task_struct *task)
 {
 	struct uts_namespace *ns = NULL;
@@ -155,17 +160,17 @@ static void *utsns_get(struct task_struct *task)
 	}
 	task_unlock(task);
 
-	return ns;
+	return ns ? &ns->ns : NULL;
 }
 
 static void utsns_put(void *ns)
 {
-	put_uts_ns(ns);
+	put_uts_ns(to_uts_ns(ns));
 }
 
 static int utsns_install(struct nsproxy *nsproxy, void *new)
 {
-	struct uts_namespace *ns = new;
+	struct uts_namespace *ns = to_uts_ns(new);
 
 	if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
 	    !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
@@ -179,9 +184,7 @@ static int utsns_install(struct nsproxy *nsproxy, void *new)
 
 static unsigned int utsns_inum(void *vp)
 {
-	struct uts_namespace *ns = vp;
-
-	return ns->ns.inum;
+	return ((struct ns_common *)vp)->inum;
 }
 
 const struct proc_ns_operations utsns_operations = {
-- 
2.24.1



More information about the Devel mailing list