Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pid_namespace: avoid optimization of accesses to ->child_reaper

To avoid potential problems related to cpu/compiler optimizations around
->child_reaper, let's use WRITE_ONCE (additional to task_list lock)
everywhere we write it and use READ_ONCE where we read it without
explicit lock. Note: It also pairs with existing READ_ONCE with no lock
in nsfs_fh_to_dentry().

Also let's add ASSERT_EXCLUSIVE_WRITER before write to identify to KCSAN
that we don't expect any concurrent ->child_reaper modifications, and
those must be detected.

--

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Link: https://patch.msgid.link/20260318122157.280595-2-ptikhomirov@virtuozzo.com
v3: Split from main commit. Add ASSERT_EXCLUSIVE_WRITER.
v5: Add one more READ_ONCE for access without lock in free_pid().
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Pavel Tikhomirov and committed by
Christian Brauner
d9c857ae 1f318b96

+8 -4
+2 -1
kernel/exit.c
··· 608 608 609 609 reaper = find_alive_thread(father); 610 610 if (reaper) { 611 - pid_ns->child_reaper = reaper; 611 + ASSERT_EXCLUSIVE_WRITER(pid_ns->child_reaper); 612 + WRITE_ONCE(pid_ns->child_reaper, reaper); 612 613 return reaper; 613 614 } 614 615
+4 -1
kernel/fork.c
··· 2423 2423 init_task_pid(p, PIDTYPE_SID, task_session(current)); 2424 2424 2425 2425 if (is_child_reaper(pid)) { 2426 - ns_of_pid(pid)->child_reaper = p; 2426 + struct pid_namespace *ns = ns_of_pid(pid); 2427 + 2428 + ASSERT_EXCLUSIVE_WRITER(ns->child_reaper); 2429 + WRITE_ONCE(ns->child_reaper, p); 2427 2430 p->signal->flags |= SIGNAL_UNKILLABLE; 2428 2431 } 2429 2432 p->signal->shared_pending.signal = delayed.signal;
+2 -2
kernel/pid.c
··· 128 128 * is the reaper wake up the reaper. The reaper 129 129 * may be sleeping in zap_pid_ns_processes(). 130 130 */ 131 - wake_up_process(ns->child_reaper); 131 + wake_up_process(READ_ONCE(ns->child_reaper)); 132 132 break; 133 133 case PIDNS_ADDING: 134 134 /* Handle a fork failure of the first process */ ··· 219 219 * Also fail if a PID != 1 is requested and 220 220 * no PID 1 exists. 221 221 */ 222 - if (tid != 1 && !tmp->child_reaper) 222 + if (tid != 1 && !READ_ONCE(tmp->child_reaper)) 223 223 goto out_abort; 224 224 retval = -EPERM; 225 225 if (!checkpoint_restore_ns_capable(tmp->user_ns))