Skip to contentSkip to conversation

scsi: lpfc: add null check of kzalloc in lpfc_sli4_cgn_params_read

PATCH In review Kang Chen 2 participants 2 messages Feb 26, 2023 – Feb 28, 2023

Subsystems (2)
lore
Share & tools
lore

Kang Chen

author
#0 lore raw

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

kzalloc may fails, pdata might be null and it may cause null pointer dereference later.

---
 drivers/scsi/lpfc/lpfc_init.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/lpfc/lpfc_init.c +2 -0
index 6eb4085a3..54134d782 100644
@@ -7291,6 +7291,8 @@ lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
 	/* 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);
 
Signature · 1 line
2.34.1
#1 lore raw

Hi Kang,

Thanks for reporting this.

Technically, the lpfc_read_object routine already NULL checks pdata, and if it was NULL would return -ENODEV. Then, else if (ret < 0) would evaluate to true and we'd goto rd_obj_err.

However, we like the suggestion to return -ENOMEM instead. I will post a v2 of this patch to address both concerns.

Thanks,
Justin

Quoted 25 lines · Kang Chen

kzalloc may fails, pdata might be null and it may cause null pointer dereference later.

---
 drivers/scsi/lpfc/lpfc_init.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/lpfc/lpfc_init.c +2 -1
index 6eb4085a3..54134d782 100644
@@ -7291,6 +7291,8 @@ lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
        /* 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);
 
--

2.34.1