fork.c (38713c6028a3172c4c256512c3fbcfc799fe2d43) fork.c (bd74fdaea146029e4fa12c6de89adbe0779348a9)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/kernel/fork.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 1138 unchanged lines hidden (view full) ---

1147
1148 if (mm_alloc_pgd(mm))
1149 goto fail_nopgd;
1150
1151 if (init_new_context(p, mm))
1152 goto fail_nocontext;
1153
1154 mm->user_ns = get_user_ns(user_ns);
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/kernel/fork.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 1138 unchanged lines hidden (view full) ---

1147
1148 if (mm_alloc_pgd(mm))
1149 goto fail_nopgd;
1150
1151 if (init_new_context(p, mm))
1152 goto fail_nocontext;
1153
1154 mm->user_ns = get_user_ns(user_ns);
1155 lru_gen_init_mm(mm);
1155 return mm;
1156
1157fail_nocontext:
1158 mm_free_pgd(mm);
1159fail_nopgd:
1160 free_mm(mm);
1161 return NULL;
1162}

--- 26 unchanged lines hidden (view full) ---

1189 set_mm_exe_file(mm, NULL);
1190 if (!list_empty(&mm->mmlist)) {
1191 spin_lock(&mmlist_lock);
1192 list_del(&mm->mmlist);
1193 spin_unlock(&mmlist_lock);
1194 }
1195 if (mm->binfmt)
1196 module_put(mm->binfmt->module);
1156 return mm;
1157
1158fail_nocontext:
1159 mm_free_pgd(mm);
1160fail_nopgd:
1161 free_mm(mm);
1162 return NULL;
1163}

--- 26 unchanged lines hidden (view full) ---

1190 set_mm_exe_file(mm, NULL);
1191 if (!list_empty(&mm->mmlist)) {
1192 spin_lock(&mmlist_lock);
1193 list_del(&mm->mmlist);
1194 spin_unlock(&mmlist_lock);
1195 }
1196 if (mm->binfmt)
1197 module_put(mm->binfmt->module);
1198 lru_gen_del_mm(mm);
1197 mmdrop(mm);
1198}
1199
1200/*
1201 * Decrement the use count and release all resources for an mm.
1202 */
1203void mmput(struct mm_struct *mm)
1204{

--- 15 unchanged lines hidden (view full) ---

1220
1221void mmput_async(struct mm_struct *mm)
1222{
1223 if (atomic_dec_and_test(&mm->mm_users)) {
1224 INIT_WORK(&mm->async_put_work, mmput_async_fn);
1225 schedule_work(&mm->async_put_work);
1226 }
1227}
1199 mmdrop(mm);
1200}
1201
1202/*
1203 * Decrement the use count and release all resources for an mm.
1204 */
1205void mmput(struct mm_struct *mm)
1206{

--- 15 unchanged lines hidden (view full) ---

1222
1223void mmput_async(struct mm_struct *mm)
1224{
1225 if (atomic_dec_and_test(&mm->mm_users)) {
1226 INIT_WORK(&mm->async_put_work, mmput_async_fn);
1227 schedule_work(&mm->async_put_work);
1228 }
1229}
1228EXPORT_SYMBOL_GPL(mmput_async);
1229#endif
1230
1231/**
1232 * set_mm_exe_file - change a reference to the mm's executable file
1233 *
1234 * This changes mm's executable file (shown as symlink /proc/[pid]/exe).
1235 *
1236 * Main users are mmput() and sys_execve(). Callers prevent concurrent

--- 805 unchanged lines hidden (view full) ---

2042 if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
2043 (task_active_pid_ns(current) != nsp->pid_ns_for_children))
2044 return ERR_PTR(-EINVAL);
2045 }
2046
2047 /*
2048 * If the new process will be in a different time namespace
2049 * do not allow it to share VM or a thread group with the forking task.
1230#endif
1231
1232/**
1233 * set_mm_exe_file - change a reference to the mm's executable file
1234 *
1235 * This changes mm's executable file (shown as symlink /proc/[pid]/exe).
1236 *
1237 * Main users are mmput() and sys_execve(). Callers prevent concurrent

--- 805 unchanged lines hidden (view full) ---

2043 if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
2044 (task_active_pid_ns(current) != nsp->pid_ns_for_children))
2045 return ERR_PTR(-EINVAL);
2046 }
2047
2048 /*
2049 * If the new process will be in a different time namespace
2050 * do not allow it to share VM or a thread group with the forking task.
2051 *
2052 * On vfork, the child process enters the target time namespace only
2053 * after exec.
2050 */
2054 */
2051 if (clone_flags & (CLONE_THREAD | CLONE_VM)) {
2055 if ((clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM) {
2052 if (nsp->time_ns != nsp->time_ns_for_children)
2053 return ERR_PTR(-EINVAL);
2054 }
2055
2056 if (clone_flags & CLONE_PIDFD) {
2057 /*
2058 * - CLONE_DETACHED is blocked so that we can potentially
2059 * reuse it later for CLONE_PIDFD.

--- 627 unchanged lines hidden (view full) ---

2687 put_user(nr, args->parent_tid);
2688
2689 if (clone_flags & CLONE_VFORK) {
2690 p->vfork_done = &vfork;
2691 init_completion(&vfork);
2692 get_task_struct(p);
2693 }
2694
2056 if (nsp->time_ns != nsp->time_ns_for_children)
2057 return ERR_PTR(-EINVAL);
2058 }
2059
2060 if (clone_flags & CLONE_PIDFD) {
2061 /*
2062 * - CLONE_DETACHED is blocked so that we can potentially
2063 * reuse it later for CLONE_PIDFD.

--- 627 unchanged lines hidden (view full) ---

2691 put_user(nr, args->parent_tid);
2692
2693 if (clone_flags & CLONE_VFORK) {
2694 p->vfork_done = &vfork;
2695 init_completion(&vfork);
2696 get_task_struct(p);
2697 }
2698
2699 if (IS_ENABLED(CONFIG_LRU_GEN) && !(clone_flags & CLONE_VM)) {
2700 /* lock the task to synchronize with memcg migration */
2701 task_lock(p);
2702 lru_gen_add_mm(p->mm);
2703 task_unlock(p);
2704 }
2705
2695 wake_up_new_task(p);
2696
2697 /* forking complete and child started to run, tell ptracer */
2698 if (unlikely(trace))
2699 ptrace_event_pid(trace, pid);
2700
2701 if (clone_flags & CLONE_VFORK) {
2702 if (!wait_for_vfork_done(p, &vfork))

--- 598 unchanged lines hidden ---
2706 wake_up_new_task(p);
2707
2708 /* forking complete and child started to run, tell ptracer */
2709 if (unlikely(trace))
2710 ptrace_event_pid(trace, pid);
2711
2712 if (clone_flags & CLONE_VFORK) {
2713 if (!wait_for_vfork_done(p, &vfork))

--- 598 unchanged lines hidden ---