Re: [RFC PATCH v6 17/26] fork: Support CLONE_INTO_USERLAND in clone3()
From: bot+bpf-ci
Date: Sat Nov 21 2026 - 21:14:19 EST
> fork: Support CLONE_INTO_USERLAND in clone3()
TL;DR: In clone3(CLONE_INTO_USERLAND), userland_copy() takes c->lock under
tasklist_lock and siglock, but c->lock is taken elsewhere with interrupts
enabled. This may deadlock system-wide, and lockdep may report it.
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 2fceacc17e8a..3dd2c098bf32 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -2578,7 +2599,7 @@ __latent_entropy struct task_struct *copy_process(
> }
> attach_pid(p, PIDTYPE_PID);
> if (thread_group_leader(p))
> - userland_copy(p, pid, NULL);
> + userland_copy(p, pid, args->userland);
> nr_threads++;
> }
> total_forks++;
Before this patch userland_copy() was always called with a NULL userland and
returned immediately. Now the bootstrapping CLONE_INTO_USERLAND child
reaches this in copy_process() while holding write_lock_irq(&tasklist_lock)
and spin_lock(¤t->sighand->siglock):
void userland_copy(struct task_struct *tsk, struct pid *pid,
struct userland *c)
{
if (likely(!c || !is_child_reaper(pid)))
return;
scoped_guard(spinlock, &c->lock) {
...
sighand->siglock is taken from hard interrupt context, for example
it_real_fn() -> kill_pid_info() -> lock_task_sighand(), and
posix_timer_fn() -> posix_timer_queue_signal().
Every other user of c->lock takes it with a plain spin_lock() and interrupts
enabled: userland_prepare_fork(), userland_finish_fork(), userland_waitid(),
userland_get_nsfd(), userland_share_nsfd(), userland_release() and
userland_exit().
Can this produce a HARDIRQ-safe -> HARDIRQ-unsafe lock order report from
lockdep on the first bootstrap clone3(CLONE_INTO_USERLAND)?
It also looks like a real deadlock is possible:
CPU0
thread T2 of process P, in userland_prepare_fork() or waitid(P_USERLAND),
holds c->lock with interrupts enabled
hrtimer interrupt for P's ITIMER_REAL runs it_real_fn()
spins on P->sighand->siglock
CPU1
thread T1 of process P, in copy_process(), holds tasklist_lock for write
and P->sighand->siglock
userland_copy() spins on c->lock
Neither CPU can make progress, and since tasklist_lock is write-held, fork,
exit and wait stall system-wide.
Should c->lock be taken with spin_lock_irq()/irqsave at every site, or should
the FORKING -> RUNNING transition move out of the tasklist_lock/siglock
section, for example into userland_finish_fork()? I did not find a later
patch in the series (up to 942764a55437) that changes this.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44972669664