Skip to content

Commit c2670ec

Browse files
lgs2513gregkh
authored andcommitted
btrfs: fix double free in create_space_info() error path
commit 3f487be upstream. When kobject_init_and_add() fails, the call chain is: create_space_info() -> btrfs_sysfs_add_space_info_type() -> kobject_init_and_add() -> failure -> kobject_put(&space_info->kobj) -> space_info_release() -> kfree(space_info) Then control returns to create_space_info(): btrfs_sysfs_add_space_info_type() returns error -> goto out_free -> kfree(space_info) This causes a double free. Keep the direct kfree(space_info) for the earlier failure path, but after btrfs_sysfs_add_space_info_type() has called kobject_put(), let the kobject release callback handle the cleanup. Fixes: a11224a ("btrfs: fix memory leaks in create_space_info() error paths") CC: stable@vger.kernel.org # 6.19+ Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f7126b0 commit c2670ec

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/space-info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
293293

294294
ret = btrfs_sysfs_add_space_info_type(info, space_info);
295295
if (ret)
296-
goto out_free;
296+
return ret;
297297

298298
list_add(&space_info->list, &info->space_info);
299299
if (flags & BTRFS_BLOCK_GROUP_DATA)

0 commit comments

Comments
 (0)