eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup()
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 1 Feb 2024 17:33:46 +0000 (12:33 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Sun, 17 Mar 2024 11:58:52 +0000 (07:58 -0400)
There's a couple of if statements in eventfs_root_lookup() that should
never be true. Instead of removing them, add WARN_ON_ONCE() around them.

  One is a tracefs_inode not being for eventfs.

  The other is a child being freed but still on the parent's children
  list. When a child is freed, it is removed from the list under the
  same mutex that is held during the iteration.

Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/
Link: https://lore.kernel.org/linux-trace-kernel/20240201123346.724afa46@gandalf.local.home
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Ajay Kaher <ajay.kaher@broadcom.com>
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
fs/tracefs/event_inode.c

index 110e8a27218900756f3af6cd515d6e8cf33e9514..9d9c7dc3114b385c17ee367acbb5b290966b9995 100644 (file)
@@ -483,7 +483,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
        struct dentry *result = NULL;
 
        ti = get_tracefs(dir);
-       if (!(ti->flags & TRACEFS_EVENT_INODE))
+       if (WARN_ON_ONCE(!(ti->flags & TRACEFS_EVENT_INODE)))
                return ERR_PTR(-EIO);
 
        mutex_lock(&eventfs_mutex);
@@ -495,7 +495,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
        list_for_each_entry(ei_child, &ei->children, list) {
                if (strcmp(ei_child->name, name) != 0)
                        continue;
-               if (ei_child->is_freed)
+               /* A child is freed and removed from the list at the same time */
+               if (WARN_ON_ONCE(ei_child->is_freed))
                        goto out;
                result = lookup_dir_entry(dentry, ei, ei_child);
                goto out;