From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anoob Joseph Subject: [PATCH v2] lib/cryptodev: fix driver name comparison Date: Mon, 11 Mar 2019 05:55:44 +0000 Message-ID: <1552283715-18723-1-git-send-email-anoobj@marvell.com> References: <1549279528-10397-1-git-send-email-anoobj@marvell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: Anoob Joseph , Ankur Dwivedi , Jerin Jacob Kollanukkaran , Narayana Prasad Raju Athreya , Suheil Chandran , "dev@dpdk.org" To: Akhil Goyal , Declan Doherty , Pablo de Lara Return-path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id A7959375B for ; Mon, 11 Mar 2019 06:55:53 +0100 (CET) In-Reply-To: <1549279528-10397-1-git-send-email-anoobj@marvell.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The string compare to the length of driver name might give false positives when there are drivers with similar names (one being the subset of another). Following is such a naming which could result in false positive. 1. crypto_driver 2. crypto_driver1 When strncmp with len =3D strlen("crypto_driver") is done, it could give a false positive when compared against "crypto_driver1". For such cases, 'strlen + 1' is done, so that the NULL termination also would be considered for the comparison. Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto dev= ices") Signed-off-by: Ankur Dwivedi Signed-off-by: Anoob Joseph --- v2: * Using strlen + 1, instead of RTE_CRYPTODEV_NAME_MAX_LEN for the compariso= n. * Strcmp would not cause this issue. Touching only the places which would result in the issue. lib/librte_cryptodev/rte_cryptodev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rt= e_cryptodev.c index 7009735..871d7dd 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -586,7 +586,7 @@ rte_cryptodev_devices_get(const char *driver_name, uint= 8_t *devices, =20 cmp =3D strncmp(devs[i].device->driver->name, driver_name, - strlen(driver_name)); + strlen(driver_name) + 1); =20 if (cmp =3D=3D 0) devices[count++] =3D devs[i].data->dev_id; @@ -1691,7 +1691,7 @@ rte_cryptodev_driver_id_get(const char *name) =20 TAILQ_FOREACH(driver, &cryptodev_driver_list, next) { driver_name =3D driver->driver->name; - if (strncmp(driver_name, name, strlen(driver_name)) =3D=3D 0) + if (strncmp(driver_name, name, strlen(driver_name) + 1) =3D=3D 0) return driver->id; } return -1; --=20 2.7.4