From nobody Tue Apr 28 23:20:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8427C433EF for ; Fri, 27 May 2022 07:59:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242234AbiE0H7i (ORCPT ); Fri, 27 May 2022 03:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbiE0H7e (ORCPT ); Fri, 27 May 2022 03:59:34 -0400 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA51522BFD; Fri, 27 May 2022 00:59:32 -0700 (PDT) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24R74NJ7013605; Fri, 27 May 2022 00:58:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=LlqQ4B1a0P9MJ7iI3TRfT391yR7H/yJDfSHMiZJgOm8=; b=bTsUxJifrX8/XarAaJ83tfQk53Fi+xF0vsf5VSs8l6I1c6vPBjfHqKksjExXST8tuPSN rWHuK/iPgz59yQpD6LskVnzrdYXbYghR4P/kei0sVJ11XnYzXbVQulX7ATs3O8Lpevv3 uzrx6QpcN/+e0y37YzKUO9GSc//xI3xJuzbt3PmcJnArop3SRSzH23e2c6p7e/v8km10 7ARjuYt8JE/yPQ3uDqo/+9Dmqm2Vy9tSaB08kdNesaVaNSbrGx4kK5tTNgippp3vlf0y N02teEI1f4+f9tDcvPX3lGFoem6lLbdpATw1QQ0KBYNJQBSRL7DH8sgcnd3dGmXIma5t Yg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3gaf2rtjtp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 27 May 2022 00:58:36 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 27 May 2022 00:58:34 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 27 May 2022 00:58:35 -0700 Received: from localhost.localdomain (unknown [10.28.34.29]) by maili.marvell.com (Postfix) with ESMTP id 626463F7065; Fri, 27 May 2022 00:58:31 -0700 (PDT) From: Shijith Thotton To: Arnaud Ebalard , Herbert Xu , Boris Brezillon CC: Shijith Thotton , , , , Srujana Challa , "David S. Miller" , Harman Kalra , Yang Yingliang , "Dan Carpenter" , Kees Cook , Jiapeng Chong , open list Subject: [PATCH] crypto: octeontx2: fix potential null pointer access Date: Fri, 27 May 2022 13:27:56 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: nCMP_Exh7aKQiqy2ZuCfjlqnzIjuv-0G X-Proofpoint-GUID: nCMP_Exh7aKQiqy2ZuCfjlqnzIjuv-0G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-27_02,2022-05-25_02,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Added missing checks to avoid null pointer dereference. The patch fixes below issues reported by klocwork tool: 1. Pointer 'pcim_iomap_table(pdev)' returned from call to function 'pcim_iomap_table' at line 365 may be NULL and will be dereferenced at line 365 in otx2_cptvf_main.c. Also there is a similar error on line 734 in otx2_cptpf_main.c. 2. Pointer 'strsep( &val, ":" )' returned from call to function 'strsep' at line 1608 may be NULL and will be dereferenced at line 1608. Also there are 2 similar errors on lines 1620, 1632 in otx2_cptpf_ucode.c. Signed-off-by: Shijith Thotton --- .../crypto/marvell/octeontx2/otx2_cptpf_main.c | 9 ++++++++- .../marvell/octeontx2/otx2_cptpf_ucode.c | 18 +++++++++++++++--- .../crypto/marvell/octeontx2/otx2_cptvf_main.c | 9 ++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c b/drivers/c= rypto/marvell/octeontx2/otx2_cptpf_main.c index a402ccfac557..ae57cee424f0 100644 --- a/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c +++ b/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c @@ -703,6 +703,7 @@ static int otx2_cptpf_probe(struct pci_dev *pdev, { struct device *dev =3D &pdev->dev; struct otx2_cptpf_dev *cptpf; + void __iomem * const *iomap; int err; =20 cptpf =3D devm_kzalloc(dev, sizeof(*cptpf), GFP_KERNEL); @@ -731,7 +732,13 @@ static int otx2_cptpf_probe(struct pci_dev *pdev, pci_set_drvdata(pdev, cptpf); cptpf->pdev =3D pdev; =20 - cptpf->reg_base =3D pcim_iomap_table(pdev)[PCI_PF_REG_BAR_NUM]; + iomap =3D pcim_iomap_table(pdev); + if (!iomap) { + dev_err(dev, "Failed to get iomap table\n"); + err =3D -ENODEV; + goto clear_drvdata; + } + cptpf->reg_base =3D iomap[PCI_PF_REG_BAR_NUM]; =20 /* Check if AF driver is up, otherwise defer probe */ err =3D cpt_is_pf_usable(cptpf); diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c b/drivers/= crypto/marvell/octeontx2/otx2_cptpf_ucode.c index 9cba2f714c7e..b91401929fc6 100644 --- a/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c +++ b/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c @@ -1605,7 +1605,11 @@ int otx2_cpt_dl_custom_egrp_create(struct otx2_cptpf= _dev *cptpf, if (!strncasecmp(val, "se", 2) && strchr(val, ':')) { if (has_se || ucode_idx) goto err_print; - tmp =3D strim(strsep(&val, ":")); + tmp =3D strsep(&val, ":"); + if (tmp !=3D NULL) + tmp =3D strim(tmp); + else + goto err_print; if (!val) goto err_print; if (strlen(tmp) !=3D 2) @@ -1617,7 +1621,11 @@ int otx2_cpt_dl_custom_egrp_create(struct otx2_cptpf= _dev *cptpf, } else if (!strncasecmp(val, "ae", 2) && strchr(val, ':')) { if (has_ae || ucode_idx) goto err_print; - tmp =3D strim(strsep(&val, ":")); + tmp =3D strsep(&val, ":"); + if (tmp !=3D NULL) + tmp =3D strim(tmp); + else + goto err_print; if (!val) goto err_print; if (strlen(tmp) !=3D 2) @@ -1629,7 +1637,11 @@ int otx2_cpt_dl_custom_egrp_create(struct otx2_cptpf= _dev *cptpf, } else if (!strncasecmp(val, "ie", 2) && strchr(val, ':')) { if (has_ie || ucode_idx) goto err_print; - tmp =3D strim(strsep(&val, ":")); + tmp =3D strsep(&val, ":"); + if (tmp !=3D NULL) + tmp =3D strim(tmp); + else + goto err_print; if (!val) goto err_print; if (strlen(tmp) !=3D 2) diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c b/drivers/c= rypto/marvell/octeontx2/otx2_cptvf_main.c index 3411e664cf50..9249ec1783bc 100644 --- a/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c +++ b/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c @@ -334,6 +334,7 @@ static int otx2_cptvf_probe(struct pci_dev *pdev, { struct device *dev =3D &pdev->dev; struct otx2_cptvf_dev *cptvf; + void __iomem * const *iomap; int ret; =20 cptvf =3D devm_kzalloc(dev, sizeof(*cptvf), GFP_KERNEL); @@ -362,7 +363,13 @@ static int otx2_cptvf_probe(struct pci_dev *pdev, pci_set_drvdata(pdev, cptvf); cptvf->pdev =3D pdev; =20 - cptvf->reg_base =3D pcim_iomap_table(pdev)[PCI_PF_REG_BAR_NUM]; + iomap =3D pcim_iomap_table(pdev); + if (!iomap) { + dev_err(dev, "Failed to get iomap table\n"); + ret =3D -ENODEV; + goto clear_drvdata; + } + cptvf->reg_base =3D iomap[PCI_PF_REG_BAR_NUM]; =20 otx2_cpt_set_hw_caps(pdev, &cptvf->cap_flag); =20 --=20 2.25.1