Skip to content

Commit 340f0c7

Browse files
committed
eventfs: Update all the eventfs_inodes from the events descriptor
The change to update the permissions of the eventfs_inode had the misconception that using the tracefs_inode would find all the eventfs_inodes that have been updated and reset them on remount. The problem with this approach is that the eventfs_inodes are freed when they are no longer used (basically the reason the eventfs system exists). When they are freed, the updated eventfs_inodes are not reset on a remount because their tracefs_inodes have been freed. Instead, since the events directory eventfs_inode always has a tracefs_inode pointing to it (it is not freed when finished), and the events directory has a link to all its children, have the eventfs_remount() function only operate on the events eventfs_inode and have it descend into its children updating their uid and gids. Link: https://lore.kernel.org/all/CAK7LNARXgaWw3kH9JgrnH4vK6fr8LDkNKf3wq8NhMWJrVwJyVQ@mail.gmail.com/ 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: baa23a8 ("tracefs: Reset permissions on remount if permissions are options") Reported-by: Masahiro Yamada <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 27c0464 commit 340f0c7

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

fs/tracefs/event_inode.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,27 +305,27 @@ static const struct file_operations eventfs_file_operations = {
305305
.llseek = generic_file_llseek,
306306
};
307307

308-
/*
309-
* On a remount of tracefs, if UID or GID options are set, then
310-
* the mount point inode permissions should be used.
311-
* Reset the saved permission flags appropriately.
312-
*/
313-
void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
308+
static void eventfs_set_attrs(struct eventfs_inode *ei, bool update_uid, kuid_t uid,
309+
bool update_gid, kgid_t gid, int level)
314310
{
315-
struct eventfs_inode *ei = ti->private;
311+
struct eventfs_inode *ei_child;
316312

317-
if (!ei)
313+
/* Update events/<system>/<event> */
314+
if (WARN_ON_ONCE(level > 3))
318315
return;
319316

320317
if (update_uid) {
321318
ei->attr.mode &= ~EVENTFS_SAVE_UID;
322-
ei->attr.uid = ti->vfs_inode.i_uid;
319+
ei->attr.uid = uid;
323320
}
324321

325-
326322
if (update_gid) {
327323
ei->attr.mode &= ~EVENTFS_SAVE_GID;
328-
ei->attr.gid = ti->vfs_inode.i_gid;
324+
ei->attr.gid = gid;
325+
}
326+
327+
list_for_each_entry(ei_child, &ei->children, list) {
328+
eventfs_set_attrs(ei_child, update_uid, uid, update_gid, gid, level + 1);
329329
}
330330

331331
if (!ei->entry_attrs)
@@ -334,13 +334,31 @@ void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
334334
for (int i = 0; i < ei->nr_entries; i++) {
335335
if (update_uid) {
336336
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_UID;
337-
ei->entry_attrs[i].uid = ti->vfs_inode.i_uid;
337+
ei->entry_attrs[i].uid = uid;
338338
}
339339
if (update_gid) {
340340
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_GID;
341-
ei->entry_attrs[i].gid = ti->vfs_inode.i_gid;
341+
ei->entry_attrs[i].gid = gid;
342342
}
343343
}
344+
345+
}
346+
347+
/*
348+
* On a remount of tracefs, if UID or GID options are set, then
349+
* the mount point inode permissions should be used.
350+
* Reset the saved permission flags appropriately.
351+
*/
352+
void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
353+
{
354+
struct eventfs_inode *ei = ti->private;
355+
356+
/* Only the events directory does the updates */
357+
if (!ei || !ei->is_events || ei->is_freed)
358+
return;
359+
360+
eventfs_set_attrs(ei, update_uid, ti->vfs_inode.i_uid,
361+
update_gid, ti->vfs_inode.i_gid, 0);
344362
}
345363

346364
/* Return the evenfs_inode of the "events" directory */

0 commit comments

Comments
 (0)