aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/fork.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 598e5c27242c..07dd241aa1e0 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)
1388} 1388}
1389 1389
1390/* 1390/*
1391 * Unsharing of namespace for tasks created without CLONE_NEWNS is not 1391 * Unshare the namespace structure if it is being shared
1392 * supported yet
1393 */ 1392 */
1394static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp) 1393static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs)
1395{ 1394{
1396 struct namespace *ns = current->namespace; 1395 struct namespace *ns = current->namespace;
1397 1396
1398 if ((unshare_flags & CLONE_NEWNS) && 1397 if ((unshare_flags & CLONE_NEWNS) &&
1399 (ns && atomic_read(&ns->count) > 1)) 1398 (ns && atomic_read(&ns->count) > 1)) {
1400 return -EINVAL; 1399 if (!capable(CAP_SYS_ADMIN))
1400 return -EPERM;
1401
1402 *new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs);
1403 if (!*new_nsp)
1404 return -ENOMEM;
1405 }
1401 1406
1402 return 0; 1407 return 0;
1403} 1408}
@@ -1482,7 +1487,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
1482 goto bad_unshare_out; 1487 goto bad_unshare_out;
1483 if ((err = unshare_fs(unshare_flags, &new_fs))) 1488 if ((err = unshare_fs(unshare_flags, &new_fs)))
1484 goto bad_unshare_cleanup_thread; 1489 goto bad_unshare_cleanup_thread;
1485 if ((err = unshare_namespace(unshare_flags, &new_ns))) 1490 if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs)))
1486 goto bad_unshare_cleanup_fs; 1491 goto bad_unshare_cleanup_fs;
1487 if ((err = unshare_sighand(unshare_flags, &new_sigh))) 1492 if ((err = unshare_sighand(unshare_flags, &new_sigh)))
1488 goto bad_unshare_cleanup_ns; 1493 goto bad_unshare_cleanup_ns;