From nobody Sun Feb 8 11:45:50 2026 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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@g= oodmis.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 =3D entry->name; =20 mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r =3D entry->callback(name, &mode, &cdata, &fops); - else - r =3D -1; + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + r =3D entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); if (r <=3D 0) continue; --=20 2.43.0