diff mbox series

[4/6] autofs - use struct for mount params

Message ID 154207297923.11064.15608451642929332541.stgit@pluto-themaw-net (mailing list archive)
State New, archived
Headers show
Series [1/6] autofs - improve ioctl sbi checks | expand

Commit Message

Ian Kent Nov. 13, 2018, 1:36 a.m. UTC
Use a structure to hold parsed parameters to simplify the
autofs_parse_options() function call.

Also seperate option parsing and applying the options into
seperate functions.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 fs/autofs/inode.c |  193 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 116 insertions(+), 77 deletions(-)

Comments

kernel test robot Nov. 14, 2018, 1:54 a.m. UTC | #1
Hi Ian,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc2]
[cannot apply to next-20181113]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Ian-Kent/autofs-improve-ioctl-sbi-checks/20181114-021150
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   fs/autofs/inode.c: In function 'autofs_fill_super':
>> fs/autofs/inode.c:361:28: error: invalid type argument of '->' (have 'struct autofs_fs_params')
     root_inode->i_uid = params->uid;
                               ^~
   fs/autofs/inode.c:362:28: error: invalid type argument of '->' (have 'struct autofs_fs_params')
     root_inode->i_gid = params->gid;
                               ^~

vim +361 fs/autofs/inode.c

   313	
   314	int autofs_fill_super(struct super_block *s, void *data, int silent)
   315	{
   316		struct inode *root_inode;
   317		struct dentry *root;
   318		struct autofs_fs_params params;
   319		struct autofs_sb_info *sbi;
   320		struct autofs_info *ino;
   321		int ret = -EINVAL;
   322	
   323		sbi = autofs_alloc_sbi(s);
   324		if (!sbi)
   325			return -ENOMEM;
   326	
   327		pr_debug("starting up, sbi = %p\n", sbi);
   328	
   329		s->s_fs_info = sbi;
   330		s->s_blocksize = 1024;
   331		s->s_blocksize_bits = 10;
   332		s->s_magic = AUTOFS_SUPER_MAGIC;
   333		s->s_op = &autofs_sops;
   334		s->s_d_op = &autofs_dentry_operations;
   335		s->s_time_gran = 1;
   336	
   337		/*
   338		 * Get the root inode and dentry, but defer checking for errors.
   339		 */
   340		ino = autofs_new_ino(sbi);
   341		if (!ino) {
   342			ret = -ENOMEM;
   343			goto fail_free;
   344		}
   345		root_inode = autofs_get_inode(s, S_IFDIR | 0755);
   346		if (!root_inode) {
   347			ret = -ENOMEM;
   348			goto fail_ino;
   349		}
   350		root = d_make_root(root_inode);
   351		if (!root)
   352			goto fail_iput;
   353	
   354		root->d_fsdata = ino;
   355	
   356		memset(&params, 0, sizeof(struct autofs_fs_params));
   357		if (autofs_parse_options(data, &params)) {
   358			pr_err("called with bogus options\n");
   359			goto fail_dput;
   360		}
 > 361		root_inode->i_uid = params->uid;
   362		root_inode->i_gid = params->gid;
   363	
   364		ret = autofs_apply_sbi_options(sbi, &params);
   365		if (ret)
   366			goto fail_dput;
   367	
   368		if (autofs_type_trigger(sbi->type))
   369			__managed_dentry_set_managed(root);
   370	
   371		root_inode->i_fop = &autofs_root_operations;
   372		root_inode->i_op = &autofs_dir_inode_operations;
   373	
   374		/*
   375		 * Success! Install the root dentry now to indicate completion.
   376		 */
   377		s->s_root = root;
   378		return 0;
   379	
   380		/*
   381		 * Failure ... clean up.
   382		 */
   383	fail_dput:
   384		dput(root);
   385		goto fail_free;
   386	fail_iput:
   387		iput(root_inode);
   388	fail_ino:
   389		autofs_free_ino(ino);
   390	fail_free:
   391		kfree(sbi);
   392		s->s_fs_info = NULL;
   393		return ret;
   394	}
   395	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Ian Kent Nov. 14, 2018, 5:56 a.m. UTC | #2
