From: "Steven Rostedt (Google)" rostedt@goodmis.org
Al Viro brought it to my attention that the dentries may not be filled when the parse_options() is called, causing the call to set_gid() to possibly crash. It should only be called if parse_options() succeeds totally anyway.
He suggested the logical place to do the update is in apply_options().
Cc: stable@vger.kernel.org Reported-by: Al Viro viro@zeniv.linux.org.uk Fixes: 48b27b6b5191 ("tracefs: Set all files to the same group ownership as the mount option") Signed-off-by: Steven Rostedt (Google) rostedt@goodmis.org --- fs/tracefs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index bafc02bf8220..3638d330ff5a 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -264,7 +264,6 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) if (!gid_valid(gid)) return -EINVAL; opts->gid = gid; - set_gid(tracefs_mount->mnt_root, gid); break; case Opt_mode: if (match_octal(&args[0], &option)) @@ -293,6 +292,9 @@ static int tracefs_apply_options(struct super_block *sb) inode->i_uid = opts->uid; inode->i_gid = opts->gid;
+ if (tracefs_mount && tracefs_mount->mnt_root) + set_gid(tracefs_mount->mnt_root, opts->gid); + return 0; }
On Fri, Feb 25, 2022 at 11:52:00AM -0500, Steven Rostedt wrote:
@@ -293,6 +292,9 @@ static int tracefs_apply_options(struct super_block *sb) inode->i_uid = opts->uid; inode->i_gid = opts->gid;
- if (tracefs_mount && tracefs_mount->mnt_root)
set_gid(tracefs_mount->mnt_root, opts->gid);
Umm... Why bother with tracefs_mount here in the first place? You have the superblock the operation is applied for - right in the arguments.
Just make that set_gid(sb->s_root, opts->gid); and be done with that. Same place in tracefs_apply_options()...
Incidentally, I'm not sure you need to keep ->i_gid assignment - set_gid() won't miss that inode, so...
On Fri, 25 Feb 2022 17:11:00 +0000 Al Viro viro@zeniv.linux.org.uk wrote:
On Fri, Feb 25, 2022 at 11:52:00AM -0500, Steven Rostedt wrote:
@@ -293,6 +292,9 @@ static int tracefs_apply_options(struct super_block *sb) inode->i_uid = opts->uid; inode->i_gid = opts->gid;
- if (tracefs_mount && tracefs_mount->mnt_root)
set_gid(tracefs_mount->mnt_root, opts->gid);
Umm... Why bother with tracefs_mount here in the first place? You have the superblock the operation is applied for - right in the arguments.
Ah, because I didn't realize they were one and the same ;-)
Just make that set_gid(sb->s_root, opts->gid); and be done with that. Same place in tracefs_apply_options()...
Incidentally, I'm not sure you need to keep ->i_gid assignment - set_gid() won't miss that inode, so...
Makes sense. Thanks.
I guess I wont be sending my pull request to Linus now :-/
-- Steve
linux-stable-mirror@lists.linaro.org