Skip to content

Commit 6fa6985

Browse files
kdaveasj
authored andcommitted
btrfs: fix mount and ioctl device scan ioctl race
Technically this extends the critical section covered by uuid_mutex to: - parse early mount options -- here we can call device scan on paths that can be passed as 'device=/dev/...' - scan the device passed to mount - open the devices related to the fs_devices -- this increases fs_devices::opened The race can happen when mount calls one of the scans and there's another one called eg. by mkfs or 'btrfs dev scan': Mount Scan ----- ---- scan_one_device (dev1, fsid1) scan_one_device (dev2, fsid2) add the device free stale devices fsid1 fs_devices::opened == 0 find fsid1:dev1 free fsid1:dev1 if it's the last one, free fs_devices of fsid1 too open_devices (dev1, fsid1) dev1 not found When fixed, the uuid mutex will make sure that mount will increase fs_devices::opened and this will not be touched by the racing scan ioctl. Reported-and-tested-by: syzbot+909a5177749d7990ffa4@syzkaller.appspotmail.com Reported-and-tested-by: syzbot+ceb2606025ec1cc3479c@syzkaller.appspotmail.com Signed-off-by: David Sterba <dsterba@suse.com> Reviewed-by: Anand Jain <anand.jain@oracle.com>
1 parent e9f25a7 commit 6fa6985

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/btrfs/super.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,19 +1555,19 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
15551555

15561556
mutex_lock(&uuid_mutex);
15571557
error = btrfs_parse_early_options(data, mode, fs_type, &fs_devices);
1558-
mutex_unlock(&uuid_mutex);
1559-
if (error)
1558+
if (error) {
1559+
mutex_unlock(&uuid_mutex);
15601560
goto error_fs_info;
1561+
}
15611562

1562-
mutex_lock(&uuid_mutex);
15631563
error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
1564-
mutex_unlock(&uuid_mutex);
1565-
if (error)
1564+
if (error) {
1565+
mutex_unlock(&uuid_mutex);
15661566
goto error_fs_info;
1567+
}
15671568

15681569
fs_info->fs_devices = fs_devices;
15691570

1570-
mutex_lock(&uuid_mutex);
15711571
error = btrfs_open_devices(fs_devices, mode, fs_type);
15721572
mutex_unlock(&uuid_mutex);
15731573
if (error)

0 commit comments

Comments
 (0)