Skip to content

Commit 47311db

Browse files
computersforpeacerostedt
authored andcommitted
tracefs: Only clobber mode/uid/gid on remount if asked
Users may have explicitly configured their tracefs permissions; we shouldn't overwrite those just because a second mount appeared. Only clobber if the options were provided at mount time. Note: the previous behavior was especially surprising in the presence of automounted /sys/kernel/debug/tracing/. Existing behavior: ## Pre-existing status: tracefs is 0755. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x ## (Re)trigger the automount. # umount /sys/kernel/debug/tracing # stat -c '%A' /sys/kernel/debug/tracing/. drwx------ ## Unexpected: the automount changed mode for other mount instances. # stat -c '%A' /sys/kernel/tracing/ drwx------ New behavior (after this change): ## Pre-existing status: tracefs is 0755. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x ## (Re)trigger the automount. # umount /sys/kernel/debug/tracing # stat -c '%A' /sys/kernel/debug/tracing/. drwxr-xr-x ## Expected: the automount does not change other mount instances. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x Link: https://lkml.kernel.org/r/20220826174353.2.Iab6e5ea57963d6deca5311b27fb7226790d44406@changeid Cc: [email protected] Fixes: 4282d60 ("tracefs: Add new tracefs file system") Signed-off-by: Brian Norris <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 1efda38 commit 47311db

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

fs/tracefs/inode.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ struct tracefs_mount_opts {
141141
kuid_t uid;
142142
kgid_t gid;
143143
umode_t mode;
144+
/* Opt_* bitfield. */
145+
unsigned int opts;
144146
};
145147

146148
enum {
@@ -241,6 +243,7 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts)
241243
kgid_t gid;
242244
char *p;
243245

246+
opts->opts = 0;
244247
opts->mode = TRACEFS_DEFAULT_MODE;
245248

246249
while ((p = strsep(&data, ",")) != NULL) {
@@ -275,24 +278,36 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts)
275278
* but traditionally tracefs has ignored all mount options
276279
*/
277280
}
281+
282+
opts->opts |= BIT(token);
278283
}
279284

280285
return 0;
281286
}
282287

283-
static int tracefs_apply_options(struct super_block *sb)
288+
static int tracefs_apply_options(struct super_block *sb, bool remount)
284289
{
285290
struct tracefs_fs_info *fsi = sb->s_fs_info;
286291
struct inode *inode = d_inode(sb->s_root);
287292
struct tracefs_mount_opts *opts = &fsi->mount_opts;
288293

289-
inode->i_mode &= ~S_IALLUGO;
290-
inode->i_mode |= opts->mode;
294+
/*
295+
* On remount, only reset mode/uid/gid if they were provided as mount
296+
* options.
297+
*/
298+
299+
if (!remount || opts->opts & BIT(Opt_mode)) {
300+
inode->i_mode &= ~S_IALLUGO;
301+
inode->i_mode |= opts->mode;
302+
}
291303

292-
inode->i_uid = opts->uid;
304+
if (!remount || opts->opts & BIT(Opt_uid))
305+
inode->i_uid = opts->uid;
293306

294-
/* Set all the group ids to the mount option */
295-
set_gid(sb->s_root, opts->gid);
307+
if (!remount || opts->opts & BIT(Opt_gid)) {
308+
/* Set all the group ids to the mount option */
309+
set_gid(sb->s_root, opts->gid);
310+
}
296311

297312
return 0;
298313
}
@@ -307,7 +322,7 @@ static int tracefs_remount(struct super_block *sb, int *flags, char *data)
307322
if (err)
308323
goto fail;
309324

310-
tracefs_apply_options(sb);
325+
tracefs_apply_options(sb, true);
311326

312327
fail:
313328
return err;
@@ -359,7 +374,7 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent)
359374

360375
sb->s_op = &tracefs_super_operations;
361376

362-
tracefs_apply_options(sb);
377+
tracefs_apply_options(sb, false);
363378

364379
return 0;
365380

0 commit comments

Comments
 (0)