]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 6 Feb 2024 11:32:02 +0000 (06:32 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2024 08:51:43 +0000 (09:51 +0100)
commit e109deadb73318cf4a3bd61287d969f705df278f upstream.

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 <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/tracefs/event_inode.c

index e6c40a3e07c259e57a5c45181495de98ca5a9919..63eabca959a5aa79d5248e0bed49b5b73d7cdd63 100644 (file)
@@ -750,11 +750,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;