OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH RFC hci-8.2 0/2] ve: Container start on the 26.3 kernel with libvzctl before 10.0.144
@ 2026-11-19 21:49 Konstantin Khorenko
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task Konstantin Khorenko
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init Konstantin Khorenko
  0 siblings, 2 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 21:49 UTC (permalink / raw)
  To: Mirian Shilakadze, Pavel Tikhomirov; +Cc: devel

The VSTOR-151265 series (26.3) hides the setup tasks of a VE from every
other task of it while the VE is pseudosuper. ve_setup_task() marks a
host task a setup task only while the VE is VE_STATE_STARTING; a host
task entering afterwards is a VD_VE_ENTER_TASK and does not see them.

libvzctl before 10.0.144 starts a Container like this: pseudosuper=1,
clone the init, the init writes START (the VE is RUNNING from here on),
then a helper joins the init's namespaces one by one through setns()
and only then opens /proc/<init>/ns/mnt. The open comes from an ENTER
task of a pseudosuper VE, so it is refused:

  Failed to open /proc/<pid>/ns/mnt: Permission denied
  Failed to configure disk
  Cancel init execution

Every Container start fails on the hci-8.1 userspace (libvzctl 10.0.134
and older). libvzctl 10.0.144 (vzctl commit 8bf40747, VSTOR-151174)
opens every namespace fd before it joins the first, while the helper is
still a ve0 task, and the start works; hci-8.2 ships 10.1.3 together
with the 26.3 kernel.

Verified on a test VM with the six Containers there:

  +----------------------------+-------------------+-----------------+
  | kernel                     | libvzctl 10.0.134 | libvzctl 10.1.3 |
  +----------------------------+-------------------+-----------------+
  | 26.3 as is                 | no CT starts      | all start       |
  | 26.3 + patch 1             | all start         | not run         |
  | RHEL 10.3 rebase as is     | no CT starts      | not run         |
  | RHEL 10.3 rebase + patch 1 | all start         | not run         |
  +----------------------------+-------------------+-----------------+

So the 26.3 kernel depends on a libvzctl version and does not say so:
no commit of the series, its Jira or kernel.spec names libvzctl >=
10.0.144, and no vz kernel spec ever carried a Conflicts: on vzctl or
libvzctl. A node that gets the kernel, or a ReadyKernel patch with the
series, without the libvzctl update loses every Container start.

Two ways out, hence the RFC:

1. Apply patch 1. A host task that enters a VE while it is still
   pseudosuper becomes a setup task whatever ve.state says, so the old
   start sequence works again. The price: such a helper, if it stays in
   the VE without exec, turns into an ordinary task once pseudosuper is
   cleared (VD_VE_SETUP_TASK counts as VD_PTRACE_COREDUMP then), so the
   container can reach its host fds, while as an ENTER task it stays
   hidden for good. Mirian's view: the kernel is right, userspace must
   be 10.0.144 or newer.

2. Drop patch 1 and declare the dependency instead: Conflicts:
   libvzctl < 10.0.144 in kernel.spec, a release note, or both. Patch 2
   is then wrong as it stands and can be turned round to check the
   series' contract: a host task joining a running pseudosuper VE does
   not reach the init, namespace fds opened before joining work, an
   exec'd binary does not reach it.

Patch 2 is the selftest for the start sequence of libvzctl before
10.0.144: it starts a real VE (pseudosuper, clone3 into new pid, cgroup,
net and mnt namespaces, START) and checks that a host task joining
afterwards reaches the init's namespaces and an exec'd binary does not.
It fails on 26.3 as is and passes with patch 1.

https://virtuozzo.atlassian.net/browse/VSTOR-156164

To: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
To: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Assisted-by: LLM
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
Konstantin Khorenko (2):
      ve: mark a host task entering a pseudosuper VE as a setup task
      selftests/ve: check a host task entering a pseudosuper VE reaches its init

 kernel/ve/ve.c                                  |  17 +-
 tools/testing/selftests/ve/.gitignore           |   1 +
 tools/testing/selftests/ve/Makefile             |   1 +
 tools/testing/selftests/ve/ve_setup_task_test.c | 284 ++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 8 deletions(-)
