Skip to content

Commit f085381

Browse files
asjmasoncl
authored andcommitted
btrfs: fix null pointer deference at btrfs_sysfs_add_one+0x105
bdev is null when disk has disappeared and mounted with the degrade option stack trace --------- btrfs_sysfs_add_one+0x105/0x1c0 [btrfs] open_ctree+0x15f3/0x1fe0 [btrfs] btrfs_mount+0x5db/0x790 [btrfs] ? alloc_pages_current+0xa4/0x160 mount_fs+0x34/0x1b0 vfs_kern_mount+0x62/0xf0 do_mount+0x22e/0xa80 ? __get_free_pages+0x9/0x40 ? copy_mount_options+0x31/0x170 SyS_mount+0x7e/0xc0 system_call_fastpath+0x16/0x1b --------- reproducer: ------- mkfs.btrfs -draid1 -mraid1 /dev/sdc /dev/sdd (detach a disk) devmgt detach /dev/sdc [1] mount -o degrade /dev/sdd /btrfs ------- [1] github.com/anajain/devmgt.git Signed-off-by: Anand Jain <Anand.Jain@oracle.com> Tested-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 3a0dfa6 commit f085381

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/btrfs/sysfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,14 @@ static int add_device_membership(struct btrfs_fs_info *fs_info)
578578
return -ENOMEM;
579579

580580
list_for_each_entry(dev, &fs_devices->devices, dev_list) {
581-
struct hd_struct *disk = dev->bdev->bd_part;
582-
struct kobject *disk_kobj = &part_to_dev(disk)->kobj;
581+
struct hd_struct *disk;
582+
struct kobject *disk_kobj;
583+
584+
if (!dev->bdev)
585+
continue;
586+
587+
disk = dev->bdev->bd_part;
588+
disk_kobj = &part_to_dev(disk)->kobj;
583589

584590
error = sysfs_create_link(fs_info->device_dir_kobj,
585591
disk_kobj, disk_kobj->name);

0 commit comments

Comments
 (0)