Skip to contentSkip to conversation

lib/cryptodev: fix driver name comparison

PATCH Superseded Anoob Joseph 3 participants 19 messages Feb 4, 2019 – Mar 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/cryptodev: fix driver name comparison

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")
---
 lib/librte_cryptodev/rte_cryptodev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +6 -5
index 7009735..b743c60 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 79 lines

-----Original Message-----
From: Anoob Joseph
Sent: Monday, February 4, 2019 4:56 PM
To: Akhil Goyal <[email protected]>; Declan Doherty <[email protected]>; Pablo de Lara <[email protected]>
Cc: Anoob Joseph <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: [PATCH] lib/cryptodev: fix driver name comparison

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

---
 lib/librte_cryptodev/rte_cryptodev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +5 -4
index 7009735..b743c60 100644
@@ -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)

lib/librte_cryptodev/rte_cryptodev.c +1 -1
 	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)

lib/librte_cryptodev/rte_cryptodev.c +0 -1
 			return driver->id;
 	}
 	return -1;
--

2.7.4

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Anoob Joseph
Sent: Wednesday, February 20, 2019 3:42 PM
To: Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 24 lines

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 17 lines

-----Original Message-----
From: Anoob Joseph
Sent: Monday, February 4, 2019 4:56 PM
To: Akhil Goyal <[email protected]>; Declan Doherty <[email protected]>; Pablo de Lara <[email protected]>
Cc: Anoob Joseph <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: [PATCH] lib/cryptodev: fix driver name comparison

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

[Fiona] This patch changes compare for both driver and device names. Update description to mention device names too.

Quoted 28 lines
Quoted 28 lines

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

---
 lib/librte_cryptodev/rte_cryptodev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +2 -1
index 7009735..b743c60 100644
@@ -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;
 	}
Quoted 8 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name) · line 547

Quoted 8 lines
lib/librte_cryptodev/rte_cryptodev.c +2 -2
@@ -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) &&

[Fiona] Is this safe? The const passed to this may not be the full length 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?

Quoted 10 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_devices_get(const char *driver_name, · line 591

Quoted 10 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -1
 				(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);

[Fiona] Is this safe? Same comment as for device name.
Also assumes RTE_CRYPTODEV_NAME_MAX_LEN is same as RTE_DEV_NAME_MAX_LEN. They're both 64 at the moment so not currently an issue.

Quoted 15 lines
Quoted 15 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
 			if (cmp == 0)
 				devices[count++] = devs[i].data->dev_id; @@ -

1691,7 +1692,7 @@ rte_cryptodev_driver_id_get(const char *name)

lib/librte_cryptodev/rte_cryptodev.c +1 -1
 	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)

lib/librte_cryptodev/rte_cryptodev.c +0 -1
 			return driver->id;
 	}
 	return -1;
--

2.7.4

#3 lore raw

Hi Fiona,

Please see inline.

Thanks,
Anoob

Quoted 46 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Thursday, February 21, 2019 10:33 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 12 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Anoob Joseph
Sent: Wednesday, February 20, 2019 3:42 PM
To: Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 21 lines

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 14 lines

-----Original Message-----
From: Anoob Joseph
Sent: Monday, February 4, 2019 4:56 PM
To: Akhil Goyal <[email protected]>; Declan Doherty <[email protected]>; Pablo de Lara <[email protected]>
Cc: Anoob Joseph <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: [PATCH] lib/cryptodev: fix driver name comparison

The string compare to the length of driver name might give false positives when there are drivers with similar names (one being the

Quoted 7 lines

subset of another).

Quoted 4 lines
Quoted 4 lines

Following is such a naming which could result in false positive.
1. crypto_driver
2. crypto_driver1

[Fiona] This patch changes compare for both driver and device names. Update description to mention device names too.

[Anoob] Will update that.

Quoted 34 lines
Quoted 14 lines
Quoted 14 lines

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

---
 lib/librte_cryptodev/rte_cryptodev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 6 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_pmd_get_named_dev(const char

Quoted 6 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
index 7009735..b743c60 100644
@@ -510,7 +510,8 @@ rte_cryptodev_pmd_get_named_dev(const char

*name)

Quoted 13 lines
Quoted 13 lines
lib/librte_cryptodev/rte_cryptodev.c +2 -1
 		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;
 
Quoted 11 lines
Quoted 5 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name)

