All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE
@ 2026-11-18 10:36 Mirian Shilakadze
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

While a container starts or is restored, ve.pseudosuper is on and its
relaxations apply to every process in the container. The container's
own binaries that vzctl and CRIU run in that window get them too, such
as quotaon at start and the tee that vz-rst-action runs at post-restore.
Such a binary can rewrite the container's root memory.max, skip the
mount limit and the mount option filter, use NETLINK_REPAIR, or clear
pseudosuper early. During a restore it can also open /proc/<pid>/fd of
CRIU's restoring tasks and take CRIU's log, its /proc fd and the
transport socket.

This series marks the tasks the host sends into a starting VE as setup
tasks. Fork keeps the mark, exec drops it, and only a task coming from
the host gets it.

- 1/6 passes ve_setup_task() the VE a task comes from
- 2/6 hides only the tasks the host sends into a VE, in any state but
  starting
- 3/6 marks setup tasks and lets them be reached only by each other
  while the VE is pseudosuper
- 4/6 to 6/6 give the pseudosuper relaxations only to setup tasks: the
  container's root cgroup files, the mount filter and limit, and the
  rest. A host task that joins the VE after it has started, such as the
  CRIU helper that mounts proc for a nested pid namespace, still skips
  the mount limit.

Once pseudosuper is cleared, the restored processes are ordinary
container processes again. vzctl and CRIU need no change.

Changes since v2, after Konstantin's review and Sashiko's:
- a setup task that leaves its VE after pseudosuper is cleared drops
  the mark, so it is not a setup task in another pseudosuper VE. It is
  not hidden in the VE it enters either, the 3/6 message says why (3/6)
- ve_try_reserve_mount() no longer tests ve_is_super(ve), and its
  comment says the limit is skipped for the host's tasks of a
  pseudosuper VE (5/6)
- the paragraph about tasks leaving a pseudosuper VE stands on its own
  in the 3/6 message, the ve_vps_dumpable() kernel-doc no longer reads
  as if a setup task stayed one in ve0, and the 4/6 comment says
  "one has to be"
- the v1 change log below drops the line about a task that setns()es
  into its own VE, as v1 kept that mark too

Changes since v1, after Konstantin's review and Sashiko's:
- a host task that moves from a starting VE into a running one is
  hidden there again: a setup task leaving a VE that is still
  pseudosuper counts as sent by the host (2/6 and 3/6)
- ve_setup_task() runs before the old VE namespace is put, which may
  drop the last reference to the VE it now reads (1/6)
- 5/6 has a new subject and uses ve_current_is_host_task() instead of
  the open-coded test in the mount limit
- 3/6 adds ve_current_has_mark(), which ve_current_is_pseudosuper()
  and the 5/6 helper share
- the comments on VD_VE_SETUP_TASK, ve_current_is_pseudosuper(),
  ve_pseudosuper_write(), ve_devmnt_process() and
  devcgroup_legacy_check_permission() describe the new checks
- the 2/6 message says why a container task must not get
  VD_VE_ENTER_TASK and that a task entering its nested VE is no longer
  hidden there, and its first paragraph is reworded

- Link to v1: http://lore.virtuozzo.com/20261116104552.102938-1-mirian.shilakadze@virtuozzo.com
- Link to v2: http://lore.virtuozzo.com/20261117101329.225854-1-mirian.shilakadze@virtuozzo.com

Tested on the hci-8.2 tip with this series, on a VHI 8.2 node with
vzctl 10.0.159 and criu 4.2.1.18, stock against patched:
- a probe in place of the container's quotaon and tee: on stock it
  reads the fds of every restoring task, restore.log included, sets
  NETLINK_REPAIR and rewrites the root memory.max, on patched all of
  it is refused
- the same probe gains nothing by moving into a nested VE and
  unsharing it from a vfork child that shares its mm
- a host task that enters a starting VE, then joins a running
  container and its user namespace without exec: hidden on stock and
  on patched
- the same task moving on only after pseudosuper is cleared: hidden
  on stock, visible on patched, as 3/6 says
- a setup task of a VE whose pseudosuper is cleared, moving on into
  another starting VE: gets NETLINK_REPAIR there on stock and with v2,
  refused with v3. A task the host sends into that VE still gets it.
- a host task that joins the container and its user namespace without
  exec stays hidden, and becomes visible once it execs
- a container with a nested pid namespace restored with its mount
  limit lowered to 10: restores. Without the exemption in 5/6 the
  proc mount for that namespace failed with ENOMEM.
- after resume the container sees its restored processes and they
  dump core, and start, stop, suspend, resume, a second disk and a
  container at its mount limit behave as on stock
- the VE selftests (ve, ve_devcg_bpf, ve_printk): same results as on
  stock, ve_ns_owner_test fails on both
- CRIU zdtm in the ve flavor, with every userns test forced into it:
  441 passed, 8 failed, all 8 fail on stock too. bridge, sit and
  socket_udplite cannot set up their devices in a VE on that node.
- vzctl pytest 10.0.159: 1377 passed, 0 failed

