Skip to content

Commit 6599bd5

Browse files
committed
tracefs: Still use mount point as default permissions for instances
If the instances directory's permissions were never change, then have it and its children use the mount point permissions as the default. Currently, the permissions of instance directories are determined by the instance directory's permissions itself. But if the tracefs file system is remounted and changes the permissions, the instance directory and its children should use the new permission. But because both the instance directory and its children use the instance directory's inode for permissions, it misses the update. To demonstrate this: # cd /sys/kernel/tracing/ # mkdir instances/foo # ls -ld instances/foo drwxr-x--- 5 root root 0 May 1 19:07 instances/foo # ls -ld instances drwxr-x--- 3 root root 0 May 1 18:57 instances # ls -ld current_tracer -rw-r----- 1 root root 0 May 1 18:57 current_tracer # mount -o remount,gid=1002 . # ls -ld instances drwxr-x--- 3 root root 0 May 1 18:57 instances # ls -ld instances/foo/ drwxr-x--- 5 root root 0 May 1 19:07 instances/foo/ # ls -ld current_tracer -rw-r----- 1 root lkp 0 May 1 18:57 current_tracer Notice that changing the group id to that of "lkp" did not affect the instances directory nor its children. It should have been: # ls -ld current_tracer -rw-r----- 1 root root 0 May 1 19:19 current_tracer # ls -ld instances/foo/ drwxr-x--- 5 root root 0 May 1 19:25 instances/foo/ # ls -ld instances drwxr-x--- 3 root root 0 May 1 19:19 instances # mount -o remount,gid=1002 . # ls -ld current_tracer -rw-r----- 1 root lkp 0 May 1 19:19 current_tracer # ls -ld instances drwxr-x--- 3 root lkp 0 May 1 19:19 instances # ls -ld instances/foo/ drwxr-x--- 5 root lkp 0 May 1 19:25 instances/foo/ Where all files were updated by the remount gid update. 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: 8186fff ("tracefs/eventfs: Use root and instance inodes as default ownership") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent baa23a8 commit 6599bd5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

fs/tracefs/inode.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,39 @@ static void set_tracefs_inode_owner(struct inode *inode)
180180
{
181181
struct tracefs_inode *ti = get_tracefs(inode);
182182
struct inode *root_inode = ti->private;
183+
kuid_t uid;
184+
kgid_t gid;
185+
186+
uid = root_inode->i_uid;
187+
gid = root_inode->i_gid;
188+
189+
/*
190+
* If the root is not the mount point, then check the root's
191+
* permissions. If it was never set, then default to the
192+
* mount point.
193+
*/
194+
if (root_inode != d_inode(root_inode->i_sb->s_root)) {
195+
struct tracefs_inode *rti;
196+
197+
rti = get_tracefs(root_inode);
198+
root_inode = d_inode(root_inode->i_sb->s_root);
199+
200+
if (!(rti->flags & TRACEFS_UID_PERM_SET))
201+
uid = root_inode->i_uid;
202+
203+
if (!(rti->flags & TRACEFS_GID_PERM_SET))
204+
gid = root_inode->i_gid;
205+
}
183206

184207
/*
185208
* If this inode has never been referenced, then update
186209
* the permissions to the superblock.
187210
*/
188211
if (!(ti->flags & TRACEFS_UID_PERM_SET))
189-
inode->i_uid = root_inode->i_uid;
212+
inode->i_uid = uid;
190213

191214
if (!(ti->flags & TRACEFS_GID_PERM_SET))
192-
inode->i_gid = root_inode->i_gid;
215+
inode->i_gid = gid;
193216
}
194217

195218
static int tracefs_permission(struct mnt_idmap *idmap,

0 commit comments

Comments
 (0)