From patchwork Tue Feb 6 11:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482608dyb; Tue, 6 Feb 2024 03:53:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR+K1HOmVga4YiyWbZqL59IzzH7QS06x2X2q3gciYij+zBJQ/7DCiwcBZzNd/afea68VfC X-Received: by 2002:a17:902:d4cb:b0:1d8:ffbe:82d9 with SMTP id o11-20020a170902d4cb00b001d8ffbe82d9mr2246480plg.14.1707220416660; Tue, 06 Feb 2024 03:53:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220416; cv=pass; d=google.com; s=arc-20160816; b=gFJz8RTGHh92r/D1Sj1QLCyC5LxGhYoipqsxo9lTEekXNNMJU0VKyLbRDl500OZxR4 19HM3Ql3fwnKaHvmhexfAbepCdDn7yAHwoN4EQbvBF4X5vvEAJIyEB9ktjdNKjfQoP2j xzUdwBGO1J7SEZCuHRCHpvafUQnYrMGeS/JJW2DOpoUTQ481jD+OB3X/L4rjB83i9jWY eHuL/pgByuSXhq+8iHq0pgOWthUyudxBYXMtJdZNGSoHN9jMjiVGX/d1LwIOyLcblq7h R+HsETanbOjJGWqTUfVnEQHO2H5VaehQQj2H1tsdhOO3voSGuyl2sRAYCNvGVBEdkWqZ a7VQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Es1r5HTFTxAVE2/80lM01ZTjBkU6nxyuvtLC74Fluw4=; fh=EwNlCSW1Q1A17pJKCFqYnPbYcCYL+52jUgQ2gBk/W/8=; b=ckkL26OAp4ADMDbx9snrZH+z41v3Gx7knHtWvnOAmYFq6883Y8dj0RjAefqKhLd1gq XgRGkgXjx08ViERrnM2oT5CWoP5dSy4q9ZWlCRWqonCAyyA403WjrVGDJ5uuBa7ZlRrk 6SXAWAk3dZp3gZvCYuTu/h2Ce8A9kzvPPbTOQsM5yv9WAmKhrzG1SpWaKD/I0I0lpQlP Cn3TkRgVw1PqF/xeyVuPYGdbm5+6AAbtKJ3EWh2GKBNn6g4nxHpOysrA+tjs08cCu6GZ XxAM025p6WOyhzfBx5YYllqi4JhfQuiUh+9QJMQZ/ToT6Jx0Nus72i7WDrkc1DmT7Srg lAnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUoltyEVabYx6qOpLFr+Qb2aUBRxOdVTe5uVUC7sDrjpEB6APn40MAeklaWR/4iooVMfZQBgTOOEF+pOfC/s5wM9hg0TA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001d98c856c67si1576853plx.222.2024.02.06.03.53.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6CC0F2855A7 for ; Tue, 6 Feb 2024 11:53:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 864EB13A268; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D48B1350C9; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=QoR0OSxG988P4HJlVviihmPRGCk3cYlFX4QI1cN7F6/clbBDn3MesyWsyWwy5Uti/NivEwa2ncZh697vQdx5gD3DxRTnkq4dVb9I8DI1YjJ+0CsEKjsGGvv7Kc+oZO3G+4dYFxvrt6HbWdtgVKqJYWr++l70or0gAx9R4CKhlMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=TqvI80mt2ZF0Gnam5nEwnKCPn9ZXmcExO8VO54BJ8Dg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=tMOudrTHLR74+2JBsZ7vW/W3ESa8tCEkK4ZsF5MdE7AWFddfmvEUhXCmsVqSSXWK0V00EY2dXWFDuTrJRnJOUgrXOqDGwPKcplaQkjhSPiLUpXJ4pcilm76UZiVcJh86se6EgHUJmVX8udnPRxCzXF7UpL5ZYQX8b4TIpkj/Ofs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C08AC433B1; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aQK-1xR7; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.324608021@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:18 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 20/23] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150355919363576 X-GMAIL-MSGID: 1790150355919363576 From: "Steven Rostedt (Google)" There should never be a case where an evenfs_inode is being freed without is_freed being set. Add a WARN_ON_ONCE() if it ever happens. That would mean there was one too many put_ei()s. Link: https://lore.kernel.org/linux-trace-kernel/20240201161616.843551963@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 5a49f996046ba947466bc7461e4b19c4d1daf978) --- fs/tracefs/event_inode.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 515fdace1eea..ca7daee7c811 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -73,6 +73,9 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + + WARN_ON_ONCE(!ei->is_freed); + kfree(ei->entry_attrs); kfree_const(ei->name); kfree_rcu(ei, rcu); @@ -84,6 +87,14 @@ static inline void put_ei(struct eventfs_inode *ei) kref_put(&ei->kref, release_ei); } +static inline void free_ei(struct eventfs_inode *ei) +{ + if (ei) { + ei->is_freed = 1; + put_ei(ei); + } +} + static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) { if (ei) @@ -679,7 +690,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - put_ei(ei); + free_ei(ei); ei = NULL; } return ei; @@ -770,7 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - put_ei(ei); + free_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } @@ -801,9 +812,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - ei->is_freed = 1; list_del(&ei->list); - put_ei(ei); + free_ei(ei); } /**