From patchwork Fri Jan 5 18:00:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 185477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6377251dyb; Fri, 5 Jan 2024 10:01:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM7oLQCbuPbgqKv/2qH8gK6MobGg1Ykg9Gn5dXhMdQdSW1Gq/7Ug12NHZyczH0h+oNd8o+ X-Received: by 2002:a05:6402:2038:b0:553:a3ec:3be1 with SMTP id ay24-20020a056402203800b00553a3ec3be1mr765281edb.163.1704477716427; Fri, 05 Jan 2024 10:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704477716; cv=none; d=google.com; s=arc-20160816; b=XUNscZAJnB2KigCrmFppMKeYvpFEslqNq7kj8LBVXHyBmAjtmOOSFAqlPDsEDAtWTN O2IcopaU6h7F2/GYyvT2EaVCv31gaEV+ftGmI2DVyGjot9ZMiT5GYEBxDzrhNf0uhd/B 5eVGwWlh1VE1g+I1/LzqwEsETbyARMbtN+CX/iyBAwZyu8G5Ey3+o37/guYjchXz3/rm GkShLO1T4fQ4CIYlx8XAH/U2KvJOBk7igUFLc1Y4m+slYzLrKw0uFjHepJQCp0aRKT2n VYJoA8Z9Qdxhj7Pz6kz7M5krt1rL1eT3vEBCUYuOfQiFC+LgaN/W2CQjqVAELchQOHEx JkOA== ARC-Message-Signature: i=1; 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=NTI+YfePI3I5G/EEG+DFn0HC3ZD6RLqAYp3NGlSyhTs=; fh=vkFQlI0+F6MeP6c8OufhDbPZhDE+E+f9sPZRB/bqb3w=; b=MV4lIz0mTzcM8PIMxegSQ4zJ19t5phG7c5RjvojdDWpcogH8gqJ/DMm2hdlSqAjvx/ c0iRnPZ52dg14CsHhgbiR6lSFx6u9+JneMPoM5Z6av/L7Z1wf3nUiZYP6xFndy5royG3 tGmwmTONSE4cZqMNB9OCH2hpqEhjSBBpm2fy4/HBXkGBFb4invUr/2dNJWpVKH1JlYHI FQY56PBObOXJ4EEUOcWiXjjM9TWKFE/LgXBjENYLjnyVjXixUaWCHURamjZL2loTdca8 OeGEc5GCKSJIzEEq+hTPILVQuOKiiEkm8J928eNLjKh67q6KrKkyaKeOlYSzQMcEdmh3 N65Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18160-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dd13-20020a056402312d00b00553ae9870f4si849959edb.191.2024.01.05.10.01.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:01:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18160-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 am.mirrors.kernel.org (Postfix) with ESMTPS id AB50D1F2456C for ; Fri, 5 Jan 2024 18:01:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35623358B1; Fri, 5 Jan 2024 18:00:12 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org 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 AD68C328D1 for ; Fri, 5 Jan 2024 18:00:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50BA1C433C7; Fri, 5 Jan 2024 18:00:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLoVT-000000012Uu-0E2Y; Fri, 05 Jan 2024 13:01:19 -0500 Message-ID: <20240105180118.917102213@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 05 Jan 2024 13:00:52 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Al Viro , Christian Brauner , Greg Kroah-Hartman Subject: [for-next][PATCH 1/4] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set References: <20240105180051.741934288@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: 1787274425839309497 X-GMAIL-MSGID: 1787274425839309497 From: "Steven Rostedt (Google)" If ei->is_freed is set in eventfs_iterate(), it means that the directory that is being iterated on is in the process of being freed. Just exit the loop immediately when that is ever detected, and separate out the return of the entry->callback() from ei->is_freed. Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.016261289@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 72912b5f9a90..0aca6910efb3 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -788,11 +788,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = entry->name; mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); if (r <= 0) continue;