Skip to content

Commit 259af68

Browse files
lgs2513gregkh
authored andcommitted
btrfs: fix double free in create_space_info_sub_group() error path
commit a7449ed upstream. When kobject_init_and_add() fails, the call chain is: create_space_info_sub_group() -> btrfs_sysfs_add_space_info_type() -> kobject_init_and_add() -> failure -> kobject_put(&sub_group->kobj) -> space_info_release() -> kfree(sub_group) Then control returns to create_space_info_sub_group(), where: btrfs_sysfs_add_space_info_type() returns error -> kfree(sub_group) Thus, sub_group is freed twice. Keep parent->sub_group[index] = NULL for the failure path, but after btrfs_sysfs_add_space_info_type() has called kobject_put(), let the kobject release callback handle the cleanup. Fixes: f92ee31 ("btrfs: introduce btrfs_space_info sub-group") CC: stable@vger.kernel.org # 6.18+ 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 dd6ade0 commit 259af68

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

fs/btrfs/space-info.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,8 @@ static int create_space_info_sub_group(struct btrfs_space_info *parent, u64 flag
276276
sub_group->subgroup_id = id;
277277

278278
ret = btrfs_sysfs_add_space_info_type(sub_group);
279-
if (ret) {
280-
kfree(sub_group);
279+
if (ret)
281280
parent->sub_group[index] = NULL;
282-
}
283281
return ret;
284282
}
285283

0 commit comments

Comments
 (0)