summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/exit.c3
-rw-r--r--kernel/fork.c5
-rw-r--r--kernel/pid.c19
-rw-r--r--kernel/pid_namespace.c9
-rw-r--r--kernel/signal.c5
5 files changed, 20 insertions, 21 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index ede3117fa7d4..31b714c3a791 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -608,7 +608,8 @@ static struct task_struct *find_child_reaper(struct task_struct *father,
reaper = find_alive_thread(father);
if (reaper) {
- pid_ns->child_reaper = reaper;
+ ASSERT_EXCLUSIVE_WRITER(pid_ns->child_reaper);
+ WRITE_ONCE(pid_ns->child_reaper, reaper);
return reaper;
}
diff --git a/kernel/fork.c b/kernel/fork.c
index 9c194fc58736..8c61c8dd4372 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2469,7 +2469,10 @@ __latent_entropy struct task_struct *copy_process(
init_task_pid(p, PIDTYPE_SID, task_session(current));
if (is_child_reaper(pid)) {
- ns_of_pid(pid)->child_reaper = p;
+ struct pid_namespace *ns = ns_of_pid(pid);
+
+ ASSERT_EXCLUSIVE_WRITER(ns->child_reaper);
+ WRITE_ONCE(ns->child_reaper, p);
p->signal->flags |= SIGNAL_UNKILLABLE;
}
p->signal->shared_pending.signal = delayed.signal;
diff --git a/kernel/pid.c b/kernel/pid.c
index 3b96571d0fe6..677c84e319dd 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -128,7 +128,7 @@ void free_pid(struct pid *pid)
* is the reaper wake up the reaper. The reaper
* may be sleeping in zap_pid_ns_processes().
*/
- wake_up_process(ns->child_reaper);
+ wake_up_process(READ_ONCE(ns->child_reaper));
break;
case PIDNS_ADDING:
/* Handle a fork failure of the first process */
@@ -215,12 +215,6 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *arg_set_tid,
retval = -EINVAL;
if (tid < 1 || tid >= pid_max[ns->level - i])
goto out_abort;
- /*
- * Also fail if a PID != 1 is requested and
- * no PID 1 exists.
- */
- if (tid != 1 && !tmp->child_reaper)
- goto out_abort;
retval = -EPERM;
if (!checkpoint_restore_ns_capable(tmp->user_ns))
goto out_abort;
@@ -296,9 +290,18 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *arg_set_tid,
pid->numbers[i].nr = nr;
pid->numbers[i].ns = tmp;
- tmp = tmp->parent;
i--;
retried_preload = false;
+
+ /*
+ * PID 1 (init) must be created first.
+ */
+ if (!READ_ONCE(tmp->child_reaper) && nr != 1) {
+ retval = -EINVAL;
+ goto out_free;
+ }
+
+ tmp = tmp->parent;
}
/*
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index e48f5de41361..d36afc58ee1d 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -369,15 +369,6 @@ static struct ns_common *pidns_for_children_get(struct task_struct *task)
}
task_unlock(task);
- if (ns) {
- read_lock(&tasklist_lock);
- if (!ns->child_reaper) {
- put_pid_ns(ns);
- ns = NULL;
- }
- read_unlock(&tasklist_lock);
- }
-
return ns ? &ns->ns : NULL;
}
diff --git a/kernel/signal.c b/kernel/signal.c
index e61f39fa8c8a..21d881b95ffb 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2818,8 +2818,9 @@ bool get_signal(struct ksignal *ksig)
/*
* Do this once, we can't return to user-mode if freezing() == T.
- * do_signal_stop() and ptrace_stop() do freezable_schedule() and
- * thus do not need another check after return.
+ * do_signal_stop() and ptrace_stop() set TASK_STOPPED/TASK_TRACED
+ * and the freezer handles those states via TASK_FROZEN, thus they
+ * do not need another check after return.
*/
try_to_freeze();