Skip to content

Commit 45ea609

Browse files
trofichrismason-xx
authored andcommitted
btrfs: fix double-free 'tree_root' in 'btrfs_mount()'
On error path 'tree_root' is treed in 'free_fs_info()'. No need to free it explicitely. Noticed by SLUB in debug mode: Complete reproducer under usermode linux (discovered on real machine): bdev=/dev/ubda btr_root=/btr /mkfs.btrfs $bdev mount $bdev $btr_root mkdir $btr_root/subvols/ cd $btr_root/subvols/ /btrfs su cr foo /btrfs su cr bar mount $bdev -osubvol=subvols/foo $btr_root/subvols/bar umount $btr_root/subvols/bar which gives device fsid 4d55aa28-45b1-474b-b4ec-da912322195e devid 1 transid 7 /dev/ubda ============================================================================= BUG kmalloc-2048: Object already free ----------------------------------------------------------------------------- INFO: Allocated in btrfs_mount+0x389/0x7f0 age=0 cpu=0 pid=277 INFO: Freed in btrfs_mount+0x51c/0x7f0 age=0 cpu=0 pid=277 INFO: Slab 0x0000000062886200 objects=15 used=9 fp=0x0000000070b4d2d0 flags=0x4081 INFO: Object 0x0000000070b4d2d0 @offset=21200 fp=0x0000000070b4a968 ... Call Trace: 70b31948: [<6008c522>] print_trailer+0xe2/0x130 70b31978: [<6008c5aa>] object_err+0x3a/0x50 70b319a: [<6008e242>] free_debug_processing+0x142/0x2a0 70b319e0: [<600ebf6f>] btrfs_mount+0x55f/0x7f0 70b319f8: [<6008e5c1>] __slab_free+0x221/0x2d0 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Cc: Arne Jansen <sensille@gmx.net> Cc: Chris Mason <chris.mason@oracle.com> Cc: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 7c7e82a commit 45ea609

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎fs/btrfs/super.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,12 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
933933
* then open_ctree will properly initialize everything later.
934934
*/
935935
fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
936+
if (!fs_info) {
937+
error = -ENOMEM;
938+
goto error_close_devices;
939+
}
936940
tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
937-
if (!fs_info || !tree_root) {
941+
if (!tree_root) {
938942
error = -ENOMEM;
939943
goto error_close_devices;
940944
}
@@ -964,7 +968,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
964968

965969
btrfs_close_devices(fs_devices);
966970
free_fs_info(fs_info);
967-
kfree(tree_root);
968971
} else {
969972
char b[BDEVNAME_SIZE];
970973

@@ -992,7 +995,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
992995
error_close_devices:
993996
btrfs_close_devices(fs_devices);
994997
free_fs_info(fs_info);
995-
kfree(tree_root);
996998
return ERR_PTR(error);
997999
}
9981000

0 commit comments

Comments
 (0)