All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] debugfs: Only clobber mode/uid/gid on remount if asked
@ 2022-08-27  0:44 Brian Norris
  2022-08-27  0:44 ` [PATCH 2/2] tracefs: " Brian Norris
  2022-09-01 15:58 ` [PATCH 1/2] debugfs: " Greg Kroah-Hartman
  0 siblings, 2 replies; 17+ messages in thread
From: Brian Norris @ 2022-08-27  0:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J . Wysocki, Ingo Molnar, Steven Rostedt
  Cc: linux-kernel, Brian Norris

Users may have explicitly configured their debugfs permissions; we
shouldn't overwrite those just because a second mount appeared.

Only clobber if the options were provided at mount time.

  # Don't change /sys/kernel/debug/ permissions.
  mount -t debugfs none /mnt/foo

  # Change /sys/kernel/debug/ mode and uid, but not gid.
  mount -t debugfs -o uid=bar,mode=0750 none /mnt/baz

Signed-off-by: Brian Norris <briannorris@chromium.org>
---
I'm open to writing an LTP test case for this, if that seems like a good
idea.

 fs/debugfs/inode.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 3dcf0b8b4e93..1e36ce013631 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -82,6 +82,8 @@ struct debugfs_mount_opts {
 	kuid_t uid;
 	kgid_t gid;
 	umode_t mode;
+	/* Opt_* bitfield. */
+	unsigned int opts;
 };
 
 enum {
@@ -111,6 +113,7 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
 	kgid_t gid;
 	char *p;
 
+	opts->opts = 0;
 	opts->mode = DEBUGFS_DEFAULT_MODE;
 
 	while ((p = strsep(&data, ",")) != NULL) {
@@ -145,22 +148,34 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
 		 * but traditionally debugfs has ignored all mount options
 		 */
 		}
+
+		opts->opts |= BIT(token);
 	}
 
 	return 0;
 }
 
-static int debugfs_apply_options(struct super_block *sb)
+static int debugfs_apply_options(struct super_block *sb, bool remount)
 {
 	struct debugfs_fs_info *fsi = sb->s_fs_info;
 	struct inode *inode = d_inode(sb->s_root);
 	struct debugfs_mount_opts *opts = &fsi->mount_opts;
 
-	inode->i_mode &= ~S_IALLUGO;
-	inode->i_mode |= opts->mode;
+	/*
+	 * On remount, only reset mode/uid/gid if they were provided as mount
+	 * options.
+	 */
+
+	if (!remount || opts->opts & BIT(Opt_mode)) {
+		inode->i_mode &= ~S_IALLUGO;
+		inode->i_mode |= opts->mode;
+	}
+
+	if (!remount || opts->opts & BIT(Opt_uid))
+		inode->i_uid = opts->uid;
 
-	inode->i_uid = opts->uid;
-	inode->i_gid = opts->gid;
+	if (!remount || opts->opts & BIT(Opt_gid))
+		inode->i_gid = opts->gid;
 
 	return 0;
 }
@@ -175,7 +190,7 @@ static int debugfs_remount(struct super_block *sb, int *flags, char *data)
 	if (err)
 		goto fail;
 
-	debugfs_apply_options(sb);
+	debugfs_apply_options(sb, true);
 
 fail:
 	return err;
@@ -257,7 +272,7 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_op = &debugfs_super_operations;
 	sb->s_d_op = &debugfs_dops;
 
-	debugfs_apply_options(sb);
+	debugfs_apply_options(sb, false);
 
 	return 0;
 
-- 
2.37.2.672.g94769d06f0-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-09-09  1:05 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27  0:44 [PATCH 1/2] debugfs: Only clobber mode/uid/gid on remount if asked Brian Norris
2022-08-27  0:44 ` [PATCH 2/2] tracefs: " Brian Norris
2022-09-07 11:44   ` Steven Rostedt
2022-09-07 20:52     ` Brian Norris
2022-09-08  1:25       ` Steven Rostedt
2022-09-07 21:46   ` Steven Rostedt
2022-09-07 21:48     ` Steven Rostedt
2022-09-07 21:53       ` Brian Norris
2022-09-07 22:45         ` Steven Rostedt
2022-09-01 15:58 ` [PATCH 1/2] debugfs: " Greg Kroah-Hartman
2022-09-01 16:11   ` Steven Rostedt
2022-09-01 22:32   ` Brian Norris
2022-09-02  5:45     ` Greg Kroah-Hartman
2022-09-09  0:16       ` Brian Norris
2022-09-09  0:43         ` Steven Rostedt
2022-09-09  0:57           ` Brian Norris
2022-09-09  1:05             ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.