[RFC PATCH v6 13/26] userland: Add USERLAND_GET_NSFD ioctl

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Sun Nov 22 02:13:43 UTC 2026


> userland: Add USERLAND_GET_NSFD ioctl

TL;DR: userland->lock is taken with irqs enabled but, once
clone3(CLONE_INTO_USERLAND) lands later in the series, also under siglock; a
possible deadlock lockdep would report. Latent at this commit.

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

[ ... ]

> +static long userland_get_nsfd(struct userland *userland, unsigned long nstype)
> +{

[ ... ]

> +	scoped_guard(spinlock, &userland->lock) {
> +		switch (nstype) {
> +		case CLONE_NEWNS:
> +			ns = from_mnt_ns(userland->ns->mnt_ns);
> +			break;

[ ... ]

Can this lock be taken with hardirqs enabled?  Later in the series,
commit 498ccb2ffbc4 ("fork: Support CLONE_INTO_USERLAND in clone3()")
passes args->userland to userland_copy(), and copy_process() calls it
while holding write_lock_irq(&tasklist_lock) and
spin_lock(&current->sighand->siglock):

copy_process()
  write_lock_irq(&tasklist_lock)
  spin_lock(&current->sighand->siglock)
  userland_copy()
    scoped_guard(spinlock, &c->lock)

siglock is hardirq-safe, since it_real_fn() reaches it through
kill_pid_info()->lock_task_sighand() from a hard hrtimer callback.  That
gives siglock -> userland->lock, with userland->lock taken here with
irqs enabled, which lockdep will report and which can deadlock:

CPU0
ioctl(USERLAND_GET_NSFD, CLONE_NEWNET)
  spin_lock(&userland->lock)        irqs still enabled

CPU1
clone3(CLONE_INTO_USERLAND)
  copy_process()
    write_lock_irq(&tasklist_lock)
    spin_lock(&parent->sighand->siglock)
    userland_copy()
      spins on userland->lock

CPU0
hardirq: parent's ITIMER_REAL fires
  it_real_fn()
    lock_task_sighand(parent)       spins on siglock held by CPU1

GET_NSFD has no state check for types other than CLONE_NEWPID, so it can
run while the userland is in USERLAND_INIT or USERLAND_FORKING, at the
same time as the bootstrapping clone.

At this commit userland_copy() is still passed NULL, so this is latent
until that later commit.  userland_release(), userland_exit() and the
later userland_share_nsfd() take the lock the same way, and the series up
to 942764a55437 still uses scoped_guard(spinlock, ...) at every site.
Should these sites use spinlock_irq, or should the userland_copy()
bookkeeping move out of the tasklist_lock/siglock section?


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


More information about the Linux-security-module-archive mailing list