Skip to content

Commit f91192c

Browse files
bragathemanickkdave
authored andcommitted
btrfs: ref-verify: fix memory leaks in btrfs_ref_tree_mod()
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: stable@vger.kernel.org # 5.10+ Reported-and-tested-by: syzbot+d66de4cbf532749df35f@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=d66de4cbf532749df35f Signed-off-by: Bragatheswaran Manickavel <bragathemanick0908@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 2db3132 commit f91192c

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/btrfs/ref-verify.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
794794
dump_ref_action(fs_info, ra);
795795
kfree(ref);
796796
kfree(ra);
797+
kfree(re);
797798
goto out_unlock;
798799
} else if (be->num_refs == 0) {
799800
btrfs_err(fs_info,
@@ -803,6 +804,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
803804
dump_ref_action(fs_info, ra);
804805
kfree(ref);
805806
kfree(ra);
807+
kfree(re);
806808
goto out_unlock;
807809
}
808810

0 commit comments

Comments
 (0)