From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id EC95A292D for ; Fri, 22 Feb 2019 16:39:18 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Feb 2019 07:39:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,400,1544515200"; d="scan'208";a="149160641" Received: from irsmsx108.ger.corp.intel.com ([163.33.3.3]) by fmsmga001.fm.intel.com with ESMTP; 22 Feb 2019 07:39:16 -0800 Received: from irsmsx101.ger.corp.intel.com ([169.254.1.185]) by IRSMSX108.ger.corp.intel.com ([169.254.11.28]) with mapi id 14.03.0415.000; Fri, 22 Feb 2019 15:39:15 +0000 From: "Trahe, Fiona" To: Anoob Joseph , Akhil Goyal , "Doherty, Declan" , "De Lara Guarch, Pablo" CC: Jerin Jacob Kollanukkaran , "Narayana Prasad Raju Athreya" , "dev@dpdk.org" , Ankur Dwivedi , "Trahe, Fiona" Thread-Topic: [PATCH] lib/cryptodev: fix driver name comparison Thread-Index: AQHUvHxsntNewzBh2Ey4taeN+7Qt9aXo7DZAgAGkSYCAAMGkYIAAvGkQ Date: Fri, 22 Feb 2019 15:39:14 +0000 Message-ID: <348A99DA5F5B7549AA880327E580B435896F4E65@IRSMSX101.ger.corp.intel.com> References: <1549279528-10397-1-git-send-email-anoobj@marvell.com> <348A99DA5F5B7549AA880327E580B435896F431A@IRSMSX101.ger.corp.intel.com> In-Reply-To: Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOGMwYTM3ODYtM2RiMS00ZjdjLTgzZmEtNzJlODI1M2MzYmQ2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibzRodXNjWlBrOEczdVNWMUZ1VHNYeFFCWEJ5Z0hISlRlNEt2RmNWdnRnKzRzdlRwZ2pUVDFvYVIrYWYxWU80UCJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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: Fri, 22 Feb 2019 15:39:19 -0000 Hi Anoob, > > > > @@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char *name) > > > > return -1; > > > > > > > > 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) > > && > > [Fiona] Is this safe? The const passed to this may not be the full leng= th of > > RTE_CRYPTODEV_NAME_MAX_LEN. Does this prototype need to specify > > that a full length const filled with trailing zeros must be passed in? = And if so is > > this an ABI breakage? > > >=20 > [Anoob] strcmp itself is not safe when we have buffers which are not NULL= terminated. Strncmp will make > sure the check won't exceed RTE_CRYPTODEV_NAME_MAX_LEN. >=20 > From man page, "The strncmp() function is similar, except it only compare= s the first (at most) n bytes of > s1 and s2." >=20 > The main issue here is the usage of strncmp with strlen(driver_name), as = in the below cases. Strlen will > return string length, which doesn't include \0. strcmp is good enough to = fix the issue. But usage of strcmp > would assume that the const is filled with trailing zero. IMO, none of th= ese options are really safe. So > please advise on what would be the best solution here. I'll revise the pa= tch accordingly. [Fiona] I agree and think it is safest as you've coded it. However I'd sugg= est adding a comment on the relevant APIs saying that the string must be pa= ssed in in a buffer of size with trailing zeros.