From 435d5f4bb2ccba3b791d9ef61d2590e30b8e806e Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 31 Oct 2014 22:56:04 -0400 Subject: common object embedded into various struct ....ns for now - just move corresponding ->proc_inum instances over there Acked-by: "Eric W. Biederman" Signed-off-by: Al Viro --- ipc/msgutil.c | 2 +- ipc/namespace.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ipc') diff --git a/ipc/msgutil.c b/ipc/msgutil.c index 7e7095974d54..5930471a2902 100644 --- a/ipc/msgutil.c +++ b/ipc/msgutil.c @@ -31,7 +31,7 @@ DEFINE_SPINLOCK(mq_lock); struct ipc_namespace init_ipc_ns = { .count = ATOMIC_INIT(1), .user_ns = &init_user_ns, - .proc_inum = PROC_IPC_INIT_INO, + .ns.inum = PROC_IPC_INIT_INO, }; atomic_t nr_ipc_ns = ATOMIC_INIT(1); diff --git a/ipc/namespace.c b/ipc/namespace.c index b54468e48e32..177fa9db391d 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -26,7 +26,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, if (ns == NULL) return ERR_PTR(-ENOMEM); - err = proc_alloc_inum(&ns->proc_inum); + err = proc_alloc_inum(&ns->ns.inum); if (err) { kfree(ns); return ERR_PTR(err); @@ -35,7 +35,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, atomic_set(&ns->count, 1); err = mq_init_ns(ns); if (err) { - proc_free_inum(ns->proc_inum); + proc_free_inum(ns->ns.inum); kfree(ns); return ERR_PTR(err); } @@ -119,7 +119,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) */ ipcns_notify(IPCNS_REMOVED); put_user_ns(ns->user_ns); - proc_free_inum(ns->proc_inum); + proc_free_inum(ns->ns.inum); kfree(ns); } @@ -186,7 +186,7 @@ static unsigned int ipcns_inum(void *vp) { struct ipc_namespace *ns = vp; - return ns->proc_inum; + return ns->ns.inum; } const struct proc_ns_operations ipcns_operations = { -- cgit v1.2.3 From 3c0411846118a578de3a979faf2da3ab5fb81179 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 1 Nov 2014 00:25:30 -0400 Subject: switch the rest of proc_ns_operations to working with &...->ns Signed-off-by: Al Viro --- ipc/namespace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ipc') diff --git a/ipc/namespace.c b/ipc/namespace.c index 177fa9db391d..3c1e8d3bd7d3 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -149,6 +149,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; @@ -160,17 +165,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; @@ -184,9 +189,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 = { -- cgit v1.2.3 From 64964528b24ea390824f0e5ce9d34b8d39b28cde Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 1 Nov 2014 00:37:32 -0400 Subject: make proc_ns_operations work with struct ns_common * instead of void * We can do that now. And kill ->inum(), while we are at it - all instances are identical. Signed-off-by: Al Viro --- ipc/namespace.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'ipc') diff --git a/ipc/namespace.c b/ipc/namespace.c index 3c1e8d3bd7d3..531029a67fef 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -154,7 +154,7 @@ 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) +static struct ns_common *ipcns_get(struct task_struct *task) { struct ipc_namespace *ns = NULL; struct nsproxy *nsproxy; @@ -168,12 +168,12 @@ static void *ipcns_get(struct task_struct *task) return ns ? &ns->ns : NULL; } -static void ipcns_put(void *ns) +static void ipcns_put(struct ns_common *ns) { return put_ipc_ns(to_ipc_ns(ns)); } -static int ipcns_install(struct nsproxy *nsproxy, void *new) +static int ipcns_install(struct nsproxy *nsproxy, struct ns_common *new) { struct ipc_namespace *ns = to_ipc_ns(new); if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || @@ -187,16 +187,10 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new) return 0; } -static unsigned int ipcns_inum(void *vp) -{ - return ((struct ns_common *)vp)->inum; -} - const struct proc_ns_operations ipcns_operations = { .name = "ipc", .type = CLONE_NEWIPC, .get = ipcns_get, .put = ipcns_put, .install = ipcns_install, - .inum = ipcns_inum, }; -- cgit v1.2.3 From 6344c433a452b1a05d03a61a6a85d89f793bb7b8 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 1 Nov 2014 00:45:45 -0400 Subject: new helpers: ns_alloc_inum/ns_free_inum take struct ns_common *, for now simply wrappers around proc_{alloc,free}_inum() Signed-off-by: Al Viro --- ipc/namespace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ipc') diff --git a/ipc/namespace.c b/ipc/namespace.c index 531029a67fef..bcdd7a5c122a 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -26,7 +26,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, if (ns == NULL) return ERR_PTR(-ENOMEM); - err = proc_alloc_inum(&ns->ns.inum); + err = ns_alloc_inum(&ns->ns); if (err) { kfree(ns); return ERR_PTR(err); @@ -35,7 +35,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, atomic_set(&ns->count, 1); err = mq_init_ns(ns); if (err) { - proc_free_inum(ns->ns.inum); + ns_free_inum(&ns->ns); kfree(ns); return ERR_PTR(err); } @@ -119,7 +119,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) */ ipcns_notify(IPCNS_REMOVED); put_user_ns(ns->user_ns); - proc_free_inum(ns->ns.inum); + ns_free_inum(&ns->ns); kfree(ns); } -- cgit v1.2.3 From 33c429405a2c8d9e42afb9fee88a63cfb2de1e98 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 1 Nov 2014 02:32:53 -0400 Subject: copy address of proc_ns_ops into ns_common Signed-off-by: Al Viro --- ipc/msgutil.c | 3 +++ ipc/namespace.c | 1 + 2 files changed, 4 insertions(+) (limited to 'ipc') diff --git a/ipc/msgutil.c b/ipc/msgutil.c index 5930471a2902..2b491590ebab 100644 --- a/ipc/msgutil.c +++ b/ipc/msgutil.c @@ -32,6 +32,9 @@ struct ipc_namespace init_ipc_ns = { .count = ATOMIC_INIT(1), .user_ns = &init_user_ns, .ns.inum = PROC_IPC_INIT_INO, +#ifdef CONFIG_IPC_NS + .ns.ops = &ipcns_operations, +#endif }; atomic_t nr_ipc_ns = ATOMIC_INIT(1); diff --git a/ipc/namespace.c b/ipc/namespace.c index bcdd7a5c122a..382e2aa42d8a 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -31,6 +31,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, kfree(ns); return ERR_PTR(err); } + ns->ns.ops = &ipcns_operations; atomic_set(&ns->count, 1); err = mq_init_ns(ns); -- cgit v1.2.3