Skip to contentSkip to conversation

Btrfs: fix memory leak in the extent_same ioctl

PATCH Superseded [email protected] 2 participants 4 messages Jul 3, 2015 – Jul 6, 2015

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

PATCH 1/1 Btrfs: fix memory leak in the extent_same ioctl

From: Filipe Manana <[email protected]>

We were allocating memory with memdup_user() but we were never releasing that memory. This affected pretty much every call to the ioctl, whether it deduplicated extents or not.

This issue was reported on IRC by Julian Taylor and on the mailing list by Marcel Ritter, credit goes to them for finding the issue.

---
 fs/btrfs/ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/ioctl.c +3 -1
index c86b835..78e6a28 100644
@@ -2958,7 +2958,7 @@ out_unlock:
 static long btrfs_ioctl_file_extent_same(struct file *file,
 			struct btrfs_ioctl_same_args __user *argp)
 {
-	struct btrfs_ioctl_same_args *same;
+	struct btrfs_ioctl_same_args *same = NULL;
 	struct btrfs_ioctl_same_extent_info *info;
 	struct inode *src = file_inode(file);
 	u64 off;
@@ -2988,6 +2988,7 @@ static long btrfs_ioctl_file_extent_same(struct file *file,
 
 	if (IS_ERR(same)) {
 		ret = PTR_ERR(same);
+		same = NULL;
 		goto out;
 	}
 
@@ -3058,6 +3059,7 @@ static long btrfs_ioctl_file_extent_same(struct file *file,
 
 out:
 	mnt_drop_write_file(file);
+	kfree(same);
 	return ret;
 }
 
Signature · 1 line
2.1.3
#1 lore raw

PATCH v2 1/1 Btrfs: fix memory leak in the extent_same ioctl

From: Filipe Manana <[email protected]>

We were allocating memory with memdup_user() but we were never releasing that memory. This affected pretty much every call to the ioctl, whether it deduplicated extents or not.

This issue was reported on IRC by Julian Taylor and on the mailing list by Marcel Ritter, credit goes to them for finding the issue.

---

V2: Added cc to stable, forgotten in v1, and Julian's mail address.

 fs/btrfs/ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/ioctl.c +3 -1
index c86b835..78e6a28 100644
@@ -2958,7 +2958,7 @@ out_unlock:
 static long btrfs_ioctl_file_extent_same(struct file *file,
 			struct btrfs_ioctl_same_args __user *argp)
 {
-	struct btrfs_ioctl_same_args *same;
+	struct btrfs_ioctl_same_args *same = NULL;
 	struct btrfs_ioctl_same_extent_info *info;
 	struct inode *src = file_inode(file);
 	u64 off;
@@ -2988,6 +2988,7 @@ static long btrfs_ioctl_file_extent_same(struct file *file,
 
 	if (IS_ERR(same)) {
 		ret = PTR_ERR(same);
+		same = NULL;
 		goto out;
 	}
 
@@ -3058,6 +3059,7 @@ static long btrfs_ioctl_file_extent_same(struct file *file,
 
 out:
 	mnt_drop_write_file(file);
+	kfree(same);
 	return ret;
 }
 
Signature · 1 line
2.1.3
Reviewed-by on v2 1/1
#2 lore raw

Thanks for this Filipe,

Quoted 6 lines · On Fri, Jul 03, 2015 at 11:36:49AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

We were allocating memory with memdup_user() but we were never releasing that memory. This affected pretty much every call to the ioctl, whether it deduplicated extents or not.

Quoted 7 lines

This issue was reported on IRC by Julian Taylor and on the mailing list by Marcel Ritter, credit goes to them for finding the issue.

	--Mark

--
Mark Fasheh

Reviewed-by on v1 1/1
#3 lore raw
In reply to [email protected]

That looks great, thanks for fixing this Filipe.

Quoted 6 lines · On Fri, Jul 03, 2015 at 08:48:22AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

We were allocating memory with memdup_user() but we were never releasing that memory. This affected pretty much every call to the ioctl, whether it deduplicated extents or not.

Quoted 6 lines

This issue was reported on IRC by Julian Taylor and on the mailing list by Marcel Ritter, credit goes to them for finding the issue.

	--Mark

--
Mark Fasheh