DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anoob Joseph <anoobj@marvell.com>
To: Akhil Goyal <akhil.goyal@nxp.com>,
	Declan Doherty <declan.doherty@intel.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Cc: Anoob Joseph <anoobj@marvell.com>,
	Ankur Dwivedi <adwivedi@marvell.com>,
	Jerin Jacob Kollanukkaran <jerinj@marvell.com>,
	Narayana Prasad Raju Athreya <pathreya@marvell.com>,
	Suheil Chandran <schandran@marvell.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH v2] lib/cryptodev: fix driver name comparison
Date: Mon, 11 Mar 2019 05:55:44 +0000	[thread overview]
Message-ID: <1552283715-18723-1-git-send-email-anoobj@marvell.com> (raw)
In-Reply-To: <1549279528-10397-1-git-send-email-anoobj@marvell.com>

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 = 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 devices")

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
v2:
* Using strlen + 1, instead of RTE_CRYPTODEV_NAME_MAX_LEN for the comparison.
* 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/rte_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, uint8_t *devices,
 
 			cmp = strncmp(devs[i].device->driver->name,
 					driver_name,
-					strlen(driver_name));
+					strlen(driver_name) + 1);
 
 			if (cmp == 0)
 				devices[count++] = devs[i].data->dev_id;
@@ -1691,7 +1691,7 @@ rte_cryptodev_driver_id_get(const char *name)
 
 	TAILQ_FOREACH(driver, &cryptodev_driver_list, next) {
 		driver_name = driver->driver->name;
-		if (strncmp(driver_name, name, strlen(driver_name)) == 0)
+		if (strncmp(driver_name, name, strlen(driver_name) + 1) == 0)
 			return driver->id;
 	}
 	return -1;
-- 
2.7.4

  parent reply	other threads:[~2019-03-11  5:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 11:26 [dpdk-dev] [PATCH] " Anoob Joseph
2019-02-20 15:41 ` Anoob Joseph
2019-02-21 17:03   ` Trahe, Fiona
2019-02-22  4:47     ` Anoob Joseph
2019-02-22 15:39       ` Trahe, Fiona
2019-02-23  6:11         ` Anoob Joseph
2019-02-25 11:52           ` Trahe, Fiona
2019-02-28  6:48             ` Anoob Joseph
2019-02-28  8:51               ` Akhil Goyal
2019-02-28  9:27                 ` Anoob Joseph
2019-02-28 10:20                   ` Akhil Goyal
2019-02-28 14:30                     ` Trahe, Fiona
2019-03-01  6:24                       ` Anoob Joseph
2019-03-07  5:51                         ` Anoob Joseph
2019-03-11  5:55 ` Anoob Joseph [this message]
2019-03-11 10:41   ` [dpdk-dev] [PATCH v2] " Trahe, Fiona
2019-03-19  4:38     ` Anoob Joseph
2019-03-19  4:38       ` Anoob Joseph
2019-03-19 13:42   ` Akhil Goyal
2019-03-19 13:42     ` Akhil Goyal
2019-03-19 14:06     ` Akhil Goyal
2019-03-19 14:06       ` Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1552283715-18723-1-git-send-email-anoobj@marvell.com \
    --to=anoobj@marvell.com \
    --cc=adwivedi@marvell.com \
    --cc=akhil.goyal@nxp.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=pathreya@marvell.com \
    --cc=schandran@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).