Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 346312
b: refs/heads/master
c: 57e8391
h: refs/heads/master
v: v3
  • Loading branch information
Eric W. Biederman committed Nov 19, 2012
1 parent af94264 commit 5e0d48e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 225778d68d98e7cfe2579f8d8b2d7b76f8541b8b
refs/heads/master: 57e8391d327609cbf12d843259c968b9e5c1838f
3 changes: 3 additions & 0 deletions trunk/fs/proc/namespaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ static const struct proc_ns_operations *ns_entries[] = {
#ifdef CONFIG_IPC_NS
&ipcns_operations,
#endif
#ifdef CONFIG_PID_NS
&pidns_operations,
#endif
};

static const struct file_operations ns_file_operations = {
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/proc_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct proc_ns_operations {
extern const struct proc_ns_operations netns_operations;
extern const struct proc_ns_operations utsns_operations;
extern const struct proc_ns_operations ipcns_operations;
extern const struct proc_ns_operations pidns_operations;

union proc_op {
int (*proc_get_link)(struct dentry *, struct path *);
Expand Down
54 changes: 54 additions & 0 deletions trunk/kernel/pid_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,60 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
return 0;
}

static void *pidns_get(struct task_struct *task)
{
struct pid_namespace *ns;

rcu_read_lock();
ns = get_pid_ns(task_active_pid_ns(task));
rcu_read_unlock();

return ns;
}

static void pidns_put(void *ns)
{
put_pid_ns(ns);
}

static int pidns_install(struct nsproxy *nsproxy, void *ns)
{
struct pid_namespace *active = task_active_pid_ns(current);
struct pid_namespace *ancestor, *new = ns;

if (!ns_capable(new->user_ns, CAP_SYS_ADMIN))
return -EPERM;

/*
* Only allow entering the current active pid namespace
* or a child of the current active pid namespace.
*
* This is required for fork to return a usable pid value and
* this maintains the property that processes and their
* children can not escape their current pid namespace.
*/
if (new->level < active->level)
return -EINVAL;

ancestor = new;
while (ancestor->level > active->level)
ancestor = ancestor->parent;
if (ancestor != active)
return -EINVAL;

put_pid_ns(nsproxy->pid_ns);
nsproxy->pid_ns = get_pid_ns(new);
return 0;
}

const struct proc_ns_operations pidns_operations = {
.name = "pid",
.type = CLONE_NEWPID,
.get = pidns_get,
.put = pidns_put,
.install = pidns_install,
};

static __init int pid_namespaces_init(void)
{
pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
Expand Down

0 comments on commit 5e0d48e

Please sign in to comment.