Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: ioctl: Fix memory leak on duplicated memory
@ 2025-09-25 18:41 Miquel Sabaté Solà
  2025-09-26  9:04 ` Filipe Manana
  0 siblings, 1 reply; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-09-25 18:41 UTC (permalink / raw)
  To: linux-btrfs
  Cc: clm, dsterba, wqu, linux-kernel, Miquel Sabaté Solà,
	Boris Burkov

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.

Fixes: 4addc1ffd67a ("btrfs: qgroup: preallocate memory before adding a relation")
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
---
 fs/btrfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 185bef0df1c2..8cb7d5a462ef 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;
 		}
 	}

--
2.51.0

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

* Re: [PATCH v2] btrfs: ioctl: Fix memory leak on duplicated memory
  2025-09-25 18:41 [PATCH v2] btrfs: ioctl: Fix memory leak on duplicated memory Miquel Sabaté Solà
@ 2025-09-26  9:04 ` Filipe Manana
  2025-09-26  9:36   ` Miquel Sabaté Solà
  0 siblings, 1 reply; 3+ messages in thread
From: Filipe Manana @ 2025-09-26  9:04 UTC (permalink / raw)
  To: Miquel Sabaté Solà
  Cc: linux-btrfs, clm, dsterba, wqu, linux-kernel, Boris Burkov

On Thu, Sep 25, 2025 at 11:42 PM Miquel Sabaté Solà <mssola@mssola.com> wrote:
>
> 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.
>
> Fixes: 4addc1ffd67a ("btrfs: qgroup: preallocate memory before adding a relation")
> Reviewed-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

I pushed it  into the for-next branch [1] with a changed subject to:

btrfs: fix memory leak on duplicated memory in the qgroup assign ioctl

Note that we don't capitalize the first word after the prefix in the subject.
I also made it more specific by mentioning which ioctl, since we have many.

Thanks.

[1] https://github.com/btrfs/linux/commits/for-next/

> ---
>  fs/btrfs/ioctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 185bef0df1c2..8cb7d5a462ef 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;
>                 }
>         }
>
> --
> 2.51.0
>

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

* Re: [PATCH v2] btrfs: ioctl: Fix memory leak on duplicated memory
  2025-09-26  9:04 ` Filipe Manana
@ 2025-09-26  9:36   ` Miquel Sabaté Solà
  0 siblings, 0 replies; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-09-26  9:36 UTC (permalink / raw)
  To: Filipe Manana; +Cc: linux-btrfs, clm, dsterba, wqu, linux-kernel, Boris Burkov

[-- Attachment #1: Type: text/plain, Size: 1856 bytes --]

Filipe Manana @ 2025-09-26 10:04 +01:

> On Thu, Sep 25, 2025 at 11:42 PM Miquel Sabaté Solà <mssola@mssola.com> wrote:
>>
>> 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.
>>
>> Fixes: 4addc1ffd67a ("btrfs: qgroup: preallocate memory before adding a relation")
>> Reviewed-by: Boris Burkov <boris@bur.io>
>> Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
>
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
>
> I pushed it  into the for-next branch [1] with a changed subject to:
>
> btrfs: fix memory leak on duplicated memory in the qgroup assign ioctl
>
> Note that we don't capitalize the first word after the prefix in the subject.
> I also made it more specific by mentioning which ioctl, since we have many.

Understood! Thanks for applying the patch.

>
> Thanks.
>
> [1] https://github.com/btrfs/linux/commits/for-next/
>
>> ---
>>  fs/btrfs/ioctl.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 185bef0df1c2..8cb7d5a462ef 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;
>>                 }
>>         }
>>
>> --
>> 2.51.0
>>

Cheers,
Miquel

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 897 bytes --]

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

end of thread, other threads:[~2025-09-26  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25 18:41 [PATCH v2] btrfs: ioctl: Fix memory leak on duplicated memory Miquel Sabaté Solà
2025-09-26  9:04 ` Filipe Manana
2025-09-26  9:36   ` Miquel Sabaté Solà

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox