Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: fix NULL pointer crash of deleting a seed device

Same as normal devices, seed devices should be initialized with
fs_info->dev_root as well, otherwise we'll get a NULL pointer crash.

Cc: Chris Murphy <lists@colorremedies.com>
Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Liu Bo and committed by
Chris Mason
29cc83f6 f017f15f

+8 -4
+8 -4
fs/btrfs/volumes.c
··· 6146 6146 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; 6147 6147 struct btrfs_device *device; 6148 6148 6149 - mutex_lock(&fs_devices->device_list_mutex); 6150 - list_for_each_entry(device, &fs_devices->devices, dev_list) 6151 - device->dev_root = fs_info->dev_root; 6152 - mutex_unlock(&fs_devices->device_list_mutex); 6149 + while (fs_devices) { 6150 + mutex_lock(&fs_devices->device_list_mutex); 6151 + list_for_each_entry(device, &fs_devices->devices, dev_list) 6152 + device->dev_root = fs_info->dev_root; 6153 + mutex_unlock(&fs_devices->device_list_mutex); 6154 + 6155 + fs_devices = fs_devices->seed; 6156 + } 6153 6157 } 6154 6158 6155 6159 static void __btrfs_reset_dev_stats(struct btrfs_device *dev)