Skip to content

Commit a00eaf1

Browse files
committed
ns proc: Add support for the ipc namespace
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
1 parent 34482e8 commit a00eaf1

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎fs/proc/namespaces.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ static const struct proc_ns_operations *ns_entries[] = {
2222
#ifdef CONFIG_UTS_NS
2323
&utsns_operations,
2424
#endif
25+
#ifdef CONFIG_IPC_NS
26+
&ipcns_operations,
27+
#endif
2528
};
2629

2730
static const struct file_operations ns_file_operations = {

‎include/linux/proc_fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct proc_ns_operations {
267267
};
268268
extern const struct proc_ns_operations netns_operations;
269269
extern const struct proc_ns_operations utsns_operations;
270+
extern const struct proc_ns_operations ipcns_operations;
270271

271272
union proc_op {
272273
int (*proc_get_link)(struct inode *, struct path *);

‎ipc/namespace.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/fs.h>
1313
#include <linux/mount.h>
1414
#include <linux/user_namespace.h>
15+
#include <linux/proc_fs.h>
1516

1617
#include "util.h"
1718

@@ -140,3 +141,39 @@ void put_ipc_ns(struct ipc_namespace *ns)
140141
free_ipc_ns(ns);
141142
}
142143
}
144+
145+
static void *ipcns_get(struct task_struct *task)
146+
{
147+
struct ipc_namespace *ns = NULL;
148+
struct nsproxy *nsproxy;
149+
150+
rcu_read_lock();
151+
nsproxy = task_nsproxy(task);
152+
if (nsproxy)
153+
ns = get_ipc_ns(nsproxy->ipc_ns);
154+
rcu_read_unlock();
155+
156+
return ns;
157+
}
158+
159+
static void ipcns_put(void *ns)
160+
{
161+
return put_ipc_ns(ns);
162+
}
163+
164+
static int ipcns_install(struct nsproxy *nsproxy, void *ns)
165+
{
166+
/* Ditch state from the old ipc namespace */
167+
exit_sem(current);
168+
put_ipc_ns(nsproxy->ipc_ns);
169+
nsproxy->ipc_ns = get_ipc_ns(ns);
170+
return 0;
171+
}
172+
173+
const struct proc_ns_operations ipcns_operations = {
174+
.name = "ipc",
175+
.type = CLONE_NEWIPC,
176+
.get = ipcns_get,
177+
.put = ipcns_put,
178+
.install = ipcns_install,
179+
};

0 commit comments

Comments
 (0)