summaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorJANAK DESAI <janak@us.ibm.com>2006-02-07 12:59:00 -0800
committerLinus Torvalds <torvalds@g5.osdl.org>2006-02-07 16:12:34 -0800
commit741a295130606143edbf9fc740f633dbc1e6225f (patch)
tree3679047dd44e94ba94ee1487880a94def93a06f9 /kernel/fork.c
parent99d1419d96d7df9cfa56bc977810be831bd5ef64 (diff)
downloadop-kernel-dev-741a295130606143edbf9fc740f633dbc1e6225f.zip
op-kernel-dev-741a295130606143edbf9fc740f633dbc1e6225f.tar.gz
[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 <janak@us.ibm.com> Cc: Al Viro <viro@ftp.linux.org.uk> Cc: Christoph Hellwig <hch@lst.de> Cc: Michael Kerrisk <mtk-manpages@gmx.net> Cc: Andi Kleen <ak@muc.de> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 598e5c2..07dd241 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1388,16 +1388,21 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
}
/*
- * Unsharing of namespace for tasks created without CLONE_NEWNS is not
- * supported yet
+ * Unshare the namespace structure if it is being shared
*/
-static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
+static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs)
{
struct namespace *ns = current->namespace;
if ((unshare_flags & CLONE_NEWNS) &&
- (ns && atomic_read(&ns->count) > 1))
- return -EINVAL;
+ (ns && atomic_read(&ns->count) > 1)) {
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ *new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs);
+ if (!*new_nsp)
+ return -ENOMEM;
+ }
return 0;
}
@@ -1482,7 +1487,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
goto bad_unshare_out;
if ((err = unshare_fs(unshare_flags, &new_fs)))
goto bad_unshare_cleanup_thread;
- if ((err = unshare_namespace(unshare_flags, &new_ns)))
+ if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs)))
goto bad_unshare_cleanup_fs;
if ((err = unshare_sighand(unshare_flags, &new_sigh)))
goto bad_unshare_cleanup_ns;
OpenPOWER on IntegriCloud