Mirian Shilakadze (6):
  ve: tell ve_setup_task() which VE the task comes from
  ve: hide only the tasks the host sends into a VE
  ve: hide the tasks that set up a starting VE from the rest of it
  cgroup: give the CT root file writes and hidden roots only to setup
    tasks
  fs: keep the mount relaxations of a pseudosuper VE from container
    binaries
  ve: give the remaining pseudosuper relaxations only to setup tasks

 fs/coredump.c            |  2 +-
 fs/namespace.c           | 18 ++++----
 include/linux/mm_types.h |  3 ++
 include/linux/ve.h       | 12 ++++-
 kernel/cgroup/cgroup.c   |  4 +-
 kernel/ptrace.c          | 23 ++++++++--
 kernel/sys.c             |  2 +-
 kernel/ve/ve.c           | 96 +++++++++++++++++++++++++++++++++++-----
 kernel/ve/ve_namespace.c | 10 +++--
 net/netlink/af_netlink.c |  2 +-
 security/device_cgroup.c |  8 ++--
 11 files changed, 143 insertions(+), 37 deletions(-)

-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:41   ` no-reply
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE Mirian Shilakadze
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

The next changes mark a task entering a VE by where it comes from. Pass
the VE the task leaves to ve_setup_task(), and call it before the old
VE namespace is put, as that may drop the last reference to that VE.
No functional change.

Feature: ve: ve generic structures
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 include/linux/ve.h       |  6 ++++--
 kernel/ve/ve.c           |  3 ++-
 kernel/ve/ve_namespace.c | 10 +++++++---
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index a400d21593b2..2fe1a1c9ff55 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -282,7 +282,8 @@ int ve_net_hide_sysctl(struct net *net);
 
 extern bool is_ve_init_net(const struct net *net);
 
-void ve_setup_task(struct task_struct *p, struct ve_struct *ve);
+void ve_setup_task(struct task_struct *p, struct ve_struct *old_ve,
+		   struct ve_struct *ve);
 
 void ve_set_rpc_kill_fn(void (*fn)(struct net *, bool));
 
@@ -390,7 +391,8 @@ static inline struct cgroup_subsys_state *css_ve_root1(
 static inline int vz_security_family_check(struct net *net, int family, int type) { return 0; }
 static inline int vz_security_protocol_check(struct net *net, int protocol) { return 0; }
 
-static inline void ve_setup_task(struct task_struct *p, struct ve_struct *ve) { }
+static inline void ve_setup_task(struct task_struct *p, struct ve_struct *old_ve,
+				 struct ve_struct *ve) { }
 
 static inline void ve_set_rpc_kill_fn(void (*fn)(struct net *, bool)) { }
 
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index cdfd03416b39..72a2834707c5 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1831,7 +1831,8 @@ int ve_get_cpu_stat(struct ve_struct *ve, struct kernel_cpustat *kstat)
 }
 EXPORT_SYMBOL(ve_get_cpu_stat);
 
-void ve_setup_task(struct task_struct *task, struct ve_struct *ve)
+void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
+		   struct ve_struct *ve)
 {
 	if (ve == &ve0)
 		return;
diff --git a/kernel/ve/ve_namespace.c b/kernel/ve/ve_namespace.c
index 6b12bcd605ea..890fa126bbdd 100644
--- a/kernel/ve/ve_namespace.c
+++ b/kernel/ve/ve_namespace.c
@@ -106,6 +106,7 @@ int copy_ve_ns(unsigned long flags, struct task_struct *p)
 {
 	struct user_namespace *user_ns = task_cred_xxx(p, user_ns);
 	struct ve_namespace *old_ve_ns = p->ve_ns;
+	struct ve_struct *old_ve = p->task_ve;
 	struct ve_namespace *new_ve_ns;
 
 	if (!(flags & CLONE_NEWVE)) {
@@ -123,7 +124,7 @@ int copy_ve_ns(unsigned long flags, struct task_struct *p)
 	p->ve_ns = new_ve_ns;
 	p->task_ve = new_ve_ns->ve;
 
-	ve_setup_task(p, p->task_ve);
+	ve_setup_task(p, old_ve, p->task_ve);
 
 	return 0;
 }
@@ -161,6 +162,7 @@ void free_ve_ns(struct ve_namespace *ns)
 void switch_ve_namespace(struct task_struct *p, struct ve_namespace *new)
 {
 	struct ve_namespace *old;
+	struct ve_struct *old_ve;
 
 	/*
 	 * FIXME
@@ -170,14 +172,16 @@ void switch_ve_namespace(struct task_struct *p, struct ve_namespace *new)
 
 	scoped_guard(task_lock, p) {
 		old = p->ve_ns;
+		old_ve = p->task_ve;
 		p->ve_ns = new;
 		p->task_ve = new ? new->ve : &ve0;
 	}
 
+	/* @old may hold the last reference to @old_ve */
+	ve_setup_task(p, old_ve, p->task_ve);
+
 	if (old)
 		put_ve_ns(old);
-
-	ve_setup_task(p, p->task_ve);
 }
 
 void exit_ve_namespace(struct task_struct *p)
-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:42   ` no-reply
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it Mirian Shilakadze
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

