mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
[PATCH] unshare system call -v5: unshare namespace
If the namespace structure is being shared, allocate a new one and copy information from the current, shared, structure. Signed-off-by: Janak Desai <[email protected]> Cc: Al Viro <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Michael Kerrisk <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Paul Mackerras <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
99d1419d96
commit
741a295130
3 changed files with 48 additions and 26 deletions
|
|
@ -1325,27 +1325,17 @@ dput_out:
|
|||
return retval;
|
||||
}
|
||||
|
||||
int copy_namespace(int flags, struct task_struct *tsk)
|
||||
/*
|
||||
* Allocate a new namespace structure and populate it with contents
|
||||
* copied from the namespace of the passed in task structure.
|
||||
*/
|
||||
struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
|
||||
{
|
||||
struct namespace *namespace = tsk->namespace;
|
||||
struct namespace *new_ns;
|
||||
struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
|
||||
struct fs_struct *fs = tsk->fs;
|
||||
struct vfsmount *p, *q;
|
||||
|
||||
if (!namespace)
|
||||
return 0;
|
||||
|
||||
get_namespace(namespace);
|
||||
|
||||
if (!(flags & CLONE_NEWNS))
|
||||
return 0;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN)) {
|
||||
put_namespace(namespace);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
|
||||
if (!new_ns)
|
||||
goto out;
|
||||
|
|
@ -1396,8 +1386,6 @@ int copy_namespace(int flags, struct task_struct *tsk)
|
|||
}
|
||||
up_write(&namespace_sem);
|
||||
|
||||
tsk->namespace = new_ns;
|
||||
|
||||
if (rootmnt)
|
||||
mntput(rootmnt);
|
||||
if (pwdmnt)
|
||||
|
|
@ -1405,12 +1393,40 @@ int copy_namespace(int flags, struct task_struct *tsk)
|
|||
if (altrootmnt)
|
||||
mntput(altrootmnt);
|
||||
|
||||
put_namespace(namespace);
|
||||
return 0;
|
||||
out:
|
||||
return new_ns;
|
||||
}
|
||||
|
||||
int copy_namespace(int flags, struct task_struct *tsk)
|
||||
{
|
||||
struct namespace *namespace = tsk->namespace;
|
||||
struct namespace *new_ns;
|
||||
int err = 0;
|
||||
|
||||
if (!namespace)
|
||||
return 0;
|
||||
|
||||
get_namespace(namespace);
|
||||
|
||||
if (!(flags & CLONE_NEWNS))
|
||||
return 0;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN)) {
|
||||
err = -EPERM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
new_ns = dup_namespace(tsk, tsk->fs);
|
||||
if (!new_ns) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
tsk->namespace = new_ns;
|
||||
|
||||
out:
|
||||
put_namespace(namespace);
|
||||
return -ENOMEM;
|
||||
return err;
|
||||
}
|
||||
|
||||
asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue