Skip to content

Commit 55793c0

Browse files
kdaveJosef Bacik
authored andcommitted
btrfs: read entire device info under lock
There's a theoretical possibility of reading stale (or even more theoretically, freed) data from DEV_INFO ioctl when the device would disappear between an early mutex unlock and data being copied from the device structure. Signed-off-by: David Sterba <[email protected]> Signed-off-by: Josef Bacik <[email protected]>
1 parent f7a52a4 commit 55793c0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,6 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
24322432

24332433
mutex_lock(&fs_devices->device_list_mutex);
24342434
dev = btrfs_find_device(root->fs_info, di_args->devid, s_uuid, NULL);
2435-
mutex_unlock(&fs_devices->device_list_mutex);
24362435

24372436
if (!dev) {
24382437
ret = -ENODEV;
@@ -2456,6 +2455,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
24562455
}
24572456

24582457
out:
2458+
mutex_unlock(&fs_devices->device_list_mutex);
24592459
if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
24602460
ret = -EFAULT;
24612461

0 commit comments

Comments
 (0)