OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
To: khorenko@virtuozzo.com, ptikhomirov@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH vz10 3/6] ve: hide the tasks that set up a starting VE from the rest of it
Date: Mon, 16 Nov 2026 14:45:46 +0400	[thread overview]
Message-ID: <20261116104552.102938-4-mirian.shilakadze@virtuozzo.com> (raw)
In-Reply-To: <20261116104552.102938-1-mirian.shilakadze@virtuozzo.com>

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.

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 |  4 ++++
 include/linux/ve.h       |  4 ++++
 kernel/ptrace.c          | 23 +++++++++++++++----
 kernel/ve/ve.c           | 48 +++++++++++++++++++++++++++++++++++-----
 5 files changed, 71 insertions(+), 10 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..9067efbaccac 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1115,6 +1115,10 @@ 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 and the
+				  * only ones with the pseudosuper relaxations,
+				  * VD_PTRACE_COREDUMP once pseudosuper is off */
 
 /* 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 4db2d06da643..f7f802dc7ffb 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1788,6 +1788,42 @@ bool ve_check_trusted_exec(struct file *file, struct filename *name)
 	return false;
 }
 
+/**
+ * ve_current_is_pseudosuper - may current use the pseudosuper relaxations of @ve
+ * @ve: the VE that grants them
+ *
+ * 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)
+{
+	struct mm_struct *mm = current->mm;
+
+	if (ve_is_super(ve))
+		return true;
+
+	return ve->is_pseudosuper && task_ve(current) == ve &&
+	       mm && mm->vps_dumpable == 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 becomes an ordinary one once @ve leaves pseudosuper, which
+ * cannot be set again while @ve runs. ve0 never leaves it.
+ */
+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)
 {
@@ -1848,12 +1884,14 @@ void ve_setup_task(struct task_struct *task, struct ve_struct *old_ve,
 		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.
+	 * 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. The
+	 * mark goes to the mm, which may be shared, so a task coming from a
+	 * container never gets either.
 	 */
-	if (task->mm && ve_is_super(old_ve) && ve->state != VE_STATE_STARTING)
-		task->mm->vps_dumpable = VD_VE_ENTER_TASK;
+	if (task->mm && ve_is_super(old_ve))
+		task->mm->vps_dumpable = ve->state == VE_STATE_STARTING ?
+					 VD_VE_SETUP_TASK : VD_VE_ENTER_TASK;
 
 	/* 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

  parent reply	other threads:[~2026-11-16 10:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 10:45 [Devel] [PATCH vz10 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Mirian Shilakadze
2026-11-16 10:45 ` [Devel] [PATCH vz10 1/6] ve: tell ve_setup_task() which VE the task comes from Mirian Shilakadze
2026-11-16 10:50   ` no-reply
2026-11-16 10:45 ` [Devel] [PATCH vz10 2/6] ve: hide only the tasks the host sends into a VE Mirian Shilakadze
2026-11-16 10:50   ` no-reply
2026-11-16 17:17   ` Konstantin Khorenko
2026-11-16 10:45 ` Mirian Shilakadze [this message]
2026-11-16 10:55   ` [Devel] [PATCH vz10 3/6] ve: hide the tasks that set up a starting VE from the rest of it no-reply
2026-11-16 17:17   ` Konstantin Khorenko
2026-11-16 10:45 ` [Devel] [PATCH vz10 4/6] cgroup: give the CT root file writes and hidden roots only to setup tasks Mirian Shilakadze
2026-11-16 10:53   ` no-reply
2026-11-16 17:17   ` Konstantin Khorenko
2026-11-16 10:45 ` [Devel] [PATCH vz10 5/6] fs: give the mount relaxations of a pseudosuper VE " Mirian Shilakadze
2026-11-16 10:56   ` no-reply
2026-11-16 17:17   ` Konstantin Khorenko
2026-11-16 10:45 ` [Devel] [PATCH vz10 6/6] ve: give the remaining pseudosuper relaxations " Mirian Shilakadze
2026-11-16 10:56   ` no-reply
2026-11-16 17:17   ` Konstantin Khorenko
2026-11-16 17:17 ` [Devel] [PATCH vz10 0/6] ve: give the pseudosuper privileges only to the tasks setting up a VE Konstantin Khorenko
2026-11-17 10:21   ` Mirian Shilakadze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116104552.102938-4-mirian.shilakadze@virtuozzo.com \
    --to=mirian.shilakadze@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox