scsi: zfcp: fix use-after-free in zfcp_sysfs_port_remove_store
Subsystems (3)
PATCH 1/1 scsi: zfcp: fix use-after-free in zfcp_sysfs_port_remove_store
kfree(port) is called in put_device(&port->dev) so that following use would cause use-after-free bug.
the former put_device is redundant for device_unregister contains put_device already. So just remove it to fix this.
--- drivers/s390/scsi/zfcp_sysfs.c | 2 -- 1 file changed, 2 deletions(-)
drivers/s390/scsi/zfcp_sysfs.c +0 -2
@@ -327,8 +327,6 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,list_del (&port->list);write_unlock_irq (&adapter->port_list_lock); -put_device (&port->dev); -zfcp_erp_port_shutdown (port,0 ,"syprs_1" );device_unregister (&port->dev); out:
Signature · 1 line
2.23.0
Quoted 18 lines · Qinglang Miao
kfree(port) is called in
put_device(&port->dev)so that following use would cause use-after-free bug.the former
put_deviceis redundant fordevice_unregistercontainsput_devicealready. So just remove it to fix this.Fixes 83d4e1c33d93 ("[SCSI] zfcp: cleanup port sysfs attribute usage")Reported-by Hulk Robot <[email protected]>Signed-off-by Qinglang Miao <[email protected]>--- drivers/s390/scsi/zfcp_sysfs.c | 2 -- 1 file changed, 2 deletions(-)drivers/s390/scsi/zfcp_sysfs.c +0
-0
drivers/s390/scsi/zfcp_sysfs.c static ssize_t zfcp_sysfs_port_remove_store(struct device *dev, · line 332
Quoted 8 lines
drivers/s390/scsi/zfcp_sysfs.c +0
-2@@ -327,8 +327,6 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,list_del (&port->list);write_unlock_irq (&adapter->port_list_lock); -put_device (&port->dev); -zfcp_erp_port_shutdown (port,0 ,"syprs_1" );device_unregister (&port->dev); out:
Hmm, the placement of the put_device() is indeed strange, now that I think about it. But just removing it and then having a dangling reference also seems wrong - we do get one explicitly in zfcp_get_port_by_wwpn().
My first thought would be to move it after the device_unregister() call, and before the out: label.
Signature · 4 lines
Best Regards, Benjamin Block / Linux on IBM Z Kernel Development / IBM Systems IBM Deutschland Research & Development GmbH / https://www.ibm.com/privacy Vorsitz. AufsR.: Gregor Pillen / Gesch�ftsf�hrung: Dirk Wittkopp Sitz der Gesellschaft: B�blingen / Registergericht: AmtsG Stuttgart, HRB 243294