Skip to content

Commit adbbb86

Browse files
Miao Xiemasoncl
authored andcommitted
Btrfs: fix unprotected device list access when cloning fs devices
We can build a new filesystem based a seed filesystem, and we need clone the fs devices when we open the new filesystem. But someone might clear the seed flag of the seed filesystem, then mount that filesystem and remove some device. If we mount the new filesystem, we might access a device list which was being changed when we clone the fs devices. Fix it. Signed-off-by: Miao Xie <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 2196d6e commit adbbb86

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
583583
if (IS_ERR(fs_devices))
584584
return fs_devices;
585585

586+
mutex_lock(&orig->device_list_mutex);
586587
fs_devices->total_devices = orig->total_devices;
587588

588589
/* We have held the volume lock, it is safe to get the devices. */
@@ -611,8 +612,10 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
611612
device->fs_devices = fs_devices;
612613
fs_devices->num_devices++;
613614
}
615+
mutex_unlock(&orig->device_list_mutex);
614616
return fs_devices;
615617
error:
618+
mutex_unlock(&orig->device_list_mutex);
616619
free_fs_devices(fs_devices);
617620
return ERR_PTR(-ENOMEM);
618621
}

0 commit comments

Comments
 (0)