aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/util.c')
-rw-r--r--ipc/util.c54
1 files changed, 10 insertions, 44 deletions
diff --git a/ipc/util.c b/ipc/util.c
index 0b652387d169..7536a7292d48 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -21,7 +21,6 @@
21#include <linux/shm.h> 21#include <linux/shm.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/msg.h> 23#include <linux/msg.h>
24#include <linux/smp_lock.h>
25#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27#include <linux/capability.h> 26#include <linux/capability.h>
@@ -85,53 +84,20 @@ err_mem:
85 return ERR_PTR(err); 84 return ERR_PTR(err);
86} 85}
87 86
88int unshare_ipcs(unsigned long unshare_flags, struct ipc_namespace **new_ipc) 87struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
89{ 88{
90 struct ipc_namespace *new;
91
92 if (unshare_flags & CLONE_NEWIPC) {
93 if (!capable(CAP_SYS_ADMIN))
94 return -EPERM;
95
96 new = clone_ipc_ns(current->nsproxy->ipc_ns);
97 if (IS_ERR(new))
98 return PTR_ERR(new);
99
100 *new_ipc = new;
101 }
102
103 return 0;
104}
105
106int copy_ipcs(unsigned long flags, struct task_struct *tsk)
107{
108 struct ipc_namespace *old_ns = tsk->nsproxy->ipc_ns;
109 struct ipc_namespace *new_ns; 89 struct ipc_namespace *new_ns;
110 int err = 0;
111 90
112 if (!old_ns) 91 BUG_ON(!ns);
113 return 0; 92 get_ipc_ns(ns);
114
115 get_ipc_ns(old_ns);
116 93
117 if (!(flags & CLONE_NEWIPC)) 94 if (!(flags & CLONE_NEWIPC))
118 return 0; 95 return ns;
119 96
120 if (!capable(CAP_SYS_ADMIN)) { 97 new_ns = clone_ipc_ns(ns);
121 err = -EPERM;
122 goto out;
123 }
124 98
125 new_ns = clone_ipc_ns(old_ns); 99 put_ipc_ns(ns);
126 if (!new_ns) { 100 return new_ns;
127 err = -ENOMEM;
128 goto out;
129 }
130
131 tsk->nsproxy->ipc_ns = new_ns;
132out:
133 put_ipc_ns(old_ns);
134 return err;
135} 101}
136 102
137void free_ipc_ns(struct kref *kref) 103void free_ipc_ns(struct kref *kref)
@@ -145,11 +111,11 @@ void free_ipc_ns(struct kref *kref)
145 kfree(ns); 111 kfree(ns);
146} 112}
147#else 113#else
148int copy_ipcs(unsigned long flags, struct task_struct *tsk) 114struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
149{ 115{
150 if (flags & CLONE_NEWIPC) 116 if (flags & CLONE_NEWIPC)
151 return -EINVAL; 117 return ERR_PTR(-EINVAL);
152 return 0; 118 return ns;
153} 119}
154#endif 120#endif
155 121