Skip to content

Commit 6e3d7c9

Browse files
committed
eventfs: Cleanup permissions in creation of inodes
The permissions being set during the creation of the inodes was updating eventfs_inode attributes as well. Those attributes should only be touched by the setattr or remount operations, not during the creation of inodes. The eventfs_inode attributes should only be used to set the inodes and should not be modified during the inode creation. Simplify the code and fix the situation by: 1) Removing the eventfs_find_events() and doing a simple lookup for the events descriptor in eventfs_get_inode() 2) Remove update_events_attr() as the attributes should only be used to update the inode and should not be modified here. 3) Add update_inode_attr() that uses the attributes to determine what the inode permissions should be. 4) As the parent_inode of the eventfs_root_inode structure is no longer needed, remove it. Now on creation, the inode gets the proper permissions without causing side effects to the ei->attr field. Link: https://lore.kernel.org/lkml/20240522165031.944088388@goodmis.org Cc: Linus Torvalds <torvalds@linux-foundation.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> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 37cd0d1 commit 6e3d7c9

1 file changed

Lines changed: 23 additions & 67 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static DEFINE_MUTEX(eventfs_mutex);
3737

3838
struct eventfs_root_inode {
3939
struct eventfs_inode ei;
40-
struct inode *parent_inode;
4140
struct dentry *events_dir;
4241
};
4342

@@ -229,27 +228,6 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
229228
return ret;
230229
}
231230

232-
static void update_events_attr(struct eventfs_inode *ei, struct super_block *sb)
233-
{
234-
struct eventfs_root_inode *rei;
235-
struct inode *parent;
236-
237-
rei = get_root_inode(ei);
238-
239-
/* Use the parent inode permissions unless root set its permissions */
240-
parent = rei->parent_inode;
241-
242-
if (rei->ei.attr.mode & EVENTFS_SAVE_UID)
243-
ei->attr.uid = rei->ei.attr.uid;
244-
else
245-
ei->attr.uid = parent->i_uid;
246-
247-
if (rei->ei.attr.mode & EVENTFS_SAVE_GID)
248-
ei->attr.gid = rei->ei.attr.gid;
249-
else
250-
ei->attr.gid = parent->i_gid;
251-
}
252-
253231
static const struct inode_operations eventfs_dir_inode_operations = {
254232
.lookup = eventfs_root_lookup,
255233
.setattr = eventfs_set_attr,
@@ -321,60 +299,30 @@ void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
321299
update_gid, ti->vfs_inode.i_gid, 0);
322300
}
323301

324-
/* Return the evenfs_inode of the "events" directory */
325-
static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
302+
static void update_inode_attr(struct inode *inode, umode_t mode,
303+
struct eventfs_attr *attr, struct eventfs_root_inode *rei)
326304
{
327-
struct eventfs_inode *ei;
328-
329-
do {
330-
// The parent is stable because we do not do renames
331-
dentry = dentry->d_parent;
332-
// ... and directories always have d_fsdata
333-
ei = dentry->d_fsdata;
334-
335-
/*
336-
* If the ei is being freed, the ownership of the children
337-
* doesn't matter.
338-
*/
339-
if (ei->is_freed)
340-
return NULL;
341-
342-
// Walk upwards until you find the events inode
343-
} while (!ei->is_events);
344-
345-
update_events_attr(ei, dentry->d_sb);
346-
347-
return ei;
348-
}
349-
350-
static void update_inode_attr(struct dentry *dentry, struct inode *inode,
351-
struct eventfs_attr *attr, umode_t mode)
352-
{
353-
struct eventfs_inode *events_ei = eventfs_find_events(dentry);
354-
355-
if (!events_ei)
356-
return;
357-
358-
inode->i_mode = mode;
359-
inode->i_uid = events_ei->attr.uid;
360-
inode->i_gid = events_ei->attr.gid;
361-
362-
if (!attr)
363-
return;
364-
365-
if (attr->mode & EVENTFS_SAVE_MODE)
305+
if (attr && attr->mode & EVENTFS_SAVE_MODE)
366306
inode->i_mode = attr->mode & EVENTFS_MODE_MASK;
307+
else
308+
inode->i_mode = mode;
367309

368-
if (attr->mode & EVENTFS_SAVE_UID)
310+
if (attr && attr->mode & EVENTFS_SAVE_UID)
369311
inode->i_uid = attr->uid;
312+
else
313+
inode->i_uid = rei->ei.attr.uid;
370314

371-
if (attr->mode & EVENTFS_SAVE_GID)
315+
if (attr && attr->mode & EVENTFS_SAVE_GID)
372316
inode->i_gid = attr->gid;
317+
else
318+
inode->i_gid = rei->ei.attr.gid;
373319
}
374320

375321
static struct inode *eventfs_get_inode(struct dentry *dentry, struct eventfs_attr *attr,
376322
umode_t mode, struct eventfs_inode *ei)
377323
{
324+
struct eventfs_root_inode *rei;
325+
struct eventfs_inode *pei;
378326
struct tracefs_inode *ti;
379327
struct inode *inode;
380328

@@ -386,7 +334,16 @@ static struct inode *eventfs_get_inode(struct dentry *dentry, struct eventfs_att
386334
ti->private = ei;
387335
ti->flags |= TRACEFS_EVENT_INODE;
388336

389-
update_inode_attr(dentry, inode, attr, mode);
337+
/* Find the top dentry that holds the "events" directory */
338+
do {
339+
dentry = dentry->d_parent;
340+
/* Directories always have d_fsdata */
341+
pei = dentry->d_fsdata;
342+
} while (!pei->is_events);
343+
344+
rei = get_root_inode(pei);
345+
346+
update_inode_attr(inode, mode, attr, rei);
390347

391348
return inode;
392349
}
@@ -823,7 +780,6 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
823780
// Note: we have a ref to the dentry from tracefs_start_creating()
824781
rei = get_root_inode(ei);
825782
rei->events_dir = dentry;
826-
rei->parent_inode = d_inode(dentry->d_sb->s_root);
827783

828784
ei->entries = entries;
829785
ei->nr_entries = size;

0 commit comments

Comments
 (0)