---
base-commit: c1acd2c05aa3ebe0313958e2bd09f60f2040a5cb
change-id: 20261119-b4-prep-khorenko-vstor-156164-ve-setup-task-pseudosuper-e11df3a8c1ba

Best regards,
--  
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task
  2026-11-19 21:49 [Devel] [PATCH RFC hci-8.2 0/2] ve: Container start on the 26.3 kernel with libvzctl before 10.0.144 Konstantin Khorenko
@ 2026-11-19 21:49 ` Konstantin Khorenko
  2026-11-19 21:56   ` no-reply
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init Konstantin Khorenko
  1 sibling, 1 reply; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 21:49 UTC (permalink / raw)
  To: Mirian Shilakadze, Pavel Tikhomirov; +Cc: devel

ve_setup_task() marks a task the host sends into a VE as
VD_VE_SETUP_TASK only while the VE is VE_STATE_STARTING, and as
VD_VE_ENTER_TASK afterwards. While the VE is pseudosuper, a setup task
is reachable only from another setup task.

libvzctl before 10.0.144 writes START to ve.state, which ends in
VE_STATE_RUNNING, before it configures the disk: a helper then enters
the init task's namespaces one by one through setns(), the VE namespace
among them, and opens /proc/<init>/ns/mnt. It enters a running VE, so
it becomes an ENTER task, and pseudosuper is cleared only after the
setup, so the init task, a setup task, is still hidden from it.

Every container start with such a libvzctl fails:

  Failed to open /proc/<pid>/ns/mnt: Permission denied
  Failed to configure disk
  Cancel init execution

libvzctl 10.0.144 and newer open the namespaces before joining any and
are not affected.

A host task entering a VE that is still pseudosuper is part of its
setup whatever ve.state says: mark it VD_VE_SETUP_TASK while
is_pseudosuper is set. Container binaries such a helper execs still
drop the mark on exec, so they gain nothing.

Fixes: a7d797d177e7 ("ve: hide the tasks that set up a starting VE from the rest of it")
https://virtuozzo.atlassian.net/browse/VSTOR-156164

