Re: [RFC PATCH v6 11/26] userland: Track init lifecycle via copy_process() and pid_namespace

From: bot+bpf-ci

Date: Sat Nov 21 2026 - 21:13:41 EST


> userland: Track init lifecycle via copy_process() and pid_namespace

TL;DR: userland_copy() may take c->lock inside siglock and tasklist_lock,
while c->lock is taken with IRQs enabled elsewhere; this could trigger a
lockdep report and a possible deadlock once CLONE_INTO_USERLAND goes live.

> diff --git a/kernel/fork.c b/kernel/fork.c
> --- a/kernel/fork.c
> +++ b/kernel/fork.c

[ ... ]

> @@ -2573,12 +2574,14 @@ __latent_entropy struct task_struct *copy_process(
> attach_pid(p, PIDTYPE_PID);
> + if (thread_group_leader(p))
> + userland_copy(p, pid, NULL);
> nr_threads++;
> }
> total_forks++;
> hlist_del_init(&delayed.node);
> spin_unlock(&current->sighand->siglock);

[ ... ]

> diff --git a/kernel/userland.c b/kernel/userland.c
> --- a/kernel/userland.c
> +++ b/kernel/userland.c
> @@ -82,6 +82,49 @@ static const struct file_operations userland_fops = {

[ ... ]

> +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) {
> + if (c->state != USERLAND_FORKING)
> + return;
> + refcount_inc(&c->usage);

Can this nest c->lock inside siglock and tasklist_lock in an unsafe way?

userland_copy() is called from copy_process() while tasklist_lock is held
for write with interrupts disabled, and while current->sighand->siglock is
held:

attach_pid(p, PIDTYPE_PID);
if (thread_group_leader(p))
userland_copy(p, pid, NULL);
nr_threads++;
...
spin_unlock(&current->sighand->siglock);
write_unlock_irq(&tasklist_lock);

siglock is taken from hard interrupt context. For example, the ITIMER_REAL
timer uses a non-soft hrtimer, and it_real_fn() -> kill_pid_info() ->
do_send_sig_info() -> lock_task_sighand() takes siglock in hardirq. So
holding siglock while acquiring c->lock records a siglock -> c->lock
dependency.

Every other acquisition of c->lock in the series uses plain
scoped_guard(spinlock, ...) with interrupts enabled: userland_release(),
userland_exit(), and, from later commits, userland_prepare_fork(),
userland_finish_fork(), userland_waitid(), userland_get_nsfd() and
userland_share_nsfd(). That makes c->lock hardirq-unsafe while it is
nested under a hardirq-safe lock, and lockdep should report "HARDIRQ-safe ->
HARDIRQ-unsafe lock order detected" the first time a userland is
bootstrapped on a CONFIG_PROVE_LOCKING kernel.

It also looks like a real deadlock:

CPU0: a second clone3(CLONE_INTO_USERLAND) caller in
userland_prepare_fork() (or waitid(P_USERLAND), or USERLAND_SHARE_NSFD on
the same userland) holds c->lock with IRQs enabled.

CPU1: the bootstrapping parent is in copy_process() holding tasklist_lock
(write) and its siglock, and spins in userland_copy() on c->lock.

CPU0: takes the parent's ITIMER_REAL (or a posix-timer) hrtimer interrupt,
and it_real_fn() spins on the parent's siglock, which CPU1 holds.

Neither CPU can make progress. This looks reachable without privilege,
since userland_open() creates its own user namespace and the caller holds
CAP_SYS_ADMIN/CAP_SYS_CHROOT there.

In this commit the call passes NULL, so userland_copy() returns early. The
path becomes live with 498ccb2ffbc4 ("fork: Support CLONE_INTO_USERLAND in
clone3()"), which changes the call to userland_copy(p, pid, args->userland).
I don't see a later commit in the series that addresses this; at 942764a55437
every c->lock user still uses scoped_guard(spinlock, ...).

Should c->lock be taken IRQ-safe everywhere (spinlock_irq/spinlock_irqsave),
or should the FORKING->RUNNING commit happen outside the tasklist_lock and
siglock section?

> + ns_of_pid(pid)->userland = c;
> + WRITE_ONCE(c->init_pid, get_pid(pid));
> + WRITE_ONCE(c->state, USERLAND_RUNNING);
> + }
> +}


---
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