From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 9EB448017D for ; Wed, 18 Nov 2026 10:38:29 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIAbFEe023419; Wed, 18 Nov 2026 13:37:16 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIAbFEe023419 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="FWmjKLy0" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIAb1Xd023382 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 18 Nov 2026 13:37:01 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIAb1Xd023382 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4903fc8537aso637970f8f.0 for ; Wed, 18 Nov 2026 02:37:01 -0800 (PST) X-Gm-Message-State: APuU4Z9haf9hJcB2ENHKocERlYiicJZmRwGZztyTxaRodDfIqP4QEpMG mYs0QlS0Hy19oQ02ppxGihJ3a/z9lfu2a7CiqElvZjnQMNv/RWULFJPIBDeBpGGb0gFTqUdv50p Byv/lJMVJubHxcEyEjwqDW6nDlisOQx5jC2uk7fekU/OIQGh/01m8UA== X-Gm-Gg: AYBFou1zAm/IwTZSKrpchf11IRJtN+1I1vtT4Da0CH0HPvvuylmEeovxyuuEqeYxjUd 7WSDZSxUz+9HwL+LnDmkUhdB1BrwXNOnROv0yMGfUXA+SaHIqmMo87ohzv3cstgnRa6PmrQbs6d ch35Crzfg3+41zGTxnPw8gvOwSUNBrhfRIxnr5c2Zz9J1vo7oKZAxKh3i9EFHalXLRjwi/bTzYJ lJMKkWOHHwYnTm7KC9GbL2N0lYzHSjxk+29jahUzGu4ytMxoudKrg1AaV5iwHKEXsT1QZB7lo7v qpiFJ/wdmCpj9goohtJM7tVw6U1ia1uTUMSbl1oDL8EVwBU9n8MZZULOjM5/y+kHyBLyVt1yJJd FCGmMqQO+n9Z6sSSLl6oYgLuQTFvfpQ== X-Received: by 2002:a05:600c:6092:b0:4a2:e0c:2b0a with SMTP id 5b1f17b1804b1-4bb7da1dab6mr38817515e9.16.1794998221232; Wed, 18 Nov 2026 02:37:01 -0800 (PST) X-Received: by 2002:a05:600c:6092:b0:4a2:e0c:2b0a with SMTP id 5b1f17b1804b1-4bb7da1dab6mr38817065e9.16.1794998220678; Wed, 18 Nov 2026 02:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794998220; cv=none; d=google.com; s=arc-20260327; b=gpzmLJNWWDR4kkb1m4wDQw4FFmLYeUxn65ZUSv+0xv7Z+o2A+angfkj3+zEaWiegXS T/UEAtL82xHADjO9SmH4u8G2OhtBnD/JJM1Hb2Vhn/9Y0NqePho4Baof3JB4p3tvrMui TKuW4oVVB3bfwu9feR1lhoE6UmMXcqSpUXHxbXLiRRB9hdY3m9VYy+jh/7ecWOLm5LvO tgSnlRPAg+hkgV+l+PyU4Ghd7QMHr6IhgXEHm3d3OueR4vozMABzTZBolWCK9AGXl4Zc FRnykenR9i2ZseZTBsNKTHqXLAbTq3LFNEqTChZItbiB3VnhVwEv7zFCpXCornKN41pE LWQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=azI8lAIMfhuVTMK80PLe5ZbFomPnzQp6GChBA/SDYZo=; fh=wpoNUURlquLpJK/14Kny0oMIYkY7mYwjJ/Ils9UT2kk=; b=irx+wCqUBBE4dkXaBiV0msUk5DjV3HfxXPiXpXm37xgVMnZ9vB/eOOAkqwwNXo9SRi cRvF8sX3Ma1Dp9oH+iyU9mtl9AUca4xp640riqsgwEo795Djb0fbQIKXv9XRflNH0pIM CBM7GcTLo5glX7L+U4rijcxVZuD0U1G/W19LCREHbyMHCtcKpUI+DNgl5CB9Lg5fV4Lx JKk5vvIn29rtvSQHhfyZWUsJXDiZN/2FTQxK4qHgNcI0MRBOHrGH/wNIY15U1TTNF/kO UraSy9o1QnlxSgDBwbKbbYcLYDIPULt5zv6MLh2Z4Qj88aZPYDpRgmZI7bHCGI44Sg92 cqcA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=FWmjKLy0; spf=pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=mirian.shilakadze@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a6574b1509si4008787f8f.76.2026.11.18.02.37.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 02:37:00 -0800 (PST) Received-SPF: pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=FWmjKLy0; spf=pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=mirian.shilakadze@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=azI8lAIMfhuVTMK80PLe5ZbFomPnzQp6GChBA/SDYZo=; b=FWmjKLy0psYa mOrpmnV6a4BJPWsdpi/tajZAutp2PYNAvEJ+vzeH5bkjLZLooYplzki5jMPOScYobSZdiOX+ZUI4V Vd1M/obqpl+2IMqUolIEddfp4LqzCDiDlqNrCVUVKspQKRzWOj9L1+L/KdavdCJeXc0G8OmVZxI4n lu9dbT1HCxbxAu/ZXFCP32anQ8QRVrt2dCxo61hJnWBOgw+vc8wgOCLPoaC3tkW04nTT7nEqwKk08 QWS13cAynEu1JKjYq4tu8+UXtF+oPr1LQi5Yz3z0xT/FeF3G78DJpgPtIMZMN/BFCjEgTWAK3VAkc LuHA1UaFXUS1aQSf4oiwwQ==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=localhost.localdomain) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTcxu-001uKo-1O; Wed, 18 Nov 2026 11:36:59 +0100 From: Mirian Shilakadze To: khorenko@virtuozzo.com, ptikhomirov@virtuozzo.com Date: Wed, 18 Nov 2026 14:36:35 +0400 Message-ID: <20261118103656.363171-4-mirian.shilakadze@virtuozzo.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118103656.363171-1-mirian.shilakadze@virtuozzo.com> References: <20261118103656.363171-1-mirian.shilakadze@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v3 3/6] ve: hide the tasks that set up a starting VE from the rest of it X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org 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//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 --- 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