From patchwork Tue Feb 6 12:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501885dyb; Tue, 6 Feb 2024 04:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNzj8FMlGFbfg9ExBTKE3KuEgUINZmqXYLkMtgGK2Q9a7afaoWhliEQLYrXA3WJhZ3rcGq X-Received: by 2002:a05:6870:2181:b0:210:96cf:b552 with SMTP id l1-20020a056870218100b0021096cfb552mr2947772oae.23.1707222512781; Tue, 06 Feb 2024 04:28:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222512; cv=pass; d=google.com; s=arc-20160816; b=vqncKZOW8AgzMR4G2q0UUT+weJ1A5pDijEFnrbFHzuXIDXFqHfLNB0gQMwdy2rsoms n8xDWmt31e0Jb3XJsWFreUogPQ4qURHF4TA64e5iQ5UNvHmneKYlVUJklpEIjM1MfMkD yhyoyQtF9X6xmzsXOOe8AcZDjBvqhm4FSZvulyVn2GGSo8y5YZS6sjfLZKLJjoU3ELd+ sd88mas+9sH8I9L+MxvTPa6p4/l9TzjL2fomtC8QnrKjKtxURHu51f6hdPI0truJXLAj rDGo3fDRj+tX5LXC4zKi8mTwBQWHMocwoqKXMXdPiKCKjTKR1i26A0orAVlPPWChGWYa AjhQ== 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=jKDkXlawu1eDdlwexUANHmD4caMCzxPQaBQE8EpSNLI=; b=dLPJPBPl9tFTxt+HEnUoSYnrhjU+G3P0wjp2+bxRQGEfbvwmcIvdt4JxvQbQTJ+NTu fkyh4p4Uq3z2KopPPAP2MRkFqyYNzKQrXfx8ZYjH5j5H36S+2+2MvzXL+aBTV1Tl1HUf y8XABtUWHnIW+fRrW77cm7LkPz46EtbdYiB0RCbV6K/DmhsWCH6UWxo80X+Ck8brR5sS LBBIdG9xLOpMBIXzRaX6XUCjavwKEijn2AkPaD/AiI5vJbfg4T77W5bIKPnTaNfkjrg0 LEzSnudhOlrZrlAlm+/YIeLYopCfiodk/KElT+iV5YY7rh4yt+7fvpKFI0AVghOOuxOK NILg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVSI+KKv+0vyZ1uAzOysuiK1BiQL1FCs/OcRIrqJw9rxLyaxGFM555cpf68Xk72+u/cW++RVAkwwa18Yecwil8cH/4G2Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f7-20020ac85d07000000b0042bf8e02246si2247240qtx.614.2024.02.06.04.28.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54929-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 80ECE1C24341 for ; Tue, 6 Feb 2024 12:28:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8167152C10; Tue, 6 Feb 2024 12:09:42 +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 0F19613BE82; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=madVwKdpydAolG+Hk4HHDzQjFbMnAZHzdKbz0V47OKeN+iG1uMICistydMskwJxW2gdskAhdHjwzdGj4J9mxyw8I8cCG2BypSUmS5vCrWRAzmoLnY3ivc5C4tqpkuZkbe7Myv1XVyMrQuMN+YAEyOwKRLwt5Yn4wrZCSQsw6e6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=TqvI80mt2ZF0Gnam5nEwnKCPn9ZXmcExO8VO54BJ8Dg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=e66sEhClnVpO7/FtNIgYch6DT/ROVjWLF2fb4UsZ5m3zIIO0osSt8gZW22LNEMR1UurEpLlrtUXUfQPAA6gIUGY1VQ5pghvqvHfMummGG9dvTAHeAAzRBYAI4lk7tTQfs5+xJEFHt3iqlkaZzIS2LyTJEklP5Mmgyd/vB4y0wyk= 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 D6ADAC43394; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bSL-1Jh7; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.173872948@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:59 -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.6][PATCH 54/57] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240206120905.570408983@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: 1790152553833528065 X-GMAIL-MSGID: 1790152553833528065 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); } /**