Skip to content

Commit 99b86d8

Browse files
rostedtgregkh
authored andcommitted
eventfs: Update all the eventfs_inodes from the events descriptor
[ Upstream commit 340f0c7 ] 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/20240523051539.754424703@goodmis.org Cc: stable@vger.kernel.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> Fixes: baa23a8 ("tracefs: Reset permissions on remount if permissions are options") Reported-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d74ac0a commit 99b86d8

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

fs/tracefs/event_inode.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,33 +305,60 @@ 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

320-
if (update_uid)
317+
if (update_uid) {
321318
ei->attr.mode &= ~EVENTFS_SAVE_UID;
319+
ei->attr.uid = uid;
320+
}
322321

323-
if (update_gid)
322+
if (update_gid) {
324323
ei->attr.mode &= ~EVENTFS_SAVE_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);
329+
}
325330

326331
if (!ei->entry_attrs)
327332
return;
328333

329334
for (int i = 0; i < ei->nr_entries; i++) {
330-
if (update_uid)
335+
if (update_uid) {
331336
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_UID;
332-
if (update_gid)
337+
ei->entry_attrs[i].uid = uid;
338+
}
339+
if (update_gid) {
333340
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_GID;
341+
ei->entry_attrs[i].gid = gid;
342+
}
334343
}
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);
335362
}
336363

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

0 commit comments

Comments
 (0)