All of lore.kernel.org
 help / color / mirror / Atom feed
* [V9fs-developer][PATCH v2 1/2] net/9p: detecting invalid options as much as possible
@ 2018-04-17  6:45 Chengguang Xu
  2018-04-17  6:45 ` [V9fs-developer][PATCH v2 2/2] fs/9p: " Chengguang Xu
  2018-05-02 22:32 ` [V9fs-developer] [PATCH v2 1/2] net/9p: " Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Chengguang Xu @ 2018-04-17  6:45 UTC (permalink / raw)
  To: ericvh, rminnich, lucho; +Cc: v9fs-developer, linux-kernel, Chengguang Xu

Currently when detecting invalid options in option parsing,
some options(e.g. msize) just set errno and allow to continuously
validate other options so that it can detect invalid options
as much as possible and give proper error messages together.

This patch applies same rule to option 'trans' and 'version'
when detecting EINVAL.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
Changes since v1:
- Do not change behavior when detecting ENOMEM or unrecognized options.

 net/9p/client.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/9p/client.c b/net/9p/client.c
index 21e6df1..38b02fb 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
 					s);
 				ret = -EINVAL;
 				kfree(s);
-				goto free_and_return;
+				continue;
 			}
 			kfree(s);
 			break;
@@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
 			ret = get_protocol_version(s);
 			if (ret == -EINVAL) {
 				kfree(s);
-				goto free_and_return;
+				continue;
 			}
 			kfree(s);
 			clnt->proto_version = ret;
-- 
1.8.3.1

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

* [V9fs-developer][PATCH v2 2/2] fs/9p: detecting invalid options as much as possible
  2018-04-17  6:45 [V9fs-developer][PATCH v2 1/2] net/9p: detecting invalid options as much as possible Chengguang Xu
@ 2018-04-17  6:45 ` Chengguang Xu
  2018-05-02 22:32 ` [V9fs-developer] [PATCH v2 1/2] net/9p: " Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: Chengguang Xu @ 2018-04-17  6:45 UTC (permalink / raw)
  To: ericvh, rminnich, lucho; +Cc: v9fs-developer, linux-kernel, Chengguang Xu

Currently when detecting invalid options in option parsing,
some options(e.g. msize) just set errno and allow to continuously
validate other options so that it can detect invalid options
as much as possible and give proper error messages together.

This patch applies same rule to option 'cache' and 'access'
when detecting EINVAL.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
Changes since v1:
- Do not change behavior when detecting ENOMEM or unrecognized options. 

 fs/9p/v9fs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index e622f0f..2c7a0ef 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -309,7 +309,7 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 			ret = get_cache_mode(s);
 			if (ret == -EINVAL) {
 				kfree(s);
-				goto free_and_return;
+				continue;
 			}
 
 			v9ses->cache = ret;
@@ -341,14 +341,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 					pr_info("Unknown access argument %s\n",
 						s);
 					kfree(s);
-					goto free_and_return;
+					continue;
 				}
 				v9ses->uid = make_kuid(current_user_ns(), uid);
 				if (!uid_valid(v9ses->uid)) {
 					ret = -EINVAL;
 					pr_info("Uknown uid %s\n", s);
 					kfree(s);
-					goto free_and_return;
+					continue;
 				}
 			}
 
-- 
1.8.3.1

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

* Re: [V9fs-developer] [PATCH v2 1/2] net/9p: detecting invalid options as much as possible
  2018-04-17  6:45 [V9fs-developer][PATCH v2 1/2] net/9p: detecting invalid options as much as possible Chengguang Xu
  2018-04-17  6:45 ` [V9fs-developer][PATCH v2 2/2] fs/9p: " Chengguang Xu
@ 2018-05-02 22:32 ` Andrew Morton
  2018-05-03  6:14   ` cgxu519
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2018-05-02 22:32 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: ericvh, rminnich, lucho, v9fs-developer, linux-kernel

On Tue, 17 Apr 2018 14:45:01 +0800 Chengguang Xu <cgxu519@gmx.com> wrote:

> Currently when detecting invalid options in option parsing,
> some options(e.g. msize) just set errno and allow to continuously
> validate other options so that it can detect invalid options
> as much as possible and give proper error messages together.
> 
> This patch applies same rule to option 'trans' and 'version'
> when detecting EINVAL.
> 
> ...

A few issues:

> --- a/net/9p/client.c
> +++ b/net/9p/client.c
> @@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>  					s);
>  				ret = -EINVAL;
>  				kfree(s);
> -				goto free_and_return;
> +				continue;
>  			}
>  			kfree(s);
>  			break;

Here we can just do

--- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
+++ a/net/9p/client.c
@@ -198,8 +198,6 @@ static int parse_opts(char *opts, struct
 				pr_info("Could not find request transport: %s\n",
 					s);
 				ret = -EINVAL;
-				kfree(s);
-				continue;
 			}
 			kfree(s);
 			break;

> @@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>  			ret = get_protocol_version(s);

And here's the patch introduces a bug: if `ret' has value -EINVAL from
an earlier parsing error, this code will overwrite that error code with
zero.

