fs: affs: fix a memroy leak in affs_remount
Subsystems (3)
PATCH 1/1 fs: affs: fix a memroy leak in affs_remount
In affs_remount if data is provided it is duplicated into new_opts. But this is not actually used later! The allocated memory for new_opts is only released if pare_options fail. This commit adds release for new_opts.
--- fs/affs/super.c | 2 ++ 1 file changed, 2 insertions(+)
fs/affs/super.c +2 -0
@@ -598,6 +598,8 @@ affs_remount(struct super_block *sb, int *flags, char *data)memcpy (sbi->s_volume, volume,32 );spin_unlock (&sbi->symlink_lock); +kfree (new_opts); +if ((bool )(*flags &SB_RDONLY ) ==sb_rdonly (sb))return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH] fs: affs: fix a memory leak in affs_remount
* Please avoid typos in the commit message.
* I would prefer an other wording for the change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=97f9a3c4eee55b0178b518ae7114a6a53372913d#n151
Quoted 1 line
But this is not actually used later!
Can this information trigger the deletion of questionable source code instead of adding a missing function call “kfree(new_opts)”?
How do you think about to add the tag “Fixes”?
Regards,
Markus
PATCH v2 1/1 fs: affs: fix a memory leak in affs_remount
In affs_remount if data is provided it is duplicated into new_opts. The allocated memory for new_opts is only released if pare_options fail. The release for new_opts is added.
---
Changes in v2:
-- fix a type in title, and add fixes tag
--- fs/affs/super.c | 2 ++ 1 file changed, 2 insertions(+)
fs/affs/super.c +2 -0
@@ -598,6 +598,8 @@ affs_remount(struct super_block *sb, int *flags, char *data)memcpy (sbi->s_volume, volume,32 );spin_unlock (&sbi->symlink_lock); +kfree (new_opts); +if ((bool )(*flags &SB_RDONLY ) ==sb_rdonly (sb))return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount
Quoted 1 line
The allocated memory for
new_optsis only released ifpare_optionsfail.
Can the following wording be nicer?
The allocated memory for the buffer “new_opts” will be released only if a call of the function “parse_options” failed.
Quoted 1 line
The release for
new_optsis added.
* How do you think about the change possibility to delete questionable source code here?
* Would you like to complete the data processing for corresponding options any more?
Quoted 1 line
-- fix a type in title, …
Please avoid typos also in your version comments.
Quoted 1 line
---
I suggest to replace this second delimiter by a blank line.
Regards,
Markus
Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount
Hi Markus, thanks for your suggestions for improving the quality of the patch. At the moment I prefer first get a confirmation from contributors about the leak and then work on any possible improvements for the patch.
Thanks,
Navid.
Quoted 29 lines · Markus Elfring
Quoted 2 lines
The allocated memory for
new_optsis only released ifpare_optionsfail.Can the following wording be nicer?
The allocated memory for the buffer “new_opts” will be released only if a call of the function “parse_options” failed.
Quoted 1 line
The release for
new_optsis added.* How do you think about the change possibility to delete questionable source code here?
* Would you like to complete the data processing for corresponding options any more?
Quoted 1 line
-- fix a type in title, …
Please avoid typos also in your version comments.
Quoted 1 line
---
I suggest to replace this second delimiter by a blank line.
Regards,
Markus
Signature · 1 line
Navid.
Re: [v2] fs: affs: fix a memory leak in affs_remount
Quoted 4 lines
Hi Markus, thanks for your suggestions for improving the quality of the patch. At the moment I prefer first get a confirmation from contributors about the leak and then work on any possible improvements for the patch.
Please fix this patch as soon as possible if you care for the correctness of the provided information.
Regards,
Markus
Re: [v2] fs: affs: fix a memory leak in affs_remount
In reply to Navid EmamdoostQuoted 4 lines
Hi Markus, thanks for your suggestions for improving the quality of the patch. At the moment I prefer first get a confirmation from contributors about the leak and then work on any possible improvements for the patch.
Please fix this patch as soon as possible if you care for the correctness of the provided information.
Regards,
Markus
Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount
In reply to Navid EmamdoostQuoted 3 lines · Navid Emamdoost
In
affs_remountif data is provided it is duplicated intonew_opts. The allocated memory fornew_optsis only released ifpare_optionsfail. The release fornew_optsis added.
A variable that is allocated and freed without use should ring a bell to look closer at the code. There's a bit of history behind new_options, originally there was save/replace options on the VFS layer so the 'data' passed must not change (thus strdup), this got cleaned up in later patches. But not completely.
There's no reason to do the strdup in cases where the filesystem does not need to reuse the 'data' again, because strsep would modify it directly.
So new_opts should be removed.
Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount
Thanks David,
Quoted 12 lines · David Sterba
Quoted 3 lines · Navid Emamdoost
In
affs_remountif data is provided it is duplicated intonew_opts. The allocated memory fornew_optsis only released ifpare_optionsfail. The release fornew_optsis added.A variable that is allocated and freed without use should ring a bell to look closer at the code. There's a bit of history behind
new_options, originally there was save/replace options on the VFS layer so the 'data' passed must not change (thus strdup), this got cleaned up in later patches. But not completely.
Quoted 5 lines
There's no reason to do the strdup in cases where the filesystem does not need to reuse the 'data' again, because strsep would modify it directly.
So
new_optsshould be removed.
I will send a new patch with the unused variable removed.
Signature · 1 line
Navid.
PATCH v3 1/1 fs: affs: fix a memory leak in affs_remount
In reply to David SterbaIn affs_remount if data is provided it is duplicated into new_opts. The allocated memory for new_opts is only released if pare_options fail. But the variable is not used anywhere. So the new_opts should be removed.
---
Changes in v2:
-- fix typo
Changes in v3:
-- remove the call to kstrdup, as new_opts is not used anymore.
--- fs/affs/super.c | 5 ----- 1 file changed, 5 deletions(-)
fs/affs/super.c +0 -5
@@ -565,10 +565,6 @@ affs_remount(struct super_block *sb, int *flags, char *data)char volume[32 ];char *prefix =NULL ; - new_opts =kstrdup (data,GFP_KERNEL ); -if (data && !new_opts) -return -ENOMEM ; -pr_debug ("%s(flags=0x%x,opts=\"%s\")\n" , __func__, *flags, data);sync_filesystem (sb);
@@ -579,7 +575,6 @@ affs_remount(struct super_block *sb, int *flags, char *data) &blocksize, &prefix, volume, &mount_flags)) {kfree (prefix); -kfree (new_opts);return -EINVAL ; }
Signature · 1 line
2.17.1
Re: [PATCH v3] fs: affs: fix a memory leak in affs_remount
Quoted 5 lines · Navid Emamdoost
In
affs_remountif data is provided it is duplicated intonew_opts. The allocated memory fornew_optsis only released ifpare_optionsfail. But the variable is not used anywhere. So thenew_optsshould be removed.
Quoted 7 lines
Fixes c8f33d0bec99 ("affs: kstrdup() memory handling")Signed-off-by Navid Emamdoost <[email protected]>---
Changes in v2:
-- fix typo
Changes in v3:
-- remove the call to kstrdup, asnew_optsis not used anymore.
Added it to affs queue. There are still typos in the changelog and this was pointed out, and v3 lacks the explanations I replied to v2. I'll fix it up.
Re: [PATCH] fs: affs: fix a memory leak in affs_remount
In reply to Markus ElfringFixed the issues in v2.
Thanks,
Navid.
Quoted 17 lines · Markus Elfring
* Please avoid typos in the commit message.
* I would prefer an other wording for the change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=97f9a3c4eee55b0178b518ae7114a6a53372913d#n151Quoted 1 line
But this is not actually used later!
Can this information trigger the deletion of questionable source code instead of adding a missing function call “kfree(new_opts)”?
How do you think about to add the tag “Fixes”?
Regards,
Markus
Signature · 1 line
Navid.