Quoted 5 lines
lib/librte_cryptodev/rte_cryptodev.c +2 -2
 	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)

&&
[Fiona] Is this safe? The const passed to this may not be the full length 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?

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

Quoted 1 line

From man page, "The strncmp() function is similar, except it only compares the first (at most) n bytes of s1 and s2."

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 these options are really safe. So please advise on what would be the best solution here. I'll revise the patch accordingly.

Quoted 8 lines
Quoted 3 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name) · line 549

Quoted 3 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
 				(cryptodev_globals.devs[i].attached ==
 

RTE_CRYPTODEV_ATTACHED))

Quoted 4 lines
Quoted 4 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
 			return i;
@@ -586,7 +587,7 @@ rte_cryptodev_devices_get(const char
 *driver_name, uint8_t *devices,
 
Quoted 9 lines
Quoted 4 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices, · line 590

Quoted 4 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -1
 			cmp = strncmp(devs[i].device->driver->name,
 					driver_name,
-					strlen(driver_name));
+					RTE_CRYPTODEV_NAME_MAX_LEN);

[Fiona] Is this safe? Same comment as for device name. Also assumes RTE_CRYPTODEV_NAME_MAX_LEN is same as RTE_DEV_NAME_MAX_LEN. They're both 64 at the moment so not currently an issue.

[Anoob] Will fix this with v2.

Quoted 16 lines
Quoted 3 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices, · line 593

Quoted 3 lines
lib/librte_cryptodev/rte_cryptodev.c +0 -0
 			if (cmp == 0)
 				devices[count++] = devs[i].data->dev_id;

@@ -

Quoted 12 lines
Quoted 12 lines

1691,7 +1692,7 @@ rte_cryptodev_driver_id_get(const char *name)

lib/librte_cryptodev/rte_cryptodev.c +1 -1
 	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)

lib/librte_cryptodev/rte_cryptodev.c +0 -1
 			return driver->id;
 	}
 	return -1;
--

2.7.4

#4 lore raw

Hi Anoob,

Quoted 18 lines
Quoted 14 lines
Quoted 8 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name) · line 547

Quoted 8 lines
lib/librte_cryptodev/rte_cryptodev.c +2 -2
@@ -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)

&&
[Fiona] Is this safe? The const passed to this may not be the full length 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?

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

Quoted 7 lines

From man page, "The strncmp() function is similar, except it only compares the first (at most) n bytes of s1 and s2."

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 these options are really safe. So please advise on what would be the best solution here. I'll revise the patch accordingly.

[Fiona] I agree and think it is safest as you've coded it. However I'd suggest adding a comment on the relevant APIs saying that the string must be passed in in a buffer of size <use relevant #define> with trailing zeros.

#5 lore raw

Hi Fiona,

Quoted 42 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name) · line 546

Quoted 7 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -2
@@ -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,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char *name) · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

== 0)

Quoted 9 lines
Quoted 6 lines

&&
[Fiona] Is this safe? The const passed to this may not be the full length 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?

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

Quoted 9 lines

From man page, "The strncmp() function is similar, except it only compares the first (at most) n bytes of
s1 and s2."

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

Quoted 5 lines

these options are really safe. So please advise on what would be the best solution here. I'll revise the patch accordingly.
[Fiona] I agree and think it is safest as you've coded it. However I'd suggest adding a comment on the relevant APIs saying that the string must be passed in in a buffer of size <use relevant #define> with trailing zeros.

[Anoob] Do you want this patch to address that? And wouldn't specifying something like that explicitly, be an ABI breakage?

Also, I think the same is applicable for other similar functions (rte_eth_dev_get_port_by_name() etc), wherever we expect a string. Please do share your thoughts on what all I should include in this patch.

Thanks,
Anoob

#6 lore raw

Hi Anoob

Quoted 54 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona,

Quoted 42 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_get_dev_id(const char *name) · line 546

Quoted 7 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -2
@@ -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,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char *name) · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

== 0)

Quoted 9 lines
Quoted 6 lines

&&
[Fiona] Is this safe? The const passed to this may not be the full length 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?

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

