DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison
@ 2019-02-04 11:26 Anoob Joseph
  2019-02-20 15:41 ` Anoob Joseph
  2019-03-11  5:55 ` [dpdk-dev] [PATCH v2] " Anoob Joseph
  0 siblings, 2 replies; 22+ messages in thread
From: Anoob Joseph @ 2019-02-04 11:26 UTC (permalink / raw)
  To: Akhil Goyal, Declan Doherty, Pablo de Lara
  Cc: Anoob Joseph, Jerin Jacob Kollanukkaran,
	Narayana Prasad Raju Athreya, dev, Ankur Dwivedi

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".

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>
---
 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/rte_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 = &cryptodev_globals.devs[i];
 
 		if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
-				(strcmp(dev->data->name, name) == 0))
+				(strncmp(dev->data->name, name,
+					 RTE_CRYPTODEV_NAME_MAX_LEN) == 0))
 			return dev;
 	}
 
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char *name)
 		return -1;
 
 	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name, name)
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name, name,
+				RTE_CRYPTODEV_NAME_MAX_LEN) == 0) &&
 				(cryptodev_globals.devs[i].attached ==
 						RTE_CRYPTODEV_ATTACHED))
 			return i;
@@ -586,7 +587,7 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
 
 			cmp = strncmp(devs[i].device->driver->name,
 					driver_name,
-					strlen(driver_name));
+					RTE_CRYPTODEV_NAME_MAX_LEN);
 
 			if (cmp == 0)
 				devices[count++] = devs[i].data->dev_id;
@@ -1691,7 +1692,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, RTE_CRYPTODEV_NAME_MAX_LEN) == 0)
 			return driver->id;
 	}
 	return -1;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-03-19 14:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-04 11:26 [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison 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 ` [dpdk-dev] [PATCH v2] " Anoob Joseph
2019-03-11 10:41   ` 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

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).