Skip to contentSkip to conversation

fs: affs: fix a memroy leak in affs_remount

PATCH Superseded Navid Emamdoost 3 participants 12 messages Sep 30, 2019 – Oct 30, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index cc463ae47c12..1d38fdbc5148 100644
@@ -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
#1 lore raw

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

#2 lore raw

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.

Fixes c8f33d0bec99 ("affs: kstrdup() memory handling")

---
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
index cc463ae47c12..1d38fdbc5148 100644
@@ -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
#3 lore raw

Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount

Quoted 1 line

The allocated memory for new_opts is only released if pare_options fail.

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_opts is 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

#4 lore raw

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_opts is only released if pare_options fail.

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_opts is 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.
#5 lore raw

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

#6 lore raw

Re: [v2] fs: affs: fix a memory leak in affs_remount

In reply to Navid Emamdoost
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

#7 lore raw

Re: [PATCH v2] fs: affs: fix a memory leak in affs_remount

In reply to Navid Emamdoost
Quoted 3 lines · Navid Emamdoost

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.

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.

#8 lore raw

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_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.

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_opts should be removed.

I will send a new patch with the unused variable removed.

Signature · 1 line
Navid.
#9 lore raw

PATCH v3 1/1 fs: affs: fix a memory leak in affs_remount

In reply to David Sterba

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. But the variable is not used anywhere. So the new_opts should be removed.

Fixes c8f33d0bec99 ("affs: kstrdup() memory handling")

---
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
index cc463ae47c12..b6c6080d186c 100644
@@ -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
#10 lore raw

Re: [PATCH v3] fs: affs: fix a memory leak in affs_remount

Quoted 5 lines · Navid Emamdoost

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. But the variable is not used anywhere. So the new_opts should be removed.

Quoted 7 lines
Fixes c8f33d0bec99 ("affs: kstrdup() memory handling")

---
Changes in v2:
-- fix typo
Changes in v3:
-- remove the call to kstrdup, as new_opts is 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.

#11 lore raw

Re: [PATCH] fs: affs: fix a memory leak in affs_remount

In reply to Markus Elfring

Fixed 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#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

Signature · 1 line
Navid.