2018-04-14 12:20:56

by Chengguang Xu

[permalink] [raw]
Subject: [PATCH] isofs: fix potential memory leak in mount option parsing

When specifying string type mount option (e.g., iocharset)
several times in a mount, current option parsing may
cause memory leak. Hence, call kfree for previous one
in this case. Meanwhile, check memory allocation result
for it.

Signed-off-by: Chengguang Xu <[email protected]>
---
fs/isofs/inode.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index bc258a4..ec3fba7 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -394,7 +394,10 @@ static int parse_options(char *options, struct iso9660_options *popt)
break;
#ifdef CONFIG_JOLIET
case Opt_iocharset:
+ kfree(popt->iocharset);
popt->iocharset = match_strdup(&args[0]);
+ if (!popt->iocharset)
+ return 0;
break;
#endif
case Opt_map_a:
--
1.8.3.1



2018-04-16 07:50:51

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH] isofs: fix potential memory leak in mount option parsing

On Sat 14-04-18 20:16:06, Chengguang Xu wrote:
> When specifying string type mount option (e.g., iocharset)
> several times in a mount, current option parsing may
> cause memory leak. Hence, call kfree for previous one
> in this case. Meanwhile, check memory allocation result
> for it.
>
> Signed-off-by: Chengguang Xu <[email protected]>

Thanks. I've added the patch to my tree.

Honza

> ---
> fs/isofs/inode.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
> index bc258a4..ec3fba7 100644
> --- a/fs/isofs/inode.c
> +++ b/fs/isofs/inode.c
> @@ -394,7 +394,10 @@ static int parse_options(char *options, struct iso9660_options *popt)
> break;
> #ifdef CONFIG_JOLIET
> case Opt_iocharset:
> + kfree(popt->iocharset);
> popt->iocharset = match_strdup(&args[0]);
> + if (!popt->iocharset)
> + return 0;
> break;
> #endif
> case Opt_map_a:
> --
> 1.8.3.1
>
--
Jan Kara <[email protected]>
SUSE Labs, CR