From patchwork Sun Feb 4 01:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147325dyb; Sat, 3 Feb 2024 17:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrRAIQbtKe+O6u/oKl53LXgXSNr/LHhHqCqg7HDKpjt3TwWWTEB3yg4H1PxzYGGl+5Hc4O X-Received: by 2002:a17:902:f683:b0:1d9:3edf:1e2 with SMTP id l3-20020a170902f68300b001d93edf01e2mr3726702plg.3.1707009571794; Sat, 03 Feb 2024 17:19:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009571; cv=pass; d=google.com; s=arc-20160816; b=kzOPTvhv5g320zaE+Nw289DRWM21SMlL+Pbl4wf/cTtxhRXRB2+KdWmpmAtFLNFBq0 c7upI4C/Djdi4/GcjVg04XTqggtq8xeaHT0iGXfWTZ5ToX1hJMl2tfV98JBrD815LcT+ jl6F9ODa/3IEGvXjPNbJWl8SCFAA6qtO44+QmUdHl+RqVfOqL1F/b4S148ymEMhEobGL laeS9rbPk0kY8S51Sb1BBgbMHZPoPm27FflCIBpcUrPJslmd0/+7oyssH0baGqiMGlLS vRk/B0nW6784MFbv9+H6DV9RhN1sHp48jlQIUhg8lLN1QBW0W7mlZ6GUqOaKFgySQI/R HbkQ== 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=G94krBZ90YOfynXklLjFFv1YKZHn7bbkOvvSG6fKVRk=; fh=HdcLdX95CU86UmCXKUSi7mbymhyVDdLUjSahVdAJOIE=; b=X6GmBZ9fl1CmnyIO9INxC4tQNBtOplCZRuEWLhjBZafQOUBZ0e2CFwjGkKJHT34jgr 6FEKkF3R6JnZFpcXd6SLbARWKlaJTCvE1invQ3lUOxh95BUp24dj+uebbhWYRHmQd8r6 p7hmJI29UI5elQfKwNpo3CRQQKFesXM6jWVxAMUYca1PCDVbxnHVBfFXwj5OR0GqAs0T w+8QtWv0hlGKbV7NajHq69zLvj2O9dFKIzGq4+m9No+apUSJU45nWNzrk+2MW3usgsWz kAvXsrblVVloN0XgK6H03h9NoXvsbpuzfophI/XiVO5SmmorQtCF3KIkTa/gPDe45+vC HY8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1+OXxLdZF4Snzekurvq+Bo9A9G4mYHVue28HXChZ7AE4v5PfPcmp5YPZTWocRjHUQAmGPN8xiV74jo/+bQ5N6CJkenQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z1-20020a631901000000b005dbee5249fcsi3954088pgl.688.2024.02.03.17.19.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51339-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4C570B23CCC for ; Sun, 4 Feb 2024 01:19:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48115AD55; Sun, 4 Feb 2024 01:18:07 +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 75F20138E; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=lQk0ENDVnhfdSD1eHW8kl2EhWF+qvRKrJotqySWs598qOS7dfAYhn4TcZ7IDHAewWGZo92zDDrVizsQRjLv/WkT27LOsEolI627saoEBpLcc7suJbxMenK8vAnroBFyAfqK3p5pUDLK4oEBmj1qfNrnoh0cr80Tr9v+D69oLnHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=ggzO8piDWd729+n8HwEUay+QGmmX3pyBkc192DI4teg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=d0uv/Z7th/C39yWIWSuVDdhJ15MCtX7AYkX2FiqRY+AgGD27TppyEcpBEbhW9AeUFrotCUgZSPQkJSHWGPIVzBy3w6ZkN84oB2ikiPQ3XG4xzf1ZQfiEbCwTa6CMxQEtPZaJXBItwoxQafR27d9YfpMxVJp0L+qhNLXMUZpr6GM= 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 0ABE8C43609; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006OmP-2pcL; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.535604040@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:19 -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 , Al Viro , Christian Brauner Subject: [v6.7][PATCH 04/23] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is 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: 1789929268337435507 X-GMAIL-MSGID: 1789929268337435507 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;