Skip to content

Commit

Permalink
tracefs: Update inode permissions on remount
Browse files Browse the repository at this point in the history
When a remount happens, if a gid or uid is specified update the inodes to
have the same gid and uid. This will allow the simplification of the
permissions logic for the dynamically created files and directories.

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]>
Cc: Masahiro Yamada <[email protected]>
Fixes: baa23a8 ("tracefs: Reset permissions on remount if permissions are options")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed May 23, 2024
1 parent 8898e7f commit 27c0464
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 13 additions & 4 deletions fs/tracefs/event_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,29 @@ void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
if (!ei)
return;

if (update_uid)
if (update_uid) {
ei->attr.mode &= ~EVENTFS_SAVE_UID;
ei->attr.uid = ti->vfs_inode.i_uid;
}


if (update_gid)
if (update_gid) {
ei->attr.mode &= ~EVENTFS_SAVE_GID;
ei->attr.gid = ti->vfs_inode.i_gid;
}

if (!ei->entry_attrs)
return;

for (int i = 0; i < ei->nr_entries; i++) {
if (update_uid)
if (update_uid) {
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_UID;
if (update_gid)
ei->entry_attrs[i].uid = ti->vfs_inode.i_uid;
}
if (update_gid) {
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_GID;
ei->entry_attrs[i].gid = ti->vfs_inode.i_gid;
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions fs/tracefs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,21 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)

rcu_read_lock();
list_for_each_entry_rcu(ti, &tracefs_inodes, list) {
if (update_uid)
if (update_uid) {
ti->flags &= ~TRACEFS_UID_PERM_SET;
ti->vfs_inode.i_uid = fsi->uid;
}

if (update_gid)
if (update_gid) {
ti->flags &= ~TRACEFS_GID_PERM_SET;

ti->vfs_inode.i_gid = fsi->gid;
}

/*
* Note, the above ti->vfs_inode updates are
* used in eventfs_remount() so they must come
* before calling it.
*/
if (ti->flags & TRACEFS_EVENT_INODE)
eventfs_remount(ti, update_uid, update_gid);
}
Expand Down

0 comments on commit 27c0464

Please sign in to comment.