[Devel,rh7,2/2] ve/fs/devmnt: allow more than one mount option inside a CT

Submitted by Konstantin Khorenko on June 26, 2017, 11:51 a.m.

Details

Message ID 1498477892-3683-1-git-send-email-khorenko@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko June 26, 2017, 11:51 a.m.
strsep() changes provided string: puts '\0' instead of separators,
thus after successful call to ve_devmnt_check() we insert
only first provided mount options, ignoring others.

Fixes: bc4143b ("ve/fs/devmnt: process mount options")

Found during implementation of
https://jira.sw.ru/browse/PSBM-40075

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/namespace.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/namespace.c b/fs/namespace.c
index 7aed8f5..f2d1f84 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1899,6 +1899,7 @@  static char *strstr_separated(char *haystack, char *needle, char sep)
 static int ve_devmnt_check(char *options, char *allowed)
 {
 	char *p;
+	char *tmp_options;
 
 	if (!options || !*options)
 		return 0;
@@ -1906,14 +1907,22 @@  static int ve_devmnt_check(char *options, char *allowed)
 	if (!allowed)
 		return -EPERM;
 
-	while ((p = strsep(&options, ",")) != NULL) {
+	/* strsep() changes provided string: puts '\0' instead of separators */
+	tmp_options = kstrdup(options, GFP_KERNEL);
+	if (!tmp_options)
+		return -ENOMEM;
+
+	while ((p = strsep(&tmp_options, ",")) != NULL) {
 		if (!*p)
 			continue;
 
-		if (!strstr_separated(allowed, p, ','))
+		if (!strstr_separated(allowed, p, ',')) {
+			kfree(tmp_options);
 			return -EPERM;
+		}
 	}
 
+	kfree(tmp_options);
 	return 0;
 }
 

Comments

Kirill Tkhai June 26, 2017, 4 p.m.
On Mon, Jun 26, 2017 at 15:51, Konstantin Khorenko wrote:
> strsep() changes provided string: puts '\0' instead of separators,
> thus after successful call to ve_devmnt_check() we insert
> only first provided mount options, ignoring others.
> 
> Fixes: bc4143b ("ve/fs/devmnt: process mount options")
> 
> Found during implementation of
> https://jira.sw.ru/browse/PSBM-40075
> 
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  fs/namespace.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 7aed8f5..f2d1f84 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -1899,6 +1899,7 @@ static char *strstr_separated(char *haystack, char *needle, char sep)
>  static int ve_devmnt_check(char *options, char *allowed)
>  {
>  	char *p;
> +	char *tmp_options;
>  
>  	if (!options || !*options)
>  		return 0;
> @@ -1906,14 +1907,22 @@ static int ve_devmnt_check(char *options, char *allowed)
>  	if (!allowed)
>  		return -EPERM;
>  
> -	while ((p = strsep(&options, ",")) != NULL) {
> +	/* strsep() changes provided string: puts '\0' instead of separators */
> +	tmp_options = kstrdup(options, GFP_KERNEL);
> +	if (!tmp_options)
> +		return -ENOMEM;
> +
> +	while ((p = strsep(&tmp_options, ",")) != NULL) {
>  		if (!*p)
>  			continue;
>  
> -		if (!strstr_separated(allowed, p, ','))
> +		if (!strstr_separated(allowed, p, ',')) {
> +			kfree(tmp_options);
>  			return -EPERM;
> +		}
>  	}
>  
> +	kfree(tmp_options);
>  	return 0;
>  }
>  
> -- 
> 1.8.3.1
>