Skip to contentSkip to conversation

tracefs: Set the group ownership in apply_options() not parse_options()

PATCH Superseded Steven Rostedt 1 participant 2 messages Feb 25, 2022 Tracing

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH v2 1/1 tracefs: Set the group ownership in apply_options() not parse_options()

From: "Steven Rostedt (Google)" <[email protected]>

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().

Fixes 48b27b6b5191 ("tracefs: Set all files to the same group ownership as the mount option")
---
 fs/tracefs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/tracefs/inode.c +3 -1
index bafc02bf8220..3638d330ff5a 100644
@@ -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;
 }
 
Signature · 1 line
2.34.1
author maintainer
#1 lore raw
Quoted 32 lines · On Fri, 25 Feb 2022 15:21:23 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (Google)" <[email protected]>

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().

Fixes 48b27b6b5191 ("tracefs: Set all files to the same group ownership as the mount option")
---
 fs/tracefs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/tracefs/inode.c +0 -1
index bafc02bf8220..3638d330ff5a 100644
@@ -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))

fs/tracefs/inode.c static int tracefs_apply_options(struct super_block *sb) · line 296

Quoted 5 lines
fs/tracefs/inode.c +2 -0
@@ -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);

Bah, I forgot the '-a' in 'git commit -a --amend'

Ignore this :-/

-- Steve

Quoted 4 lines
fs/tracefs/inode.c +1 -0
+
 	return 0;
 }