Commit c6b4616c411942e2e9bba4671627f7faf0a5db6a

Authored by Liu Bo
Committed by Greg Kroah-Hartman
1 parent add81375ec

Btrfs: fix NULL pointer crash of deleting a seed device

commit 29cc83f69c8338ff8fd1383c9be263d4bdf52d73 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 8 additions and 4 deletions Side-by-side Diff

... ... @@ -6080,10 +6080,14 @@
6080 6080 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
6081 6081 struct btrfs_device *device;
6082 6082  
6083   - mutex_lock(&fs_devices->device_list_mutex);
6084   - list_for_each_entry(device, &fs_devices->devices, dev_list)
6085   - device->dev_root = fs_info->dev_root;
6086   - mutex_unlock(&fs_devices->device_list_mutex);
  6083 + while (fs_devices) {
  6084 + mutex_lock(&fs_devices->device_list_mutex);
  6085 + list_for_each_entry(device, &fs_devices->devices, dev_list)
  6086 + device->dev_root = fs_info->dev_root;
  6087 + mutex_unlock(&fs_devices->device_list_mutex);
  6088 +
  6089 + fs_devices = fs_devices->seed;
  6090 + }
6087 6091 }
6088 6092  
6089 6093 static void __btrfs_reset_dev_stats(struct btrfs_device *dev)