Quoted 9 lines

From man page, "The strncmp() function is similar, except it only compares the first (at most) n bytes of
s1 and s2."

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

Quoted 8 lines
Quoted 5 lines

these options are really safe. So please advise on what would be the best solution here. I'll revise the patch accordingly.
[Fiona] I agree and think it is safest as you've coded it. However I'd suggest adding a comment on the relevant APIs saying that the string must be passed in in a buffer of size <use relevant #define> with trailing zeros.

[Anoob] Do you want this patch to address that? And wouldn't specifying something like that explicitly, be an ABI breakage?

[Fiona] Yes, I think it should be in this patch as this patch is causing it.
But it's up to the maintainers what's acceptable - it seems to me that it's an ABI breakage, avoiding saying it explicitly doesn't make it less so.

Quoted 6 lines

Also, I think the same is applicable for other similar functions (rte_eth_dev_get_port_by_name() etc), wherever we expect a string. Please do share your thoughts on what all I should include in this patch.

Thanks,
Anoob

#7 lore raw

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 94 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 25 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona,

Quoted 11 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 3 lines
Quoted 3 lines

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 4 lines
(quoted diff) +0 -1
 		return -1;
 
 	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name,

name)

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name,

name,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

== 0)

Quoted 3 lines
Quoted 3 lines

&&
[Fiona] Is this safe? The const passed to this may not be the full length of RTE_CRYPTODEV_NAME_MAX_LEN. Does this

prototype

Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
Quoted 3 lines

need to specify that a full length const filled with trailing zeros must be passed in? And if so is this an ABI breakage?

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

Quoted 10 lines

From man page, "The strncmp() function is similar, except it only compares the first (at most) n bytes of
s1 and s2."

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

Quoted 5 lines
Quoted 5 lines

these options are really safe. So please advise on what would be the best solution here. I'll revise the patch accordingly. [Fiona] I agree and think it is safest as you've coded it. However I'd suggest adding a comment on the relevant APIs saying that the string must be passed in in a buffer of size <use relevant #define> with

trailing zeros.

Quoted 3 lines

[Anoob] Do you want this patch to address that? And wouldn't specifying something like that explicitly, be an ABI breakage?

[Fiona] Yes, I think it should be in this patch as this patch is causing it. But it's up to the maintainers what's acceptable - it seems to me that it's an ABI breakage, avoiding saying it explicitly doesn't make it less so.

Quoted 3 lines

Also, I think the same is applicable for other similar functions (rte_eth_dev_get_port_by_name() etc), wherever we expect a string.

Please do share your thoughts on what all I should include in this patch.

Quoted 3 lines

Thanks,
Anoob

#8 lore raw

Hi Anoob,

Quoted 52 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 45 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 25 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona,

Quoted 11 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 3 lines
Quoted 3 lines

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0 -0
  		return -1;
 
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 2 lines
(quoted diff) +0 -1
  	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name,

name)

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name,

name,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN. This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings. What say?

-Akhil

#9 lore raw

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 76 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, February 28, 2019 2:22 PM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 12 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>;

De

Quoted 22 lines
Quoted 22 lines

Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 13 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Hi Fiona,

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan

<[email protected]>;

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 4 lines
(quoted diff) +0 -1
  		return -1;
 
  	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name,

name)

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name,

name,

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN.
This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings.
What say?

[Anoob] In that case, I'll restrict the patch to two places. Wherever strlen(name) is used, I'll make it strlen(name)+1. I won't touch strcmp ones as that would work as is. Shall I prepare a v2?

#10 lore raw
Quoted 83 lines · Anoob Joseph

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 76 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, February 28, 2019 2:22 PM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 12 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>;

De

Quoted 22 lines
Quoted 22 lines

Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 13 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Hi Fiona,

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan

<[email protected]>;

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 4 lines
(quoted diff) +0 -1
   		return -1;
 
   	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name,

name)

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name,

name,

Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN.
This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings.
What say?

[Anoob] In that case, I'll restrict the patch to two places. Wherever strlen(name) is used, I'll make it strlen(name)+1. I won't touch strcmp ones as that would work as is. Shall I prepare a v2?

I think it should be fine.

Fiona,
Any comments?

