Skip to contentSkip to conversation

eventfs: Initialise ei->children before it can be freed

PATCH In review David Carlier 2 participants 3 messages Aug 25 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eventfs: Initialise ei->children before it can be freed

eventfs_create_events_dir() runs INIT_LIST_HEAD(&ei->children) only after tracefs_get_inode() succeeds, but that call's failure path jumps to "fail", which calls cleanup_ei() and then free_ei(). free_ei() reads the list with WARN_ON_ONCE(!list_empty(&ei->children)), and alloc_root_ei() uses kzalloc(), so children.next is NULL there and the WARN fires.

The path is reachable at runtime: mkdir /sys/kernel/tracing/instances/foo ends up in create_event_toplevel_files() and eventfs_create_events_dir().

Move both INIT_LIST_HEAD() calls up to right after the allocation.

Fixes f0ece16ffca7 ("eventfs: Use children field for rcu head and add memory barriers")
---
 fs/tracefs/event_inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/tracefs/event_inode.c +3 -3
index 604ba3e841d2..1d9edc99ff3f 100644
@@ -779,6 +779,9 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	if (!ei)
 		goto fail;
 
+	INIT_LIST_HEAD(&ei->children);
+	INIT_LIST_HEAD(&ei->list);
+
 	inode = tracefs_get_inode(dentry->d_sb);
 	if (unlikely(!inode))
 		goto fail;
@@ -802,9 +805,6 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	ei->attr.uid = uid;
 	ei->attr.gid = gid;
 
-	INIT_LIST_HEAD(&ei->children);
-	INIT_LIST_HEAD(&ei->list);
-
 	ti = get_tracefs(inode);
 	ti->flags |= TRACEFS_EVENT_INODE;
 	ti->private = ei;
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 6 lines · On Tue, 25 Aug 2026 22:57:18 +0100 David Carlier <[email protected]> wrote:

eventfs_create_events_dir() runs INIT_LIST_HEAD(&ei->children) only after tracefs_get_inode() succeeds, but that call's failure path jumps to "fail", which calls cleanup_ei() and then free_ei(). free_ei() reads the list with WARN_ON_ONCE(!list_empty(&ei->children)), and alloc_root_ei() uses kzalloc(), so children.next is NULL there and the WARN fires.

Quoted 7 lines

The path is reachable at runtime: mkdir /sys/kernel/tracing/instances/foo ends up in create_event_toplevel_files() and eventfs_create_events_dir().

Move both INIT_LIST_HEAD() calls up to right after the allocation.

Fixes f0ece16ffca7 ("eventfs: Use children field for rcu head and add memory barriers")

Already queued by someone else.

https://patch.msgid.link/[email protected]

-- Steve

#2 lore raw

ah forgot to check, fair :)

Cheers.

Quoted 23 lines · Steven Rostedt
Quoted 6 lines · On Tue, 25 Aug 2026 22:57:18 +0100 David Carlier <[email protected]> wrote:

eventfs_create_events_dir() runs INIT_LIST_HEAD(&ei->children) only after tracefs_get_inode() succeeds, but that call's failure path jumps to "fail", which calls cleanup_ei() and then free_ei(). free_ei() reads the list with WARN_ON_ONCE(!list_empty(&ei->children)), and alloc_root_ei() uses kzalloc(), so children.next is NULL there and the WARN fires.

Quoted 7 lines

The path is reachable at runtime: mkdir /sys/kernel/tracing/instances/foo ends up in create_event_toplevel_files() and eventfs_create_events_dir().

Move both INIT_LIST_HEAD() calls up to right after the allocation.

Fixes f0ece16ffca7 ("eventfs: Use children field for rcu head and add memory barriers")

Already queued by someone else.

https://patch.msgid.link/[email protected]

-- Steve