Feature: trace: prohibit tracing sensitive tasks from CT
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 kernel/ve/ve.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 076892a750cfc..7323ea2053ac6 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1899,18 +1899,19 @@ void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
 		return;
 
 	/*
-	 * A task the host sends into a starting VE is a setup task, one it
-	 * sends into a started VE is hidden from the tasks of the VE. A setup
-	 * task leaving a VE that is still pseudosuper was sent by the host
-	 * too. The mark goes to the mm, which may be shared, so a task coming
-	 * from a container never gets either. A setup task leaving a VE that
-	 * is not pseudosuper drops the mark: after pseudosuper is cleared it
-	 * cannot be told from the restored processes.
+	 * A task the host sends into a VE (from ve0, or a setup task of a
+	 * VE still pseudosuper) becomes a setup task if the VE starts or
+	 * stays pseudosuper, else one hidden from the VE's tasks.
+	 *
+	 * The mark lives in the mm, which may be shared, so a task from a
+	 * container keeps its mark, except a setup mark of a VE that left
+	 * pseudosuper: it is an ordinary task now.
 	 */
 	if (mm && old_ve != ve) {
 		if (ve_is_super(old_ve) ||
 		    ve_vps_dumpable(mm, old_ve) == VD_VE_SETUP_TASK)
-			mm->vps_dumpable = ve->state == VE_STATE_STARTING ?
+			mm->vps_dumpable = ve->state == VE_STATE_STARTING ||
+					   ve->is_pseudosuper ?
 					   VD_VE_SETUP_TASK : VD_VE_ENTER_TASK;
 		else if (mm->vps_dumpable == VD_VE_SETUP_TASK)
 			mm->vps_dumpable = VD_PTRACE_COREDUMP;

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init
  2026-11-19 21:49 [Devel] [PATCH RFC hci-8.2 0/2] ve: Container start on the 26.3 kernel with libvzctl before 10.0.144 Konstantin Khorenko
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task Konstantin Khorenko
@ 2026-11-19 21:49 ` Konstantin Khorenko
  2026-11-19 21:54   ` no-reply
  1 sibling, 1 reply; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 21:49 UTC (permalink / raw)
  To: Mirian Shilakadze, Pavel Tikhomirov; +Cc: devel

vzctl starts a Container with ve.pseudosuper set: the init it clones
writes START to ve.state, then a helper forked on the host enters the
init's namespaces and opens its /proc/<pid>/ns/mnt. While the VE is
pseudosuper its setup tasks are reachable only from each other, so the
helper must be a setup task too.

Start a VE the same way and check that a host task entering it through
the ve namespace reaches the init, and that a binary exec'd inside the
VE still does not. Before the fix the first test fails with EACCES, the
error vzctl start reports.

https://virtuozzo.atlassian.net/browse/VSTOR-156164

Feature: trace: prohibit tracing sensitive tasks from CT
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 tools/testing/selftests/ve/.gitignore           |   1 +
 tools/testing/selftests/ve/Makefile             |   1 +
 tools/testing/selftests/ve/ve_setup_task_test.c | 284 ++++++++++++++++++++++++
 3 files changed, 286 insertions(+)

diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore
index a468ef980e28b..fbaea9c8ee39d 100644
--- a/tools/testing/selftests/ve/.gitignore
+++ b/tools/testing/selftests/ve/.gitignore
@@ -7,3 +7,4 @@ ve_numa_migrate_test
 ve_aio_ring_test
 ve_numa_syscalls_prohibited_test
 ve_tmpfs_mpol_test
+ve_setup_task_test
diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
index fa4f858227e5e..baf035219da98 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -10,6 +10,7 @@ TEST_GEN_PROGS += ve_numa_migrate_test
 TEST_GEN_PROGS += ve_aio_ring_test
 TEST_GEN_PROGS += ve_numa_syscalls_prohibited_test
 TEST_GEN_PROGS += ve_tmpfs_mpol_test
+TEST_GEN_PROGS += ve_setup_task_test
 
 # CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
 # picks the clang target by its emptiness, so decide by the compiler.
diff --git a/tools/testing/selftests/ve/ve_setup_task_test.c b/tools/testing/selftests/ve/ve_setup_task_test.c
new file mode 100644
index 0000000000000..e9f8851e91724
--- /dev/null
+++ b/tools/testing/selftests/ve/ve_setup_task_test.c
@@ -0,0 +1,284 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ve_setup_task selftest
+ *
+ * vzctl starts a Container with ve.pseudosuper set: the init it clones
+ * writes START to ve.state, and only then a helper forked on the host
+ * enters the init's namespaces and opens its /proc/<pid>/ns/mnt. While
+ * the VE is pseudosuper its setup tasks are reachable only from each
+ * other, so the helper must be a setup task too, or the start fails
+ * with EACCES. A container binary, one exec'd inside the VE, must still
+ * not reach the init.
+ *
+ * The tests start a VE the way vzctl does and check that:
+ *
+ *   - a host task entering the running pseudosuper VE reaches the init
+ *   - a binary exec'd inside the VE does not
+ */
+#define _GNU_SOURCE
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/sched.h>
+#include <sys/prctl.h>
+#include <sys/random.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+
+#include "../kselftest_harness.h"
+#include "ve_selftest.h"
+
+/* Re-exec of the test binary: open the mnt namespace of the given pid. */
+#define PROBE_ARG		"--open-mnt-ns"
+
+FIXTURE(ve_setup_task)
+{
+	int cgv2_fd;
+	int ctid;
+	pid_t init_pid;
+	int init_release;		/* its read end holds the init */
+	struct namespace_ctx ns_ctx;	/* the VE namespace of the init */
+	char exe[PATH_MAX];		/* this binary, for the probe exec */
+};
+
+/* 0 when /proc/@pid/ns/mnt opens, else errno. */
+static int open_mnt_ns(pid_t pid)
+{
+	char path[64];
+	int fd;
+
+	snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid);
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		return errno;
+	close(fd);
+	return 0;
+}
+
+static int ve_write(FIXTURE_DATA(ve_setup_task) * self, const char *file,
+		    const char *val)
+{
+	char path[64];
+
+	snprintf(path, sizeof(path), "%d/%s", self->ctid, file);
+	return write_file_at(self->cgv2_fd, path, val);
+}
+
+static int ve_read(FIXTURE_DATA(ve_setup_task) * self, const char *file,
+		   char *buf, size_t len)
+{
+	char path[64];
+
+	snprintf(path, sizeof(path), "%d/%s", self->ctid, file);
+	return read_file_at(self->cgv2_fd, path, buf, len);
+}
+
+/*
+ * The init of the VE: start it, report the result and stay until the
+ * test closes the release pipe.
+ */
+static void run_init(FIXTURE_DATA(ve_setup_task) * self, int status[2],
+		     int release[2])
+{
+	char c;
+
+	prctl(PR_SET_PDEATHSIG, SIGKILL);
+	close(status[0]);
+	close(release[1]);
+	c = ve_write(self, "ve.state", "START") ? errno : 0;
+	if (write(status[1], &c, 1) != 1)
+		_exit(1);
+	close(status[1]);
+	while (read(release[0], &c, 1) < 0 && errno == EINTR)
+		;
+	_exit(0);
+}
+
+/* Wait for the VE to stop after the init is released, then remove it. */
+static void stop_ve(FIXTURE_DATA(ve_setup_task) * self)
+{
+	char state[32], path[64];
+	int i;
+
+	if (self->init_pid > 0) {
+		close(self->init_release);
+		waitpid(self->init_pid, NULL, 0);
+	}
+	for (i = 0; i < 500; i++) {
+		if (ve_read(self, "ve.state", state, sizeof(state)) < 0 ||
+		    !strncmp(state, "STOPPED", 7) ||
+		    !strncmp(state, "STARTING", 8))
+			break;
+		usleep(10000);
+	}
+	ve_write(self, "ve.pseudosuper", "0");
+	/* The start makes a vz.slice child under the VE root */
+	snprintf(path, sizeof(path), "%d/vz.slice", self->ctid);
+	unlinkat(self->cgv2_fd, path, AT_REMOVEDIR);
+	destroy_ve(self->cgv2_fd, self->ctid);
+}
+
+/*
+ * Start the VE the way vzctl does: pseudosuper first, then an init cloned
+ * from the host writes START. The start needs the init in its own pid,
+ * cgroup and net namespaces. Returns -1 with the failed step in @what.
+ */
+static int start_ve(FIXTURE_DATA(ve_setup_task) * self, const char **what)
+{
+	struct clone_args cargs = {
+		.flags = CLONE_NEWVE | CLONE_NEWPID | CLONE_NEWCGROUP |
+			 CLONE_NEWNS | CLONE_NEWNET,
+		.exit_signal = SIGCHLD,
+	};
+	char state[32], path[64], val[32];
+	int status[2], release[2];
+	unsigned int veid;
+	char c;
+
+	*what = "ve cgroup";
+	self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
+	if (self->ctid < 0)
+		return -1;
+
+	/* A random high veid, as a container gets, so it clashes with none */
+	*what = "ve.veid";
+	if (getrandom(&veid, sizeof(veid), 0) != sizeof(veid))
+		return -1;
+	veid = (veid >> 2) | (1u << 30);
+	snprintf(val, sizeof(val), "%u", veid);
+	if (ve_write(self, "ve.veid", val) < 0)
+		return -1;
+	*what = "ve.pseudosuper";
+	if (ve_write(self, "ve.pseudosuper", "1") < 0)
+		return -1;
+
+	*what = "pipe";
+	if (pipe(status) < 0 || pipe(release) < 0)
+		return -1;
+
+	/* The init: a host task cloned into the VE while it starts */
+	*what = "clone3";
+	if (enter_cgroup(self->cgv2_fd, self->ctid) < 0)
+		return -1;
+	self->init_pid = syscall(__NR_clone3, &cargs, sizeof(cargs));
+	if (self->init_pid == 0)
+		run_init(self, status, release);
+	close(status[1]);
+	close(release[0]);
+	self->init_release = release[1];
+	if (enter_cgroup(self->cgv2_fd, 0) < 0 || self->init_pid < 0)
+		return -1;
+
+	*what = "ve.state START";
+	if (read(status[0], &c, 1) != 1)
+		return -1;
+	close(status[0]);
+	if (c) {
+		errno = c;
+		return -1;
+	}
+	*what = "ve.state is not RUNNING";
+	if (ve_read(self, "ve.state", state, sizeof(state)) <= 0 ||
+	    strncmp(state, "RUNNING", 7))
+		return -1;
+
+	*what = "/proc/<init>/ns/ve";
+	snprintf(path, sizeof(path), "/proc/%d/ns/ve", self->init_pid);
+	self->ns_ctx.ve_fd = open(path, O_RDONLY);
+	if (self->ns_ctx.ve_fd < 0)
+		return -1;
+	self->ns_ctx.ns_save_mask = CLONE_NEWVE;
+	return 0;
+}
+
+FIXTURE_SETUP(ve_setup_task)
+{
+	const char *what;
+	ssize_t len;
+	int ret, err;
+
+	self->ctid = -1;
+	self->init_pid = -1;
+	self->ns_ctx.ns_save_mask = 0;
+
+	len = readlink("/proc/self/exe", self->exe, sizeof(self->exe) - 1);
+	ASSERT_GT(len, 0);
+	self->exe[len] = '\0';
+
+	self->cgv2_fd = mount_cg2_fd();
+	if (self->cgv2_fd < 0)
+		SKIP(return, "cannot mount cgroup2: %s", strerror(errno));
+	if (write_file_at(self->cgv2_fd, "cgroup.subtree_control",
+			  VE_CONTROLLERS) < 0)
+		SKIP(return, "cannot enable the ve controller: %s",
+		     strerror(errno));
+
+	/* The harness skips the teardown when the setup fails */
+	ret = start_ve(self, &what);
+	err = errno;
+	if (ret)
+		stop_ve(self);
+	ASSERT_EQ(ret, 0) TH_LOG("%s: %s", what, strerror(err));
+}
+
+FIXTURE_TEARDOWN(ve_setup_task)
+{
+	if (self->ctid < 0)
+		return;
+	close_namespace_fds(&self->ns_ctx);
+	stop_ve(self);
+	close(self->cgv2_fd);
+}
+
+static int open_init_mnt_ns(void *arg)
+{
+	int err = open_mnt_ns(*(pid_t *)arg);
+
+	if (err)
+		fprintf(stderr, "%s: /proc/<init>/ns/mnt: %s\n", __func__,
+			strerror(err));
+	return err ? -1 : 0;
+}
+
+TEST_F(ve_setup_task, host_task_reaches_init)
+{
+	EXPECT_EQ(run_in_ve(self->cgv2_fd, self->ctid, &self->ns_ctx,
+			    CLONE_NEWVE, open_init_mnt_ns, &self->init_pid), 0);
+}
+
+TEST_F(ve_setup_task, exec_in_ve_does_not_reach_init)
+{
+	char pid[16];
+	int status;
+	pid_t p;
+
+	snprintf(pid, sizeof(pid), "%d", self->init_pid);
+	p = fork();
+	ASSERT_GE(p, 0);
+	if (p == 0) {
+		if (enter_cgroup(self->cgv2_fd, self->ctid) < 0 ||
+		    enter_namespaces(&self->ns_ctx, CLONE_NEWVE) < 0)
+			_exit(254);
+		execl(self->exe, self->exe, PROBE_ARG, pid, NULL);
+		fprintf(stderr, "execl(%s): %s\n", self->exe, strerror(errno));
+		_exit(254);
+	}
+	ASSERT_EQ(waitpid(p, &status, 0), p);
+	ASSERT_TRUE(WIFEXITED(status));
+	ASSERT_NE(WEXITSTATUS(status), 254);
+	EXPECT_EQ(WEXITSTATUS(status), EACCES)
+		TH_LOG("open of the init's mnt namespace: %s",
+		       strerror(WEXITSTATUS(status)));
+}
+
+int main(int argc, char **argv)
+{
+	if (argc == 3 && !strcmp(argv[1], PROBE_ARG))
+		return open_mnt_ns(atoi(argv[2]));
+	return test_harness_run(argc, argv);
+}

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init Konstantin Khorenko
@ 2026-11-19 21:54   ` no-reply
  0 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2026-11-19 21:54 UTC (permalink / raw)
  To: Konstantin Khorenko, Mirian Shilakadze, Pavel Tikhomirov; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/ve: setup failure leaves cgv2_fd and pipe fds open
- [Low] selftests/ve: start_ve() leaks pipe fds on failure returns
--

commit e8d0bb859d8ed5e2c6bc741aea13996d73568ff
Author: Konstantin Khorenko <khorenko@virtuozzo.com>

selftests/ve: check a host task entering a pseudosuper VE reaches its init

This adds ve_setup_task_test. It starts a VE the way vzctl does, with ve.pseudosuper set and an init cloned from the host that writes START to ve.state. It then checks that a host task entering the VE through the ve namespace can open the init's mnt namespace, and that a binary exec'd inside the VE still cannot.

> diff --git a/tools/testing/selftests/ve/ve_setup_task_test.c b/tools/testing/selftests/ve/ve_setup_task_test.c
> new file mode 100644
> index 0000000000000..e9f8851e91724
> --- /dev/null
> +++ b/tools/testing/selftests/ve/ve_setup_task_test.c

[ ... ]

> +	/* The init: a host task cloned into the VE while it starts */
> +	*what = "clone3";
> +	if (enter_cgroup(self->cgv2_fd, self->ctid) < 0)
> +		return -1;
> +	self->init_pid = syscall(__NR_clone3, &cargs, sizeof(cargs));
> +	if (self->init_pid == 0)
> +		run_init(self, status, release);
> +	close(status[1]);
> +	close(release[0]);
> +	self->init_release = release[1];
> +	if (enter_cgroup(self->cgv2_fd, 0) < 0 || self->init_pid < 0)
> +		return -1;
> +
> +	*what = "ve.state START";
> +	if (read(status[0], &c, 1) != 1)
> +		return -1;
> +	close(status[0]);
> +	if (c) {
> +		errno = c;
> +		return -1;
> +	}

[Severity: Low]
Do these early returns leak the pipe descriptors? If clone3() fails,
init_pid is -1 and start_ve() returns with release[1] stored in
init_release. stop_ve() closes init_release only when init_pid > 0, so
release[1] is never closed. If the read of status[0] fails, status[0]
is not closed either. The process is short-lived, so the effect is
small, but closing both descriptors on the failure paths would keep
the error handling tidy.

[ ... ]

> +	/* The harness skips the teardown when the setup fails */
> +	ret = start_ve(self, &what);
> +	err = errno;
> +	if (ret)
> +		stop_ve(self);
> +	ASSERT_EQ(ret, 0) TH_LOG("%s: %s", what, strerror(err));

[Severity: Low]
Does this failure path leak self->cgv2_fd? As the comment says, the
harness skips FIXTURE_TEARDOWN when setup fails. Only stop_ve() runs
here, and it never closes cgv2_fd. The close(self->cgv2_fd) sits only
in FIXTURE_TEARDOWN. Closing cgv2_fd in this error branch after
stop_ve() would fix it.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119-b4-prep-khorenko-vstor-156164-ve-setup-task-pseudosuper-v1-0-06fa0b8994a8@virtuozzo.com?part=2

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task
  2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task Konstantin Khorenko
@ 2026-11-19 21:56   ` no-reply
  0 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2026-11-19 21:56 UTC (permalink / raw)
  To: Konstantin Khorenko, Mirian Shilakadze, Pavel Tikhomirov; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] ve: stale ENTER_TASK docs/branch after ve_setup_task() marks
  pseudosuper entrants SETUP