ve_setup_task() marks a task entering a running VE VD_VE_ENTER_TASK,
which hides it from ptrace and /proc/<pid>/exe inside the VE. A
container task gets the mark too when it setns()es into its own VE or
enters a nested one, and a host task entering a stopping or stopped VE
is not hidden at all.

The mark says a task is the host's, a later change lets it skip the
mount limit of a pseudosuper VE, and it goes to the mm, which a
container task may share with others. So mark only tasks coming from
the host, in every VE state but starting, which the next change
handles. A task entering its nested VE is no longer hidden there. In a
pseudosuper VE the host's tasks cannot be told from the container's
yet, so a task leaving one is still marked until the next change.

Feature: trace: prohibit tracing sensitive tasks from CT
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 kernel/ve/ve.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 72a2834707c5..ff1c7f9b88c7 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1837,8 +1837,14 @@ void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
 	if (ve == &ve0)
 		return;
 
-	/* this prohibits ptracing of task entered to VE from host system */
-	if (VE_IS_RUNNING(ve) && task->mm)
+	/*
+	 * A task the host sends into a started VE is hidden from the tasks of
+	 * the VE. The mark goes to the mm, which may be shared, so a task
+	 * coming from a container never gets it, unless the container is
+	 * pseudosuper: the host's tasks there cannot be told from its own.
+	 */
+	if (task->mm && old_ve != ve && ve->state != VE_STATE_STARTING &&
+	    (ve_is_super(old_ve) || old_ve->is_pseudosuper))
 		task->mm->vps_dumpable = VD_VE_ENTER_TASK;
 
 	/* Drop OOM protection. */
-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:47   ` no-reply
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks Mirian Shilakadze
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

CRIU's restoring tasks enter the VE before it runs, so they stay
VD_PTRACE_COREDUMP. A container binary run during the restore, such as
the tee that post-restore runs via vzctl exec3, can open their
/proc/<pid>/fd and take CRIU's log, its /proc fd and the transport
socket.

Mark a task the host sends into a starting VE as VD_VE_SETUP_TASK.
Fork keeps the mark and exec drops it. While the VE is pseudosuper, such
a task dumps no core and is reachable only from another setup task of
the VE, so CRIU's tasks still reach each other and what they exec does
not. Once pseudosuper is cleared the mark counts as VD_PTRACE_COREDUMP,
so the restored processes become ordinary ones.

Of the tasks leaving a pseudosuper VE, only its setup tasks are marked
in the VE they enter, so a host task that moves on to a running VE
stays hidden there.

A setup task that leaves after pseudosuper is cleared is no longer
hidden in the VE it enters. It cannot be told from the restored
processes, which carry the same mark and are the container's own
processes now. It drops the mark instead, so the mark does not count
again in another pseudosuper VE.

Feature: trace: prohibit tracing sensitive tasks from CT
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 fs/coredump.c            |  2 +-
 include/linux/mm_types.h |  3 ++
 include/linux/ve.h       |  4 +++
 kernel/ptrace.c          | 23 +++++++++++---
 kernel/ve/ve.c           | 67 +++++++++++++++++++++++++++++++++++-----
 5 files changed, 87 insertions(+), 12 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 3d15612e3493..6977c31aad59 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -618,7 +618,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
 		goto fail;
 
 	/* Avoid dumping sensitive tasks */
-	if (mm->vps_dumpable != VD_PTRACE_COREDUMP)
+	if (ve_vps_dumpable(mm, get_exec_env()) != VD_PTRACE_COREDUMP)
 		goto fail;
 	cred = prepare_creds();
 	if (!cred)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index befdf38ef855..53cb5ff32a23 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1115,6 +1115,9 @@ extern struct mm_struct init_mm;
 #define VD_PTRACE_COREDUMP	1/* tasks with ptrace and coredump allowed */
 #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 */
 
 /* 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 2fe1a1c9ff55..56c310205394 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -284,6 +284,8 @@ 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);
+int ve_vps_dumpable(struct mm_struct *mm, struct ve_struct *ve);
 
 void ve_set_rpc_kill_fn(void (*fn)(struct net *, bool));
 
@@ -393,6 +395,8 @@ 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; }
+#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 faf60bb8ae2c..ff71c3e37bc1 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -284,11 +284,26 @@ static bool task_still_dumpable(struct task_struct *task, unsigned int mode)
 	 * whose mm was already dropped in exit_mm() or a kernel thread - cannot
 	 * 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.
+	 * pidfd_getfd()) after exit_mm() cleared ->mm. While its VE is
+	 * pseudosuper, a setup task is only inspectable by another one.
 	 */
-	if (!ve_is_super(get_exec_env()) &&
-	    (!mm || mm->vps_dumpable != VD_PTRACE_COREDUMP))
-		return false;
+	if (!ve_is_super(get_exec_env())) {
+		struct ve_struct *ve = task_ve(task);
+
+		if (!mm)
+			return false;
+
+		switch (ve_vps_dumpable(mm, ve)) {
+		case VD_PTRACE_COREDUMP:
+			break;
+		case VD_VE_SETUP_TASK:
+			if (!ve_current_is_pseudosuper(ve))
+				return false;
+			break;
+		default:
+			return false;
+		}
+	}
 
 	if (mm) {
 		if (get_dumpable(mm) == SUID_DUMP_USER)
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index ff1c7f9b88c7..9c7dc3a8612a 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1778,6 +1778,49 @@ 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.
+ */
+bool ve_current_is_pseudosuper(struct ve_struct *ve)
+{
+	return ve_is_super(ve) || ve_current_has_mark(ve, VD_VE_SETUP_TASK);
+}
+
+/**
+ * ve_vps_dumpable - vps_dumpable of a task as the access checks see it
+ * @mm: the task's mm
+ * @ve: the task's VE
+ *
+ * A setup task is an ordinary one in ve0, and in @ve once @ve leaves
+ * pseudosuper, which cannot be set again while @ve runs.
+ */
+int ve_vps_dumpable(struct mm_struct *mm, struct ve_struct *ve)
+{
+	if (mm->vps_dumpable == VD_VE_SETUP_TASK &&
+	    (ve_is_super(ve) || !ve->is_pseudosuper))
+		return VD_PTRACE_COREDUMP;
+
+	return mm->vps_dumpable;
+}
+
 #ifdef CONFIG_CGROUP_SCHED
 int ve_show_cpu_stat(struct ve_struct *ve, struct seq_file *p)
 {
@@ -1834,18 +1877,28 @@ EXPORT_SYMBOL(ve_get_cpu_stat);
 void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
 		   struct ve_struct *ve)
 {
+	struct mm_struct *mm = task->mm;
+
 	if (ve == &ve0)
 		return;
 
 	/*
-	 * A task the host sends into a started VE is hidden from the tasks of
-	 * the VE. The mark goes to the mm, which may be shared, so a task
-	 * coming from a container never gets it, unless the container is
-	 * pseudosuper: the host's tasks there cannot be told from its own.
+	 * 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.
 	 */
-	if (task->mm && old_ve != ve && ve->state != VE_STATE_STARTING &&
-	    (ve_is_super(old_ve) || old_ve->is_pseudosuper))
-		task->mm->vps_dumpable = VD_VE_ENTER_TASK;
+	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 ?
+					   VD_VE_SETUP_TASK : VD_VE_ENTER_TASK;
+		else if (mm->vps_dumpable == VD_VE_SETUP_TASK)
+			mm->vps_dumpable = VD_PTRACE_COREDUMP;
+	}
 
 	/* Drop OOM protection. */
 	task->signal->oom_score_adj = 0;
-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (2 preceding siblings ...)
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:46   ` no-reply
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries Mirian Shilakadze
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

