eventfs: fix SRCU read lock leak in eventfs_iterate()
PATCH 1/1 eventfs: fix SRCU read lock leak in eventfs_iterate()
Commit 25d27d5fa864 ("eventfs: Use children field for rcu head and add memory barriers") added an early bail out to the ei->children loop:
smp_rmb(); if (ei->is_freed) return -EINVAL;
Upstream wraps eventfs_iterate() in guard(srcu)(&eventfs_srcu), so that return still drops the read lock. The 6.6.y backport instead brackets the function with srcu_read_lock() and a shared "out" label that calls srcu_read_unlock(), so this path returns while still holding eventfs_srcu for reading.
The unbalanced reader prevents the grace period from ever completing, so the call_srcu() callback queued by free_ei() never runs and the eventfs_inode is leaked. Every readdir that races with removal adds another reader.
Set ret and jump to "out" like the other bail out paths in this function do.
--- fs/tracefs/event_inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/tracefs/event_inode.c +4 -2
@@ -740,8 +740,10 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)* Matches the smp_wmb() in free_ei() */ smp_rmb (); -if (ei->is_freed) -return -EINVAL ; +if (ei->is_freed) { + ret = -EINVAL ; + goto out; + }if (c >0 ) { c--;
Signature · 1 line
2.39.3
Quoted 4 lines
The unbalanced reader prevents the grace period from ever completing, so the
call_srcu()callback queued byfree_ei()never runs and theeventfs_inodeis leaked. Every readdir that races with removal adds another reader.
Queued for 6.18, 6.12 and 6.6, thanks.
Signature · 2 lines
Thanks, Sasha