All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: ioctl: Fix memory leak on duplicated memory
@ 2025-09-25 14:53 Miquel Sabaté Solà
  2025-09-25 17:25 ` Boris Burkov
  0 siblings, 1 reply; 6+ messages in thread
From: Miquel Sabaté Solà @ 2025-09-25 14:53 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba, linux-kernel, Miquel Sabaté Solà

On 'btrfs_ioctl_qgroup_assign' we first duplicate the argument as
provided by the user, which is kfree'd in the end. But this was not the
case when allocating memory for 'prealloc'. In this case, if it somehow
failed, then the previous code would go directly into calling
'mnt_drop_write_file', without freeing the string duplicated from the
user space.

Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
---
 fs/btrfs/ioctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 185bef0df1c2..00381fdbff9d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3740,7 +3740,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
 		prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
 		if (!prealloc) {
 			ret = -ENOMEM;
-			goto drop_write;
+			goto out_sa_drop_write;
 		}
 	}
 
@@ -3775,6 +3775,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
 
 out:
 	kfree(prealloc);
+out_sa_drop_write:
 	kfree(sa);
 drop_write:
 	mnt_drop_write_file(file);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-25 18:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25 14:53 [PATCH] btrfs: ioctl: Fix memory leak on duplicated memory Miquel Sabaté Solà
2025-09-25 17:25 ` Boris Burkov
2025-09-25 17:47   ` David Sterba
2025-09-25 17:48   ` Filipe Manana
2025-09-25 18:26     ` Miquel Sabaté Solà
2025-09-25 18:56       ` Miquel Sabaté Solà

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.