diff mbox

[1/2] hfs: fix potential refcnt problem of nls module

Message ID 1523948733-8537-1-git-send-email-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu April 17, 2018, 7:05 a.m. UTC
When specifying iocharset/codepage multiple times in a mount,
current option parsing will cause inaccurate refcount of nls
module. Hence, call unload_nls for previous one in this case.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/hfs/super.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Viacheslav Dubeyko April 18, 2018, 5:10 p.m. UTC | #1
On Tue, 2018-04-17 at 15:05 +0800, Chengguang Xu wrote:
> When specifying iocharset/codepage multiple times in a mount,
> current option parsing will cause inaccurate refcount of nls
> module. Hence, call unload_nls for previous one in this case.
> 
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>


Looks good.

Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com>

Thanks,
Vyacheslav Dubeyko.


> ---
>  fs/hfs/super.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/hfs/super.c b/fs/hfs/super.c
> index 1738767..6a5f6fd 100644
> --- a/fs/hfs/super.c
> +++ b/fs/hfs/super.c
> @@ -329,8 +329,10 @@ static int parse_options(char *options, struct
> hfs_sb_info *hsb)
>  				return 0;
>  			}
>  			p = match_strdup(&args[0]);
> -			if (p)
> +			if (p) {
> +				unload_nls(hsb->nls_disk);
>  				hsb->nls_disk = load_nls(p);
> +			}
>  			if (!hsb->nls_disk) {
>  				pr_err("unable to load codepage
> \"%s\"\n", p);
>  				kfree(p);
> @@ -344,8 +346,10 @@ static int parse_options(char *options, struct
> hfs_sb_info *hsb)
>  				return 0;
>  			}
>  			p = match_strdup(&args[0]);
> -			if (p)
> +			if (p) {
> +				unload_nls(hsb->nls_io);
>  				hsb->nls_io = load_nls(p);
> +			}
>  			if (!hsb->nls_io) {
>  				pr_err("unable to load iocharset
> \"%s\"\n", p);
>  				kfree(p);
Andrew Morton April 18, 2018, 7:42 p.m. UTC | #2
On Tue, 17 Apr 2018 15:05:32 +0800 Chengguang Xu <cgxu519@gmx.com> wrote:

> When specifying iocharset/codepage multiple times in a mount,
> current option parsing will cause inaccurate refcount of nls
> module. Hence, call unload_nls for previous one in this case.
> 
> ...
>
> --- a/fs/hfs/super.c
> +++ b/fs/hfs/super.c
> @@ -329,8 +329,10 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
>  				return 0;
>  			}
>  			p = match_strdup(&args[0]);
> -			if (p)
> +			if (p) {
> +				unload_nls(hsb->nls_disk);
>  				hsb->nls_disk = load_nls(p);
> +			}
>  			if (!hsb->nls_disk) {
>  				pr_err("unable to load codepage \"%s\"\n", p);
>  				kfree(p);
> @@ -344,8 +346,10 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
>  				return 0;
>  			}
>  			p = match_strdup(&args[0]);
> -			if (p)
> +			if (p) {
> +				unload_nls(hsb->nls_io);
>  				hsb->nls_io = load_nls(p);
> +			}
>  			if (!hsb->nls_io) {
>  				pr_err("unable to load iocharset \"%s\"\n", p);
>  				kfree(p);

Confused.

			break;
: 		case opt_codepage:
: 			if (hsb->nls_disk) {
: 				pr_err("unable to change codepage\n");
: 				return 0;
: 			}

Here, hsb->nls_disk is known to be zero.

: 			p = match_strdup(&args[0]);
: 			if (p) {
: 				unload_nls(hsb->nls_disk);

So this will always do unload_nls(0).

: 				hsb->nls_disk = load_nls(p);
: 			}

And the same applies to your opt_iocharset change.
Chengguang Xu April 19, 2018, 1:18 a.m. UTC | #3
在 2018年4月19日,上午3:42,Andrew Morton <akpm@linux-foundation.org> 写道:
> 
> On Tue, 17 Apr 2018 15:05:32 +0800 Chengguang Xu <cgxu519@gmx.com> wrote:
> 
>> When specifying iocharset/codepage multiple times in a mount,
>> current option parsing will cause inaccurate refcount of nls
>> module. Hence, call unload_nls for previous one in this case.
>> 
>> ...
>> 
>> --- a/fs/hfs/super.c
>> +++ b/fs/hfs/super.c
>> @@ -329,8 +329,10 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
>> 				return 0;
>> 			}
>> 			p = match_strdup(&args[0]);
>> -			if (p)
>> +			if (p) {
>> +				unload_nls(hsb->nls_disk);
>> 				hsb->nls_disk = load_nls(p);
>> +			}
>> 			if (!hsb->nls_disk) {
>> 				pr_err("unable to load codepage \"%s\"\n", p);
>> 				kfree(p);
>> @@ -344,8 +346,10 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
>> 				return 0;
>> 			}
>> 			p = match_strdup(&args[0]);
>> -			if (p)
>> +			if (p) {
>> +				unload_nls(hsb->nls_io);
>> 				hsb->nls_io = load_nls(p);
>> +			}
>> 			if (!hsb->nls_io) {
>> 				pr_err("unable to load iocharset \"%s\"\n", p);
>> 				kfree(p);
> 
> Confused.
> 
> 			break;
> : 		case opt_codepage:
> : 			if (hsb->nls_disk) {
> : 				pr_err("unable to change codepage\n");
> : 				return 0;
> : 			}
> 
> Here, hsb->nls_disk is known to be zero.
> 
> : 			p = match_strdup(&args[0]);
> : 			if (p) {
> : 				unload_nls(hsb->nls_disk);
> 
> So this will always do unload_nls(0).
> 
> : 				hsb->nls_disk = load_nls(p);
> : 			}
> 
> And the same applies to your opt_iocharset change.

You are right. Sorry I just misread this part, please just drop the patch.

Thanks.
diff mbox

Patch

diff --git a/fs/hfs/super.c b/fs/hfs/super.c
index 1738767..6a5f6fd 100644
--- a/fs/hfs/super.c
+++ b/fs/hfs/super.c
@@ -329,8 +329,10 @@  static int parse_options(char *options, struct hfs_sb_info *hsb)
 				return 0;
 			}
 			p = match_strdup(&args[0]);
-			if (p)
+			if (p) {
+				unload_nls(hsb->nls_disk);
 				hsb->nls_disk = load_nls(p);
+			}
 			if (!hsb->nls_disk) {
 				pr_err("unable to load codepage \"%s\"\n", p);
 				kfree(p);
@@ -344,8 +346,10 @@  static int parse_options(char *options, struct hfs_sb_info *hsb)
 				return 0;
 			}
 			p = match_strdup(&args[0]);
-			if (p)
+			if (p) {
+				unload_nls(hsb->nls_io);
 				hsb->nls_io = load_nls(p);
+			}
 			if (!hsb->nls_io) {
 				pr_err("unable to load iocharset \"%s\"\n", p);
 				kfree(p);