-Akhil

#11 lore raw

Hi Akhil, Anoob,

Quoted 102 lines

-----Original Message-----
From: Akhil Goyal [mailto:[email protected]]
Sent: Thursday, February 28, 2019 10:20 AM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 89 lines · Anoob Joseph

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 82 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, February 28, 2019 2:22 PM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 12 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>;

De

Quoted 22 lines
Quoted 22 lines

Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 13 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Hi Fiona,

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan

<[email protected]>;

Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0 -0
   		return -1;
 
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 2 lines
(quoted diff) +0 -1
   	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data->name,

name)

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data->name,

name,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char · line 547

Quoted 1 line
(quoted diff) +1 -0
+				RTE_CRYPTODEV_NAME_MAX_LEN)

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN.
This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings.
What say?

Quoted 6 lines
Quoted 1 line

[Anoob] In that case, I'll restrict the patch to two places. Wherever strlen(name) is used, I'll make it

strlen(name)+1. I won't touch strcmp ones as that would work as is. Shall I prepare a v2? I think it should be fine.

Fiona,
Any comments?

[Fiona] Good idea. That should be ok.

Quoted 2 lines

-Akhil

#12 lore raw

Hi Fiona, Akhil,

Quoted 133 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Trahe, Fiona
Sent: Thursday, February 28, 2019 8:00 PM
To: Akhil Goyal <[email protected]>; Anoob Joseph <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Akhil, Anoob,

Quoted 15 lines

-----Original Message-----
From: Akhil Goyal [mailto:[email protected]]
Sent: Thursday, February 28, 2019 10:20 AM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 44 lines
Quoted 43 lines · Anoob Joseph

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 36 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, February 28, 2019 2:22 PM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 13 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 6 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>;

De

Quoted 5 lines
Quoted 5 lines

Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon

