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 D45EA8017D for ; Mon, 9 Nov 2026 19:37:30 +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 6A9JaFqC003184; Mon, 9 Nov 2026 22:36:16 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9JaFqC003184 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="w7cP4IfE" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A9Ja8wZ003150 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 9 Nov 2026 22:36:09 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9Ja8wZ003150 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-490c1867460so958851f8f.2 for ; Mon, 09 Nov 2026 11:36:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHa9YWT6RWfwqcGL9aXZMSw7TW8lj5KellVQyLzitjMuXF90hOoFotvdfYUEnM0dHj7wqjt/g==@openvz.org X-Gm-Message-State: APuU4Z+QG6rlwurhDS3uwQLSlwpXdwBMzMnw/0aWltzh/hTnKmOgFZoQ cCNqn5teG3ecr+rrcZvE6IFHH8gjFUtoZaKXO+WwpLDTsyVSd5JvKn355VLWDMGzS5ENJnApcWg KB+SNK25GqUpI6KVCW+TDodiPLAvvAg+HK6Sw8X2zFIYHHf9Sp+M25A== X-Gm-Gg: AYBFou2pLlqXe4j/8CNobhGg2wsJeJk/MPT44giBWA4VLvYSpSa2QXUe4qyuOqXHhFw 18viv1FuCXsg70aJnthB2/SD4UDMcyaeYYTrRtxNChTyvdNRv7G4ZxCNXfrqlvIqjULmel50Y8h ACqPR01yc//sFiuuqcBJ+NykOg7rJcLufebQ/Ald182kJKq6o36qYKjPO0umFTDkbq3RjVI9sTP eEqpu0N+wfiPbrntpoCOZElH6Rbu/yZ1XrJjLWXfM4aqRT5+fvepcy/o0Q15W4Xm3Hp2Bg8cDMu Nmg0h2hG7CdhTCVPRdaJoxdEVCUEfchJimc2VEZKH8Nh4eOW/DBgQbSjnvR9VgScO3icfjv419N 3J7RhFcbGtYOlP97gCXij8p7L2or1 X-Received: by 2002:a05:6000:2511:b0:492:20e0:f200 with SMTP id ffacd0b85a97d-49842870943mr405268f8f.14.1794252968535; Mon, 09 Nov 2026 11:36:08 -0800 (PST) X-Received: by 2002:a05:6000:2511:b0:492:20e0:f200 with SMTP id ffacd0b85a97d-49842870943mr405245f8f.14.1794252968050; Mon, 09 Nov 2026 11:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794252968; cv=none; d=google.com; s=arc-20260327; b=OUaBmROH6oDeiPaobtPMu2G1TqfRCPkg3U1BT+BJ8jAjopZhMXmsrd7UxAMO53br+A MRK16vTH+/6gUY0d3CtiFTk2YclN55PGFyukp/3tF4vsmkZ6FH4quQcTtzIE4/DVrYFB 3P3PezSanptc+lmxVV/fz4fMIL0UNgSIUOx1JW3sUIPCGu9OqRsUDfbwvl0NRBvFdd6y bqAPKOPLeh2Ec4uF7KEd/uUUblDd6WIIo+eXa2Onxz9dFrw5k1X8KXD/f8WGZJur588r mvPqCrw7SGAxytQ/STjodXZ3aiWHglN/pGJUMAJNAXxP7LXdxr2Aj2ZdZzz3SOnEmFdf e1mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=/e9hEj4KS1rEVKvJVcCnjbDR8lw/tGlpNJ+aggG9r+M=; fh=5hQRK+XZF8m8FADH0g5yAiDkSoTAVGTSxnnvVVATGZQ=; b=A0tOcxbcSzTEN8QlgjrHvMGFX5Ag1raRzi01W3Ay6pUMa5GVJBZXs/IeyRGvu7WnIj Yl/dbS64vZhfxUcuD2uc8IEzu7ZOiX9/HG+n4vKv8IHwS+oPA4xIK+ftLZylnGpSrUV+ ZkGpHcEAwd2O4bHievne7G0YMavnZawAvcU/b9ntkm3Z5Z91RjeWIwjEIaK8ptZKsFxR QnQLWoNaUrbZEn8MfPakCfZeHhwtogBAyXH169RpCr+JWzF+cxNyrx6fV17dxMMrWYTN yVdYoD4RMts4vsgFxkuy8ZNvyW1gNh1EUR5F5qg7jPNfva5AxzWjiSRUaIqzqdqRus/d 6ARQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=w7cP4IfE; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@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-49837618103si564954f8f.367.2026.11.09.11.36.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 11:36:08 -0800 (PST) Received-SPF: pass (google.com: domain of vladimir.riabchun@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=w7cP4IfE; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@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=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=/e9hEj4KS1rEVKvJVcCnjbDR8lw/tGlpNJ+aggG9r+M=; b=w7cP4IfEVppEtb5E4FQ PmXXxSsAgMfIjt71XPtf42sJZxbFJxBfV8PjIkyZc14MnwSJJXPHeTCVUZXrUDQVP2LDQsPYo8ZPG WxC5Ofcwy5FdFZaT3LbMZS+72lLaBTwnsR6/Bk4Ry1rRzuLAB36IP3xmN6Uw/VafK2gm2cBKZ+JAh 4mee7pupIeYncxUSdj6dfzoc68+dK6xiO5gTsIZckyfhzXKgZwi4bK4CrCRJJxL+17SgW7Fz3E2ZL kcrGhQ03gdG/9gOhEktopcQUn65TV9RZtPX6obmGyynnSE3BdgBJvC8Gwlxx7CDVYdldJud6+VG7T nKRcIYobT4OsgTQ==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=192.168.1.87) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xQV5u-00CGp3-3D; Mon, 09 Nov 2026 20:35:59 +0100 From: Vladimir Riabchun Date: Mon, 09 Nov 2026 20:36:00 +0100 MIME-Version: 1.0 Message-Id: <20261109-ovl-use-orig-ve-v4-2-88e65484dc5b@virtuozzo.com> References: <20261109-ovl-use-orig-ve-v4-0-88e65484dc5b@virtuozzo.com> In-Reply-To: <20261109-ovl-use-orig-ve-v4-0-88e65484dc5b@virtuozzo.com> To: ptikhomirov@virtuozzo.com, Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v4 2/5] ve: Introduce override_ve/revert_ve helpers 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 These helpers mirror override_creds/revert_creds and are supposed to be used together in cases when VE creds may be stored and later used by the different VE task. To keep task_ve consistent for other users, introduce a separate task->overrided_ve field. Nobody should race on it since its updates are supposed to go with override_creds, and non-current processes shouldn't do this. This field is not supposed to be inherited via fork, so report a check for this was added as well. https://virtuozzo.atlassian.net/browse/VSTOR-142405 Signed-off-by: Vladimir Riabchun --- include/linux/sched.h | 1 + include/linux/ve.h | 27 +++++++++++++++++++++++++++ kernel/capability.c | 6 ++++-- kernel/fork.c | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 10545e470d3d..7f4e6b1fde38 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1065,6 +1065,7 @@ struct task_struct { #ifdef CONFIG_VE struct ve_struct *task_ve; struct ve_namespace *ve_ns; + struct ve_struct *overrided_ve; /* NULL when no overrides */ #endif #ifdef CONFIG_PREEMPT_RT struct netdev_xmit net_xmit; diff --git a/include/linux/ve.h b/include/linux/ve.h index 717567775f58..fb8a4cabb951 100644 --- a/include/linux/ve.h +++ b/include/linux/ve.h @@ -295,6 +295,26 @@ static inline struct vdso_image *ve_get_vdso_64(struct ve_struct *ve) return ve->vdso_64; } +static inline struct ve_struct *override_ve(struct ve_struct *new_ve) +{ + struct ve_struct *old_ve = current->overrided_ve; + + /* CT tasks are not supposed to switch VE context, this is a breach */ + if (WARN_ON(new_ve != get_exec_env() && !ve_is_super(get_exec_env()))) + return ERR_PTR(-EPERM); + + current->overrided_ve = new_ve; + return old_ve; +} + +static inline void revert_ve(struct ve_struct *orig_ve) +{ + /* Somebody forgot to check override_ve return value? */ + if (WARN_ON(IS_ERR(orig_ve))) + return; + current->overrided_ve = orig_ve; +} + #else /* CONFIG_VE */ #include #include @@ -405,6 +425,13 @@ static inline struct vdso_image *ve_get_vdso_64(struct ve_struct *ve) } #endif /* CONFIG_X86 */ +static inline struct ve_struct *override_ve(struct ve_struct *new_ve) +{ + return NULL; +} + +static inline void revert_ve(struct ve_struct *orig_ve) {} + #endif /* CONFIG_VE */ struct seq_file; diff --git a/kernel/capability.c b/kernel/capability.c index 34716847c6b8..6de4dcba2283 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -389,10 +389,11 @@ EXPORT_SYMBOL(ns_capable); bool ve_capable(int cap) { struct cred *cred; + struct ve_struct *ve = current->overrided_ve ?: get_exec_env(); bool ret; rcu_read_lock(); - cred = get_exec_env()->init_cred; + cred = ve->init_cred; if (cred == NULL) /* ve isn't running */ cred = ve0.init_cred; @@ -406,10 +407,11 @@ bool ve_capable(int cap) bool ve_capable_noaudit(int cap) { struct cred *cred; + struct ve_struct *ve = current->overrided_ve ?: get_exec_env(); bool ret; rcu_read_lock(); - cred = get_exec_env()->init_cred; + cred = ve->init_cred; if (cred == NULL) /* ve isn't running */ cred = ve0.init_cred; diff --git a/kernel/fork.c b/kernel/fork.c index 25e87cdbeb07..0cb8ccb2f4f3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1161,6 +1161,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) #ifdef CONFIG_VE memset(tsk->alloc_lat, 0, sizeof(tsk->alloc_lat)); + WARN_ON(orig->overrided_ve); + tsk->overrided_ve = NULL; #endif /* -- 2.52.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel