]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: fix memory leak on duplicated memory in the qgroup assign ioctl
authorMiquel Sabaté Solà <mssola@mssola.com>
Thu, 25 Sep 2025 18:41:39 +0000 (20:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Oct 2025 14:20:20 +0000 (16:20 +0200)
commit 53a4acbfc1de85fa637521ffab4f4e2ee03cbeeb upstream.

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")
CC: stable@vger.kernel.org # 6.12+
Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/ioctl.c

index 1706f6d9b12e6837574100ad6f1d39bb6791558f..03c3b5d0abbe4fcf5aafe9f098f1e1a48a60328f 100644 (file)
@@ -3852,7 +3852,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;
                }
        }