Skip to content

Commit d57cf30

Browse files
committed
eventfs: Have "events" directory get permissions from its parent
The events directory gets its permissions from the root inode. But this can cause an inconsistency if the instances directory changes its permissions, as the permissions of the created directories under it should inherit the permissions of the instances directory when directories under it are created. Currently the behavior is: # cd /sys/kernel/tracing # chgrp 1002 instances # mkdir instances/foo # ls -l instances/foo [..] -r--r----- 1 root lkp 0 May 1 18:55 buffer_total_size_kb -rw-r----- 1 root lkp 0 May 1 18:55 current_tracer -rw-r----- 1 root lkp 0 May 1 18:55 error_log drwxr-xr-x 1 root root 0 May 1 18:55 events --w------- 1 root lkp 0 May 1 18:55 free_buffer drwxr-x--- 2 root lkp 0 May 1 18:55 options drwxr-x--- 10 root lkp 0 May 1 18:55 per_cpu -rw-r----- 1 root lkp 0 May 1 18:55 set_event All the files and directories under "foo" has the "lkp" group except the "events" directory. That's because its getting its default value from the mount point instead of its parent. Have the "events" directory make its default value based on its parent's permissions. That now gives: # ls -l instances/foo [..] -rw-r----- 1 root lkp 0 May 1 21:16 buffer_subbuf_size_kb -r--r----- 1 root lkp 0 May 1 21:16 buffer_total_size_kb -rw-r----- 1 root lkp 0 May 1 21:16 current_tracer -rw-r----- 1 root lkp 0 May 1 21:16 error_log drwxr-xr-x 1 root lkp 0 May 1 21:16 events --w------- 1 root lkp 0 May 1 21:16 free_buffer drwxr-x--- 2 root lkp 0 May 1 21:16 options drwxr-x--- 10 root lkp 0 May 1 21:16 per_cpu -rw-r----- 1 root lkp 0 May 1 21:16 set_event 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 22e61e1 commit d57cf30

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

fs/tracefs/event_inode.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static DEFINE_MUTEX(eventfs_mutex);
3737

3838
struct eventfs_root_inode {
3939
struct eventfs_inode ei;
40+
struct inode *parent_inode;
4041
struct dentry *events_dir;
4142
};
4243

@@ -226,12 +227,23 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
226227

227228
static void update_events_attr(struct eventfs_inode *ei, struct super_block *sb)
228229
{
229-
struct inode *root;
230+
struct eventfs_root_inode *rei;
231+
struct inode *parent;
232+
233+
rei = get_root_inode(ei);
234+
235+
/* Use the parent inode permissions unless root set its permissions */
236+
parent = rei->parent_inode;
230237

231-
/* Get the tracefs root inode. */
232-
root = d_inode(sb->s_root);
233-
ei->attr.uid = root->i_uid;
234-
ei->attr.gid = root->i_gid;
238+
if (rei->ei.attr.mode & EVENTFS_SAVE_UID)
239+
ei->attr.uid = rei->ei.attr.uid;
240+
else
241+
ei->attr.uid = parent->i_uid;
242+
243+
if (rei->ei.attr.mode & EVENTFS_SAVE_GID)
244+
ei->attr.gid = rei->ei.attr.gid;
245+
else
246+
ei->attr.gid = parent->i_gid;
235247
}
236248

237249
static void set_top_events_ownership(struct inode *inode)
@@ -817,6 +829,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
817829
// Note: we have a ref to the dentry from tracefs_start_creating()
818830
rei = get_root_inode(ei);
819831
rei->events_dir = dentry;
832+
rei->parent_inode = d_inode(dentry->d_sb->s_root);
820833

821834
ei->entries = entries;
822835
ei->nr_entries = size;
@@ -826,10 +839,15 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
826839
uid = d_inode(dentry->d_parent)->i_uid;
827840
gid = d_inode(dentry->d_parent)->i_gid;
828841

829-
/* This is used as the default ownership of the files and directories */
830842
ei->attr.uid = uid;
831843
ei->attr.gid = gid;
832844

845+
/*
846+
* When the "events" directory is created, it takes on the
847+
* permissions of its parent. But can be reset on remount.
848+
*/
849+
ei->attr.mode |= EVENTFS_SAVE_UID | EVENTFS_SAVE_GID;
850+
833851
INIT_LIST_HEAD(&ei->children);
834852
INIT_LIST_HEAD(&ei->list);
835853

0 commit comments

Comments
 (0)