[Devel] [PATCH hci-8.2 v4 1/3] ve: trust every host task of a pseudosuper VE until it execs

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 20 19:34:49 MSK 2026


Since "ve: hide the tasks that set up a starting VE from the rest of
it" a host task entering a VE is marked VD_VE_SETUP_TASK only while the
VE is VE_STATE_STARTING, and VD_VE_ENTER_TASK afterwards. While the VE
is pseudosuper only the setup tasks may reach each other and use the
pseudosuper relaxations; an entered task only skips the mount limit.

libvzctl before 10.0.144 writes START to ve.state, which ends in
VE_STATE_RUNNING, before it configures the disk: a helper then joins
the init task's namespaces one by one through setns(), opens
/proc/<init>/ns/mnt, makes the ploop device nodes and mounts the second
disk inside the container. It joined a running VE, so it is an entered
task, and the init task, a setup task, is 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.

Both kinds of task come from the host and have not exec'd. Before the
series every task of a pseudosuper VE had the relaxations, and libvzctl
runs its in-process helpers for disks, devices, bind mounts and GPUs
inside the VE after START, so trust them alike: ve_current_is_pseudosuper()
accepts either mark while the VE is pseudosuper, and
ve_current_is_host_task() goes. An entered task stays hidden from the
container after pseudosuper is cleared, as before, and a binary the host
tools exec still drops its mark.

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
Reviewed-by: Mirian Shilakadze <mirian.shilakadze at virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 fs/namespace.c           |  4 ++--
 include/linux/mm_types.h |  4 ++--
 include/linux/ve.h       |  2 --
 kernel/ptrace.c          |  2 +-
 kernel/ve/ve.c           | 43 ++++++++++++-------------------------------
 security/device_cgroup.c |  2 +-
 6 files changed, 18 insertions(+), 39 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 0eae165b1299e..db0100203dc29 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3226,7 +3226,7 @@ int ve_devmnt_process(struct ve_struct *ve, dev_t dev, void **data_pp, int remou
 		if (devmnt->dev == dev) {
 			err = ve_devmnt_check(data, devmnt->allowed_options);
 			/*
-			 * Setup tasks of a pseudosuper VE, ie the restore
+			 * Host tasks of a pseudosuper VE, ie the restore
 			 * procedure, skip the allowed options filtering, since
 			 * restore mode is special.
 			 */
@@ -3367,7 +3367,7 @@ int ve_devmnt_verify(struct ve_struct *ve, dev_t dev, char *opts, bool new_mount
 
 static inline int ve_try_reserve_mount(struct ve_struct *ve)
 {
-	int ret = ve_current_is_host_task(ve) || ve_is_super(get_exec_env());
+	int ret = ve_current_is_pseudosuper(ve) || ve_is_super(get_exec_env());
 	/*
 	 * Ignore limits in ve0 and for the host's tasks of a pseudosuper VE,
 	 * but still count.
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 53cb5ff32a233..388b256ed4af8 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1116,8 +1116,8 @@ extern struct mm_struct init_mm;
 #define VD_LICDATA_ACCESS	2/* tasks accessed containers license data,
 				  * no ptrace and no coredump allowed */
 #define VD_VE_SETUP_TASK	3/* tasks the host sent into a starting VE,
-				  * reachable only from each other while it
-				  * is pseudosuper, VD_PTRACE_COREDUMP after */
+				  * reachable only from the host's tasks while
+				  * it is pseudosuper, VD_PTRACE_COREDUMP after */
 
 /* Pointer magic because the dynamic array size confuses some compilers. */
 static inline void mm_init_cpumask(struct mm_struct *mm)
diff --git a/include/linux/ve.h b/include/linux/ve.h
index f83d2229d36de..d29339112f250 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -284,7 +284,6 @@ extern bool is_ve_init_net(const struct net *net);
 void ve_setup_task(struct task_struct *p, struct ve_struct *old_ve,
 		   struct ve_struct *ve);
 bool ve_current_is_pseudosuper(struct ve_struct *ve);
-bool ve_current_is_host_task(struct ve_struct *ve);
 int ve_vps_dumpable(struct mm_struct *mm, struct ve_struct *ve);
 
 void ve_set_rpc_kill_fn(void (*fn)(struct net *, bool));
@@ -419,7 +418,6 @@ static inline int vz_security_protocol_check(struct net *net, int protocol) { re
 static inline void ve_setup_task(struct task_struct *p, struct ve_struct *old_ve,
 				 struct ve_struct *ve) { }
 static inline bool ve_current_is_pseudosuper(struct ve_struct *ve) { return true; }
-static inline bool ve_current_is_host_task(struct ve_struct *ve) { return true; }
 #define ve_vps_dumpable(mm, ve)	((mm)->vps_dumpable)
 
 static inline void ve_set_rpc_kill_fn(void (*fn)(struct net *, bool)) { }
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index ff71c3e37bc14..c2b27e455c8ee 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -285,7 +285,7 @@ static bool task_still_dumpable(struct task_struct *task, unsigned int mode)
 	 * have its vps_dumpable confirmed, so deny it. This closes the window
 	 * where a dying CT task could be inspected (e.g. an fd stolen via
 	 * pidfd_getfd()) after exit_mm() cleared ->mm. While its VE is
-	 * pseudosuper, a setup task is only inspectable by another one.
+	 * pseudosuper, a setup task is only inspectable by a host task.
 	 */
 	if (!ve_is_super(get_exec_env())) {
 		struct ve_struct *ve = task_ve(task);
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 076892a750cfc..0ad145b38b54b 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1022,7 +1022,7 @@ static u64 ve_pseudosuper_read(struct cgroup_subsys_state *css, struct cftype *c
  * is allowed in a sake of container restore for example.
  *
  * To set this value up one has to be a real node's owner.
- * Inside the VE only its setup tasks may drop it, see
+ * Inside the VE only its host tasks may drop it, see
  * cgroup_file_write().
  */
 static int ve_pseudosuper_write(struct cgroup_subsys_state *css, struct cftype *cft, u64 val)
@@ -1780,44 +1780,25 @@ bool ve_check_trusted_exec(struct file *file, struct filename *name)
 	return false;
 }
 
-/**
- * ve_current_has_mark - is current a task of pseudosuper @ve with @mark
- * @ve: the VE
- * @mark: the vps_dumpable value
- */
-static bool ve_current_has_mark(struct ve_struct *ve, unsigned int mark)
-{
-	struct mm_struct *mm = current->mm;
-
-	return ve->is_pseudosuper && task_ve(current) == ve &&
-	       mm && mm->vps_dumpable == mark;
-}
-
 /**
  * ve_current_is_pseudosuper - may current use the pseudosuper relaxations of @ve
  * @ve: the VE that grants them
  *
- * Always true for ve0. Otherwise only a VD_VE_SETUP_TASK of @ve may, and only
- * until pseudosuper is cleared. Exec clears VD_VE_SETUP_TASK, so the container
- * binaries that the host tools run may not.
+ * Always true for ve0. Otherwise only a host task of @ve may, one the host
+ * sent in while @ve was starting (VD_VE_SETUP_TASK) or after that
+ * (VD_VE_ENTER_TASK), and only until pseudosuper is cleared. Exec clears
+ * both marks, so the container binaries that the host tools run may not.
  */
 bool ve_current_is_pseudosuper(struct ve_struct *ve)
 {
-	return ve_is_super(ve) || ve_current_has_mark(ve, VD_VE_SETUP_TASK);
-}
+	struct mm_struct *mm = current->mm;
 
-/**
- * ve_current_is_host_task - is current a host task of pseudosuper @ve
- * @ve: the VE
- *
- * Always true for ve0. Otherwise true for a setup task of @ve and for a host
- * task that joined @ve after it started, such as the CRIU helper that mounts
- * proc for a nested pid namespace, until pseudosuper is cleared.
- */
-bool ve_current_is_host_task(struct ve_struct *ve)
-{
-	return ve_current_is_pseudosuper(ve) ||
-	       ve_current_has_mark(ve, VD_VE_ENTER_TASK);
+	if (ve_is_super(ve))
+		return true;
+
+	return ve->is_pseudosuper && task_ve(current) == ve && mm &&
+	       (mm->vps_dumpable == VD_VE_SETUP_TASK ||
+		mm->vps_dumpable == VD_VE_ENTER_TASK);
 }
 
 /**
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index b0ef5f9380d1f..013fa00f15d8a 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -924,7 +924,7 @@ static int devcgroup_legacy_check_permission(short type, u32 major, u32 minor,
 #ifdef CONFIG_VE
 	/*
 	 * When restoring container allow everything to its
-	 * setup tasks in pseudosuper state. We need this for
+	 * host tasks in pseudosuper state. We need this for
 	 * early mounting of second ploop device. Still, don't
 	 * change behaviour on the ve0.
 	 */

-- 
2.43.0



More information about the Devel mailing list