Skip to contentSkip to conversation

scsi: lpfc: add null check of kzalloc in lpfc_sli4_cgn_params_read

PATCH Applied Justin Tee 2 participants 2 messages Feb 28, 2023 – Mar 7, 2023

Subsystems (2)
lore
Share & tools
lore

Justin Tee

author
#0 lore raw

PATCH v2 1/1 scsi: lpfc: add null check of kzalloc in lpfc_sli4_cgn_params_read

If kzalloc fails in lpfc_sli4_cgn_params_read, then we rely on lpfc_read_object's routine to null check pdata.

Currently, an early return error is thrown from lpfc_read_object to protect us from null ptr dereference, but the errno code is -ENODEV.

Change the errno code to a more appropriate -ENOMEM.

---
 drivers/scsi/lpfc/lpfc_init.c | 2 ++
 drivers/scsi/lpfc/lpfc_sli.c  | 4 ----
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_init.c +2 -0
index 7573708..def0b9a 100644
@@ -7290,6 +7290,8 @@ void lpfc_host_attrib_init(struct Scsi_Host *shost)
 	/* Find out if the FW has a new set of congestion parameters. */
 	len = sizeof(struct lpfc_cgn_param);
 	pdata = kzalloc(len, GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
 	ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
 			       pdata, len);
 
drivers/scsi/lpfc/lpfc_sli.c +0 -4
index c5b69f3..c5ad46f 100644
@@ -22109,10 +22109,6 @@ struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
 	struct lpfc_dmabuf *pcmd;
 	u32 rd_object_name[LPFC_MBX_OBJECT_NAME_LEN_DW] = {0};
 
-	/* sanity check on queue memory */
-	if (!datap)
-		return -ENODEV;
-
 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 	if (!mbox)
 		return -ENOMEM;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Justin Tee

If kzalloc fails in lpfc_sli4_cgn_params_read, then we rely on lpfc_read_object's routine to null check pdata.

Currently, an early return error is thrown from lpfc_read_object to protect us from null ptr dereference, but the errno code is -ENODEV.

Change the errno code to a more appropriate -ENOMEM.

[...]

Applied to 6.3/scsi-fixes, thanks!

[1/1] scsi: lpfc: add null check of kzalloc in lpfc_sli4_cgn_params_read

      https://git.kernel.org/mkp/scsi/c/312320b0e0ec
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering