Skip to content

Commit cd63ffb

Browse files
fdmananakdave
authored andcommitted
btrfs: fix error pointer dereference after failure to allocate fs devices
At device_list_add() we allocate a btrfs_fs_devices structure and then before checking if the allocation failed (pointer is ERR_PTR(-ENOMEM)), we dereference the error pointer in a memcpy() argument if the feature BTRFS_FEATURE_INCOMPAT_METADATA_UUID is enabled. Fix this by checking for an allocation error before trying the memcpy(). Fixes: f7361d8 ("btrfs: sipmlify uuid parameters of alloc_fs_devices()") Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 47e2b06 commit cd63ffb

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

fs/btrfs/volumes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,13 +746,13 @@ static noinline struct btrfs_device *device_list_add(const char *path,
746746

747747
if (!fs_devices) {
748748
fs_devices = alloc_fs_devices(disk_super->fsid);
749+
if (IS_ERR(fs_devices))
750+
return ERR_CAST(fs_devices);
751+
749752
if (has_metadata_uuid)
750753
memcpy(fs_devices->metadata_uuid,
751754
disk_super->metadata_uuid, BTRFS_FSID_SIZE);
752755

753-
if (IS_ERR(fs_devices))
754-
return ERR_CAST(fs_devices);
755-
756756
if (same_fsid_diff_dev) {
757757
generate_random_uuid(fs_devices->fsid);
758758
fs_devices->temp_fsid = true;

0 commit comments

Comments
 (0)