From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 1B24D8017D for ; Mon, 19 Oct 2026 00:08:24 +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 69J07AbF015411; Mon, 19 Oct 2026 03:07:11 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69J07AbF015411 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="CQefuxxX" 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 69J06sbO015369 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 19 Oct 2026 03:06:54 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69J06sbO015369 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48dfdc0fa95so915455f8f.3 for ; Sun, 18 Oct 2026 17:06:54 -0700 (PDT) X-Gm-Message-State: AFq9FYIAm70G1rN4EDMKwWm1zJuhsKOOfcGR3MRfuaYNtdc+3+F6sHn0 zQmGqovZjMc7TFkI2IJdKJyeE6qVoGaYt4pv1AQqtrl/0RW4ddNb9fOn4Ci62G+QgWONZYFKJle 59FllmzmWhni5VpJBALkw/2GETPXtf5/fWjGJOvgRWBaQGICh0du8EQ== X-Gm-Gg: AYBFou1l6/fWUVEICOooswsagwFQGPlNB8/zQAZwf6mWmZ+yFs1Tz0yKTyzWdvnVxfD xCQkvQNQXtZCC6Ut0mhBdxtpFUsUkeo1qpYfkkk2g5eAbh/Yplz8OBC+h+yBcbQsm1tnJb4atag 9zwgwXJFZjGVImHfzkG0FhhECKfd7zRiN1KCsdvF+w5u15SWIN6l76uJWUQTXbevrXFX0R6kxR2 fKIJl7NJDo66VXMO0ZZFHb18TqhCcRfOfqvZnZ66aXoMj4G5JDNVMhcbATUCvYM6XnM7MiP5ebZ Yk2qfGtJiOUVwrIH1lFDF2KNmr5wVMhMoCN2lqRVT1jWKLi6ezvHRjzlCd7Sv3njwZ8J0iTDR/2 SRQ5qZMx6JtPRc8uson5CVEzA3w== X-Received: by 2002:a05:6000:468d:b0:48d:f39b:83de with SMTP id ffacd0b85a97d-48e07b92058mr7786381f8f.3.1792368414567; Sun, 18 Oct 2026 17:06:54 -0700 (PDT) X-Received: by 2002:a05:6000:468d:b0:48d:f39b:83de with SMTP id ffacd0b85a97d-48e07b92058mr7786357f8f.3.1792368414048; Sun, 18 Oct 2026 17:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1792368414; cv=none; d=google.com; s=arc-20260327; b=QKyFt144E07pI8BqIWiZYn9omFrWiRZEEgNjWIeV80vInurBgP+EFgvJk+IoJ0AtYU jsVnICu3VL4bArC9XIDEOtGHuFQipHwEr45XxAM9xI5wl9LMsorrUBvF0mlVp1tg1dQF Mg4b7edL7UZTGyVEB4BkR8j234jSWX6/GqlMKpnagmy+b22/EKgKjVD83JzjB+GihFTp YyJv9Upw78GN666zxx6TVKUpy8+81/SiNl6aN2jZDNHeBVt9p+vuVOBIBuiWktAF24QB jPUS7fkZVPMUej1igIX6jIaq4JH4C/fdCj4i6uCK19WzNL8X27o7yXflBPQXJOE0j5Gw vgsA== 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=56ZuRB+mCt2tWZRBOByVifjwkHUzcs5Hfl3n2gz0sDI=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=BIDpWFtxaXiE2q5UNUgBQdUO/f9z4PiyCfpM72dTdzneuiUg6Wf1RIarcIle11XXHP mlGRXxFe+U+o+RW+I7hv4Ab6T0QXsXn1H8T/q1BB14tDK5SWkQhqSk2IzCecdfpPZSVa nX0SzefN7l9qsmpTSfpLCbNBv1UjWx6eRWs92qQ6eaBAdB1h19Bfbe3aI8W7+ZF5iS4S +e1516hSAAoYNn8gccsNMTH14c2+/ro1Dtw0ojXHI/qyM8UswKIlcpEdDNOhAzzjMI5e 2gj0Kb+X82yUnb8MTdaWZKgTx+9e7ZD1eqfyYji0qrLyjAzlrBElZebsgf7VnbH7ZheI 9OEg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=CQefuxxX; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@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-48dfd539807si17349165f8f.487.2026.10.18.17.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2026 17:06:54 -0700 (PDT) Received-SPF: pass (google.com: domain of eva.kurchatova@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=CQefuxxX; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@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=56ZuRB+mCt2tWZRBOByVifjwkHUzcs5Hfl3n2gz0sDI=; b=CQefuxxXwfou JJFmS0pSAU98Kmr5hee50AgULPc3p8xMX7OOQG96/Gv2iKobEbPkjaTkIeyAFj/wXWU2VAhbxdNbW UD7VCVbPNN33neJv9L+uV+Q5jscc87ma6tOh8bKq9wuizK3HC0TqgU3rv6kRDA7r04/BScjMTv93Q yt3GnoBAEAHhuue5JUUcuG2zJ3fYmsuGeeNjR5xD53/ugqF6qVoz+aMTsjQREWYmFXTgphLIp6Vgk eEkz8oo1lDLW+oq6ikDFowNifgSC4J+5BSPRlewEdk2HIu2ZAXWt/sRPLMHULFjOJvczGj42fmABK HH4x+QT+3lbpBjs/Mdlkjw==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xIaqQ-004bGD-0A; Mon, 19 Oct 2026 02:06:46 +0200 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Mon, 19 Oct 2026 03:05:56 +0300 Message-ID: <20261019000649.1371025-5-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261019000649.1371025-1-eva.kurchatova@virtuozzo.com> References: <20261019000649.1371025-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 4/6] timens: freeze the offsets on the first join without the vDSO too 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 A time namespace's offsets may be written until the first task joins it; from then on they are read without a lock, so that join freezes them. The freeze sat in the code that fills the namespace's vDSO page, and since 1b6c89285d37 ("timens: Remove dependency on the vDSO") a kernel without a generic vDSO, User Mode Linux now, never froze: the owner could rewrite the offsets under the tasks already running there, and the clocks they read moved with them. Freeze in timens_commit() itself and fill the vDSO page from there, where there is one. Fixes: 1b6c89285d37 ("timens: Remove dependency on the vDSO") https://virtuozzo.atlassian.net/browse/VSTOR-148112 Feature: fix ms/timens Signed-off-by: Eva Kurchatova --- include/linux/time_namespace.h | 11 ++++++----- kernel/time/namespace.c | 28 +++++++++++++++++++++++++++ kernel/time/namespace_internal.h | 10 ++++++++++ kernel/time/namespace_vdso.c | 33 +++++--------------------------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index e91910656301..bfe55d9066b5 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -49,6 +49,7 @@ struct time_namespace *copy_time_ns(unsigned long flags, struct time_namespace *old_ns); void free_time_ns(struct time_namespace *ns); void timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk); +void timens_commit(struct task_struct *tsk, struct time_namespace *ns); static inline void put_time_ns(struct time_namespace *ns) { @@ -134,6 +135,11 @@ static inline void timens_on_fork(struct nsproxy *nsproxy, return; } +static inline void timens_commit(struct task_struct *tsk, + struct time_namespace *ns) +{ +} + static inline void timens_add_monotonic(struct timespec64 *ts) { } static inline void timens_add_boottime(struct timespec64 *ts) { } @@ -151,13 +157,8 @@ static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim) #endif #ifdef CONFIG_TIME_NS_VDSO -extern void timens_commit(struct task_struct *tsk, struct time_namespace *ns); struct page *find_timens_vvar_page(struct vm_area_struct *vma); #else /* !CONFIG_TIME_NS_VDSO */ -static inline void timens_commit(struct task_struct *tsk, struct time_namespace *ns) -{ -} - static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) { return NULL; diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index cf95f9e0ad94..9bd21eb8bf2d 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -192,6 +192,34 @@ static void timens_put(struct ns_common *ns) put_time_ns(to_time_ns(ns)); } +/* + * The offsets are read without a lock once a task runs in the namespace, + * so the first task to join freezes them, and sets up the vDSO page from + * them where there is one. + */ +static void timens_freeze_offsets(struct time_namespace *ns) +{ + if (ns == &init_time_ns) + return; + + /* Fast-path, taken by every task in namespace except the first. */ + if (likely(ns->frozen_offsets)) + return; + + guard(mutex)(&timens_offset_lock); + if (ns->frozen_offsets) + return; + + timens_vdso_setup_vvar_page(ns); + ns->frozen_offsets = true; +} + +void timens_commit(struct task_struct *tsk, struct time_namespace *ns) +{ + timens_freeze_offsets(ns); + timens_vdso_join(tsk, ns); +} + static int timens_install(struct nsset *nsset, struct ns_common *new) { struct nsproxy *nsproxy = nsset->nsproxy; diff --git a/kernel/time/namespace_internal.h b/kernel/time/namespace_internal.h index b37ba179f43b..564c22b639dc 100644 --- a/kernel/time/namespace_internal.h +++ b/kernel/time/namespace_internal.h @@ -4,6 +4,7 @@ #include +struct task_struct; struct time_namespace; /* @@ -15,6 +16,8 @@ extern struct mutex timens_offset_lock; #ifdef CONFIG_TIME_NS_VDSO int timens_vdso_alloc_vvar_page(struct time_namespace *ns); void timens_vdso_free_vvar_page(struct time_namespace *ns); +void timens_vdso_setup_vvar_page(struct time_namespace *ns); +void timens_vdso_join(struct task_struct *task, struct time_namespace *ns); #else /* !CONFIG_TIME_NS_VDSO */ static inline int timens_vdso_alloc_vvar_page(struct time_namespace *ns) { @@ -23,6 +26,13 @@ static inline int timens_vdso_alloc_vvar_page(struct time_namespace *ns) static inline void timens_vdso_free_vvar_page(struct time_namespace *ns) { } +static inline void timens_vdso_setup_vvar_page(struct time_namespace *ns) +{ +} +static inline void timens_vdso_join(struct task_struct *task, + struct time_namespace *ns) +{ +} #endif /* CONFIG_TIME_NS_VDSO */ #endif /* _TIME_NAMESPACE_INTERNAL_H */ diff --git a/kernel/time/namespace_vdso.c b/kernel/time/namespace_vdso.c index 08d69270eb2c..8a2fc9d23687 100644 --- a/kernel/time/namespace_vdso.c +++ b/kernel/time/namespace_vdso.c @@ -86,29 +86,13 @@ struct page *find_timens_vvar_page(struct vm_area_struct *vma) return NULL; } -static void timens_set_vvar_page(struct task_struct *task, - struct time_namespace *ns) +/* Called once per namespace, under timens_offset_lock, before any task reads */ +void timens_vdso_setup_vvar_page(struct time_namespace *ns) { - struct vdso_time_data *vdata; - struct vdso_clock *vc; + struct vdso_time_data *vdata = page_address(ns->vvar_page); + struct vdso_clock *vc = vdata->clock_data; unsigned int i; - if (ns == &init_time_ns) - return; - - /* Fast-path, taken by every task in namespace except the first. */ - if (likely(ns->frozen_offsets)) - return; - - guard(mutex)(&timens_offset_lock); - /* Nothing to-do: vvar_page has been already initialized. */ - if (ns->frozen_offsets) - return; - - ns->frozen_offsets = true; - vdata = page_address(ns->vvar_page); - vc = vdata->clock_data; - for (i = 0; i < CS_BASES; i++) timens_setup_vdso_clock_data(&vc[i], ns); } @@ -120,7 +104,7 @@ static void timens_set_vvar_page(struct task_struct *task, * corresponding layout. * See also the comment near timens_setup_vdso_clock_data() for details. */ -static int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) +void timens_vdso_join(struct task_struct *task, struct time_namespace *ns) { struct mm_struct *mm = task->mm; struct vm_area_struct *vma; @@ -131,13 +115,6 @@ static int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) if (vma_is_special_mapping(vma, &vdso_vvar_mapping)) zap_vma_pages(vma); } - return 0; -} - -void timens_commit(struct task_struct *tsk, struct time_namespace *ns) -{ - timens_set_vvar_page(tsk, ns); - vdso_join_timens(tsk, ns); } int timens_vdso_alloc_vvar_page(struct time_namespace *ns) -- 2.56.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel