aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c181
1 files changed, 125 insertions, 56 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 8b20ab7d3aa2..1766d324d5e3 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -146,7 +146,7 @@ void __weak arch_release_thread_info(struct thread_info *ti)
146static struct thread_info *alloc_thread_info_node(struct task_struct *tsk, 146static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
147 int node) 147 int node)
148{ 148{
149 struct page *page = alloc_pages_node(node, THREADINFO_GFP, 149 struct page *page = alloc_pages_node(node, THREADINFO_GFP_ACCOUNTED,
150 THREAD_SIZE_ORDER); 150 THREAD_SIZE_ORDER);
151 151
152 return page ? page_address(page) : NULL; 152 return page ? page_address(page) : NULL;
@@ -154,7 +154,7 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
154 154
155static inline void free_thread_info(struct thread_info *ti) 155static inline void free_thread_info(struct thread_info *ti)
156{ 156{
157 free_pages((unsigned long)ti, THREAD_SIZE_ORDER); 157 free_memcg_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER);
158} 158}
159# else 159# else
160static struct kmem_cache *thread_info_cache; 160static struct kmem_cache *thread_info_cache;
@@ -352,6 +352,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
352 unsigned long charge; 352 unsigned long charge;
353 struct mempolicy *pol; 353 struct mempolicy *pol;
354 354
355 uprobe_start_dup_mmap();
355 down_write(&oldmm->mmap_sem); 356 down_write(&oldmm->mmap_sem);
356 flush_cache_dup_mm(oldmm); 357 flush_cache_dup_mm(oldmm);
357 uprobe_dup_mmap(oldmm, mm); 358 uprobe_dup_mmap(oldmm, mm);
@@ -412,7 +413,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
412 tmp->vm_next = tmp->vm_prev = NULL; 413 tmp->vm_next = tmp->vm_prev = NULL;
413 file = tmp->vm_file; 414 file = tmp->vm_file;
414 if (file) { 415 if (file) {
415 struct inode *inode = file->f_path.dentry->d_inode; 416 struct inode *inode = file_inode(file);
416 struct address_space *mapping = file->f_mapping; 417 struct address_space *mapping = file->f_mapping;
417 418
418 get_file(file); 419 get_file(file);
@@ -469,6 +470,7 @@ out:
469 up_write(&mm->mmap_sem); 470 up_write(&mm->mmap_sem);
470 flush_tlb_mm(oldmm); 471 flush_tlb_mm(oldmm);
471 up_write(&oldmm->mmap_sem); 472 up_write(&oldmm->mmap_sem);
473 uprobe_end_dup_mmap();
472 return retval; 474 return retval;
473fail_nomem_anon_vma_fork: 475fail_nomem_anon_vma_fork:
474 mpol_put(pol); 476 mpol_put(pol);
@@ -821,6 +823,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
821#ifdef CONFIG_TRANSPARENT_HUGEPAGE 823#ifdef CONFIG_TRANSPARENT_HUGEPAGE
822 mm->pmd_huge_pte = NULL; 824 mm->pmd_huge_pte = NULL;
823#endif 825#endif
826#ifdef CONFIG_NUMA_BALANCING
827 mm->first_nid = NUMA_PTE_SCAN_INIT;
828#endif
824 if (!mm_init(mm, tsk)) 829 if (!mm_init(mm, tsk))
825 goto fail_nomem; 830 goto fail_nomem;
826 831
@@ -1039,8 +1044,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
1039 atomic_set(&sig->live, 1); 1044 atomic_set(&sig->live, 1);
1040 atomic_set(&sig->sigcnt, 1); 1045 atomic_set(&sig->sigcnt, 1);
1041 init_waitqueue_head(&sig->wait_chldexit); 1046 init_waitqueue_head(&sig->wait_chldexit);
1042 if (clone_flags & CLONE_NEWPID)
1043 sig->flags |= SIGNAL_UNKILLABLE;
1044 sig->curr_target = tsk; 1047 sig->curr_target = tsk;
1045 init_sigpending(&sig->shared_pending); 1048 init_sigpending(&sig->shared_pending);
1046 INIT_LIST_HEAD(&sig->posix_timers); 1049 INIT_LIST_HEAD(&sig->posix_timers);
@@ -1127,7 +1130,6 @@ static void posix_cpu_timers_init(struct task_struct *tsk)
1127 */ 1130 */
1128static struct task_struct *copy_process(unsigned long clone_flags, 1131static struct task_struct *copy_process(unsigned long clone_flags,
1129 unsigned long stack_start, 1132 unsigned long stack_start,
1130 struct pt_regs *regs,
1131 unsigned long stack_size, 1133 unsigned long stack_size,
1132 int __user *child_tidptr, 1134 int __user *child_tidptr,
1133 struct pid *pid, 1135 struct pid *pid,
@@ -1135,11 +1137,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1135{ 1137{
1136 int retval; 1138 int retval;
1137 struct task_struct *p; 1139 struct task_struct *p;
1138 int cgroup_callbacks_done = 0;
1139 1140
1140 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) 1141 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
1141 return ERR_PTR(-EINVAL); 1142 return ERR_PTR(-EINVAL);
1142 1143
1144 if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS))
1145 return ERR_PTR(-EINVAL);
1146
1143 /* 1147 /*
1144 * Thread groups must share signals as well, and detached threads 1148 * Thread groups must share signals as well, and detached threads
1145 * can only be started up within the thread group. 1149 * can only be started up within the thread group.
@@ -1165,6 +1169,14 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1165 current->signal->flags & SIGNAL_UNKILLABLE) 1169 current->signal->flags & SIGNAL_UNKILLABLE)
1166 return ERR_PTR(-EINVAL); 1170 return ERR_PTR(-EINVAL);
1167 1171
1172 /*
1173 * If the new process will be in a different pid namespace
1174 * don't allow the creation of threads.
1175 */
1176 if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) &&
1177 (task_active_pid_ns(current) != current->nsproxy->pid_ns))
1178 return ERR_PTR(-EINVAL);
1179
1168 retval = security_task_create(clone_flags); 1180 retval = security_task_create(clone_flags);
1169 if (retval) 1181 if (retval)
1170 goto fork_out; 1182 goto fork_out;
@@ -1222,8 +1234,14 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1222 p->utime = p->stime = p->gtime = 0; 1234 p->utime = p->stime = p->gtime = 0;
1223 p->utimescaled = p->stimescaled = 0; 1235 p->utimescaled = p->stimescaled = 0;
1224#ifndef CONFIG_VIRT_CPU_ACCOUNTING 1236#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1225 p->prev_utime = p->prev_stime = 0; 1237 p->prev_cputime.utime = p->prev_cputime.stime = 0;
1226#endif 1238#endif
1239#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
1240 seqlock_init(&p->vtime_seqlock);
1241 p->vtime_snap = 0;
1242 p->vtime_snap_whence = VTIME_SLEEPING;
1243#endif
1244
1227#if defined(SPLIT_RSS_COUNTING) 1245#if defined(SPLIT_RSS_COUNTING)
1228 memset(&p->rss_stat, 0, sizeof(p->rss_stat)); 1246 memset(&p->rss_stat, 0, sizeof(p->rss_stat));
1229#endif 1247#endif
@@ -1320,7 +1338,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1320 retval = copy_io(clone_flags, p); 1338 retval = copy_io(clone_flags, p);
1321 if (retval) 1339 if (retval)
1322 goto bad_fork_cleanup_namespaces; 1340 goto bad_fork_cleanup_namespaces;
1323 retval = copy_thread(clone_flags, stack_start, stack_size, p, regs); 1341 retval = copy_thread(clone_flags, stack_start, stack_size, p);
1324 if (retval) 1342 if (retval)
1325 goto bad_fork_cleanup_io; 1343 goto bad_fork_cleanup_io;
1326 1344
@@ -1393,12 +1411,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1393 INIT_LIST_HEAD(&p->thread_group); 1411 INIT_LIST_HEAD(&p->thread_group);
1394 p->task_works = NULL; 1412 p->task_works = NULL;
1395 1413
1396 /* Now that the task is set up, run cgroup callbacks if
1397 * necessary. We need to run them before the task is visible
1398 * on the tasklist. */
1399 cgroup_fork_callbacks(p);
1400 cgroup_callbacks_done = 1;
1401
1402 /* Need tasklist lock for parent etc handling! */ 1414 /* Need tasklist lock for parent etc handling! */
1403 write_lock_irq(&tasklist_lock); 1415 write_lock_irq(&tasklist_lock);
1404 1416
@@ -1441,8 +1453,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1441 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace); 1453 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
1442 1454
1443 if (thread_group_leader(p)) { 1455 if (thread_group_leader(p)) {
1444 if (is_child_reaper(pid)) 1456 if (is_child_reaper(pid)) {
1445 p->nsproxy->pid_ns->child_reaper = p; 1457 ns_of_pid(pid)->child_reaper = p;
1458 p->signal->flags |= SIGNAL_UNKILLABLE;
1459 }
1446 1460
1447 p->signal->leader_pid = pid; 1461 p->signal->leader_pid = pid;
1448 p->signal->tty = tty_kref_get(current->signal->tty); 1462 p->signal->tty = tty_kref_get(current->signal->tty);
@@ -1476,8 +1490,6 @@ bad_fork_cleanup_io:
1476 if (p->io_context) 1490 if (p->io_context)
1477 exit_io_context(p); 1491 exit_io_context(p);
1478bad_fork_cleanup_namespaces: 1492bad_fork_cleanup_namespaces:
1479 if (unlikely(clone_flags & CLONE_NEWPID))
1480 pid_ns_release_proc(p->nsproxy->pid_ns);
1481 exit_task_namespaces(p); 1493 exit_task_namespaces(p);
1482bad_fork_cleanup_mm: 1494bad_fork_cleanup_mm:
1483 if (p->mm) 1495 if (p->mm)
@@ -1503,7 +1515,7 @@ bad_fork_cleanup_cgroup:
1503#endif 1515#endif
1504 if (clone_flags & CLONE_THREAD) 1516 if (clone_flags & CLONE_THREAD)
1505 threadgroup_change_end(current); 1517 threadgroup_change_end(current);
1506 cgroup_exit(p, cgroup_callbacks_done); 1518 cgroup_exit(p, 0);
1507 delayacct_tsk_free(p); 1519 delayacct_tsk_free(p);
1508 module_put(task_thread_info(p)->exec_domain->module); 1520 module_put(task_thread_info(p)->exec_domain->module);
1509bad_fork_cleanup_count: 1521bad_fork_cleanup_count:
@@ -1515,12 +1527,6 @@ fork_out:
1515 return ERR_PTR(retval); 1527 return ERR_PTR(retval);
1516} 1528}
1517 1529
1518noinline struct pt_regs * __cpuinit __attribute__((weak)) idle_regs(struct pt_regs *regs)
1519{
1520 memset(regs, 0, sizeof(struct pt_regs));
1521 return regs;
1522}
1523
1524static inline void init_idle_pids(struct pid_link *links) 1530static inline void init_idle_pids(struct pid_link *links)
1525{ 1531{
1526 enum pid_type type; 1532 enum pid_type type;
@@ -1534,10 +1540,7 @@ static inline void init_idle_pids(struct pid_link *links)
1534struct task_struct * __cpuinit fork_idle(int cpu) 1540struct task_struct * __cpuinit fork_idle(int cpu)
1535{ 1541{
1536 struct task_struct *task; 1542 struct task_struct *task;
1537 struct pt_regs regs; 1543 task = copy_process(CLONE_VM, 0, 0, NULL, &init_struct_pid, 0);
1538
1539 task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL,
1540 &init_struct_pid, 0);
1541 if (!IS_ERR(task)) { 1544 if (!IS_ERR(task)) {
1542 init_idle_pids(task->pids); 1545 init_idle_pids(task->pids);
1543 init_idle(task, cpu); 1546 init_idle(task, cpu);
@@ -1554,7 +1557,6 @@ struct task_struct * __cpuinit fork_idle(int cpu)
1554 */ 1557 */
1555long do_fork(unsigned long clone_flags, 1558long do_fork(unsigned long clone_flags,
1556 unsigned long stack_start, 1559 unsigned long stack_start,
1557 struct pt_regs *regs,
1558 unsigned long stack_size, 1560 unsigned long stack_size,
1559 int __user *parent_tidptr, 1561 int __user *parent_tidptr,
1560 int __user *child_tidptr) 1562 int __user *child_tidptr)
@@ -1567,15 +1569,9 @@ long do_fork(unsigned long clone_flags,
1567 * Do some preliminary argument and permissions checking before we 1569 * Do some preliminary argument and permissions checking before we
1568 * actually start allocating stuff 1570 * actually start allocating stuff
1569 */ 1571 */
1570 if (clone_flags & CLONE_NEWUSER) { 1572 if (clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) {
1571 if (clone_flags & CLONE_THREAD) 1573 if (clone_flags & (CLONE_THREAD|CLONE_PARENT))
1572 return -EINVAL; 1574 return -EINVAL;
1573 /* hopefully this check will go away when userns support is
1574 * complete
1575 */
1576 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
1577 !capable(CAP_SETGID))
1578 return -EPERM;
1579 } 1575 }
1580 1576
1581 /* 1577 /*
@@ -1584,7 +1580,7 @@ long do_fork(unsigned long clone_flags,
1584 * requested, no event is reported; otherwise, report if the event 1580 * requested, no event is reported; otherwise, report if the event
1585 * for the type of forking is enabled. 1581 * for the type of forking is enabled.
1586 */ 1582 */
1587 if (!(clone_flags & CLONE_UNTRACED) && likely(user_mode(regs))) { 1583 if (!(clone_flags & CLONE_UNTRACED)) {
1588 if (clone_flags & CLONE_VFORK) 1584 if (clone_flags & CLONE_VFORK)
1589 trace = PTRACE_EVENT_VFORK; 1585 trace = PTRACE_EVENT_VFORK;
1590 else if ((clone_flags & CSIGNAL) != SIGCHLD) 1586 else if ((clone_flags & CSIGNAL) != SIGCHLD)
@@ -1596,7 +1592,7 @@ long do_fork(unsigned long clone_flags,
1596 trace = 0; 1592 trace = 0;
1597 } 1593 }
1598 1594
1599 p = copy_process(clone_flags, stack_start, regs, stack_size, 1595 p = copy_process(clone_flags, stack_start, stack_size,
1600 child_tidptr, NULL, trace); 1596 child_tidptr, NULL, trace);
1601 /* 1597 /*
1602 * Do this prior waking up the new thread - the thread pointer 1598 * Do this prior waking up the new thread - the thread pointer
@@ -1634,15 +1630,58 @@ long do_fork(unsigned long clone_flags,
1634 return nr; 1630 return nr;
1635} 1631}
1636 1632
1637#ifdef CONFIG_GENERIC_KERNEL_THREAD
1638/* 1633/*
1639 * Create a kernel thread. 1634 * Create a kernel thread.
1640 */ 1635 */
1641pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) 1636pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
1642{ 1637{
1643 return do_fork(flags|CLONE_VM|CLONE_UNTRACED, (unsigned long)fn, NULL, 1638 return do_fork(flags|CLONE_VM|CLONE_UNTRACED, (unsigned long)fn,
1644 (unsigned long)arg, NULL, NULL); 1639 (unsigned long)arg, NULL, NULL);
1645} 1640}
1641
1642#ifdef __ARCH_WANT_SYS_FORK
1643SYSCALL_DEFINE0(fork)
1644{
1645#ifdef CONFIG_MMU
1646 return do_fork(SIGCHLD, 0, 0, NULL, NULL);
1647#else
1648 /* can not support in nommu mode */
1649 return(-EINVAL);
1650#endif
1651}
1652#endif
1653
1654#ifdef __ARCH_WANT_SYS_VFORK
1655SYSCALL_DEFINE0(vfork)
1656{
1657 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
1658 0, NULL, NULL);
1659}
1660#endif
1661
1662#ifdef __ARCH_WANT_SYS_CLONE
1663#ifdef CONFIG_CLONE_BACKWARDS
1664SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
1665 int __user *, parent_tidptr,
1666 int, tls_val,
1667 int __user *, child_tidptr)
1668#elif defined(CONFIG_CLONE_BACKWARDS2)
1669SYSCALL_DEFINE5(clone, unsigned long, newsp, unsigned long, clone_flags,
1670 int __user *, parent_tidptr,
1671 int __user *, child_tidptr,
1672 int, tls_val)
1673#else
1674SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
1675 int __user *, parent_tidptr,
1676 int __user *, child_tidptr,
1677 int, tls_val)
1678#endif
1679{
1680 long ret = do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr);
1681 asmlinkage_protect(5, ret, clone_flags, newsp,
1682 parent_tidptr, child_tidptr, tls_val);
1683 return ret;
1684}
1646#endif 1685#endif
1647 1686
1648#ifndef ARCH_MIN_MMSTRUCT_ALIGN 1687#ifndef ARCH_MIN_MMSTRUCT_ALIGN
@@ -1694,7 +1733,8 @@ static int check_unshare_flags(unsigned long unshare_flags)
1694{ 1733{
1695 if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND| 1734 if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND|
1696 CLONE_VM|CLONE_FILES|CLONE_SYSVSEM| 1735 CLONE_VM|CLONE_FILES|CLONE_SYSVSEM|
1697 CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET)) 1736 CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET|
1737 CLONE_NEWUSER|CLONE_NEWPID))
1698 return -EINVAL; 1738 return -EINVAL;
1699 /* 1739 /*
1700 * Not implemented, but pretend it works if there is nothing to 1740 * Not implemented, but pretend it works if there is nothing to
@@ -1761,19 +1801,40 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
1761{ 1801{
1762 struct fs_struct *fs, *new_fs = NULL; 1802 struct fs_struct *fs, *new_fs = NULL;
1763 struct files_struct *fd, *new_fd = NULL; 1803 struct files_struct *fd, *new_fd = NULL;
1804 struct cred *new_cred = NULL;
1764 struct nsproxy *new_nsproxy = NULL; 1805 struct nsproxy *new_nsproxy = NULL;
1765 int do_sysvsem = 0; 1806 int do_sysvsem = 0;
1766 int err; 1807 int err;
1767 1808
1768 err = check_unshare_flags(unshare_flags); 1809 /*
1769 if (err) 1810 * If unsharing a user namespace must also unshare the thread.
1770 goto bad_unshare_out; 1811 */
1771 1812 if (unshare_flags & CLONE_NEWUSER)
1813 unshare_flags |= CLONE_THREAD | CLONE_FS;
1814 /*
1815 * If unsharing a pid namespace must also unshare the thread.
1816 */
1817 if (unshare_flags & CLONE_NEWPID)
1818 unshare_flags |= CLONE_THREAD;
1819 /*
1820 * If unsharing a thread from a thread group, must also unshare vm.
1821 */
1822 if (unshare_flags & CLONE_THREAD)
1823 unshare_flags |= CLONE_VM;
1824 /*
1825 * If unsharing vm, must also unshare signal handlers.
1826 */
1827 if (unshare_flags & CLONE_VM)
1828 unshare_flags |= CLONE_SIGHAND;
1772 /* 1829 /*
1773 * If unsharing namespace, must also unshare filesystem information. 1830 * If unsharing namespace, must also unshare filesystem information.
1774 */ 1831 */
1775 if (unshare_flags & CLONE_NEWNS) 1832 if (unshare_flags & CLONE_NEWNS)
1776 unshare_flags |= CLONE_FS; 1833 unshare_flags |= CLONE_FS;
1834
1835 err = check_unshare_flags(unshare_flags);
1836 if (err)
1837 goto bad_unshare_out;
1777 /* 1838 /*
1778 * CLONE_NEWIPC must also detach from the undolist: after switching 1839 * CLONE_NEWIPC must also detach from the undolist: after switching
1779 * to a new ipc namespace, the semaphore arrays from the old 1840 * to a new ipc namespace, the semaphore arrays from the old
@@ -1787,11 +1848,15 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
1787 err = unshare_fd(unshare_flags, &new_fd); 1848 err = unshare_fd(unshare_flags, &new_fd);
1788 if (err) 1849 if (err)
1789 goto bad_unshare_cleanup_fs; 1850 goto bad_unshare_cleanup_fs;
1790 err = unshare_nsproxy_namespaces(unshare_flags, &new_nsproxy, new_fs); 1851 err = unshare_userns(unshare_flags, &new_cred);
1791 if (err) 1852 if (err)
1792 goto bad_unshare_cleanup_fd; 1853 goto bad_unshare_cleanup_fd;
1854 err = unshare_nsproxy_namespaces(unshare_flags, &new_nsproxy,
1855 new_cred, new_fs);
1856 if (err)
1857 goto bad_unshare_cleanup_cred;
1793 1858
1794 if (new_fs || new_fd || do_sysvsem || new_nsproxy) { 1859 if (new_fs || new_fd || do_sysvsem || new_cred || new_nsproxy) {
1795 if (do_sysvsem) { 1860 if (do_sysvsem) {
1796 /* 1861 /*
1797 * CLONE_SYSVSEM is equivalent to sys_exit(). 1862 * CLONE_SYSVSEM is equivalent to sys_exit().
@@ -1799,10 +1864,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
1799 exit_sem(current); 1864 exit_sem(current);
1800 } 1865 }
1801 1866
1802 if (new_nsproxy) { 1867 if (new_nsproxy)
1803 switch_task_namespaces(current, new_nsproxy); 1868 switch_task_namespaces(current, new_nsproxy);
1804 new_nsproxy = NULL;
1805 }
1806 1869
1807 task_lock(current); 1870 task_lock(current);
1808 1871
@@ -1824,11 +1887,17 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
1824 } 1887 }
1825 1888
1826 task_unlock(current); 1889 task_unlock(current);
1827 }
1828 1890
1829 if (new_nsproxy) 1891 if (new_cred) {
1830 put_nsproxy(new_nsproxy); 1892 /* Install the new user namespace */
1893 commit_creds(new_cred);
1894 new_cred = NULL;
1895 }
1896 }
1831 1897
1898bad_unshare_cleanup_cred:
1899 if (new_cred)
1900 put_cred(new_cred);
1832bad_unshare_cleanup_fd: 1901bad_unshare_cleanup_fd:
1833 if (new_fd) 1902 if (new_fd)
1834 put_files_struct(new_fd); 1903 put_files_struct(new_fd);