Skip to content

Commit 017f2e3

Browse files
Nagendra Singh TomarJames Bottomley
authored andcommitted
[SCSI] sd: udev accessing an uninitialized scsi_disk field results in a crash
sd_probe() calls class_device_add() even before initializing the sdkp->device variable. class_device_add() eventually results in the user mode udev program to be called. udev program can read the the allow_restart attribute of the newly created scsi device. This is resulting in a crash as the show function for allow_restart (i.e sd_show_allow_restart) returns the attribute value by reading the sdkp->device->allow_restart variable. As the sdkp->device is not initialized before calling the user mode hotplug helper, this results in a crash. The patch below solves it by calling class_device_add() only after the necessary fields in the scsi_disk structure are initialized properly. Signed-off-by: Nagendra Singh Tomar <nagendra_tomar@adaptec.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
1 parent 91614c0 commit 017f2e3

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎drivers/scsi/sd.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,16 +1647,6 @@ static int sd_probe(struct device *dev)
16471647
if (error)
16481648
goto out_put;
16491649

1650-
class_device_initialize(&sdkp->cdev);
1651-
sdkp->cdev.dev = &sdp->sdev_gendev;
1652-
sdkp->cdev.class = &sd_disk_class;
1653-
strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
1654-
1655-
if (class_device_add(&sdkp->cdev))
1656-
goto out_put;
1657-
1658-
get_device(&sdp->sdev_gendev);
1659-
16601650
sdkp->device = sdp;
16611651
sdkp->driver = &sd_template;
16621652
sdkp->disk = gd;
@@ -1670,6 +1660,16 @@ static int sd_probe(struct device *dev)
16701660
sdp->timeout = SD_MOD_TIMEOUT;
16711661
}
16721662

1663+
class_device_initialize(&sdkp->cdev);
1664+
sdkp->cdev.dev = &sdp->sdev_gendev;
1665+
sdkp->cdev.class = &sd_disk_class;
1666+
strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
1667+
1668+
if (class_device_add(&sdkp->cdev))
1669+
goto out_put;
1670+
1671+
get_device(&sdp->sdev_gendev);
1672+
16731673
gd->major = sd_major((index & 0xf0) >> 4);
16741674
gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00);
16751675
gd->minors = 16;

0 commit comments

Comments
 (0)