pidns: call pid_ns_prepare_proc() from create_pid_namespace()
Reorganize proc_get_sb() so it can be called before the struct pid of the first process is allocated. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Acked-by: Serge E. Hallyn <serge@hallyn.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
45a68628d3
commit
4308eebbeb
3 changed files with 16 additions and 26 deletions
|
@ -43,17 +43,6 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
|
||||||
struct pid_namespace *ns;
|
struct pid_namespace *ns;
|
||||||
struct proc_inode *ei;
|
struct proc_inode *ei;
|
||||||
|
|
||||||
if (proc_mnt) {
|
|
||||||
/* Seed the root directory with a pid so it doesn't need
|
|
||||||
* to be special in base.c. I would do this earlier but
|
|
||||||
* the only task alive when /proc is mounted the first time
|
|
||||||
* is the init_task and it doesn't have any pids.
|
|
||||||
*/
|
|
||||||
ei = PROC_I(proc_mnt->mnt_sb->s_root->d_inode);
|
|
||||||
if (!ei->pid)
|
|
||||||
ei->pid = find_get_pid(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & MS_KERNMOUNT)
|
if (flags & MS_KERNMOUNT)
|
||||||
ns = (struct pid_namespace *)data;
|
ns = (struct pid_namespace *)data;
|
||||||
else
|
else
|
||||||
|
@ -71,6 +60,9 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
|
||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb->s_flags |= MS_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
ei = PROC_I(sb->s_root->d_inode);
|
ei = PROC_I(sb->s_root->d_inode);
|
||||||
if (!ei->pid) {
|
if (!ei->pid) {
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
@ -78,9 +70,6 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
sb->s_flags |= MS_ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dget(sb->s_root);
|
return dget(sb->s_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1187,12 +1187,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
|
||||||
pid = alloc_pid(p->nsproxy->pid_ns);
|
pid = alloc_pid(p->nsproxy->pid_ns);
|
||||||
if (!pid)
|
if (!pid)
|
||||||
goto bad_fork_cleanup_io;
|
goto bad_fork_cleanup_io;
|
||||||
|
|
||||||
if (clone_flags & CLONE_NEWPID) {
|
|
||||||
retval = pid_ns_prepare_proc(p->nsproxy->pid_ns);
|
|
||||||
if (retval < 0)
|
|
||||||
goto bad_fork_free_pid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p->pid = pid_nr(pid);
|
p->pid = pid_nr(pid);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/acct.h>
|
#include <linux/acct.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/proc_fs.h>
|
||||||
|
|
||||||
#define BITS_PER_PAGE (PAGE_SIZE*8)
|
#define BITS_PER_PAGE (PAGE_SIZE*8)
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_p
|
||||||
{
|
{
|
||||||
struct pid_namespace *ns;
|
struct pid_namespace *ns;
|
||||||
unsigned int level = parent_pid_ns->level + 1;
|
unsigned int level = parent_pid_ns->level + 1;
|
||||||
int i;
|
int i, err = -ENOMEM;
|
||||||
|
|
||||||
ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL);
|
ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL);
|
||||||
if (ns == NULL)
|
if (ns == NULL)
|
||||||
|
@ -96,14 +97,20 @@ static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_p
|
||||||
for (i = 1; i < PIDMAP_ENTRIES; i++)
|
for (i = 1; i < PIDMAP_ENTRIES; i++)
|
||||||
atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
|
atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
|
||||||
|
|
||||||
|
err = pid_ns_prepare_proc(ns);
|
||||||
|
if (err)
|
||||||
|
goto out_put_parent_pid_ns;
|
||||||
|
|
||||||
return ns;
|
return ns;
|
||||||
|
|
||||||
|
out_put_parent_pid_ns:
|
||||||
|
put_pid_ns(parent_pid_ns);
|
||||||
out_free_map:
|
out_free_map:
|
||||||
kfree(ns->pidmap[0].page);
|
kfree(ns->pidmap[0].page);
|
||||||
out_free:
|
out_free:
|
||||||
kmem_cache_free(pid_ns_cachep, ns);
|
kmem_cache_free(pid_ns_cachep, ns);
|
||||||
out:
|
out:
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_pid_namespace(struct pid_namespace *ns)
|
static void destroy_pid_namespace(struct pid_namespace *ns)
|
||||||
|
|
Loading…
Add table
Reference in a new issue