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 C43238017D for ; Thu, 12 Nov 2026 00:12:17 +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 6AC0AflH032308; Thu, 12 Nov 2026 03:10:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AC0AflH032308 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="i+FKKjIW" 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 6AC0AUPt032278 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 12 Nov 2026 03:10:31 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AC0AUPt032278 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0461e040so2826011f8f.0 for ; Wed, 11 Nov 2026 16:10:31 -0800 (PST) X-Gm-Message-State: APuU4Z8tlBrV19I/L2wFFaVxx1zfnTs6jnMfWIlXCLIn2k/v2wIKywS7 H2OVuagAF+6lSaaSZRxZTIJJB2jGlrIJKUtUxhdm7TJWiKv7h6+z2XbP9ppNyGyNSzFamy35LUf yDI8o7wsiitBghpqmZRBnTq+OsO9KPvWSEOKEQOZsEqMkZdr5d0KfbA== X-Gm-Gg: AYBFou3r5UBj5bWZImMHC0vvZp8hyuUR4ihGya26ATMW+6A5luDf2hWXLMjHmTjilNk lMNqDHTMXDnC6uqeX9vYPfZ4gwaHimIfb95eQd6szfO+6HBnLxrBV2VMLzCxF309x+s7wknHBbf +qbA5g8g7pw2DDi08cKBBTBxIQ4fJ7+Dm1jdFZi6YKXDvI1xS/fnX/UF2owKHSjwkhDloOW2+vq VkO7suHWRk71BnIsSeI6SgfYO2X0OVi8dw2LT8Ku7WPKo5oNXOoQsQTPY2doarfrWGcGDJ3QPcE CX9OuRQq9tNhbH7UiUH1RKd7AA3nhut8WI9NFerOBeFQbHc8s0qac4teJVvFXjUNgKtN71IU9+5 p8GpJ1aywGMlpfXvralg/Sv89 X-Received: by 2002:a05:6000:4912:b0:48e:4a8a:e17f with SMTP id ffacd0b85a97d-499c38bafdemr6238780f8f.4.1794442230491; Wed, 11 Nov 2026 16:10:30 -0800 (PST) X-Received: by 2002:a05:6000:4912:b0:48e:4a8a:e17f with SMTP id ffacd0b85a97d-499c38bafdemr6238746f8f.4.1794442230006; Wed, 11 Nov 2026 16:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794442230; cv=none; d=google.com; s=arc-20260327; b=dzvNjLD/vujI75s2dB79lA0jn89CBH+1dqRrVI2V+Bxzuk/v3QCHqNY4BgBB+9wkz3 OAef6hx7NEFl4LL2F3hfQLq7ReZwWPUDkuxJWMbohbVvjb3EjkSJE/pfQX1iHSvU2aCi RcHcw/zwY886xmo+MyUy7N0xDez8mdjOz6BjvafFKIZxB+WGPSVxzkcUaItwI/PKu/Is 2oW5qJh/7PUJwokpw79xMnrIPDB8YGldoFH21XOSGfOHp9ycqEofcmj2napZmiUq+bP1 kguiPSkqGyUCy1MVCd17r+J81+hRS2COQUCZ4SHSj4MvBZ79tVd4Vu/xuWDUQQ+aVLCe lyZQ== 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=nnd6ck79p2yd5JBrHMu+kTeNxj6NzG8k5AxgJt7mGUg=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=S8D1ADzPzgK6KvzmVcnx9WKWk9WhjyHtGWSQ06LpWnntNfUm1gFT2O4s31FGoh2l2N oNa0NNu8Vid7OfTtZinDI1xuqrsgT6BHlDmgbmNd/Pk/lJJYVwDRIXaw9V9rd93wBp1F 5uRJXVsQOjp48xXtphsivkAqisSzO0lDmZ60EHM4lWMoFL0CkALn2DiDvJ6vuedV6OBt 66XZksbO7pnfckvqiLo2WdnQh4yZ/uJeHFTnP8CP/fSQWqyPoS1alyQbVRhqJSqLqGeA yqrtpaMGK2U9+i5usBZzV/1/FSPCPtRHhzj1YQmO2awdobUwEXf/csRC2NsMV5C2NvvL HMtA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=i+FKKjIW; 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-498363dfe66si13904537f8f.236.2026.11.11.16.10.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2026 16:10:29 -0800 (PST) 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=i+FKKjIW; 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=nnd6ck79p2yd5JBrHMu+kTeNxj6NzG8k5AxgJt7mGUg=; b=i+FKKjIWVRWE TDJweW978g047s4X4U8ZlFTyD2O0W3aAxFEiO+ADE3aBGvMp18KlaV/MBUHykZYAmMN11se3YLUa2 wobtk7fYWUYco1jIMpLF5OONR1r3vthIEeWE9ozXHsnhWM9+vpUFVextw4j4QpRkefxfKJF7yNHmx IPgtwMDOQYobj3cCLAJYF4UMYOIIINMi6R8W9H2xxDnypTS9Z17fhXmP6km0IaiCI+vEXWKh+5Sg2 xoOSIMtexhMbsvZ8Gis1CfkLAgt4+ihvqRf9B/pIOoy8YoGzHWnxNBjffS8JzRIuMGgIYe66VcJP/ ACjY0RTJG7Q+J8TUS0deLw==; 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 1xRIKT-002DgU-0U; Thu, 12 Nov 2026 01:10:28 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Thu, 12 Nov 2026 02:07:55 +0200 Message-ID: <20261112000926.381308-5-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261112000926.381308-2-eva.kurchatova@virtuozzo.com> References: <20261112000926.381308-2-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 3/5] ms/eventfs: Use children field for rcu head and add memory barriers 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 From: Steven Rostedt [ Upstream commit f0ece16ffca7384787b692431961ce202907acf5 ] When an eventfs inode is freed, it sets ei->is_freed and then uses its ei->list to add it to the srcu link list as the list field is a union with the rcu list head. As the ei->list is used to iterate over an SRCU protected list without taking the eventfs_mutex, there's nothing stopping the iteration over that list to see the ei->rcu instead of the ei->list and it will read a corrupt target. To fix this, change the union of the rcu list head with the children list. On freeing the eventfs inode, set the is_free and execute a smp_wmb() before adding the eventfs inode to the SRCU list. On iteration of the ei->children list, at the start, execute a smp_rmb() and then read the is_freed of the ei to see if the children list is still valid. If is_freed is set, then the ei_child read is not valid and the loop should exit immediately. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260808094215.4252430d@robin Fixes: 704f960dbee2f ("eventfs: Read ei->entries before ei->children in eventfs_iterate()") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260806022719.375354-1-shuangpeng.kernel%40gmail.com Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt Signed-off-by: Sasha Levin (cherry picked from commit 1b95382da85cff3bf0f922ff0275f186abdadfce) https://virtuozzo.atlassian.net/browse/VSTOR-154529 Feature: fix ms/tracefs Signed-off-by: Eva Kurchatova --- fs/tracefs/event_inode.c | 24 ++++++++++++++++++++++++ fs/tracefs/internal.h | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index cc08218d6e26..a157b4cf2b30 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -124,7 +124,17 @@ static inline void put_ei(struct eventfs_inode *ei) static inline void free_ei(struct eventfs_inode *ei) { if (ei) { + /* The ei should have no children if it is being freed. */ + WARN_ON_ONCE(!list_empty(&ei->children)); ei->is_freed = 1; + /* + * The SRCU iteration has a smp_rmb() to make sure it + * sees a child (that may have already been freed) + * before it reads is_free. If is_free is set, it must + * not use the child it acquired from ei->children, as + * the list may be used for SRCU. + */ + smp_wmb(); put_ei(ei); } } @@ -647,6 +657,20 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { + /* + * If the ei is being freed, then the ei->children may be + * being used as the rcu list, which means the next element + * may be garbage. The ei->is_free is set before switching + * the ei->children over to ei->rcu. The read memory barrier + * here makes sure the ei_child is read before is_free is + * updated. + * + * Matches the smp_wmb() in free_ei() + */ + smp_rmb(); + if (ei->is_freed) + return -EINVAL; + if (c > 0) { c--; continue; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index a4a7f8431aff..c61481d04c8e 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -46,11 +46,11 @@ struct eventfs_attr { * @ino: The saved inode number */ struct eventfs_inode { + struct list_head list; union { - struct list_head list; + struct list_head children; struct rcu_head rcu; }; - struct list_head children; const struct eventfs_entry *entries; const char *name; struct eventfs_attr *entry_attrs; -- 2.56.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel