Message ID | 20200603012957.9200-1-namjae.jeon@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | exfat: fix memory leak in exfat_parse_param() | expand |
On Wed, Jun 03, 2020 at 10:29:57AM +0900, Namjae Jeon wrote: > exfat_free() should call exfat_free_iocharset() after stealing > param->string instead of kstrdup in exfat_parse_param(). ITYM extfat_free() should call exfat_free_iocharset(), to prevent a leak in case we fail after parsing iocharset= but before calling get_tree_bdev() Additionally, there's no point copying param->string in exfat_parse_param() - just steal it, leaving NULL in param->string. That's independent from the leak or fix thereof - it's simply avoiding an extra copy.
> On Wed, Jun 03, 2020 at 10:29:57AM +0900, Namjae Jeon wrote: > > > exfat_free() should call exfat_free_iocharset() after stealing > > param->string instead of kstrdup in exfat_parse_param(). > > ITYM > extfat_free() should call exfat_free_iocharset(), to prevent a leak in case we fail after > parsing iocharset= but before calling > get_tree_bdev() > > Additionally, there's no point copying param->string in > exfat_parse_param() - just steal it, leaving NULL in param->string. > That's independent from the leak or fix thereof - it's simply avoiding an extra copy. Updated it in v2. Thanks!
diff --git a/fs/exfat/super.c b/fs/exfat/super.c index 405717e4e3ea..e650e65536f8 100644 --- a/fs/exfat/super.c +++ b/fs/exfat/super.c @@ -273,9 +273,8 @@ static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_charset: exfat_free_iocharset(sbi); - opts->iocharset = kstrdup(param->string, GFP_KERNEL); - if (!opts->iocharset) - return -ENOMEM; + opts->iocharset = param->string; + param->string = NULL; break; case Opt_errors: opts->errors = result.uint_32; @@ -686,7 +685,12 @@ static int exfat_get_tree(struct fs_context *fc) static void exfat_free(struct fs_context *fc) { - kfree(fc->s_fs_info); + struct exfat_sb_info *sbi = fc->s_fs_info; + + if (sbi) { + exfat_free_iocharset(sbi); + kfree(sbi); + } } static const struct fs_context_operations exfat_context_ops = {