scsi: zfcp: Fence early sysfs interfaces for accesses of shost objects
authorBenjamin Block <bblock@linux.ibm.com>
Fri, 8 May 2020 17:23:34 +0000 (19:23 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 12 May 2020 03:19:50 +0000 (23:19 -0400)
commit71159b6ecb067565fb41faba616116e8c0fc10ea
tree68e151df9a43d526ff4f0b635e072b59f727d382
parent971f2abb4ca4095bb4bd7c2ba119d1cca078b433
scsi: zfcp: Fence early sysfs interfaces for accesses of shost objects

When setting an adapter online for the first time, we also create a couple
of entries for it in the sysfs device tree. This is also true even if the
adapter has not yet ever gone successfully through exchange config and
exchange port data.

When moving the scsi host object allocation and registration to after the
first exchange config and exchange port data, this make the `port_rescan`
attribute susceptible to invalid pointer-dereferences of the shost field
before the adapter is fully initialized.

When written to, it schedules a `scan_work` item that will in turn make use
of the associated fibre channel host object to check the topology used for
this FCP device.

Because scanning for remote ports can't be done successfully without
completing exchange config and exchange port data first, we can simply
fence `port_rescan`, and so prevent the illegal access.

As with cases where we can't get a reference to the adapter, we also return
-ENODEV here. Applications need to handle that errno today already.

After a successful allocation of the scsi host object nothing changes in
the work flow.

Link: https://lore.kernel.org/r/ef65366d309993ca91b6917727590ca7ca166c8f.1588956679.git.bblock@linux.ibm.com
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/s390/scsi/zfcp_sysfs.c