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 2764681835 for ; Mon, 16 Nov 2026 19:22:09 +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 6AGJKuW1030973; Mon, 16 Nov 2026 22:20:57 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AGJKuW1030973 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="nuHENd97" Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AGJKkl8030935 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 16 Nov 2026 22:20:46 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AGJKkl8030935 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4a4654add56so31060635e9.2 for ; Mon, 16 Nov 2026 11:20:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHMG6oDAmD6CbS7+cHXj7a0zIaZgzmur8QAQO5wB6zRO7c5pxphYQC6KGvmPJKANwIgPoT7KA==@openvz.org X-Gm-Message-State: APuU4Z90HwzQDCtLikwO33VRfNMSMt0nijRGvi1FF4nsmTVZaLMd4cp7 cvYnp3lVhxpKWYzwMuIIrAIVXKN4uKeNj+l69AFMG4YiNR5We/ZMSnZ3KS1DMDNtWYKJePT5o/4 HWhQEYr/VMJqZEKurvNoBlga8mwB/ovzMgGsD+KJoSkSuJB6YxMCDxA== X-Gm-Gg: AYBFou19d3NhyuuENI1H0zNl5en92SM+TEOo4uTXeXv6G69+8e58b6KgRQyKJvjXMbQ ByryMAz4owzp4FKHaROUtiauw+1o0EV9wqcUM1vHpns/ReKvD6ReaZuo0XWXjtQK/kNh4HcE54+ NcTtw/wUc7GTWrweXGYs84Mhcz69MpUFLH90EXEQdBjtsepGnKKvjTWecOoYGeRdniPhypnU3+T UgNOazqVJtM/h9DOYEPcjtbUOf0X1N9SbuNEhZBCcPU9ELbNX8cRqC+dkpbLwN5cGjHUBjXm8af EEXqTIMJpEWZGRuRFV/HFm/9hezgtdbjmZYMYJkFjY8wE2kiQhB36Ze9mMbgJ46tcOftyK3lXFz JE01SSdwkPCDqgxGztfJJ7270djJp6A== X-Received: by 2002:a05:600c:8b4c:b0:4b7:6b96:e431 with SMTP id 5b1f17b1804b1-4bb55ab56ffmr255616865e9.28.1794856846205; Mon, 16 Nov 2026 11:20:46 -0800 (PST) X-Received: by 2002:a05:600c:8b4c:b0:4b7:6b96:e431 with SMTP id 5b1f17b1804b1-4bb55ab56ffmr255616405e9.28.1794856845622; Mon, 16 Nov 2026 11:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794856845; cv=none; d=google.com; s=arc-20260327; b=Sk9BGWFnKfNBpZ6aviHLSr0AlY+yGiFZjytVfUnim6UrtgVQt553/RBayPAJjhSuWW IHUljHIRTLrHZ5KIsybXcp6prus8Eqf2duUG3r5Kk/DH/YInoEu6lE8lzlpNZvwhx9Si gR84R/d+TBElNmfL2p/5GLEuRNDns9HOl6YVZzgxcGrpmHFyNZ2uwPbjigCsFyanqYI2 P/Ja0pDcXaZzp6SomFVoMVHP1ZnNQW8v7rhzYuIkgKoCOKNAmXMbGBKGtVAorfInVYbD 3sE4ZZ4ht68B4X4lAba8OrMnXuiJ+2c7vKLbZRnmzkD7NPxab8Dtd4oLFgvKEvcBg5bp IvzA== 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=MofsiPBs9AA+tpeA+3nI8jJceggKqaWu5AIOLUiBBZo=; fh=eCOFrBZAqsL6jjT8ApulcBPCLrgIlXlNCEpSn7Ap5O8=; b=XhD3UXCyMJ1H5p5gtxTb46jBBlaycUGGdVrn0DO6a2AMo7B+LWP/iE6lmF9DSAM59p TvKNac3EEYUru4iJcGVeZC4oirUtnYYWtPNIf20I3+3W9fYUGDvGmYNFDm4l4TdEcge7 Pt20A47gWqb5TDMVN+xAt/UjxPrhdfPMyUuAtvcEPIhXL90kEMT8/8i57g4qGYDvFP7K sFwq7gxt4m8BHeaEBLkeLJOSUeiO2YIv1EhdJhPwEyD6A8WWWr0QHmWiI4OnXWgXGHfO Aj4bskKKvhAH/AOlU/mift4Eome/+OMTs+mHMpwjfe7v81tQTjHuNXpyGh6bh/4C0XfG UNtQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=nuHENd97; 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-49c6482b3easi33810036f8f.345.2026.11.16.11.20.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2026 11:20:45 -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=nuHENd97; 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=MofsiPBs9AA+tpeA+3nI8jJceggKqaWu5AIOLUiBBZo=; b=nuHENd97aWgs8sW7G5e ezJam+vnP7dst85uMvjLFB0t2H/Xcaa9xSU0V7Hx20s1sjPvfAwHGJYV4JNM37TRa/rOLLq2mLuhM MkIiVkDncgu69LrysOoehnZFiMTI6zxjSOgHkkB9JPduG5UxRH+f0bbhaceJ1gfltXvLtK17BcwjD d1fYKgUOKTgEQwXIy5zSSrWskS1/5+70opfaiAfWnmwSQEPegBQjadM2TZvIZyBEcIuC9OFnwOsnu BSzeyIQA5HPXdGa6E1Kr4gYmAAqMpIjrrovmBfuNRr3VtgPuY7iX7thyfr1bafo6ydFd6pP2I1ESl oU7kG9ayp9p5suA==; 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 1xT2Bh-00A2lb-3A; Mon, 16 Nov 2026 20:20:36 +0100 From: Vladimir Riabchun Date: Mon, 16 Nov 2026 20:20:40 +0100 MIME-Version: 1.0 Message-Id: <20261116-ovl-use-orig-ve-v8-2-dfe427bfd902@virtuozzo.com> References: <20261116-ovl-use-orig-ve-v8-0-dfe427bfd902@virtuozzo.com> In-Reply-To: <20261116-ovl-use-orig-ve-v8-0-dfe427bfd902@virtuozzo.com> To: vasileios.almpanis@virtuozzo.com, 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 v8 2/6] 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. ve_capable and friends now use overrided_ve field if it is non-NULL. This field is not supposed to be inherited via fork, so a check for non-NULL overrided_ve was added in fork path. https://virtuozzo.atlassian.net/browse/VSTOR-142405 Signed-off-by: Vladimir Riabchun --- include/linux/sched.h | 1 + include/linux/ve.h | 30 ++++++++++++++++++++++++++++++ kernel/capability.c | 6 ++++-- kernel/fork.c | 2 ++ 4 files changed, 37 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..5c9260799db5 100644 --- a/include/linux/ve.h +++ b/include/linux/ve.h @@ -295,6 +295,29 @@ 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 (new_ve != get_exec_env() && !ve_is_super(get_exec_env())) { + pr_err_ratelimited("Invalid VE override: %s -> %s\n", + ve_name(get_exec_env()), ve_name(new_ve)); + 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_ONCE(IS_ERR(orig_ve))) + return; + current->overrided_ve = orig_ve; +} + #else /* CONFIG_VE */ #include #include @@ -405,6 +428,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..0b4c4554bf80 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_ONCE(orig->overrided_ve); + tsk->overrided_ve = NULL; #endif /* -- 2.52.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel