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 CB8388017D for ; Wed, 11 Nov 2026 20:37:12 +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 6ABKZr0Q030939; Wed, 11 Nov 2026 23:35:54 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ABKZr0Q030939 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="AVT/v/oW" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6ABKZYVW030907 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 11 Nov 2026 23:35:35 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ABKZYVW030907 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e4d1e29f3so3408378f8f.3 for ; Wed, 11 Nov 2026 12:35:35 -0800 (PST) X-Gm-Message-State: APuU4Z8DNj45FBZakgHcOWHXsLMi7AbusITBwzLqhWapwOl3zaP0vvAi FTzoBEZNgl0sETp0YFkORe87uZaVJRxJeAANm2rFxlBQRlsXVxQyUmg0GkKwfMdps4RFmtVvufP IYWYcRmj9Wret0eLnqgFA/g0Fu+KWiq+jUEPNHM0qWdMgUjW/xU6wGA== X-Gm-Gg: AYBFou0kTxk4q7ZHWmPXOn3OUUeQwnQhfRKReeqgo4s0Y44BZXu+6FhoSUWANydVrk+ Rc748tJlo48UNRpPnUyuTX9fpI5WXhr0EFLKlqdDb+Cwc1VFQDPEe0ZVw9CleSM3maBCswhqsE9 YZJcJ37t186g27UexX8m++XcMXxgEXDY26OJvHz87+8FV5CY9TO44OX3NicRX2+VzZU33RxFs/a dUvoX6aq+YbqeVraZbCDgq+J8JparbGr1wZAcKiJqxtdC5fTDZUbgxj+giNozd4uBjuK2CSylSq CfHPE9gcDesVH0n4NcqOFGkebBE83H01X149dhPz8N2N5y4yfS4G12p2M4pn6qpg5sazexCKH0n fFFPGcfMNoDADhOFEuk+iN3v53g== X-Received: by 2002:a05:6000:428a:b0:490:88e5:92d6 with SMTP id ffacd0b85a97d-499c764c49emr6486850f8f.49.1794429334422; Wed, 11 Nov 2026 12:35:34 -0800 (PST) X-Received: by 2002:a05:6000:428a:b0:490:88e5:92d6 with SMTP id ffacd0b85a97d-499c764c49emr6486832f8f.49.1794429333976; Wed, 11 Nov 2026 12:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794429333; cv=none; d=google.com; s=arc-20260327; b=lzYApJFMXYHVVUTW+Yblj1vCKz0+pW0S3dEJ3iA1pA+Rv+G4klOpAnHQ/ZnoUbN8Dj CgmnWyrhnp/+IYiAkpicXFKGrGxj0Gm2d2PvOmQkrfsCqCoNfPrRqx43EgUvPLmpBG9h cuwqXY/Ni8Bpi4Qg5Esr3Askq8X9Alcx6kixw1RzziQ5vfysUZSnafegKw46ud+Vt+UL oPKRf+vah82vrXNaFuOZJJFtP0uyfn5ahrsmyF3wmLIPVyCrF+CQV+eCzXHmPU50OpX5 Mhpo9GkvxRegdIB+BehjEu2fuqbn8CXNBSlYKXXR5DE4yGQx2acIGrndpMW0Fd0qbp9V +eew== 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=U92nS8O9cC2cCujh0DqNhiRHa0pEpX5rBq0Bs+o6QMVvHkT/Y/lbkTG9jryd7SCjTm 6dvs5WTInTn/NyZ3zOrblCEmQuVR0j/AsDNrVctbE9EoxXYu7WKkGmHmTtqXRNzAj+AF Dh4USP8hY7p/RfoT362RQ/vOTh0FT9aKenA73qC0faMoTcp1MQEodjlPmQ/hTc8yi/v1 aNMdUDc3BaPBf2uXNInbqGKoDN5G78EwFPvtMaziBOaqGe66H+D1kxqpxJwkgJJqSQA3 oPuwt+6ZDWdCByTOUp9uaGvSamXpu1McL4p5iB9I09+f+bbmH+9+ruz+RYlOQAZww1lN cIdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="AVT/v/oW"; 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-49837ccc26fsi12798846f8f.428.2026.11.11.12.35.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2026 12:35:33 -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="AVT/v/oW"; 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=AVT/v/oWBkk/ e+zz8piKrAByfrW/pZP/pludsRezk4P4W0nfrU+wfAmphDlm/LmkTnN/cD0jKBPACe+BqSlJcCSX7 Q7/Olld3CqzG4FHRcywq5vWXzE4CAToplILMTHpW6iLEeLfLf2ItgW5pUtFUttq+zIak3wEnk0TXw 1HZZuwsNkLToeiGhivmJAXdSXfRxouu7YqVAVeGLkqp1O2JHVaZhiLIKJ5JqNmyxlZsCKPuwGEEZ+ Ei+BERUFuHcxFno2XDdrjpjjdQU1n3HkQ9wsn1wosUw3MxqThvQDdejjz/Zzj+CxZhWE4glQF7qGq 2wZinpC36KVR/ebIoMLYJw==; 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 1xREyT-00Fgix-2b; Wed, 11 Nov 2026 21:35:32 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Wed, 11 Nov 2026 22:34:18 +0200 Message-ID: <20261111203529.363554-3-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261111203529.363554-1-eva.kurchatova@virtuozzo.com> References: <20261111203529.363554-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/4] 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