Skip to content

Commit 0dfc852

Browse files
committed
eventfs: Have event files and directories default to parent uid and gid
Dongliang reported: I found that in the latest version, the nodes of tracefs have been changed to dynamically created. This has caused me to encounter a problem where the gid I specified in the mounting parameters cannot apply to all files, as in the following situation: /data/tmp/events # mount | grep tracefs tracefs on /data/tmp type tracefs (rw,seclabel,relatime,gid=3012) gid 3012 = readtracefs /data/tmp # ls -lh total 0 -r--r----- 1 root readtracefs 0 1970-01-01 08:00 README -r--r----- 1 root readtracefs 0 1970-01-01 08:00 available_events ums9621_1h10:/data/tmp/events # ls -lh total 0 drwxr-xr-x 2 root root 0 2023-12-19 00:56 alarmtimer drwxr-xr-x 2 root root 0 2023-12-19 00:56 asoc It will prevent certain applications from accessing tracefs properly, I try to avoid this issue by making the following modifications. To fix this, have the files created default to taking the ownership of the parent dentry unless the ownership was previously set by the user. Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/ Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: [email protected] Cc: Mathieu Desnoyers <[email protected]> Cc: Hongyu Jin <[email protected]> Fixes: 28e12c0 ("eventfs: Save ownership and mode") Acked-by: Masami Hiramatsu (Google) <[email protected]> Reported-by: Dongliang Cui <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 7beb82b commit 0dfc852

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fs/tracefs/event_inode.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static const struct file_operations eventfs_file_operations = {
148148
.release = eventfs_release,
149149
};
150150

151-
static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, umode_t mode)
151+
static void update_inode_attr(struct dentry *dentry, struct inode *inode,
152+
struct eventfs_attr *attr, umode_t mode)
152153
{
153154
if (!attr) {
154155
inode->i_mode = mode;
@@ -162,9 +163,13 @@ static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, um
162163

163164
if (attr->mode & EVENTFS_SAVE_UID)
164165
inode->i_uid = attr->uid;
166+
else
167+
inode->i_uid = d_inode(dentry->d_parent)->i_uid;
165168

166169
if (attr->mode & EVENTFS_SAVE_GID)
167170
inode->i_gid = attr->gid;
171+
else
172+
inode->i_gid = d_inode(dentry->d_parent)->i_gid;
168173
}
169174

170175
/**
@@ -206,7 +211,7 @@ static struct dentry *create_file(const char *name, umode_t mode,
206211
return eventfs_failed_creating(dentry);
207212

208213
/* If the user updated the directory's attributes, use them */
209-
update_inode_attr(inode, attr, mode);
214+
update_inode_attr(dentry, inode, attr, mode);
210215

211216
inode->i_op = &eventfs_file_inode_operations;
212217
inode->i_fop = fop;
@@ -242,7 +247,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent
242247
return eventfs_failed_creating(dentry);
243248

244249
/* If the user updated the directory's attributes, use them */
245-
update_inode_attr(inode, &ei->attr, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
250+
update_inode_attr(dentry, inode, &ei->attr,
251+
S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
246252

247253
inode->i_op = &eventfs_root_dir_inode_operations;
248254
inode->i_fop = &eventfs_file_operations;

0 commit comments

Comments
 (0)