On Wed, 2018-11-14 at 09:54 +0800, kbuild test robot wrote:
> Hi Ian,
> 
> I love your patch! Yet something to improve:
> 
> [auto build test ERROR on linus/master]
> [also build test ERROR on v4.20-rc2]
> [cannot apply to next-20181113]
> [if your patch is applied to the wrong git tree, please drop us a note to help
> improve the system]
> 
> url:    
> https://github.com/0day-ci/linux/commits/Ian-Kent/autofs-improve-ioctl-sbi-checks/20181114-021150
> config: i386-allmodconfig (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=i386 
> 
> All errors (new ones prefixed by >>):
> 
>    fs/autofs/inode.c: In function 'autofs_fill_super':
> > > fs/autofs/inode.c:361:28: error: invalid type argument of '->' (have
> > > 'struct autofs_fs_params')
> 
>      root_inode->i_uid = params->uid;
>                                ^~
>    fs/autofs/inode.c:362:28: error: invalid type argument of '->' (have
> 'struct autofs_fs_params')
>      root_inode->i_gid = params->gid;
>                                ^~

Oh, I fixed that, I must have messed up somewhere, I'll check what I have
again.

Andrew, due to the patch order dependencies I think it would be best for
me to re-post the series so please ignore this series.

I'll put a v2 in the title of the re-posted series so they can be identified
(is that the right thing to do?).

> 
> vim +361 fs/autofs/inode.c
> 
>    313	
>    314	int autofs_fill_super(struct super_block *s, void *data, int
> silent)
>    315	{
>    316		struct inode *root_inode;
>    317		struct dentry *root;
>    318		struct autofs_fs_params params;
>    319		struct autofs_sb_info *sbi;
>    320		struct autofs_info *ino;
>    321		int ret = -EINVAL;
>    322	
>    323		sbi = autofs_alloc_sbi(s);
>    324		if (!sbi)
>    325			return -ENOMEM;
>    326	
>    327		pr_debug("starting up, sbi = %p\n", sbi);
>    328	
>    329		s->s_fs_info = sbi;
>    330		s->s_blocksize = 1024;
>    331		s->s_blocksize_bits = 10;
>    332		s->s_magic = AUTOFS_SUPER_MAGIC;
>    333		s->s_op = &autofs_sops;
>    334		s->s_d_op = &autofs_dentry_operations;
>    335		s->s_time_gran = 1;
>    336	
>    337		/*
>    338		 * Get the root inode and dentry, but defer checking for
> errors.
>    339		 */
>    340		ino = autofs_new_ino(sbi);
>    341		if (!ino) {
>    342			ret = -ENOMEM;
>    343			goto fail_free;
>    344		}
>    345		root_inode = autofs_get_inode(s, S_IFDIR | 0755);
>    346		if (!root_inode) {
>    347			ret = -ENOMEM;
>    348			goto fail_ino;
>    349		}
>    350		root = d_make_root(root_inode);
>    351		if (!root)
>    352			goto fail_iput;
>    353	
>    354		root->d_fsdata = ino;
>    355	
>    356		memset(&params, 0, sizeof(struct autofs_fs_params));
>    357		if (autofs_parse_options(data, &params)) {
>    358			pr_err("called with bogus options\n");
>    359			goto fail_dput;
>    360		}
>  > 361		root_inode->i_uid = params->uid;
>    362		root_inode->i_gid = params->gid;
>    363	
>    364		ret = autofs_apply_sbi_options(sbi, &params);
>    365		if (ret)
>    366			goto fail_dput;
>    367	
>    368		if (autofs_type_trigger(sbi->type))
>    369			__managed_dentry_set_managed(root);
>    370	
>    371		root_inode->i_fop = &autofs_root_operations;
>    372		root_inode->i_op = &autofs_dir_inode_operations;
>    373	
>    374		/*
>    375		 * Success! Install the root dentry now to indicate
> completion.
>    376		 */
>    377		s->s_root = root;
>    378		return 0;
>    379	
>    380		/*
>    381		 * Failure ... clean up.
>    382		 */
>    383	fail_dput:
>    384		dput(root);
>    385		goto fail_free;
>    386	fail_iput:
>    387		iput(root_inode);
>    388	fail_ino:
>    389		autofs_free_ino(ino);
>    390	fail_free:
>    391		kfree(sbi);
>    392		s->s_fs_info = NULL;
>    393		return ret;
>    394	}
>    395	
> 
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index 93af0d5777ae..53ed6c637cbf 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -108,6 +108,17 @@  static const struct super_operations autofs_sops = {
 	.evict_inode	= autofs_evict_inode,
 };
 
+struct autofs_fs_params {
+	int pipefd;
+	kuid_t uid;
+	kgid_t gid;
+	int pgrp;
+	bool pgrp_set;
+	int min_proto;
+	int max_proto;
+	unsigned int type;
+};
+
 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
 	Opt_indirect, Opt_direct, Opt_offset};
 
