diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 52e725d4a866..beb31725f7e2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -799,6 +799,29 @@ struct file *get_mm_exe_file(struct mm_struct *mm) | |||
799 | EXPORT_SYMBOL(get_mm_exe_file); | 799 | EXPORT_SYMBOL(get_mm_exe_file); |
800 | 800 | ||
801 | /** | 801 | /** |
802 | * get_task_exe_file - acquire a reference to the task's executable file | ||
803 | * | ||
804 | * Returns %NULL if task's mm (if any) has no associated executable file or | ||
805 | * this is a kernel thread with borrowed mm (see the comment above get_task_mm). | ||
806 | * User must release file via fput(). | ||
807 | */ | ||
808 | struct file *get_task_exe_file(struct task_struct *task) | ||
809 | { | ||
810 | struct file *exe_file = NULL; | ||
811 | struct mm_struct *mm; | ||
812 | |||
813 | task_lock(task); | ||
814 | mm = task->mm; | ||
815 | if (mm) { | ||
816 | if (!(task->flags & PF_KTHREAD)) | ||
817 | exe_file = get_mm_exe_file(mm); | ||
818 | } | ||
819 | task_unlock(task); | ||
820 | return exe_file; | ||
821 | } | ||
822 | EXPORT_SYMBOL(get_task_exe_file); | ||
823 | |||
824 | /** | ||
802 | * get_task_mm - acquire a reference to the task's mm | 825 | * get_task_mm - acquire a reference to the task's mm |
803 | * | 826 | * |
804 | * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning | 827 | * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning |
@@ -913,14 +936,12 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) | |||
913 | deactivate_mm(tsk, mm); | 936 | deactivate_mm(tsk, mm); |
914 | 937 | ||
915 | /* | 938 | /* |
916 | * If we're exiting normally, clear a user-space tid field if | 939 | * Signal userspace if we're not exiting with a core dump |
917 | * requested. We leave this alone when dying by signal, to leave | 940 | * because we want to leave the value intact for debugging |
918 | * the value intact in a core dump, and to save the unnecessary | 941 | * purposes. |
919 | * trouble, say, a killed vfork parent shouldn't touch this mm. | ||
920 | * Userland only wants this done for a sys_exit. | ||
921 | */ | 942 | */ |
922 | if (tsk->clear_child_tid) { | 943 | if (tsk->clear_child_tid) { |
923 | if (!(tsk->flags & PF_SIGNALED) && | 944 | if (!(tsk->signal->flags & SIGNAL_GROUP_COREDUMP) && |
924 | atomic_read(&mm->mm_users) > 1) { | 945 | atomic_read(&mm->mm_users) > 1) { |
925 | /* | 946 | /* |
926 | * We don't check the error code - if userspace has | 947 | * We don't check the error code - if userspace has |
@@ -1404,7 +1425,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1404 | p->real_start_time = ktime_get_boot_ns(); | 1425 | p->real_start_time = ktime_get_boot_ns(); |
1405 | p->io_context = NULL; | 1426 | p->io_context = NULL; |
1406 | p->audit_context = NULL; | 1427 | p->audit_context = NULL; |
1407 | threadgroup_change_begin(current); | ||
1408 | cgroup_fork(p); | 1428 | cgroup_fork(p); |
1409 | #ifdef CONFIG_NUMA | 1429 | #ifdef CONFIG_NUMA |
1410 | p->mempolicy = mpol_dup(p->mempolicy); | 1430 | p->mempolicy = mpol_dup(p->mempolicy); |
@@ -1556,6 +1576,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1556 | INIT_LIST_HEAD(&p->thread_group); | 1576 | INIT_LIST_HEAD(&p->thread_group); |
1557 | p->task_works = NULL; | 1577 | p->task_works = NULL; |
1558 | 1578 | ||
1579 | threadgroup_change_begin(current); | ||
1559 | /* | 1580 | /* |
1560 | * Ensure that the cgroup subsystem policies allow the new process to be | 1581 | * Ensure that the cgroup subsystem policies allow the new process to be |
1561 | * forked. It should be noted the the new process's css_set can be changed | 1582 | * forked. It should be noted the the new process's css_set can be changed |
@@ -1656,6 +1677,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1656 | bad_fork_cancel_cgroup: | 1677 | bad_fork_cancel_cgroup: |
1657 | cgroup_cancel_fork(p); | 1678 | cgroup_cancel_fork(p); |
1658 | bad_fork_free_pid: | 1679 | bad_fork_free_pid: |
1680 | threadgroup_change_end(current); | ||
1659 | if (pid != &init_struct_pid) | 1681 | if (pid != &init_struct_pid) |
1660 | free_pid(pid); | 1682 | free_pid(pid); |
1661 | bad_fork_cleanup_thread: | 1683 | bad_fork_cleanup_thread: |
@@ -1688,7 +1710,6 @@ bad_fork_cleanup_policy: | |||
1688 | mpol_put(p->mempolicy); | 1710 | mpol_put(p->mempolicy); |
1689 | bad_fork_cleanup_threadgroup_lock: | 1711 | bad_fork_cleanup_threadgroup_lock: |
1690 | #endif | 1712 | #endif |
1691 | threadgroup_change_end(current); | ||
1692 | delayacct_tsk_free(p); | 1713 | delayacct_tsk_free(p); |
1693 | bad_fork_cleanup_count: | 1714 | bad_fork_cleanup_count: |
1694 | atomic_dec(&p->cred->user->processes); | 1715 | atomic_dec(&p->cred->user->processes); |