namespace.c (3c0411846118a578de3a979faf2da3ab5fb81179) namespace.c (64964528b24ea390824f0e5ce9d34b8d39b28cde)
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>

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

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
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>

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

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
157static void *ipcns_get(struct task_struct *task)
157static struct ns_common *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
168 return ns ? &ns->ns : NULL;
169}
170
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
168 return ns ? &ns->ns : NULL;
169}
170
171static void ipcns_put(void *ns)
171static void ipcns_put(struct ns_common *ns)
172{
173 return put_ipc_ns(to_ipc_ns(ns));
174}
175
172{
173 return put_ipc_ns(to_ipc_ns(ns));
174}
175
176static int ipcns_install(struct nsproxy *nsproxy, void *new)
176static int ipcns_install(struct nsproxy *nsproxy, struct ns_common *new)
177{
178 struct ipc_namespace *ns = to_ipc_ns(new);
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
177{
178 struct ipc_namespace *ns = to_ipc_ns(new);
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{
192 return ((struct ns_common *)vp)->inum;
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,
190const struct proc_ns_operations ipcns_operations = {
191 .name = "ipc",
192 .type = CLONE_NEWIPC,
193 .get = ipcns_get,
194 .put = ipcns_put,
195 .install = ipcns_install,
201 .inum = ipcns_inum,
202};
196};