From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-eopbgr690089.outbound.protection.outlook.com [40.107.69.89]) by dpdk.org (Postfix) with ESMTP id 37565325F for ; Mon, 12 Nov 2018 19:14:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ksjdnb7hflnizZscIDKy549rROaC4WSaoxNx3OgPv58=; b=PNapfR7NsfaWwbBsZhS1QX0z+mu22usoGcejH24gAIFU+Gt0g33rPat4LrB5EbplxCQHTNvaOucfxy4scvweKW+MUbEX+YtyjDcIXJyeIyQzhIFhfW0UiT4JV77JriTFvvQEtjVWiihLDR9UDyALv5zLP81ChV68t8SGjQ+RYco= Received: from SN6PR07MB4911.namprd07.prod.outlook.com (52.135.77.157) by SN6PR07MB5598.namprd07.prod.outlook.com (20.177.252.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.30; Mon, 12 Nov 2018 18:14:13 +0000 Received: from SN6PR07MB4911.namprd07.prod.outlook.com ([fe80::cd76:e8cc:c0:ebf4]) by SN6PR07MB4911.namprd07.prod.outlook.com ([fe80::cd76:e8cc:c0:ebf4%3]) with mapi id 15.20.1294.044; Mon, 12 Nov 2018 18:14:13 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara CC: "Joseph, Anoob" , "Jacob, Jerin" , "Athreya, Narayana Prasad" , "Dwivedi, Ankur" , "dev@dpdk.org" Thread-Topic: [PATCH v2] crypto/octeontx: fix coverity issues Thread-Index: AQHUerODyUY6tdqKt0Cfm0RBxx6Dkw== Date: Mon, 12 Nov 2018 18:14:12 +0000 Message-ID: <1542046420-31462-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1541949837-9629-1-git-send-email-anoob.joseph@caviumnetworks.com> In-Reply-To: <1541949837-9629-1-git-send-email-anoob.joseph@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [115.113.156.2] x-clientproxiedby: BM1PR01CA0089.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::29) To SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR07MB5598; 6:r/Jni3Xrm5VUIUJGerG6flUY2eQVhVSlt9BjWapi3zr2F6HrfpunCYhCdroQJy+yKPwz4HxpLnouaBlvXUJS08WQo/QSc0RvS/knEWPkkKtIsvY4gOQDXzQRPLGLDFzermhCKXeJGl4Mt6Ne0oSk9FKlqa6JT3Y1Z2QfmDFEib57cP3mI52RbE1m5Rv8hDi+geXVI8zP5E1/Wn89pMXcOh5shEpdFoImALbDhR23jSB3nDi1VxtdDUHBE6rabHJAMUi7qekbFpQk8Ei30W1GU9iW/dLqwCwfZJycX4Y4VRsDAayNjxSiYQKxU5wmXen/eBKryLXOr9L90X1MFqSx1ApXw0IPqiyH7uk6yO+U9ZwjvZ688t4eYixT0JmVXsrAMAUrbXd8S4jhjFRq8oGnktcRJyFm99V7kvKN13i0XaYmheVyk8wjYQ/aHHuD2Klni7upjkXvqUXhrR1skL6T8w==; 5:itqc5hhNlvbQQwSLyijqrXw7rcK1ZSXCK02Z2C2Zw8UBHiMv+UX5DACuNWlX1bxBdIbHt9blvZwPrW+U2gocILFru7ZqI/GcvgSAtq51JWrl81PX29Cnv4YobF6nU+SnpTt7HRPH3Rztz4QwEQJdK2WcCLW3tJDuz7FwQM4i87w=; 7:g23+RoeE+9aRkEQVKeovG6KEj1Lo1X8r94NaOoilB9SmDWV4BKPqAq9tw9jUh8EUkonnBrutY2WiHnrxT6xI+h4g1Okcb79am7JZeCt0X5qLKPctXfxbjcxpIsAfz+/VQRLIW54zusD/YI8YZEJbuQ== x-ms-office365-filtering-correlation-id: 443d4eae-7b67-4aca-3aad-08d648caa5ec x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390040)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB5598; x-ms-traffictypediagnostic: SN6PR07MB5598: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231402)(944501410)(52105112)(93006095)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:SN6PR07MB5598; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB5598; x-forefront-prvs: 0854128AF0 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(346002)(136003)(39860400002)(366004)(189003)(199004)(71190400001)(102836004)(5660300001)(8676002)(316002)(26005)(54906003)(110136005)(6512007)(6486002)(99286004)(97736004)(6436002)(3846002)(478600001)(14454004)(14444005)(4326008)(81156014)(8936002)(575784001)(81166006)(6116002)(256004)(71200400001)(76176011)(42882007)(25786009)(66066001)(476003)(2616005)(52116002)(106356001)(72206003)(105586002)(2906002)(305945005)(53936002)(6506007)(7736002)(446003)(2900100001)(486006)(11346002)(186003)(386003)(68736007)(55236004)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB5598; H:SN6PR07MB4911.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: U6CdyXAQpEnAwyfXiC/VW5HYSXTNB8AhuW3YMntjYrGlpudva4bgtZitKbqGr+BKpLAGYZbvIaoOULbzSvtVEOHw4gPfX4z4f4Mvc+oR6uJKLUs//L+5VqvuhgzHGPD+bH8bEi9iVV290kCJfxGBnx0xmUb/SRq4PkgLIxW0pzzPNJpjhoONauEz6vUT8KZJVUHOqWt5oZALR8J12ZlJ7oe5Chy0BLRId3ZMFYO6mcMhC7KQ8+Evgi7W8b0vS+CpvFbvDNQcbx8kFDzh5/qoi/fKnpL00zPuWvM7vFXLtkkUj8QGr2uNjbCGzOVYuBwz6MpssJpJbY+CNkylHTaKJBxQCz5KCwAP4PssuQz3veM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: 443d4eae-7b67-4aca-3aad-08d648caa5ec X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Nov 2018 18:14:12.9443 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB5598 Subject: [dpdk-dev] [PATCH v2] crypto/octeontx: fix coverity issues X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Nov 2018 18:14:15 -0000 Coverity Issue: 323492 If the length of string pointed by 'name' is equal to or greater than the sizeof cptvf->dev_name string, the resultant string will not be null terminated. Using strlcpy would make sure the string would always be null terminated. Fixes: 0dc1cffa4d33 ("crypto/octeontx: add hardware init routine") Coverity Issue: 323489 Fix null pointer dereferencing Fixes: bfe2ae495ee2 ("crypto/octeontx: add PMD skeleton") Coverity Issue: 323486 The function otx_cpt_get_resource() would be setting the pointer 'instance'. In case of error, 'instance' would be set to NULL, and returns rte_errno. If rte_errno when 'instance' is set to NULL, it can lead to NULL pointer dereferencing. Fixes: 0961348fdf52 ("crypto/octeontx: add queue pair functions") Signed-off-by: Ankur Dwivedi Signed-off-by: Anoob Joseph --- v2: * Squashed three commits to one drivers/crypto/octeontx/otx_cryptodev.c | 2 +- drivers/crypto/octeontx/otx_cryptodev_hw_access.c | 5 ++++- drivers/crypto/octeontx/otx_cryptodev_ops.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/octeontx/otx_cryptodev.c b/drivers/crypto/octeo= ntx/otx_cryptodev.c index 269f045..b201e0a 100644 --- a/drivers/crypto/octeontx/otx_cryptodev.c +++ b/drivers/crypto/octeontx/otx_cryptodev.c @@ -100,8 +100,8 @@ otx_cpt_pci_remove(struct rte_pci_device *pci_dev) if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) rte_free(cryptodev->data->dev_private); =20 - cryptodev->device =3D NULL; cryptodev->device->driver =3D NULL; + cryptodev->device =3D NULL; cryptodev->data =3D NULL; =20 /* free metapool memory */ diff --git a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c b/drivers/cr= ypto/octeontx/otx_cryptodev_hw_access.c index 5e705a8..18f2e6b 100644 --- a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c +++ b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 #include "otx_cryptodev_hw_access.h" #include "otx_cryptodev_mbox.h" @@ -366,7 +367,9 @@ otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void = *reg_base, char *name) =20 /* Bar0 base address */ cptvf->reg_base =3D reg_base; - strncpy(cptvf->dev_name, name, 32); + + /* Save device name */ + strlcpy(cptvf->dev_name, name, (sizeof(cptvf->dev_name))); =20 cptvf->pdev =3D pdev; =20 diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/o= cteontx/otx_cryptodev_ops.c index 23f9659..90d0c14 100644 --- a/drivers/crypto/octeontx/otx_cryptodev_ops.c +++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c @@ -216,7 +216,7 @@ otx_cpt_que_pair_setup(struct rte_cryptodev *dev, } =20 ret =3D otx_cpt_get_resource(cptvf, 0, &instance); - if (ret !=3D 0) { + if (ret !=3D 0 || instance =3D=3D NULL) { CPT_LOG_ERR("Error getting instance handle from device %s : " "ret =3D %d", dev->data->name, ret); return ret; --=20 2.7.4