- [Low] ve: host tasks entering a pseudosuper VE lose ptrace hiding once
  pseudosuper clears
--

commit 7c48a2417efa8cba2799a83bd32623176d1b8aec
Author: Konstantin Khorenko <khorenko@virtuozzo.com>

ve: mark a host task entering a pseudosuper VE as a setup task

ve_setup_task() now marks a host task entering a VE as VD_VE_SETUP_TASK while the VE is pseudosuper, not only while it is VE_STATE_STARTING. This lets the libvzctl helper that setns()es into an already running VE still reach the init task during disk setup.

> diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
> --- a/kernel/ve/ve.c
> +++ b/kernel/ve/ve.c
> @@ -1899,18 +1899,19 @@ void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
>  		return;
>  
>  	/*
> -	 * A task the host sends into a starting VE is a setup task, one it
> -	 * sends into a started VE is hidden from the tasks of the VE. A setup
> -	 * task leaving a VE that is still pseudosuper was sent by the host
> -	 * too. The mark goes to the mm, which may be shared, so a task coming
> -	 * from a container never gets either. A setup task leaving a VE that
> -	 * is not pseudosuper drops the mark: after pseudosuper is cleared it
> -	 * cannot be told from the restored processes.
> +	 * A task the host sends into a VE (from ve0, or a setup task of a
> +	 * VE still pseudosuper) becomes a setup task if the VE starts or
> +	 * stays pseudosuper, else one hidden from the VE's tasks.
> +	 *
> +	 * The mark lives in the mm, which may be shared, so a task from a
> +	 * container keeps its mark, except a setup mark of a VE that left
> +	 * pseudosuper: it is an ordinary task now.
>  	 */
>  	if (mm && old_ve != ve) {
>  		if (ve_is_super(old_ve) ||
>  		    ve_vps_dumpable(mm, old_ve) == VD_VE_SETUP_TASK)
> -			mm->vps_dumpable = ve->state == VE_STATE_STARTING ?
> +			mm->vps_dumpable = ve->state == VE_STATE_STARTING ||
> +					   ve->is_pseudosuper ?
>  					   VD_VE_SETUP_TASK : VD_VE_ENTER_TASK;
>  		else if (mm->vps_dumpable == VD_VE_SETUP_TASK)
>  			mm->vps_dumpable = VD_PTRACE_COREDUMP;

[Severity: Low]
Is the VD_VE_ENTER_TASK arm of ve_current_is_host_task() still reachable
after this change?

ve_current_has_mark(ve, VD_VE_ENTER_TASK) requires ve->is_pseudosuper,
but ve_setup_task() now gives a host entrant VD_VE_ENTER_TASK only when
the VE is neither starting nor pseudosuper. If pseudosuper cannot be set
on a running VE (ve_pseudosuper_write() returning -EBUSY), that arm can
no longer match in normal operation.

The kerneldoc of ve_current_is_host_task() still describes a host task
that joined the VE after it started, such as the CRIU helper, as a case
separate from a setup task. The VD_VE_SETUP_TASK comment in
include/linux/mm_types.h still says "tasks the host sent into a starting
VE". Could both comments be updated, the dead arm removed or justified,
and the changelog say that CRIU-style helpers joining a running
pseudosuper VE now pass the stricter ve_current_is_pseudosuper() checks
and not only the weaker host-task check?

[Severity: Low]
This problem is only partly about the libvzctl helper: the mark is now
applied to every host task entering a pseudosuper VE, whatever its
ve->state. Once pseudosuper is cleared, ve_vps_dumpable() reports a
VD_VE_SETUP_TASK mm as VD_PTRACE_COREDUMP. Before this patch such a task
stayed VD_VE_ENTER_TASK, which ptrace denies and proc_exe_link() refuses.

Can a host task that setns()es into the VE in that window, and stays
alive without exec, then be ptraced by container tasks and have its
/proc/<pid>/exe read after pseudosuper clears? The libvzctl helper is not
affected because exec drops the mark, but the commit message and the code
comment only mention the exec case.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119-b4-prep-khorenko-vstor-156164-ve-setup-task-pseudosuper-v1-0-06fa0b8994a8@virtuozzo.com?part=1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-19 21:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 21:49 [Devel] [PATCH RFC hci-8.2 0/2] ve: Container start on the 26.3 kernel with libvzctl before 10.0.144 Konstantin Khorenko
2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 1/2] ve: mark a host task entering a pseudosuper VE as a setup task Konstantin Khorenko
2026-11-19 21:56   ` no-reply
2026-11-19 21:49 ` [Devel] [PATCH RFC hci-8.2 2/2] selftests/ve: check a host task entering a pseudosuper VE reaches its init Konstantin Khorenko
2026-11-19 21:54   ` no-reply

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox