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

From
sashiko-bot@kernel.org
Date
2026-11-19 19:36:59
Also in
linux-mm
Reply to
Jarkko Sakkinen, 2026-11-18
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] rootns: unreachable init_pid check and missing -ECHILD in
  rootns_wait_common()
- [Medium] rootns: non-freezable TASK_KILLABLE sleep in
  rootns_wait_common()
--

commit 8a805a3f4fb79d05bf397b0ae4fb7738f0017723
Author: Jarkko Sakkinen [off-list ref]

rootns: Add rootns_wait() system call

This commit adds the rootns_wait() system call and its compat entry point to
wait for a root namespace init process to terminate and collect its exit
status and resource usage.
quoted hunk ↗ jump to hunk
diff --git a/kernel/rootns.c b/kernel/rootns.c
index c420e36af603f..5582ff010ca53 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -305,3 +305,106 @@ SYSCALL_DEFINE1(rootns_create, unsigned int, flags)
 
 	return fd;
 }
+
+/*
+ * Wait for rootns init to exit and report results for the caller.
+ *
+ * Returns caller-visible init TGID on success, 0 for WNOHANG when still
+ * running, and -ECHILD when init pid is not visible in caller pidns.
+ */
+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 a freezable and interruptible wait such as
wait_event_freezable() instead of wait_event_killable()?

Sleeping in TASK_KILLABLE for the lifetime of a running root namespace
prevents the PM and cgroup v2 freezers from freezing the waiting task (which
causes system suspend or hibernation to time out and fail), blocks non-fatal
signals and job control, and counts every blocked waiter toward the system
load average.
quoted hunk ↗ jump to hunk
+		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 here ever be reached, and what happens when
rootns_wait() is called before an init process has been started?

The kernel-doc for sys_rootns_wait() states that -ECHILD is returned if init
was never started.  However, rootns->state only reaches ROOTNS_DEAD in
exit_rootns() after copy_rootns() has already populated rootns->init_pid.
When init has not been started (rootns->state == ROOTNS_INIT), a call with
WNOHANG hits the rootns->state != ROOTNS_DEAD check first and returns 0,
while a call without WNOHANG sleeps in wait_event_killable() instead of
returning -ECHILD.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118193539.240065-1-jarkko@kernel.org?part=5
Thread (33 messages) 33 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help