]> Git Repo - linux.git/commitdiff
btrfs: ref-verify: fix memory leaks in btrfs_ref_tree_mod()
authorBragatheswaran Manickavel <[email protected]>
Sat, 18 Nov 2023 09:10:12 +0000 (14:40 +0530)
committerDavid Sterba <[email protected]>
Thu, 23 Nov 2023 21:27:34 +0000 (22:27 +0100)
In btrfs_ref_tree_mod(), when !parent 're' was allocated through
kmalloc(). In the following code, if an error occurs, the execution will
be redirected to 'out' or 'out_unlock' and the function will be exited.
However, on some of the paths, 're' are not deallocated and may lead to
memory leaks.

For example: lookup_block_entry() for 'be' returns NULL, the out label
will be invoked. During that flow ref and 'ra' are freed but not 're',
which can potentially lead to a memory leak.

CC: [email protected] # 5.10+
Reported-and-tested-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=d66de4cbf532749df35f
Signed-off-by: Bragatheswaran Manickavel <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
fs/btrfs/ref-verify.c

index 1f62976bee829a1865faca76f5059f66752300ae..6486f0d7e9931b4fafbc03ddc5ddca0863679d7a 100644 (file)
@@ -794,6 +794,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
                        dump_ref_action(fs_info, ra);
                        kfree(ref);
                        kfree(ra);
+                       kfree(re);
                        goto out_unlock;
                } else if (be->num_refs == 0) {
                        btrfs_err(fs_info,
@@ -803,6 +804,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
                        dump_ref_action(fs_info, ra);
                        kfree(ref);
                        kfree(ra);
+                       kfree(re);
                        goto out_unlock;
                }
 
This page took 0.063216 seconds and 4 git commands to generate.