So you'll need to introduce a new temporary variable here.  And I
suggest that for future-safety, we permit all error returns from
get_protocol_version(), not just -EINVAL.  So something like:

--- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
+++ a/net/9p/client.c
@@ -214,13 +214,12 @@ static int parse_opts(char *opts, struct
 					 "problem allocating copy of version arg\n");
 				goto free_and_return;
 			}
-			ret = get_protocol_version(s);
-			if (ret == -EINVAL) {
-				kfree(s);
-				continue;
-			}
+			pv = get_protocol_version(s);
+			if (pv >= 0)
+				clnt->proto_version = pv;
+			else
+				ret = pv;
 			kfree(s);
-			clnt->proto_version = ret;
 			break;
 		default:
 			continue;
_


Similar changes can be made to patch 2/2.

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

* Re: [V9fs-developer] [PATCH v2 1/2] net/9p: detecting invalid options as much as possible
  2018-05-02 22:32 ` [V9fs-developer] [PATCH v2 1/2] net/9p: " Andrew Morton
@ 2018-05-03  6:14   ` cgxu519
  0 siblings, 0 replies; 4+ messages in thread
From: cgxu519 @ 2018-05-03  6:14 UTC (permalink / raw)
  To: Andrew Morton
  Cc: cgxu519, ericvh, rminnich, lucho, v9fs-developer, linux-kernel

Thanks for your review, I’ll fix the issue in v3.


> 在 2018年5月3日,上午6:32,Andrew Morton <akpm@linux-foundation.org> 写道:
> 
> On Tue, 17 Apr 2018 14:45:01 +0800 Chengguang Xu <cgxu519@gmx.com> wrote:
> 
>> Currently when detecting invalid options in option parsing,
>> some options(e.g. msize) just set errno and allow to continuously
>> validate other options so that it can detect invalid options
>> as much as possible and give proper error messages together.
>> 
>> This patch applies same rule to option 'trans' and 'version'
>> when detecting EINVAL.
>> 
>> ...
> 
> A few issues:
> 
>> --- a/net/9p/client.c
>> +++ b/net/9p/client.c
>> @@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>> 					s);
>> 				ret = -EINVAL;
>> 				kfree(s);
>> -				goto free_and_return;
>> +				continue;
>> 			}
>> 			kfree(s);
>> 			break;
> 
> Here we can just do
> 
> --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
> +++ a/net/9p/client.c
> @@ -198,8 +198,6 @@ static int parse_opts(char *opts, struct
> 				pr_info("Could not find request transport: %s\n",
> 					s);
> 				ret = -EINVAL;
> -				kfree(s);
> -				continue;
> 			}
> 			kfree(s);
> 			break;
> 
>> @@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>> 			ret = get_protocol_version(s);
> 
> And here's the patch introduces a bug: if `ret' has value -EINVAL from
> an earlier parsing error, this code will overwrite that error code with
> zero.
> 
> So you'll need to introduce a new temporary variable here.  And I
> suggest that for future-safety, we permit all error returns from
> get_protocol_version(), not just -EINVAL.  So something like:
> 
> --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
> +++ a/net/9p/client.c
> @@ -214,13 +214,12 @@ static int parse_opts(char *opts, struct
> 					 "problem allocating copy of version arg\n");
> 				goto free_and_return;
> 			}
> -			ret = get_protocol_version(s);
> -			if (ret == -EINVAL) {
> -				kfree(s);
> -				continue;
> -			}
> +			pv = get_protocol_version(s);
> +			if (pv >= 0)
> +				clnt->proto_version = pv;
> +			else
> +				ret = pv;
> 			kfree(s);
> -			clnt->proto_version = ret;
> 			break;
> 		default:
> 			continue;
> _
> 
> 
> Similar changes can be made to patch 2/2.
> 

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

end of thread, other threads:[~2018-05-03  6:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17  6:45 [V9fs-developer][PATCH v2 1/2] net/9p: detecting invalid options as much as possible Chengguang Xu
2018-04-17  6:45 ` [V9fs-developer][PATCH v2 2/2] fs/9p: " Chengguang Xu
2018-05-02 22:32 ` [V9fs-developer] [PATCH v2 1/2] net/9p: " Andrew Morton
2018-05-03  6:14   ` cgxu519

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.