Skip to content

Commit 27c0464

Browse files
committed
tracefs: Update inode permissions on remount
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]>
1 parent 8898e7f commit 27c0464

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

fs/tracefs/event_inode.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,29 @@ void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool update_gid)
317317
if (!ei)
318318
return;
319319

320-
if (update_uid)
320+
if (update_uid) {
321321
ei->attr.mode &= ~EVENTFS_SAVE_UID;
322+
ei->attr.uid = ti->vfs_inode.i_uid;
323+
}
324+
322325

323-
if (update_gid)
326+
if (update_gid) {
324327
ei->attr.mode &= ~EVENTFS_SAVE_GID;
328+
ei->attr.gid = ti->vfs_inode.i_gid;
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 = ti->vfs_inode.i_uid;
338+
}
339+
if (update_gid) {
333340
ei->entry_attrs[i].mode &= ~EVENTFS_SAVE_GID;
341+
ei->entry_attrs[i].gid = ti->vfs_inode.i_gid;
342+
}
334343
}
335344
}
336345

fs/tracefs/inode.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,21 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
373373

374374
rcu_read_lock();
375375
list_for_each_entry_rcu(ti, &tracefs_inodes, list) {
376-
if (update_uid)
376+
if (update_uid) {
377377
ti->flags &= ~TRACEFS_UID_PERM_SET;
378+
ti->vfs_inode.i_uid = fsi->uid;
379+
}
378380

379-
if (update_gid)
381+
if (update_gid) {
380382
ti->flags &= ~TRACEFS_GID_PERM_SET;
381-
383+
ti->vfs_inode.i_gid = fsi->gid;
384+
}
385+
386+
/*
387+
* Note, the above ti->vfs_inode updates are
388+
* used in eventfs_remount() so they must come
389+
* before calling it.
390+
*/
382391
if (ti->flags & TRACEFS_EVENT_INODE)
383392
eventfs_remount(ti, update_uid, update_gid);
384393
}

0 commit comments

Comments
 (0)