While a VE is pseudosuper, any task in it may write the read-only files
of the container's root cgroup and sees the hidden cgroup roots. That
includes the container's own binaries that vzctl and CRIU run during
start or restore. quotaon at start can rewrite the root memory.max, and
any of them can write 0 to ve.pseudosuper, which ends the window early
and makes CRIU's restoring tasks reachable again.

Use ve_current_is_pseudosuper() for both, so only setup tasks get them.

Feature: ve: CRIU support
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 kernel/cgroup/cgroup.c | 4 ++--
 kernel/ve/ve.c         | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 77903a56b79e..b0f2e7a24b5f 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4765,7 +4765,7 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf,
 
 	if (!ve_is_super(get_exec_env())
 	    && test_bit(CGRP_VE_ROOT, &cgrp->flags)
-	    && !get_exec_env()->is_pseudosuper
+	    && !ve_current_is_pseudosuper(get_exec_env())
 	    && !(cft->flags & CFTYPE_VE_WRITABLE))
 		return -EPERM;
 
@@ -6947,7 +6947,7 @@ int ve_hide_cgroups(struct cgroup_root *root)
 	 * Hide ve cgroup in CT for docker, still showing it to pseudosuper
 	 * (criu), and also hide non-virtualized cgroups.
 	 */
-	return !ve_is_super(ve) && !ve->is_pseudosuper &&
+	return !ve_is_super(ve) && !ve_current_is_pseudosuper(ve) &&
 	       ((root->subsys_mask & hidden_mask) ||
 		!is_virtualized_cgroot(root));
 }
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 9c7dc3a8612a..5dde3bde2c53 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1019,9 +1019,9 @@ static u64 ve_pseudosuper_read(struct cgroup_subsys_state *css, struct cftype *c
  * operations such as mounting cgroups from inside of VE context
  * is allowed in a sake of container restore for example.
  *
- * While dropping pseudosuper privilegues is allowed from
- * any context to set this value up one have to be a real
- * node's owner.
+ * 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
+ * cgroup_file_write().
  */
 static int ve_pseudosuper_write(struct cgroup_subsys_state *css, struct cftype *cft, u64 val)
 {
-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (3 preceding siblings ...)
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:50   ` no-reply
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks Mirian Shilakadze
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

While a VE is pseudosuper, any task in it skips the device mount option
filter and the VE mount limit, including the container's own binaries
that vzctl and CRIU run.

Give the option filter relaxation only to setup tasks. The mount limit
also lets through a host task that joined the VE after it started, such
as the CRIU helper that mounts proc for a nested pid namespace during
restore. Without that, restoring such a container near its mount limit
fails. Add ve_current_is_host_task() for the two kinds of host task.

Feature: ve: CRIU support
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 fs/namespace.c     | 18 ++++++++++--------
 include/linux/ve.h |  2 ++
 kernel/ve/ve.c     | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index d622d9b72d32..0eae165b1299 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3226,11 +3226,11 @@ 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);
 			/*
-			 * In case of @is_pseudosuper set, ie restore procedure,
-			 * we don't check for allowed options filtering, since
+			 * Setup tasks of a pseudosuper VE, ie the restore
+			 * procedure, skip the allowed options filtering, since
 			 * restore mode is special.
 			 */
-			if (ve->is_pseudosuper)
+			if (ve_current_is_pseudosuper(ve))
 				err = 0;
 
 			if (!err && !remount)
@@ -3255,7 +3255,7 @@ int ve_devmnt_process(struct ve_struct *ve, dev_t dev, void **data_pp, int remou
 			 * the way userspace tool restore container
 			 * it might be nonempty as well.
 			 */
-			if (ve->is_pseudosuper) {
+			if (ve_current_is_pseudosuper(ve)) {
 				err = 0;
 			} else if (((char *)*data_pp)[0] == '\0') {
 				err = 0;
@@ -3330,7 +3330,7 @@ int ve_devmnt_verify(struct ve_struct *ve, dev_t dev, char *opts, bool new_mount
 	bool found = false;
 	int err = 0;
 
-	if (ve->is_pseudosuper)
+	if (ve_current_is_pseudosuper(ve))
 		return 0;
 
 	mutex_lock(&ve->devmnt_mutex);
@@ -3367,9 +3367,11 @@ 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_is_super(ve) || ve->is_pseudosuper ||
-		  ve_is_super(get_exec_env());
-	/* Ignore limits in ve0 and pseudosuper cases, but still count. */
+	int ret = ve_current_is_host_task(ve) || ve_is_super(get_exec_env());
+	/*
+	 * Ignore limits in ve0 and for the host's tasks of a pseudosuper VE,
+	 * but still count.
+	 */
 	if (ret)
 		atomic_dec(&ve->mnt_avail_nr);
 	else
diff --git a/include/linux/ve.h b/include/linux/ve.h
index 56c310205394..5859550eb07c 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -285,6 +285,7 @@ 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));
@@ -396,6 +397,7 @@ 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/ve/ve.c b/kernel/ve/ve.c
index 5dde3bde2c53..e5b152a83225 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1804,6 +1804,20 @@ bool ve_current_is_pseudosuper(struct ve_struct *ve)
 	return ve_is_super(ve) || ve_current_has_mark(ve, VD_VE_SETUP_TASK);
 }
 
+/**
+ * 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);
+}
+
 /**
  * ve_vps_dumpable - vps_dumpable of a task as the access checks see it
  * @mm: the task's mm
-- 
2.43.0

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

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

* [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (4 preceding siblings ...)
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries Mirian Shilakadze
@ 2026-11-18 10:36 ` Mirian Shilakadze
  2026-11-18 10:49   ` no-reply
  2026-11-18 11:54 ` [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Vasileios Almpanis
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 10:36 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

While a VE is pseudosuper, any task in it may set NETLINK_REPAIR, set
its CT fields with prctl, write ve.features, ve.failcount, ve.pid_max
and ve.aio_max_nr, and pass the legacy device cgroup check. That
includes the container's own binaries that vzctl and CRIU run.

Use ve_current_is_pseudosuper() for these as well.

Feature: ve: CRIU support
https://virtuozzo.atlassian.net/browse/VSTOR-151265
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 kernel/sys.c             | 2 +-
 kernel/ve/ve.c           | 8 ++++----
 net/netlink/af_netlink.c | 2 +-
 security/device_cgroup.c | 8 ++++----
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 80f8b9eb17c3..21650d331a42 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2324,7 +2324,7 @@ static int prctl_set_task_ct_fields(struct task_struct *t, unsigned long arg,
 #ifdef CONFIG_VE
 	struct ve_struct *ve __free(put_ve) = get_task_ve(t);
 
-	if (!ve_is_super(ve) && !ve->is_pseudosuper)
+	if (!ve_is_super(ve) && !ve_current_is_pseudosuper(ve))
 		return -EPERM;
 #endif
 
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index e5b152a83225..0483f9f6d30a 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1066,7 +1066,7 @@ static int ve_features_write(struct cgroup_subsys_state *css, struct cftype *cft
 	struct ve_struct *ve = css_to_ve(css);
 
 	if (!ve_is_super(get_exec_env()) &&
-	    !ve->is_pseudosuper)
+	    !ve_current_is_pseudosuper(ve))
 		return -EPERM;
 
 	down_write(&ve->op_sem);
@@ -1119,7 +1119,7 @@ static ssize_t ve_failcount_write(struct kernfs_open_file *of, char *buf,
 	const struct ve_failcount_entry *entry;
 	atomic_t *fc;
 
-	if (!ve_is_super(get_exec_env()) && !ve->is_pseudosuper)
+	if (!ve_is_super(get_exec_env()) && !ve_current_is_pseudosuper(ve))
 		return -EPERM;
 
 	for (entry = ve_failcounts; entry->name; entry++) {
@@ -1219,7 +1219,7 @@ static int ve_pid_max_write_running_u64(struct cgroup_subsys_state *css,
 	struct nsproxy *ve_nsproxy;
 
 	if (!ve_is_super(get_exec_env()) &&
-	    !ve->is_pseudosuper)
+	    !ve_current_is_pseudosuper(ve))
 		return -EPERM;
 
 	rcu_read_lock();
@@ -1437,7 +1437,7 @@ static int ve_aio_max_nr_write(struct cgroup_subsys_state *css,
 {
 	struct ve_struct *ve = css_to_ve(css);
 
-	if (!ve_is_super(get_exec_env()) && !ve->is_pseudosuper)
+	if (!ve_is_super(get_exec_env()) && !ve_current_is_pseudosuper(ve))
 		return -EPERM;
 
 	down_write(&ve->op_sem);
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f686e6ea30ce..e808d8ae3e1e 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1695,7 +1695,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
 #ifdef CONFIG_VE
 		{
 			struct ve_struct *ve = get_exec_env();
-			if (!ve_is_super(ve) && !ve->is_pseudosuper)
+			if (!ve_is_super(ve) && !ve_current_is_pseudosuper(ve))
 				return -ENOPROTOOPT;
 		}
 #endif
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 1629896b2ea1..b0ef5f9380d1 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -923,15 +923,15 @@ static int devcgroup_legacy_check_permission(short type, u32 major, u32 minor,
 
 #ifdef CONFIG_VE
 	/*
-	 * When restoring container allow everything in
-	 * pseudosuper state. We need this for early
-	 * mounting of second ploop device. Still, don't
+	 * When restoring container allow everything to its
+	 * setup tasks in pseudosuper state. We need this for
+	 * early mounting of second ploop device. Still, don't
 	 * change behaviour on the ve0.
 	 */
 	if (!rc) {
 		struct ve_struct *ve = get_exec_env();
 
-		if (!ve_is_super(ve) && ve->is_pseudosuper)
+		if (!ve_is_super(ve) && ve_current_is_pseudosuper(ve))
 			return 0;
 		return -EPERM;
 	}
-- 
2.43.0

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

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

* Re: [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
@ 2026-11-18 10:41   ` no-reply
  0 siblings, 0 replies; 17+ messages in thread
From: no-reply @ 2026-11-18 10:41 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> The next changes mark a task entering a VE by where it comes from. Pass
> the VE the task leaves to ve_setup_task(), and call it before the old
> VE namespace is put, as that may drop the last reference to that VE.
> No functional change.
> 
> Feature: ve: ve generic structures
> https://virtuozzo.atlassian.net/browse/VSTOR-151265
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=1


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

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

* Re: [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE Mirian Shilakadze
@ 2026-11-18 10:42   ` no-reply
  0 siblings, 0 replies; 17+ messages in thread
From: no-reply @ 2026-11-18 10:42 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> ve_setup_task() marks a task entering a running VE VD_VE_ENTER_TASK,
> which hides it from ptrace and /proc/<pid>/exe inside the VE. A
> container task gets the mark too when it setns()es into its own VE or
> enters a nested one, and a host task entering a stopping or stopped VE
> is not hidden at all.
> 
> The mark says a task is the host's, a later change lets it skip the
> mount limit of a pseudosuper VE, and it goes to the mm, which a
> container task may share with others. So mark only tasks coming from
> the host, in every VE state but starting, which the next change
> handles. A task entering its nested VE is no longer hidden there. In a
> pseudosuper VE the host's tasks cannot be told from the container's
> yet, so a task leaving one is still marked until the next change.
> 
> Feature: trace: prohibit tracing sensitive tasks from CT
> https://virtuozzo.atlassian.net/browse/VSTOR-151265
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=2


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

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

* Re: [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks Mirian Shilakadze
@ 2026-11-18 10:46   ` no-reply
  0 siblings, 0 replies; 17+ messages in thread
From: no-reply @ 2026-11-18 10:46 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> While a VE is pseudosuper, any task in it may write the read-only files
> of the container's root cgroup and sees the hidden cgroup roots. That
> includes the container's own binaries that vzctl and CRIU run during
> start or restore. quotaon at start can rewrite the root memory.max, and
> any of them can write 0 to ve.pseudosuper, which ends the window early
> and makes CRIU's restoring tasks reachable again.
> 
> Use ve_current_is_pseudosuper() for both, so only setup tasks get them.
> 
> Feature: ve: CRIU support
> https://virtuozzo.atlassian.net/browse/VSTOR-151265
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=4


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

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

* Re: [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it Mirian Shilakadze
@ 2026-11-18 10:47   ` no-reply
  2026-11-18 11:32     ` Mirian Shilakadze
  0 siblings, 1 reply; 17+ messages in thread
From: no-reply @ 2026-11-18 10:47 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ve: VD_VE_SETUP_TASK mark is applied on STARTING state without
  checking is_pseudosuper
--

commit 1bee34c8ee24e68c2c82698a010c5bdd82a015b8
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

ve: hide the tasks that set up a starting VE from the rest of it

The patch marks tasks the host sends into a starting VE as VD_VE_SETUP_TASK. While the VE is pseudosuper, such tasks dump no core and are reachable only from other setup tasks of that VE. Once pseudosuper is cleared, the mark counts as VD_PTRACE_COREDUMP.

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

[ ... ]

> @@ -1836,18 +1879,28 @@ EXPORT_SYMBOL(ve_get_cpu_stat);
>  void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
>  		   struct ve_struct *ve)
>  {
[ ... ]
> +	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 ?
> +					   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]
Can a task get the VD_VE_SETUP_TASK mark in a VE that is not pseudosuper? The mark is chosen from ve->state alone, and ve->is_pseudosuper is never checked here.

ve_pseudosuper_write() only refuses a 0->1 flip when VE_IS_RUNNING(ve) || ve->ve_nsproxy. ve_nsproxy is set only in ve_start_container(), so the host can still set pseudosuper=1 on a STARTING VE that already has tasks. ve_vps_dumpable() reports the mark as VD_PTRACE_COREDUMP only while is_pseudosuper is 0. After the flip, the already-marked tasks become setup tasks again. They are then unreachable from ordinary tasks of the VE and dump no core.

This also contradicts the ve_vps_dumpable() comment, which says pseudosuper "cannot be set again while @ve runs". Would it be better to require ve->is_pseudosuper when applying the mark? Alternatively, reject the 0->1 flip once the VE has tasks.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=3

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

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

* Re: [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks Mirian Shilakadze
@ 2026-11-18 10:49   ` no-reply
  0 siblings, 0 replies; 17+ messages in thread
From: no-reply @ 2026-11-18 10:49 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> While a VE is pseudosuper, any task in it may set NETLINK_REPAIR, set
> its CT fields with prctl, write ve.features, ve.failcount, ve.pid_max
> and ve.aio_max_nr, and pass the legacy device cgroup check. That
> includes the container's own binaries that vzctl and CRIU run.
> 
> Use ve_current_is_pseudosuper() for these as well.
> 
> Feature: ve: CRIU support
> https://virtuozzo.atlassian.net/browse/VSTOR-151265
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=6


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

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

* Re: [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries Mirian Shilakadze
@ 2026-11-18 10:50   ` no-reply
  0 siblings, 0 replies; 17+ messages in thread
From: no-reply @ 2026-11-18 10:50 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> While a VE is pseudosuper, any task in it skips the device mount option
> filter and the VE mount limit, including the container's own binaries
> that vzctl and CRIU run.
> 
> Give the option filter relaxation only to setup tasks. The mount limit
> also lets through a host task that joined the VE after it started, such
> as the CRIU helper that mounts proc for a nested pid namespace during
> restore. Without that, restoring such a container near its mount limit
> fails. Add ve_current_is_host_task() for the two kinds of host task.
> 
> Feature: ve: CRIU support
> https://virtuozzo.atlassian.net/browse/VSTOR-151265
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118103656.363171-1-mirian.shilakadze@virtuozzo.com?part=5


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

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

* Re: [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it
  2026-11-18 10:47   ` no-reply
@ 2026-11-18 11:32     ` Mirian Shilakadze
  0 siblings, 0 replies; 17+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:32 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel


On 11/18/26 2:47 PM, no-reply@sashiko.virtuozzo.com wrote:
> Can a task get the VD_VE_SETUP_TASK mark in a VE that is not pseudosuper? The mark is chosen from ve->state alone, and ve->is_pseudosuper is never checked here.
> 
> ve_pseudosuper_write() only refuses a 0->1 flip when VE_IS_RUNNING(ve) || ve->ve_nsproxy. ve_nsproxy is set only in ve_start_container(), so the host can still set pseudosuper=1 on a STARTING VE that already has tasks. ve_vps_dumpable() reports the mark as VD_PTRACE_COREDUMP only while is_pseudosuper is 0. After the flip, the already-marked tasks become setup tasks again. They are then unreachable from ordinary tasks of the VE and dump no core.
> 
> This also contradicts the ve_vps_dumpable() comment, which says pseudosuper "cannot be set again while @ve runs". Would it be better to require ve->is_pseudosuper when applying the mark? Alternatively, reject the 0->1 flip once the VE has tasks.

I think this one is fine as is. Only the host can set pseudosuper, and 
vzctl sets it before the first task enters the VE (do_env_create()). The 
mark can only be on tasks the host sent into the starting VE, and those 
are the setup tasks, so if the host sets pseudosuper again before START 
they are setup tasks again. A container task never gets the mark.

The ve_vps_dumpable() comment means after START, when 
ve_pseudosuper_write() refuses to set it. "Once @ve has started" would 
say it better, I will change it if there is a v4.

-- 
Best regards, Mirian Shilakadze
Linux C Virtualization Developer, Virtuozzo.

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

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

* Re: [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (5 preceding siblings ...)
  2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks Mirian Shilakadze
@ 2026-11-18 11:54 ` Vasileios Almpanis
  2026-11-18 15:14 ` Konstantin Khorenko
  2026-11-18 15:14 ` Konstantin Khorenko
  8 siblings, 0 replies; 17+ messages in thread
From: Vasileios Almpanis @ 2026-11-18 11:54 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

On Wed, 18 Nov 2026 14:36:32 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> ve: give the pseudosuper privileges only to the tasks setting up a VE
> 
> While a container starts or is restored, ve.pseudosuper is on and its
> relaxations apply to every process in the container. The container's
> own binaries that vzctl and CRIU run in that window get them too, such
> as quotaon at start and the tee that vz-rst-action runs at post-restore.
> Such a binary can rewrite the container's root memory.max, skip the
> mount limit and the mount option filter, use NETLINK_REPAIR, or clear
> pseudosuper early. During a restore it can also open /proc/<pid>/fd of
> CRIU's restoring tasks and take CRIU's log, its /proc fd and the
> transport socket.
> 
> [...]

Reviewed-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>

-- 
Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

* Re: [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (6 preceding siblings ...)
  2026-11-18 11:54 ` [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Vasileios Almpanis
@ 2026-11-18 15:14 ` Konstantin Khorenko
  2026-11-18 15:14 ` Konstantin Khorenko
  8 siblings, 0 replies; 17+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 15:14 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

Applying as is.

On Wed, 18 Nov 2026 14:36:32 +0400, Mirian Shilakadze wrote:
> Changes since v2, after Konstantin's review and Sashiko's:

All four v2 items are done. The new reset in 3/6 also takes care of
Sashiko's v2 remark about a stale mark counting in another
pseudosuper VE.

Sashiko's v3 remark on 3/6 needs no change: pseudosuper can be set
only from ve0 and only before the VE starts, so every task that has
the mark then came from the host.

Thanks.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE
  2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
                   ` (7 preceding siblings ...)
  2026-11-18 15:14 ` Konstantin Khorenko
@ 2026-11-18 15:14 ` Konstantin Khorenko
  8 siblings, 0 replies; 17+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 15:14 UTC (permalink / raw)
  To: ptikhomirov, Mirian Shilakadze; +Cc: devel

On Wed, 18 Nov 2026 14:36:32 +0400, Mirian Shilakadze wrote:
> ve: give the pseudosuper privileges only to the tasks setting up a VE
> 
> While a container starts or is restored, ve.pseudosuper is on and its
> relaxations apply to every process in the container. The container's
> own binaries that vzctl and CRIU run in that window get them too, such
> as quotaon at start and the tee that vz-rst-action runs at post-restore.
> Such a binary can rewrite the container's root memory.max, skip the
> mount limit and the mount option filter, use NETLINK_REPAIR, or clear
> pseudosuper early. During a restore it can also open /proc/<pid>/fd of
> CRIU's restoring tasks and take CRIU's log, its /proc fd and the
> transport socket.
> 
> [...]

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.3.vz10, thanks!

[1/6] ve: tell ve_setup_task() which VE the task comes from
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/75d56c3b36ed
[2/6] ve: hide only the tasks the host sends into a VE
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/09024a13fdc5
[3/6] ve: hide the tasks that set up a starting VE from the rest of it
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/a7d797d177e7
[4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/bd6d7bf907de
[5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/9f185a7ca286
[6/6] ve: give the remaining pseudosuper relaxations only to setup tasks
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/c2496901d252

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


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

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

end of thread, other threads:[~2026-11-18 15:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 10:36 [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
2026-11-18 10:41   ` no-reply
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 2/6] ve: hide only the tasks the host sends into a VE Mirian Shilakadze
2026-11-18 10:42   ` no-reply
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it Mirian Shilakadze
2026-11-18 10:47   ` no-reply
2026-11-18 11:32     ` Mirian Shilakadze
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks Mirian Shilakadze
2026-11-18 10:46   ` no-reply
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 5/6] fs: keep the mount relaxations of a pseudosuper VE from container binaries Mirian Shilakadze
2026-11-18 10:50   ` no-reply
2026-11-18 10:36 ` [Devel] [PATCH hci-8.2 v3 6/6] ve: give the remaining pseudosuper relaxations only to setup tasks Mirian Shilakadze
2026-11-18 10:49   ` no-reply
2026-11-18 11:54 ` [Devel] [PATCH hci-8.2 v3 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Vasileios Almpanis
2026-11-18 15:14 ` Konstantin Khorenko
2026-11-18 15:14 ` Konstantin Khorenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.