Skip to contentSkip to conversation

scsi: qla2xxx: Fix possible null-pointer dereferences in qla2x00_alloc_fcport()

PATCH Applied Jia-Ju Bai 2 participants 2 messages Jul 29, 2019 – Jul 30, 2019

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 scsi: qla2xxx: Fix possible null-pointer dereferences in qla2x00_alloc_fcport()

In qla2x00_alloc_fcport(), fcport is assigned to NULL in the error handling code on line 4880:

    fcport = NULL;

Then fcport is used on lines 4883-4886:

    INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
	INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
	INIT_LIST_HEAD(&fcport->gnl_entry);
	INIT_LIST_HEAD(&fcport->list);

Thus, possible null-pointer dereferences may occur.

To fix these bugs, qla2x00_alloc_fcport() directly returns NULL in the error handling code.

These bugs are found by a static analysis tool STCheck written by us.

---
 drivers/scsi/qla2xxx/qla_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_init.c +1 -1
index 4059655639d9..da83034d4759 100644
@@ -4877,7 +4877,7 @@ qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
 		ql_log(ql_log_warn, vha, 0xd049,
 		    "Failed to allocate ct_sns request.\n");
 		kfree(fcport);
-		fcport = NULL;
+		return NULL;
 	}
 
 	INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
Signature · 1 line
2.17.0
#1 lore raw

Jia-Ju,

Quoted 3 lines

In qla2x00_alloc_fcport(), fcport is assigned to NULL in the error handling code on line 4880:

    fcport = NULL;

Applied to 5.3/scsi-fixes. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering