Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796443935; b=Qwt+rMHMeN/4xvTASjYckObJNylqHhQRPdfxN1FSwBmCYlTyqgyV5Is2DL7jMB3zoog5 VdUtEdxZMXfSp149wVoa5vsK06PDu1vqQQDeLM/eeDCRYYN4Aw7Ef/mnEAUUIzzEZrYrF 44QgpOGHDF4GH96HTBwr2rGh1omLKoLu72PAMdUljzOCc0wwL0pBRsuzfecDKXwVFJHuH QYivP0YnlNAD0JYoYldQeS1ljQrb2ZsRTGVEGFYXFzD6JAgELJlASsE9U6WfELuAaw7sC TJv/g/nRLz2gP4SWHA77Z7w7NQIadWRxdzDTBqqPHlX1KnveIVOamyKTBqCdjKdqWkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443935; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=LDJhz4x+cmsoO8gtBpbc7gI8S2C/R5ObsckX73Vfu5o=; b=3C0+xFr0l780IlTiAb6cOjo/DdMH/5RU7DdRqnpRScExgKS/QMqCP3eX9/nSYacwcoxD d4msM77sO6FPtyWf96+Hub5t9oV4hQpm3HRTLjOT2X9BPZYpN1BXPEKV6lcqHcdq3OJ6E 1LLWJ1mu9+2Su7ehXgBgzTLdN0h1KC7VEv3SyuNTC7gVda2oLQIMacLYkll9g+lvOjOmu +5wO1wIWeVthoAAtEEu6BSEInSh00tqsIehdlisbHK0cW9njaUMahOUvQu2dxRiqWKdPG hqxdTNSybsNLCoxqhinhThii9d9ERjO1DZReOvR0aBBZirPyF13iLrPx7Af1FT31fjA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Hv2RBkCs; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C6AD606A322; Sat, 5 Dec 2026 04:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Hv2RBkCs Received: by smtp.kernel.org (Postfix) with ESMTPSA id A76D01F0092B; Sat, 5 Dec 2026 04:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796443935; bh=LDJhz4x+cmsoO8gtBpbc7gI8S2C/R5ObsckX73Vfu5o=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Hv2RBkCsZVRmTye6dVi0S5yZ4yoX7zqrs0hLvxZRO/1l1VBQAQN50U+gI9DQhIRqU S+lWLbdpMzLIu9b7SiJZF4A3cIC9FivL6LiSVg2/exilvM9MC7bF90jO08YkPAOUax TPU+tKuJ/fgngB9o2szkQI5qT5lQG6WC+QpKirZpnYmgCaG8BdPUvSYBbUyMH1dkWp zox0MqQN3bqdqgSfID6fDYyd6rEC9FnAZOQSPqZrbRbFQ6yfnpH23erkhrSS5YzbG4 g9yeU4BkDZCiI4Fqm0MhQ5J+MvULAJVqHD01Oyj4kDSqZxEcRKwvJvBdHpYju8J9vl RAWHqGzd4i8rw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Reply-To: sashiko-reviews@lists.linux.dev To: "Jarkko Sakkinen" Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, "Aleksa Sarai" , "Alexander Mikhalitsyn" , "Alexander Viro" , "Alexei Starovoitov" , "Andrew Morton" , "Andrii Nakryiko" , "Andy Lutomirski" , "Arnd Bergmann" , "Baolin Wang" , "Ben Segall" , "Christian Brauner" , "Daniel Borkmann" , "David Hildenbrand" , "David Howells" , "David Woodhouse" , "Davidlohr Bueso" , "Dietmar Eggemann" , "Eduard Zingerman" , "Emil Tsalapatis" , "Eric Biggers" , "Georgia Garcia" , "Giuseppe Scrivano" , =?utf-8?b?R8O8bnRoZXIgTm9hY2s=?= , "Hugh Dickins" , "Ihor Solodrai" , "Ingo Molnar" , "James Morris" , "Jan Kara" , "Jason Gunthorpe" , "Jeff Layton" , "Jiri Olsa" , "John Johansen" , "Jonathan Corbet" , "Josef Bacik" , "Juri Lelli" , "Kees Cook" , "K Prateek Nayak" , "KP Singh" , "Kumar Kartikeya Dwivedi" , "Lennart Poettering" , "Liam R. Howlett" , "Manfred Spraul" , "Martin KaFai Lau" , "Matt Bobrowski" , "Mel Gorman" , "Michal Hocko" , =?utf-8?b?TWlja2HDq2wgU2FsYcO8bg==?= , "Mike Rapoport" , "Neal Gompa" , "Oleg Nesterov" , "Paul Moore" , "Pavel Tikhomirov" , "Peter Zijlstra" , "Randy Dunlap" , "Serge E. Hallyn" , "Serge Hallyn" , "Shuah Khan" , "Song Liu" , "Stephen Smalley" , "Steven Rostedt" , "Valentin Schneider" , "Vincent Guittot" , "Yonghong Song" , "Zygmunt Krynicki" In-Reply-To: <20261205032633.1702772-19-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-19-jarkko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:12:11 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] fork: global init_fs.seq contention and duplicate root lookup in copy_fs() - [Medium] fork: pid_ns_is_adding() walks to init_pid_ns under global tasklist_lock - [Medium] cred: copy_creds() unconditionally sets child dumpable to suid_dumpable - [Medium] runfd: race between bootstrap wakeup and timens_commit() vvar_page init - [Low] runfd: runfd_prepare_fork() mixes goto unwinding with cleanup helpers - [Low] runfd: race in runfd_finish_fork() can turn -EINVAL into -EBUSY -- commit 21f693b42d4b01b11ee306dc7d32e60800ffb0d2 Author: Jarkko Sakkinen fork: Support CLONE_INTO_RUN in clone3() This commit adds CLONE_INTO_RUN and struct clone_args.runfd to clone3() so processes can spawn children directly into a run's namespaces and root mount, bootstrapping PID 1 on the first call. > diff --git a/kernel/cred.c b/kernel/cred.c > index d01df40a9a386..a5a17cab9a96e 100644 > --- a/kernel/cred.c > +++ b/kernel/cred.c [ ... ] > @@ -287,6 +291,20 @@ int copy_creds(struct task_struct *p, u64 clone_flag= s) > if (!new) > return -ENOMEM; > =20 > + if (run) { > + struct task_exec_state *exec_state; > + > + if (new->user_ns !=3D run->user_ns) { > + ret =3D install_user_ns_cred(new, run->user_ns); > + if (ret < 0) > + goto error_put; > + } > + exec_state =3D rcu_dereference_protected(p->exec_state, true); > + if (exec_state->user_ns !=3D run->user_ns) > + WRITE_ONCE(exec_state->dumpable, > + READ_ONCE(suid_dumpable)); > + } > + [Severity: Medium] Should this unconditionally overwrite exec_state->dumpable with suid_dumpable when the parent already disabled dumping? On systems with fs.suid_dumpable=3D2, a parent that explicitly set PR_SET_DUMPABLE=3D0 (TASK_DUMPABLE_OFF) will have its child's dumpable raised to TASK_DUMPABLE_ROOT, re-enabling root core dumps of the copied address space if the child crashes before execve(). Also, when fs.suid_dumpable=3D1 (TASK_DUMPABLE_OWNER), task_still_dumpable() returns true without checking CAP_SYS_PTRACE against exec_state->user_ns, which lets processes inside run->user_ns ptrace the child before execve() contrary to the DOC: CLONE_INTO_RUN comment in kernel/runfd.c. Only demoting when exec_state->dumpable =3D=3D TASK_DUMPABLE_OWNER (or setting TASK_DUMPABLE_OFF if pre-exec isolation is required under fs.suid_dumpable=3D1) would avoid raising an explicit TASK_DUMPABLE_OFF setting. > diff --git a/kernel/fork.c b/kernel/fork.c > index 46032e74e6299..8298a3bdff73e 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c [ ... ] > @@ -1633,7 +1634,7 @@ static int copy_fs(u64 clone_flags, struct task_str= uct *tsk, > if (current->nsproxy->mnt_ns !=3D &init_mnt_ns) > return -EINVAL; > fs =3D userspace_init_fs; > - } else if (flags & COPY_FS_IDLE) { > + } else if (flags & COPY_FS_IDLE || run) { > fs =3D &init_fs; > } else { > fs =3D current->fs; > @@ -1655,6 +1656,21 @@ static int copy_fs(u64 clone_flags, struct task_st= ruct *tsk, > tsk->real_fs =3D tsk->fs =3D copy_fs_struct(fs); > if (!tsk->fs) > return -ENOMEM; > + if (run) { > + struct path root __free(path_put) =3D {}; > + int err; > + > + err =3D mnt_ns_get_root(run->ns->mnt_ns, &root); > + if (err) { > + free_fs_struct(tsk->fs); > + tsk->real_fs =3D NULL; > + tsk->fs =3D NULL; > + return err; > + } > + tsk->fs->umask =3D READ_ONCE(current->fs->umask); > + set_fs_root(tsk->fs, &root); > + set_fs_pwd(tsk->fs, &root); > + } > return 0; > } [Severity: Medium] Can copying init_fs here create global lock contention when spawning children into independent runs concurrently? copy_fs_struct(&init_fs) acquires the global init_fs.seq spinlock and takes two references on init_fs.root and init_fs.pwd, which set_fs_root() and set_fs_pwd() immediately drop right after overwriting umask. On top of that, mnt_ns_get_root() repeats the vfs_path_lookup() that runfd_prepare_fork() just performed and discarded. Allocating and initializing a fresh fs_struct directly with the target root and caller umask would avoid both the global init_fs.seq contention and the duplicate root lookup. [ ... ] > @@ -2003,6 +2019,17 @@ static bool need_futex_hash_allocate_default(u64 c= lone_flags) > return clone_flags & CLONE_VM; > } > =20 > +static bool pid_ns_is_adding(const struct pid *pid) > +{ > + int i; > + > + for (i =3D pid->level; i >=3D 0; i--) { > + if (unlikely(!(pid->numbers[i].ns->pid_allocated & PIDNS_ADDING))) > + return false; > + } > + return true; > +} > + [ ... ] > @@ -2492,11 +2519,16 @@ __latent_entropy struct task_struct *copy_process( > * child missed SIGKILL. If current is not in the same namespace, > * we can't rely on fatal_signal_pending() below. > */ > - if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) { > + if (unlikely(!pid_ns_is_adding(pid))) { > retval =3D -ENOMEM; > goto bad_fork_core_free; > } [Severity: Medium] Does pid_ns_is_adding() need to walk all the way to i =3D=3D 0 (init_pid_ns) under tasklist_lock on every containerized fork? init_pid_ns never clears PIDNS_ADDING (as runfd_pidns_alive() already assumes by stopping at init_pid_ns), yet walking down to i =3D=3D 0 reads the global init_pid_ns.pid_allocated cacheline, which is dirtied on every fork and exit system-wide, while holding write_lock_irq(&tasklist_lock). For normal in-namespace forks where ns_of_pid(pid) matches task_active_pid_ns(current), any ancestor zap already sends SIGKILL to current and is caught by fatal_signal_pending(current) right below. > diff --git a/kernel/runfd.c b/kernel/runfd.c > index 81ce523c79c6b..6296b2eab12fa 100644 > --- a/kernel/runfd.c > +++ b/kernel/runfd.c [ ... ] > + ret =3D runfd_check_namespaces(run); > + if (ret) > + goto err_forking; > + > + args->run_file =3D no_free_ptr(file); > + args->run =3D run; > + args->run_bootstrapping =3D bootstrapping; > + return 0; > + > +err_forking: > + if (bootstrapping) { > + scoped_guard(spinlock, &run->lock) { > + if (run->state =3D=3D RUNFD_FORKING) > + WRITE_ONCE(run->state, RUNFD_INIT); > + } > + wake_up_all(&run->waitq); > + } > + return ret; > +} [Severity: Low] This isn't a bug, but runfd_prepare_fork() mixes goto-based error unwinding (goto err_forking) with __free(fput), __free(path_put), and scoped_guard(spinlock, &run->lock). Per cleanup.h conventions, a new function should either handle rollback via a helper/guard or avoid mixing goto unwinding with __free() variables. > +int runfd_finish_fork(struct kernel_clone_args *args, > + struct task_struct *p) > +{ > + struct file *file __free(fput) =3D args->run_file; > + struct run *run =3D args->run; > + struct pid_namespace *pid_ns =3D run->ns->pid_ns_for_children; > + int ret; > + > + args->run_file =3D NULL; > + args->run =3D NULL; > + if (!IS_ERR(p)) { > + if (args->run_bootstrapping) > + wake_up_all(&run->waitq); > + if (current->nsproxy->time_ns !=3D run->ns->time_ns) > + timens_commit(p, run->ns->time_ns); > + return 0; > + } [Severity: Medium] Can a concurrently spawned CLONE_INTO_RUN child read a zeroed or partially initialized time namespace vvar_page? runfd_copy() transitions run->state to RUNFD_RUNNING inside copy_process(), and runfd_finish_fork() calls wake_up_all(&run->waitq) before timens_commit(). A concurrent CLONE_INTO_RUN caller can then enter timens_set_vvar_page() while the bootstrapper is still initializing ns->vvar_page: CPU0 (bootstrap) CPU1 (concurrent CLONE_INTO_RUN) copy_process() runfd_copy() run->state =3D RUNFD_RUNNING runfd_finish_fork() wake_up_all(&run->waitq) runfd_prepare_fork() timens_commit() timens_set_vvar_page() ns->frozen_offsets =3D true (preempted) runfd_finish_fork() timens_commit() timens_set_vvar_page() if (ns->frozen_offsets) return; wake_up_new_task(child) vDSO reads zeroed vvar <-- bogus 0.0 Because timens_set_vvar_page() sets ns->frozen_offsets =3D true before populating ns->vvar_page and checks ns->frozen_offsets locklessly on entry, CPU1's child can map the zeroed vvar_page and return bogus 0.0 timestamps from vDSO coarse clock calls. Deferring RUNFD_RUNNING publication and wake_up_all() until after timens_commit() completes (or fixing timens_set_vvar_page() to publish frozen_offsets with smp_store_release() after populating vvar_page) would close this race. > + ret =3D PTR_ERR(p); > + if (args->run_bootstrapping) { > + scoped_guard(spinlock, &run->lock) { > + if (run->state =3D=3D RUNFD_FORKING) > + WRITE_ONCE(run->state, RUNFD_INIT); > + } > + wake_up_all(&run->waitq); > + if (ret =3D=3D -EINVAL && !args->set_tid_size && > + (READ_ONCE(pid_ns->child_reaper) || > + (READ_ONCE(pid_ns->pid_allocated) & ~PIDNS_ADDING))) > + ret =3D -EBUSY; > + } > + if ((ret =3D=3D -ENOMEM || ret =3D=3D -EBUSY) && > + !runfd_pidns_alive(pid_ns)) > + return -ESRCH; > + > + return ret; > +} [Severity: Low] Can waking waiting bootstrap callers before checking pid_ns->child_reaper and pid_ns->pid_allocated turn a validation -EINVAL into -EBUSY? Companion flag checks such as CLONE_AUTOREAP with a non-zero exit_signal run in copy_process() after runfd_prepare_fork() sets RUNFD_FORKING and return -EINVAL. If wake_up_all(&run->waitq) runs first, a woken caller can enter copy_process() and allocate a PID before this thread checks pid_ns->child_reaper and pid_ns->pid_allocated: CPU0 (invalid CLONE_INTO_RUN) CPU1 (valid CLONE_INTO_RUN) copy_process() -> -EINVAL runfd_finish_fork() run->state =3D RUNFD_INIT wake_up_all(&run->waitq) runfd_prepare_fork() run->state =3D RUNFD_FORKING copy_process() alloc_pid() checks pid_ns->pid_allocated ret =3D -EBUSY; <-- masks -EINVAL Checking pid_ns->child_reaper and pid_ns->pid_allocated before reverting run->state to RUNFD_INIT and calling wake_up_all(&run->waitq) would avoid this race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205032633.1702= 772-1-jarkko@kernel.org?part=3D18