<[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona,

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

<[email protected]>;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review rte_cryptodev_get_dev_id(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const char

*name)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0 -0
   		return -1;
 
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 545

Quoted 2 lines
(quoted diff) +0 -1
   	for (i = 0; i < cryptodev_globals.nb_devs; i++)
-		if ((strcmp(cryptodev_globals.devs[i].data-

name,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

name)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_cryptodev_get_dev_id(const char · line 546

Quoted 2 lines
(quoted diff) +1 -1
-				== 0) &&
+		if ((strncmp(cryptodev_globals.devs[i].data-

name,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

name,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +1 -0
+

RTE_CRYPTODEV_NAME_MAX_LEN)

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN.
This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings. What say?

[Anoob] In that case, I'll restrict the patch to two places. Wherever strlen(name) is used, I'll make it

Quoted 7 lines
Quoted 1 line

strlen(name)+1. I won't touch strcmp ones as that would work as is. Shall I

prepare a v2?

Quoted 4 lines

I think it should be fine.

Fiona,
Any comments?

[Fiona] Good idea. That should be ok.

[Anoob] Another thought. If we are fine with doing strlen of input buffer, then using strcmp would also do. That way the usage also would be uniform in the file.

Thanks,
Anoob

#13 lore raw

Hi Akhil, Fiona,

Would the usage of strcmp be alright? Please check my comment inline.

Thanks,
Anoob

Quoted 167 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Anoob Joseph
Sent: Friday, March 1, 2019 11:55 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona, Akhil,

Quoted 13 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Trahe, Fiona
Sent: Thursday, February 28, 2019 8:00 PM
To: Akhil Goyal <[email protected]>; Anoob Joseph <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 34 lines

Hi Akhil, Anoob,

Quoted 32 lines

-----Original Message-----
From: Akhil Goyal [mailto:[email protected]]
Sent: Thursday, February 28, 2019 10:20 AM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Quoted 15 lines · Anoob Joseph

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 8 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, February 28, 2019 2:22 PM
To: Anoob Joseph <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon

<[email protected]>

Quoted 61 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 13 lines · Anoob Joseph

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 6 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, February 25, 2019 5:22 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>;

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

De

Quoted 5 lines
Quoted 5 lines

Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Anoob Joseph [mailto:[email protected]]
Sent: Saturday, February 23, 2019 6:12 AM
To: Trahe, Fiona <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Yigit, Ferruh <[email protected]>; Thomas Monjalon

<[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Dwivedi <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Fiona,

Quoted 5 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Friday, February 22, 2019 9:09 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

<[email protected]>;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

De Lara Guarch, Pablo <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; [email protected];

Ankur

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Dwivedi <[email protected]>; Trahe, Fiona <[email protected]>
Subject: RE: [PATCH] lib/cryptodev: fix driver name comparison

Hi Anoob,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

@@ -542,8 +543,8 @@ rte_cryptodev_get_dev_id(const

char

Quoted 20 lines
Quoted 12 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

*name)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

return -1;

for (i = 0; i < cryptodev_globals.nb_devs; i++)
- if ((strcmp(cryptodev_globals.devs[i].data-

name,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

name)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- == 0) &&
+ if ((strncmp(cryptodev_globals.devs[i].data-

name,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

name,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

RTE_CRYPTODEV_NAME_MAX_LEN)

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

consider using "strlen(name) + 1" instead of RTE_CRYPTODEV_NAME_MAX_LEN.
This will not cause any ABI breakage in my opinion and and will check till we get a null terminated string in both the strings. What say?

[Anoob] In that case, I'll restrict the patch to two places. Wherever strlen(name) is used, I'll make it

Quoted 8 lines
Quoted 2 lines

strlen(name)+1. I won't touch strcmp ones as that would work as is. Shall I

prepare a v2?

Quoted 4 lines

I think it should be fine.

Fiona,
Any comments?

[Fiona] Good idea. That should be ok.

[Anoob] Another thought. If we are fine with doing strlen of input buffer, then using strcmp would also do. That way the usage also would be uniform in the file.

Thanks,
Anoob

#14 lore raw

PATCH v2 1/1 lib/cryptodev: fix driver name comparison

In reply to Anoob Joseph

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

---
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(-)
lib/librte_cryptodev/rte_cryptodev.c +2 -2
index 7009735..871d7dd 100644
@@ -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;
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#15 lore raw
Quoted 25 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Anoob Joseph
Sent: Monday, March 11, 2019 5:56 AM
To: Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Anoob Joseph <[email protected]>; Ankur Dwivedi <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; Suheil Chandran <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v2] lib/cryptodev: fix driver name comparison

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.

Quoted 4 lines
Fixes d11b0f30df88 ("cryptodev: introduce API and framework for crypto devices")
#16 lore raw

Hi Akhil, Declan, Pablo,

Can you review this patch and share your thoughts?

Thanks,
Anoob

Quoted 47 lines

-----Original Message-----
From: Trahe, Fiona <[email protected]>
Sent: Monday, March 11, 2019 4:11 PM
To: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Ankur Dwivedi <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; Suheil Chandran <[email protected]>; [email protected]
Subject: RE: [PATCH v2] lib/cryptodev: fix driver name comparison

Quoted 27 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Anoob Joseph
Sent: Monday, March 11, 2019 5:56 AM
To: Akhil Goyal <[email protected]>; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Cc: Anoob Joseph <[email protected]>; Ankur Dwivedi <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Narayana Prasad Raju Athreya <[email protected]>; Suheil Chandran <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v2] lib/cryptodev: fix driver name comparison

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.

Quoted 5 lines
Fixes d11b0f30df88 ("cryptodev: introduce API and framework for

crypto devices")

Acked-by on v2 1/1
#17 lore raw
In reply to Anoob Joseph
Quoted 40 lines · Anoob Joseph

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

---
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(-)
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 7009735..871d7dd 100644
@@ -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;

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_driver_id_get(const char *name) · line 1697

Quoted 8 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -1
@@ -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;
Applied
#18 lore raw
Quoted 43 lines · Akhil Goyal
Quoted 41 lines · Anoob Joseph

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

---
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(-)
lib/librte_cryptodev/rte_cryptodev.c +1 -1
index 7009735..871d7dd 100644
@@ -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)
 
Quoted 8 lines

lib/librte_cryptodev/rte_cryptodev.c rte_cryptodev_driver_id_get(const char *name) · line 1697

Quoted 7 lines
lib/librte_cryptodev/rte_cryptodev.c +1 -1
   	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;

Applied to dpdk-next-crypto

Thanks.