@@ -124,24 +135,26 @@  static const match_table_t tokens = {
 	{Opt_err, NULL}
 };
 
-static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,
-			 int *pgrp, bool *pgrp_set, unsigned int *type,
-			 int *minproto, int *maxproto)
+static int autofs_parse_options(char *options, struct autofs_fs_params *params)
 {
 	char *p;
 	substring_t args[MAX_OPT_ARGS];
 	int option;
+	kuid_t uid;
+	kgid_t gid;
+
+	if (!options)
+		return 1;
 
-	*uid = current_uid();
-	*gid = current_gid();
+	params->pipefd = -1;
 
-	*minproto = AUTOFS_MIN_PROTO_VERSION;
-	*maxproto = AUTOFS_MAX_PROTO_VERSION;
+	params->uid = current_uid();
+	params->gid = current_gid();
 
-	*pipefd = -1;
+	params->min_proto = AUTOFS_MIN_PROTO_VERSION;
+	params->max_proto = AUTOFS_MAX_PROTO_VERSION;
 
-	if (!options)
-		return 1;
+	params->pgrp_set = false;
 
 	while ((p = strsep(&options, ",")) != NULL) {
 		int token;
@@ -152,53 +165,126 @@  static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,
 		token = match_token(p, tokens, args);
 		switch (token) {
 		case Opt_fd:
-			if (match_int(args, pipefd))
+			if (match_int(args, &option))
 				return 1;
+			params->pipefd = option;
 			break;
 		case Opt_uid:
 			if (match_int(args, &option))
 				return 1;
-			*uid = make_kuid(current_user_ns(), option);
-			if (!uid_valid(*uid))
+			uid = make_kuid(current_user_ns(), option);
+			if (!uid_valid(uid))
 				return 1;
+			params->uid = uid;
 			break;
 		case Opt_gid:
 			if (match_int(args, &option))
 				return 1;
-			*gid = make_kgid(current_user_ns(), option);
-			if (!gid_valid(*gid))
+			gid = make_kgid(current_user_ns(), option);
+			if (!gid_valid(gid))
 				return 1;
+			params->gid = gid;
 			break;
 		case Opt_pgrp:
 			if (match_int(args, &option))
 				return 1;
-			*pgrp = option;
-			*pgrp_set = true;
+			params->pgrp = option;
+			params->pgrp_set = true;
 			break;
 		case Opt_minproto:
 			if (match_int(args, &option))
 				return 1;
-			*minproto = option;
+			params->min_proto = option;
 			break;
 		case Opt_maxproto:
 			if (match_int(args, &option))
 				return 1;
-			*maxproto = option;
+			params->max_proto = option;
 			break;
 		case Opt_indirect:
-			set_autofs_type_indirect(type);
+			set_autofs_type_indirect(&params->type);
 			break;
 		case Opt_direct:
-			set_autofs_type_direct(type);
+			set_autofs_type_direct(&params->type);
 			break;
 		case Opt_offset:
-			set_autofs_type_offset(type);
+			set_autofs_type_offset(&params->type);
 			break;
 		default:
 			return 1;
 		}
 	}
-	return (*pipefd < 0);
+	return (params->pipefd < 0);
+}
+
+static int autofs_apply_sbi_options(struct autofs_sb_info *sbi,
+				    struct autofs_fs_params *params)
+{
+	int err;
+
+	sbi->pipefd = params->pipefd;
+
+	if (params->type)
+		sbi->type = params->type;
+
+	/* Test versions first */
+	if (params->max_proto < AUTOFS_MIN_PROTO_VERSION ||
+	    params->min_proto > AUTOFS_MAX_PROTO_VERSION) {
+		pr_err("kernel does not match daemon version\n");
+		pr_err("daemon (%d, %d) kernel (%d, %d)\n",
+			params->min_proto, params->max_proto,
+			AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
+		goto out;
+	}
+
+	sbi->max_proto = params->max_proto;
+	sbi->min_proto = params->min_proto;
+
+	if (sbi->min_proto > sbi->max_proto)
+		sbi->min_proto = params->max_proto;
+
+	/* Establish highest kernel protocol version */
+	if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
+		sbi->version = AUTOFS_MAX_PROTO_VERSION;
+	else
+		sbi->version = params->max_proto;
+
+	sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
+
+	if (!params->pgrp_set)
+		sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
+	else {
+		sbi->oz_pgrp = find_get_pid(params->pgrp);
+		if (!sbi->oz_pgrp) {
+			pr_err("could not find process group %d\n",
+			       params->pgrp);
+			goto out;
+		}
+	}
+
+	pr_debug("pipe fd = %d, pgrp = %u\n",
+		  sbi->pipefd, pid_nr(sbi->oz_pgrp));
+
+	sbi->pipe = fget(sbi->pipefd);
+	if (!sbi->pipe) {
+		pr_err("could not open pipe file descriptor\n");
+		goto out_put_pid;
+	}
+
+	err = autofs_prepare_pipe(sbi->pipe);
+	if (err < 0)
+		goto out_fput;
+
+	sbi->catatonic = 0;
+
+	return 0;
+
+out_fput:
+	fput(sbi->pipe);
+out_put_pid:
+	put_pid(sbi->oz_pgrp);
+out:
+	return 1;
 }
 
 static struct autofs_sb_info *autofs_alloc_sbi(struct super_block *s)
@@ -229,12 +315,9 @@  int autofs_fill_super(struct super_block *s, void *data, int silent)
 {
 	struct inode *root_inode;
 	struct dentry *root;
-	struct file *pipe;
-	int pipefd;
+	struct autofs_fs_params params;
 	struct autofs_sb_info *sbi;
 	struct autofs_info *ino;
-	int pgrp = 0;
-	bool pgrp_set = false;
 	int ret = -EINVAL;
 
 	sbi = autofs_alloc_sbi(s);
@@ -267,45 +350,20 @@  int autofs_fill_super(struct super_block *s, void *data, int silent)
 	root = d_make_root(root_inode);
 	if (!root)
 		goto fail_iput;
-	pipe = NULL;
 
 	root->d_fsdata = ino;
 
-	/* Can this call block? */
-	if (parse_options(data, &pipefd, &root_inode->i_uid, &root_inode->i_gid,
-			  &pgrp, &pgrp_set, &sbi->type, &sbi->min_proto,
-			  &sbi->max_proto)) {
+	memset(&params, 0, sizeof(struct autofs_fs_params));
+	if (autofs_parse_options(data, &params)) {
 		pr_err("called with bogus options\n");
 		goto fail_dput;
 	}
+	root_inode->i_uid = params->uid;
+	root_inode->i_gid = params->gid;
 
-	/* Test versions first */
-	if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
-	    sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
-		pr_err("kernel does not match daemon version "
-		       "daemon (%d, %d) kernel (%d, %d)\n",
-		       sbi->min_proto, sbi->max_proto,
-		       AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
+	ret = autofs_apply_sbi_options(sbi, &params);
+	if (ret)
 		goto fail_dput;
-	}
-
-	/* Establish highest kernel protocol version */
-	if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
-		sbi->version = AUTOFS_MAX_PROTO_VERSION;
-	else
-		sbi->version = sbi->max_proto;
-	sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
-
-	if (pgrp_set) {
-		sbi->oz_pgrp = find_get_pid(pgrp);
-		if (!sbi->oz_pgrp) {
-			pr_err("could not find process group %d\n",
-				pgrp);
-			goto fail_dput;
-		}
-	} else {
-		sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
-	}
 
 	if (autofs_type_trigger(sbi->type))
 		__managed_dentry_set_managed(root);
@@ -313,20 +371,6 @@  int autofs_fill_super(struct super_block *s, void *data, int silent)
 	root_inode->i_fop = &autofs_root_operations;
 	root_inode->i_op = &autofs_dir_inode_operations;
 
-	pr_debug("pipe fd = %d, pgrp = %u\n", pipefd, pid_nr(sbi->oz_pgrp));
-
-	pipe = fget(pipefd);
-	if (!pipe) {
-		pr_err("could not open pipe file descriptor\n");
-		goto fail_put_pid;
-	}
-	ret = autofs_prepare_pipe(pipe);
-	if (ret < 0)
-		goto fail_fput;
-	sbi->pipe = pipe;
-	sbi->pipefd = pipefd;
-	sbi->catatonic = 0;
-
 	/*
 	 * Success! Install the root dentry now to indicate completion.
 	 */
@@ -336,11 +380,6 @@  int autofs_fill_super(struct super_block *s, void *data, int silent)
 	/*
 	 * Failure ... clean up.
 	 */
-fail_fput:
-	pr_err("pipe file descriptor does not contain proper ops\n");
-	fput(pipe);
-fail_put_pid:
-	put_pid(sbi->oz_pgrp);
 fail_dput:
 	dput(root);
 	goto fail_free;