From patchwork Sun Feb 4 01:16:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148371dyb; Sat, 3 Feb 2024 17:23:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHj+blfqfMA/GODFZAujy6tFjhKhh4GPWobZLODl+RWwEpVbNLqg5w78curX7V6Z4fqRG8a X-Received: by 2002:a17:90b:387:b0:296:24cf:bae6 with SMTP id ga7-20020a17090b038700b0029624cfbae6mr6086171pjb.27.1707009813725; Sat, 03 Feb 2024 17:23:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009813; cv=pass; d=google.com; s=arc-20160816; b=Ow6L9k2l7YfzApXjXwYv6qOiMo3zRFxfRvi/UQCIpAVbZCP73DKCaMJs74u4PerzMR 5VVqoiQEvAonfBIme2bAHv/nA+OEofXdbnGtGMIgY87Kl0zrLv4EfSGS8nEueqYlFWsK 7+lolUECQg6F+QWhUIIHtazpb3NJgGGS1XZtbYsilvcXLonGG3wmZL6PcNsfN31ijvGm BDlq9eCgTdS5+iT+Kf/gQs0G2lL4I/T7pNseU7PJbh8zuBclWnykKLG2kxsl6Z0pUljX BDVvWm1BnYIXt8QK+EKxRJhxJvcGvPmPuVRWy3Yj6nVGeV6F0oasn270G4CvDapAxSgu uZ4A== 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=Z0tluB0AlM/xl4gpfRjrJde9FCeKqB9q1rVWFbwkCwE=; fh=QqCO9/FAo/k1GcJ6icYnX8tB7usSHothMInOGicCz6o=; b=DoTcRDiIRA4QkuC/eEPJyhznMDed802FcAAXByQRRX4E7YvbCqJ7Z1//RyTU+2Hsm9 ZXW+f8SrMqUfiqheMPbsLthMu0+BZvLCi8dvlBHXWbBRamIqtfT5+juzQXnVxB3efDrc eqq7FFsFCJKCZ1RMz8jLkhl3tvmsBfVpfhN3jNg/5N19fggs50BUB06hqzNLlTev8yOW zekMJFyeXJuyHzT7pwMzf9JPy72fwRGjizkyAvYrTyH82uaFkWHO+R9HT8mCLhfDhRqQ X+I1ThWCZrFegBogf5FKAXwQvpX0klh+tn1HulsRJOc6tlrliV2yqRbx425uoxdrpOMJ URSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51356-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX1+yLDFwu4hqFJZyEhA9JJSbGDEhMkynfrrNf3Mak4kbicN0f3SeC28h12BVpaSfSwA3ugpxR0mTWljKmSXDpfGkYPJQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kx17-20020a17090b229100b00295d4e9dbf4si2190756pjb.54.2024.02.03.17.23.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51356-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-51356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51356-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 7EFBC285B61 for ; Sun, 4 Feb 2024 01:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1730418C05; Sun, 4 Feb 2024 01:18:13 +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 24B18E57F; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=mUG1d39Zu3n26H1r7R4SRtiYLYkj+8Qseyz8MbftZYLDBasfq0xm0TFHvz/OvYuyKikAv2Gc6uk7r7/tY/Lu//wnNh16x8bb8PK3NlZ5JjuC4nVm+6HtsbPuSLUXAaBTblae2RwHvgNLcZHr7yqiZ7cnQuKDwakAZFKGHHuZO4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=bzFVFZX6ZxTI6abHrIBPqY91OKE0skzJprX6xWIWAm4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Vpb0npwZ5jFdAdve30voao4s2bGrDIH2VsdcQwmjYKma9L7MzMwzdDOhQ7OGHZHsIDT3ZpjalA8iLppxtOiGYyNffiqkD4qpW3Q/8rrrrLKbZLhiPnlzpMezhsDQwAtK8orjLIWKsf0+x7uVlqEEcmiEZXhCOspiY/1sE/Rsbo0= 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 A3E3FC3278D; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006OuN-1E5D; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011830.140246345@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:35 -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 , Andrew Morton , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 20/23] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240204011615.703023949@goodmis.org> 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: 1789929522632022290 X-GMAIL-MSGID: 1789929522632022290 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) --- 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); } /**