aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 9b85f6b2cdcd..0c240fd5beba 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -855,6 +855,29 @@ struct file *get_mm_exe_file(struct mm_struct *mm)
855EXPORT_SYMBOL(get_mm_exe_file); 855EXPORT_SYMBOL(get_mm_exe_file);
856 856
857/** 857/**
858 * get_task_exe_file - acquire a reference to the task's executable file
859 *
860 * Returns %NULL if task's mm (if any) has no associated executable file or
861 * this is a kernel thread with borrowed mm (see the comment above get_task_mm).
862 * User must release file via fput().
863 */
864struct file *get_task_exe_file(struct task_struct *task)
865{
866 struct file *exe_file = NULL;
867 struct mm_struct *mm;
868
869 task_lock(task);
870 mm = task->mm;
871 if (mm) {
872 if (!(task->flags & PF_KTHREAD))
873 exe_file = get_mm_exe_file(mm);
874 }
875 task_unlock(task);
876 return exe_file;
877}
878EXPORT_SYMBOL(get_task_exe_file);
879
880/**
858 * get_task_mm - acquire a reference to the task's mm 881 * get_task_mm - acquire a reference to the task's mm
859 * 882 *
860 * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning 883 * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning
@@ -969,14 +992,12 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
969 deactivate_mm(tsk, mm); 992 deactivate_mm(tsk, mm);
970 993
971 /* 994 /*
972 * If we're exiting normally, clear a user-space tid field if 995 * Signal userspace if we're not exiting with a core dump
973 * requested. We leave this alone when dying by signal, to leave 996 * because we want to leave the value intact for debugging
974 * the value intact in a core dump, and to save the unnecessary 997 * purposes.
975 * trouble, say, a killed vfork parent shouldn't touch this mm.
976 * Userland only wants this done for a sys_exit.
977 */ 998 */
978 if (tsk->clear_child_tid) { 999 if (tsk->clear_child_tid) {
979 if (!(tsk->flags & PF_SIGNALED) && 1000 if (!(tsk->signal->flags & SIGNAL_GROUP_COREDUMP) &&
980 atomic_read(&mm->mm_users) > 1) { 1001 atomic_read(&mm->mm_users) > 1) {
981 /* 1002 /*
982 * We don't check the error code - if userspace has 1003 * We don't check the error code - if userspace has
@@ -1460,7 +1481,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1460 p->real_start_time = ktime_get_boot_ns(); 1481 p->real_start_time = ktime_get_boot_ns();
1461 p->io_context = NULL; 1482 p->io_context = NULL;
1462 p->audit_context = NULL; 1483 p->audit_context = NULL;
1463 threadgroup_change_begin(current);
1464 cgroup_fork(p); 1484 cgroup_fork(p);
1465#ifdef CONFIG_NUMA 1485#ifdef CONFIG_NUMA
1466 p->mempolicy = mpol_dup(p->mempolicy); 1486 p->mempolicy = mpol_dup(p->mempolicy);
@@ -1612,6 +1632,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1612 INIT_LIST_HEAD(&p->thread_group); 1632 INIT_LIST_HEAD(&p->thread_group);
1613 p->task_works = NULL; 1633 p->task_works = NULL;
1614 1634
1635 threadgroup_change_begin(current);
1615 /* 1636 /*
1616 * Ensure that the cgroup subsystem policies allow the new process to be 1637 * Ensure that the cgroup subsystem policies allow the new process to be
1617 * forked. It should be noted the the new process's css_set can be changed 1638 * forked. It should be noted the the new process's css_set can be changed
@@ -1712,6 +1733,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1712bad_fork_cancel_cgroup: 1733bad_fork_cancel_cgroup:
1713 cgroup_cancel_fork(p); 1734 cgroup_cancel_fork(p);
1714bad_fork_free_pid: 1735bad_fork_free_pid:
1736 threadgroup_change_end(current);
1715 if (pid != &init_struct_pid) 1737 if (pid != &init_struct_pid)
1716 free_pid(pid); 1738 free_pid(pid);
1717bad_fork_cleanup_thread: 1739bad_fork_cleanup_thread:
@@ -1744,7 +1766,6 @@ bad_fork_cleanup_policy:
1744 mpol_put(p->mempolicy); 1766 mpol_put(p->mempolicy);
1745bad_fork_cleanup_threadgroup_lock: 1767bad_fork_cleanup_threadgroup_lock:
1746#endif 1768#endif
1747 threadgroup_change_end(current);
1748 delayacct_tsk_free(p); 1769 delayacct_tsk_free(p);
1749bad_fork_cleanup_count: 1770bad_fork_cleanup_count:
1750 atomic_dec(&p->cred->user->processes); 1771 atomic_dec(&p->cred->user->processes);