Skip to content

Commit

Permalink
eventfs: Free all of the eventfs_inode after RCU
Browse files Browse the repository at this point in the history
The freeing of eventfs_inode via a kfree_rcu() callback. But the content
of the eventfs_inode was being freed after the last kref. This is
dangerous, as changes are being made that can access the content of an
eventfs_inode from an RCU loop.

Instead of using kfree_rcu() use call_rcu() that calls a function to do
all the freeing of the eventfs_inode after a RCU grace period has expired.

Link: https://lore.kernel.org/linux-trace-kernel/[email protected]

Cc: [email protected]
Cc: Masami Hiramatsu <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Andrew Morton <[email protected]>
Fixes: 43aa6f9 ("eventfs: Get rid of dentry pointers without refcounts")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed May 4, 2024
1 parent b63db58 commit ee4e037
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions fs/tracefs/event_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ enum {

#define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1)

static void free_ei_rcu(struct rcu_head *rcu)
{
struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu);
struct eventfs_root_inode *rei;

kfree(ei->entry_attrs);
kfree_const(ei->name);
if (ei->is_events) {
rei = get_root_inode(ei);
kfree(rei);
} else {
kfree(ei);
}
}

/*
* eventfs_inode reference count management.
*
Expand All @@ -85,7 +100,6 @@ static void release_ei(struct kref *ref)
{
struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
const struct eventfs_entry *entry;
struct eventfs_root_inode *rei;

WARN_ON_ONCE(!ei->is_freed);

Expand All @@ -95,14 +109,7 @@ static void release_ei(struct kref *ref)
entry->release(entry->name, ei->data);
}

kfree(ei->entry_attrs);
kfree_const(ei->name);
if (ei->is_events) {
rei = get_root_inode(ei);
kfree_rcu(rei, ei.rcu);
} else {
kfree_rcu(ei, rcu);
}
call_rcu(&ei->rcu, free_ei_rcu);
}

static inline void put_ei(struct eventfs_inode *ei)
Expand Down

0 comments on commit ee4e037

Please sign in to comment.