Patch "eventfs: Have "events" directory get permissions from its parent" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    eventfs: Have "events" directory get permissions from its parent

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     eventfs-have-events-directory-get-permissions-from-i.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2918c1b1bee28ae2c0c10cc10b47b5046aeba2be
Author: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
Date:   Thu May 2 16:08:27 2024 -0400

    eventfs: Have "events" directory get permissions from its parent
    
    [ Upstream commit d57cf30c4c07837799edec949102b0adf58bae79 ]
    
    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/20240502200906.161887248@xxxxxxxxxxx
    
    Cc: stable@xxxxxxxxxxxxxxx
    Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
    Cc: Mark Rutland <mark.rutland@xxxxxxx>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
    Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Fixes: 8186fff7ab649 ("tracefs/eventfs: Use root and instance inodes as default ownership")
    Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index fd111e10f04e4..3b785f4ca95e4 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -37,6 +37,7 @@ static DEFINE_MUTEX(eventfs_mutex);
 
 struct eventfs_root_inode {
 	struct eventfs_inode		ei;
+	struct inode			*parent_inode;
 	struct dentry			*events_dir;
 };
 
@@ -226,12 +227,23 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
 
 static void update_events_attr(struct eventfs_inode *ei, struct super_block *sb)
 {
-	struct inode *root;
+	struct eventfs_root_inode *rei;
+	struct inode *parent;
+
+	rei = get_root_inode(ei);
+
+	/* Use the parent inode permissions unless root set its permissions */
+	parent = rei->parent_inode;
 
-	/* Get the tracefs root inode. */
-	root = d_inode(sb->s_root);
-	ei->attr.uid = root->i_uid;
-	ei->attr.gid = root->i_gid;
+	if (rei->ei.attr.mode & EVENTFS_SAVE_UID)
+		ei->attr.uid = rei->ei.attr.uid;
+	else
+		ei->attr.uid = parent->i_uid;
+
+	if (rei->ei.attr.mode & EVENTFS_SAVE_GID)
+		ei->attr.gid = rei->ei.attr.gid;
+	else
+		ei->attr.gid = parent->i_gid;
 }
 
 static void set_top_events_ownership(struct inode *inode)
@@ -810,6 +822,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	// Note: we have a ref to the dentry from tracefs_start_creating()
 	rei = get_root_inode(ei);
 	rei->events_dir = dentry;
+	rei->parent_inode = d_inode(dentry->d_sb->s_root);
 
 	ei->entries = entries;
 	ei->nr_entries = size;
@@ -819,10 +832,15 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
 	uid = d_inode(dentry->d_parent)->i_uid;
 	gid = d_inode(dentry->d_parent)->i_gid;
 
-	/* This is used as the default ownership of the files and directories */
 	ei->attr.uid = uid;
 	ei->attr.gid = gid;
 
+	/*
+	 * When the "events" directory is created, it takes on the
+	 * permissions of its parent. But can be reset on remount.
+	 */
+	ei->attr.mode |= EVENTFS_SAVE_UID | EVENTFS_SAVE_GID;
+
 	INIT_LIST_HEAD(&ei->children);
 	INIT_LIST_HEAD(&ei->list);
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux