From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 7284A5681 for ; Mon, 4 Feb 2019 12:26:15 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x14BOke3018801; Mon, 4 Feb 2019 03:26:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=h2nD4IzKAOCsz8FW2f+F3KCXgezV4E2VbVd6tTCUfzQ=; b=phCozLmLDzJMkueulWtO2xO5vIWnOXHyIJ6rXcY2/TxYoPmFp2TXsOdbv+uCNPgnaLlr IQAqCTZqx7g0aveZMcgVwFYEm/zFefyDMBf6tOfI+X5VadZzsKDpjVblkNmfhO6Ge6nk daDiCmN5Lo+31o6qflWn3yA/nZsoEFXw5j64EjTUxYLylRs2CL8FGJUWmcT5sfHzLqAI 7F0foUlWnpECofJkXFkWgluSx+wQfxtVNr8a641DTTnlLjpSawNhc+OGyDp3Wz72yZD+ qJTqmxl0mdGyDsKzTgpQ9Xho+I8zcQCz6Y7+RrlvTVe4r6swQBYkMG9tWODm+G196pcc 9g== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2qd9erwhnq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 04 Feb 2019 03:26:14 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 4 Feb 2019 03:26:13 -0800 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (104.47.32.55) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 4 Feb 2019 03:26:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h2nD4IzKAOCsz8FW2f+F3KCXgezV4E2VbVd6tTCUfzQ=; b=cFN6qkP6OuUdHcrX/K2QOvjyLnJH1of8/B7vI33Qn9prHNWFCZ9AtDpqds7uwEJlraXg1qBpsRFiQcPe9sCFmQeKciWeYjN4az8zqnQF2RVy00XVapXhrKmO8CCrFPZcTqnSBDmeWu2W9WvMV+anAyF23vAGu190XxmzZG8Dte0= Received: from MN2PR18MB2877.namprd18.prod.outlook.com (20.179.22.16) by MN2PR18MB2685.namprd18.prod.outlook.com (20.179.84.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1580.16; Mon, 4 Feb 2019 11:26:09 +0000 Received: from MN2PR18MB2877.namprd18.prod.outlook.com ([fe80::341b:94da:672b:d400]) by MN2PR18MB2877.namprd18.prod.outlook.com ([fe80::341b:94da:672b:d400%6]) with mapi id 15.20.1580.019; Mon, 4 Feb 2019 11:26:08 +0000 From: Anoob Joseph To: Akhil Goyal , Declan Doherty , Pablo de Lara CC: Anoob Joseph , Jerin Jacob Kollanukkaran , Narayana Prasad Raju Athreya , "dev@dpdk.org" , Ankur Dwivedi Thread-Topic: [PATCH] lib/cryptodev: fix driver name comparison Thread-Index: AQHUvHxsntNewzBh2Ey4taeN+7Qt9Q== Date: Mon, 4 Feb 2019 11:26:08 +0000 Message-ID: <1549279528-10397-1-git-send-email-anoobj@marvell.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0005.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::15) To MN2PR18MB2877.namprd18.prod.outlook.com (2603:10b6:208:a0::16) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [115.113.156.2] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MN2PR18MB2685; 20:gsAdSC9xlNtq5eegNjhIH9+q6PKgqQqak8PDWH5+5QhztbNH6+QcIug+oaQ0/F1f3twNr6nae26aGGNk7Ljz3jq0U2+hKZCyy+oCO9dVPOXKShcx0nXxfqHiBWwkkgs3Gl+PjdsmS++RLFX32eUytJ+MampwkUz58e6YCz1dAVA= x-ms-office365-filtering-correlation-id: 20b2ced9-e2b4-4288-d805-08d68a938efb x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(2017052603328)(7153060)(7193020); SRVR:MN2PR18MB2685; x-ms-traffictypediagnostic: MN2PR18MB2685: x-microsoft-antispam-prvs: x-forefront-prvs: 0938781D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(136003)(39850400004)(396003)(376002)(346002)(189003)(199004)(81156014)(81166006)(8676002)(6506007)(478600001)(25786009)(2906002)(102836004)(6116002)(3846002)(107886003)(50226002)(53936002)(99286004)(256004)(5024004)(8936002)(6486002)(52116002)(4326008)(186003)(6436002)(6512007)(106356001)(105586002)(66066001)(26005)(14454004)(68736007)(2616005)(305945005)(486006)(316002)(71190400001)(97736004)(71200400001)(55236004)(36756003)(86362001)(476003)(54906003)(386003)(7736002)(110136005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2685; H:MN2PR18MB2877.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ZMgx1lYGxqksm7jYNa4P9sHrPuYtna8L5TV5u4BWNdAPbz5hp4LnD5D4LYfwlMjZmLv6uWYey9rPJ3FWabVY11JSd8oDNLNINqHBQ/ypBU2uw+L80Wr9xUYYpbChFBqDz6n7FCuIyjxEgYZQiVanq4vU/b9klyFPi4V6NIPZsqragwEh198L+zt8b4k/pG6G0VsxBpTH/qAGOnDrwL/o7ll1lClKyDsINvaWiEpaM9f2/eOYpz2wsEQ+pP1fcE30t7aQjMvbR/uSORBf5ZXH03drniSrXj+nGw6MLu3enCv5+E9FOfCelEJ9Y/hRU730ssPKZIOUrbNkI/+s5t1cuXQX61txTbHNqqHRfSnqcH3usqTRdnwoW4HmbkcFhDnSz4UiK4jlp+MWTTB/FwskyZ15+qQjQbAqPcgXIwrkeCI= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 20b2ced9-e2b4-4288-d805-08d68a938efb X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Feb 2019 11:26:05.9182 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB2685 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-04_08:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902040092 Subject: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison 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, 04 Feb 2019 11:26:15 -0000 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". Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto dev= ices") Signed-off-by: Ankur Dwivedi Signed-off-by: Anoob Joseph --- lib/librte_cryptodev/rte_cryptodev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rt= e_cryptodev.c index 7009735..b743c60 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -510,7 +510,8 @@ rte_cryptodev_pmd_get_named_dev(const char *name) dev =3D &cryptodev_globals.devs[i]; =20 if ((dev->attached =3D=3D RTE_CRYPTODEV_ATTACHED) && - (strcmp(dev->data->name, name) =3D=3D 0)) + (strncmp(dev->data->name, name, + RTE_CRYPTODEV_NAME_MAX_LEN) =3D=3D 0)) return dev; } =20 @@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char *name) return -1; =20 for (i =3D 0; i < cryptodev_globals.nb_devs; i++) - if ((strcmp(cryptodev_globals.devs[i].data->name, name) - =3D=3D 0) && + if ((strncmp(cryptodev_globals.devs[i].data->name, name, + RTE_CRYPTODEV_NAME_MAX_LEN) =3D=3D 0) && (cryptodev_globals.devs[i].attached =3D=3D RTE_CRYPTODEV_ATTACHED)) return i; @@ -586,7 +587,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)); + RTE_CRYPTODEV_NAME_MAX_LEN); =20 if (cmp =3D=3D 0) devices[count++] =3D devs[i].data->dev_id; @@ -1691,7 +1692,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, RTE_CRYPTODEV_NAME_MAX_LEN) =3D=3D 0) return driver->id; } return -1; --=20 2.7.4