[RFC PATCH v2 05/13] rootns: Add rootns_wait() system call

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Nov 18 23:15:12 UTC 2026


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] rootns: unreachable init_pid check in rootns_wait_common()
- [Medium] rootns: non-freezable TASK_KILLABLE sleep in
  rootns_wait_common()
--

commit ee16ae2e42910ad7c6f6428120bfc66d7f286658
Author: Jarkko Sakkinen <jarkko at kernel.org>

rootns: Add rootns_wait() system call

This commit adds the rootns_wait() system call and its compat entry point to
wait on a rootns file descriptor until its init thread group exits and
report its wait status and resource usage.

> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index caa810b65d0da..83ab759a31ecd 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> +static long rootns_wait_common(int rootnsfd, unsigned int options,
> +			       int *status, struct rusage *ru)
> +{
> +	CLASS(fd, f)(rootnsfd);
> +	struct pid_namespace *pid_ns = task_active_pid_ns(current);
> +	struct rootns *rootns;
> +	long ret;
> +
> +	if (fd_empty(f))
> +		return -EBADF;
> +	if (!is_rootns_file(fd_file(f)) || (options & ~WNOHANG))
> +		return -EINVAL;
> +
> +	rootns = fd_file(f)->private_data;
> +	if (!(options & WNOHANG)) {
> +		ret = wait_event_killable(rootns->waitq,
> +					  READ_ONCE(rootns->state) == ROOTNS_DEAD);

[Severity: Medium]
Should rootns_wait_common() use wait_event_freezable() instead of
wait_event_killable() here?

Waiters blocked in TASK_KILLABLE for the lifetime of a container are neither
marked TASK_FREEZABLE nor woken by signal_wake_up(), unlike do_wait() which
sleeps in TASK_INTERRUPTIBLE | TASK_FREEZABLE.  While any task is blocked in
rootns_wait(), system suspend and hibernation fail after the PM freezer
timeout, cgroup v2 freezing of the waiter's cgroup hangs, non-fatal signals
and job control cannot interrupt the wait, and each idle waiter inflates the
system load average.

> +		if (ret)
> +			return ret;
> +	}
> +
> +	scoped_guard(spinlock, &rootns->lock) {
> +		if (rootns->state != ROOTNS_DEAD)
> +			return 0;
> +		if (!rootns->init_pid)
> +			return -ECHILD;

[Severity: Medium]
Can the !rootns->init_pid check ever be reached when init was never started?

The kernel-doc for sys_rootns_wait() states that it returns -ECHILD if init
was never started, but rootns->state only reaches ROOTNS_DEAD in
exit_rootns() after copy_rootns() has already set rootns->init_pid and
transitioned the state to ROOTNS_RUNNING.  When rootns_wait() is called on a
rootns in ROOTNS_EMPTY or ROOTNS_READY before init is forked, a WNOHANG call
returns 0 at the rootns->state != ROOTNS_DEAD check above, and a blocking
call sleeps indefinitely in wait_event_killable().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=5



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