namespace.c (435d5f4bb2ccba3b791d9ef61d2590e30b8e806e) namespace.c (3c0411846118a578de3a979faf2da3ab5fb81179)
1/*
2 * linux/ipc/namespace.c
3 * Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
4 */
5
6#include <linux/ipc.h>
7#include <linux/msg.h>
8#include <linux/ipc_namespace.h>

--- 135 unchanged lines hidden (view full) ---

144 if (atomic_dec_and_lock(&ns->count, &mq_lock)) {
145 mq_clear_sbinfo(ns);
146 spin_unlock(&mq_lock);
147 mq_put_mnt(ns);
148 free_ipc_ns(ns);
149 }
150}
151
1/*
2 * linux/ipc/namespace.c
3 * Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
4 */
5
6#include <linux/ipc.h>
7#include <linux/msg.h>
8#include <linux/ipc_namespace.h>

--- 135 unchanged lines hidden (view full) ---

144 if (atomic_dec_and_lock(&ns->count, &mq_lock)) {
145 mq_clear_sbinfo(ns);
146 spin_unlock(&mq_lock);
147 mq_put_mnt(ns);
148 free_ipc_ns(ns);
149 }
150}
151
152static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
153{
154 return container_of(ns, struct ipc_namespace, ns);
155}
156
152static void *ipcns_get(struct task_struct *task)
153{
154 struct ipc_namespace *ns = NULL;
155 struct nsproxy *nsproxy;
156
157 task_lock(task);
158 nsproxy = task->nsproxy;
159 if (nsproxy)
160 ns = get_ipc_ns(nsproxy->ipc_ns);
161 task_unlock(task);
162
157static void *ipcns_get(struct task_struct *task)
158{
159 struct ipc_namespace *ns = NULL;
160 struct nsproxy *nsproxy;
161
162 task_lock(task);
163 nsproxy = task->nsproxy;
164 if (nsproxy)
165 ns = get_ipc_ns(nsproxy->ipc_ns);
166 task_unlock(task);
167
163 return ns;
168 return ns ? &ns->ns : NULL;
164}
165
166static void ipcns_put(void *ns)
167{
169}
170
171static void ipcns_put(void *ns)
172{
168 return put_ipc_ns(ns);
173 return put_ipc_ns(to_ipc_ns(ns));
169}
170
171static int ipcns_install(struct nsproxy *nsproxy, void *new)
172{
174}
175
176static int ipcns_install(struct nsproxy *nsproxy, void *new)
177{
173 struct ipc_namespace *ns = new;
178 struct ipc_namespace *ns = to_ipc_ns(new);
174 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
175 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
176 return -EPERM;
177
178 /* Ditch state from the old ipc namespace */
179 exit_sem(current);
180 put_ipc_ns(nsproxy->ipc_ns);
181 nsproxy->ipc_ns = get_ipc_ns(ns);
182 return 0;
183}
184
185static unsigned int ipcns_inum(void *vp)
186{
179 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
180 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
181 return -EPERM;
182
183 /* Ditch state from the old ipc namespace */
184 exit_sem(current);
185 put_ipc_ns(nsproxy->ipc_ns);
186 nsproxy->ipc_ns = get_ipc_ns(ns);
187 return 0;
188}
189
190static unsigned int ipcns_inum(void *vp)
191{
187 struct ipc_namespace *ns = vp;
188
189 return ns->ns.inum;
192 return ((struct ns_common *)vp)->inum;
190}
191
192const struct proc_ns_operations ipcns_operations = {
193 .name = "ipc",
194 .type = CLONE_NEWIPC,
195 .get = ipcns_get,
196 .put = ipcns_put,
197 .install = ipcns_install,
198 .inum = ipcns_inum,
199};
193}
194
195const struct proc_ns_operations ipcns_operations = {
196 .name = "ipc",
197 .type = CLONE_NEWIPC,
198 .get = ipcns_get,
199 .put = ipcns_put,
200 .install = ipcns_install,
201 .inum = ipcns_inum,
202};