All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] udf: fix potential refcnt problem of nls module
@ 2018-02-25 13:25 Chengguang Xu
  2018-02-28 12:36 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Chengguang Xu @ 2018-02-25 13:25 UTC (permalink / raw)
  To: jack; +Cc: linux-kernel, Chengguang Xu

When specifiying iocharset multiple times in a mount
or once/multiple in a remount, current option parsing
may cause inaccurate refcount of nls module.
Also, in the failure cleanup of option parsing,
the condition of calling unload_nls is not sufficient.

Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
---

Hi Jan,

I found this issue by checking code so now post the fix for rewiew,
but sorry I did't get enough resource to fully test it, I can only
make sure the fix can successfuly comiple with no error.

 fs/udf/super.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index 7b27b06..7e73a98 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -523,8 +523,12 @@ static int udf_parse_options(char *options, struct udf_options *uopt,
 			break;
 #ifdef CONFIG_UDF_NLS
 		case Opt_iocharset:
-			uopt->nls_map = load_nls(args[0].from);
-			uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
+			if (!remount) {
+				if (uopt->nls_map)
+					unload_nls(uopt->nls_map);
+				uopt->nls_map = load_nls(args[0].from);
+				uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
+			}
 			break;
 #endif
 		case Opt_uignore:
@@ -2082,8 +2086,8 @@ error_out:
 		for (i = 0; i < sbi->s_partitions; i++)
 			udf_free_partition(&sbi->s_partmaps[i]);
 #ifdef CONFIG_UDF_NLS
-	if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
-		unload_nls(sbi->s_nls_map);
+	if (uopt.nls_map)
+		unload_nls(uopt.nls_map);
 #endif
 	if (!(sb->s_flags & MS_RDONLY))
 		udf_close_lvid(sb);
-- 
1.8.3.1

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

* Re: [PATCH] udf: fix potential refcnt problem of nls module
  2018-02-25 13:25 [PATCH] udf: fix potential refcnt problem of nls module Chengguang Xu
@ 2018-02-28 12:36 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2018-02-28 12:36 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: jack, linux-kernel

On Sun 25-02-18 21:25:07, Chengguang Xu wrote:
> When specifiying iocharset multiple times in a mount
> or once/multiple in a remount, current option parsing
> may cause inaccurate refcount of nls module.
> Also, in the failure cleanup of option parsing,
> the condition of calling unload_nls is not sufficient.
> 
> Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
> ---
> 
> Hi Jan,
> 
> I found this issue by checking code so now post the fix for rewiew,
> but sorry I did't get enough resource to fully test it, I can only
> make sure the fix can successfuly comiple with no error.

Thanks for the patch. I have added it to my tree.

								Honza

> 
>  fs/udf/super.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 7b27b06..7e73a98 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -523,8 +523,12 @@ static int udf_parse_options(char *options, struct udf_options *uopt,
>  			break;
>  #ifdef CONFIG_UDF_NLS
>  		case Opt_iocharset:
> -			uopt->nls_map = load_nls(args[0].from);
> -			uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
> +			if (!remount) {
> +				if (uopt->nls_map)
> +					unload_nls(uopt->nls_map);
> +				uopt->nls_map = load_nls(args[0].from);
> +				uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
> +			}
>  			break;
>  #endif
>  		case Opt_uignore:
> @@ -2082,8 +2086,8 @@ error_out:
>  		for (i = 0; i < sbi->s_partitions; i++)
>  			udf_free_partition(&sbi->s_partmaps[i]);
>  #ifdef CONFIG_UDF_NLS
> -	if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
> -		unload_nls(sbi->s_nls_map);
> +	if (uopt.nls_map)
> +		unload_nls(uopt.nls_map);
>  #endif
>  	if (!(sb->s_flags & MS_RDONLY))
>  		udf_close_lvid(sb);
> -- 
> 1.8.3.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2018-02-28 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-25 13:25 [PATCH] udf: fix potential refcnt problem of nls module Chengguang Xu
2018-02-28 12:36 ` Jan Kara

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.