Skip to content

Commit 2331ce6

Browse files
ps-ushankarmartinkpetersen
authored andcommitted
scsi: core: Restrict legal sdev_state transitions via sysfs
Userspace can currently write to sysfs to transition sdev_state to RUNNING or OFFLINE from any source state. This causes issues because proper transitioning out of some states involves steps besides just changing sdev_state, so allowing userspace to change sdev_state regardless of the source state can result in inconsistencies; e.g. with ISCSI we can end up with sdev_state == SDEV_RUNNING while the device queue is quiesced. Any task attempting I/O on the device will then hang, and in more recent kernels, iscsid will hang as well. More detail about this bug is provided in my first attempt: https://groups.google.com/g/open-iscsi/c/PNKca4HgPDs/m/CXaDkntOAQAJ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uday Shankar <[email protected]> Suggested-by: Mike Christie <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 9abf231 commit 2331ce6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/scsi/scsi_sysfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,14 @@ store_state_field(struct device *dev, struct device_attribute *attr,
828828
}
829829

830830
mutex_lock(&sdev->state_mutex);
831+
switch (sdev->sdev_state) {
832+
case SDEV_RUNNING:
833+
case SDEV_OFFLINE:
834+
break;
835+
default:
836+
mutex_unlock(&sdev->state_mutex);
837+
return -EINVAL;
838+
}
831839
if (sdev->sdev_state == SDEV_RUNNING && state == SDEV_RUNNING) {
832840
ret = 0;
833841
} else {

0 commit comments

Comments
 (0)