Skip to contentSkip to conversation

ethdev: check for invalid device name

PATCH Applied Stephen Hemminger 4 participants 6 messages Mar 14, 2019 – Mar 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ethdev: check for invalid device name

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

---
v3 -- fix whitespace issue

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +12 -0
index 85c1794968dd..cf69daaf3224 100644
@@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name)
 {
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev = NULL;
+	size_t name_len;
+
+	name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
+	if (name_len == 0) {
+		RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
+		return NULL;
+	}
+
+	if (name_len >= RTE_ETH_NAME_MAX_LEN) {
+		RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
+		return NULL;
+	}
 
 	rte_eth_dev_shared_data_prepare();
 
Signature · 1 line
2.17.1
Acked-by on v3 1/1
#1 lore raw
Quoted 43 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Friday, March 15, 2019 12:21 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v3] ethdev: check for invalid device name

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

---
v3 -- fix whitespace issue

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +12 -1
index 85c1794968dd..cf69daaf3224 100644
@@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name)  {
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev = NULL;
+	size_t name_len;
+
+	name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
+	if (name_len == 0) {
+		RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
+		return NULL;
+	}
+
+	if (name_len >= RTE_ETH_NAME_MAX_LEN) {
+		RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
+		return NULL;
+	}
 
 	rte_eth_dev_shared_data_prepare();
 
--
Quoted 1 line

2.17.1

Applied
#2 lore raw
Quoted 9 lines · Qi Z
Quoted 9 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Friday, March 15, 2019 12:21 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v3] ethdev: check for invalid device name

Quoted 8 lines
Quoted 5 lines

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

Applied to dpdk-next-net/master, thanks.

Acked-by on v3 1/1
#3 lore raw
In reply to Stephen Hemminger
Quoted 46 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Thursday, March 14, 2019 6:21 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v3] ethdev: check for invalid device name

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

---
v3 -- fix whitespace issue

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +12 -1
index 85c1794968dd..cf69daaf3224 100644
@@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name)  {
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev = NULL;
+	size_t name_len;
+
+	name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
+	if (name_len == 0) {
+		RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device
 name\n");
+		return NULL;
+	}
+
+	if (name_len >= RTE_ETH_NAME_MAX_LEN) {
+		RTE_ETHDEV_LOG(ERR, "Ethernet device name is too
 long\n");
+		return NULL;
+	}
 
 	rte_eth_dev_shared_data_prepare();
 
--
Quoted 1 line

2.17.1

#4 lore raw
In reply to Stephen Hemminger
Quoted 17 lines · Stephen Hemminger

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

---
v3 -- fix whitespace issue

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index 85c1794968dd..cf69daaf3224 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_dev_allocate(const char *name) · line 443

Quoted 6 lines
lib/librte_ethdev/rte_ethdev.c +3 -0
@@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name)
 {
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev = NULL;
+	size_t name_len;
+
+	name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);

'strlen' does not check against NULL pointer and it will crash if NULL provided.

This is internal API, so the input is not completely out of our control but still as an API if we need to check zero length, shouldn't we check for NULL pointer as well?

Quoted 13 lines
lib/librte_ethdev/rte_ethdev.c +9 -0
+	if (name_len == 0) {
+		RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n");
+		return NULL;
+	}
+
+	if (name_len >= RTE_ETH_NAME_MAX_LEN) {
+		RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n");
+		return NULL;
+	}
 
 	rte_eth_dev_shared_data_prepare();
 
#5 lore raw
Quoted 27 lines · On Wed, 20 Mar 2019 14:28:22 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 17 lines · Stephen Hemminger

Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now.

---
v3 -- fix whitespace issue

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index 85c1794968dd..cf69daaf3224 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_dev_allocate(const char *name) · line 443

Quoted 6 lines
lib/librte_ethdev/rte_ethdev.c +3 -0
@@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name)
 {
 	uint16_t port_id;
 	struct rte_eth_dev *eth_dev = NULL;
+	size_t name_len;
+
+	name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);  

'strlen' does not check against NULL pointer and it will crash if NULL provided.

Quoted 3 lines

This is internal API, so the input is not completely out of our control but still as an API if we need to check zero length, shouldn't we check for NULL pointer as well?

Maybe, but none of the other DPDK API's check for NULL in name fields. Probably best to just crash.