ethdev: check for invalid device name
PATCH 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.
---
v1 - previously sent as RFC
lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/librte_ethdev/rte_ethdev.c +10 -0
@@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)uint16_t port_id;struct rte_eth_dev *eth_dev =NULL ; +if (*name) { +RTE_ETHDEV_LOG (ERR ,"Zero length Ethernet device name\n" ); +return NULL ; + } + +if (strnlen (name,RTE_ETH_NAME_MAX_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 ();/* Synchronize port creation between primary and secondary threads. */
Signature · 1 line
2.17.1
HI
Quoted 23 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, March 12, 2019 2:16 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device nameDo 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.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
v1 - previously sent as RFClib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)lib/librte_ethdev/rte_ethdev.c +0
-0
lib/librte_ethdev/rte_ethdev.c rte_eth_dev_allocate(const char *name) · line 442
Quoted 4 lines
lib/librte_ethdev/rte_ethdev.c +1
-0@@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)uint16_t port_id;struct rte_eth_dev *eth_dev =NULL ; +if (*name) {
Is above check same as "strlen(name) == 0"?
Quoted 15 lines
lib/librte_ethdev/rte_ethdev.c +9
-0+RTE_ETHDEV_LOG (ERR ,"Zero length Ethernet device name\n" ); +return NULL ; + } + +if (strnlen (name,RTE_ETH_NAME_MAX_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 ();/* Synchronize port creation between primary and secondary threads. */
--
2.17.1
Quoted 28 lines · Qi Z
HI
Quoted 26 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, March 12, 2019 2:16 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device nameDo 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.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
v1 - previously sent as RFClib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)lib/librte_ethdev/rte_ethdev.c +0
-0@@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)uint16_t port_id;struct rte_eth_dev *eth_dev =NULL ;
Quoted 3 lines
lib/librte_ethdev/rte_ethdev.c rte_eth_dev_allocate(const char *name) · line 442
Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1
-0+if (*name) {Is above check same as "strlen(name) == 0"?
Yes, but checking for first null byte is slightly quicker. Alternative would be to call strnlen() once.
Quoted 43 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, March 14, 2019 1:33 AM
To: Zhang, Qi Z <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] ethdev: check for invalid device nameQuoted 12 lines · Qi Z
HI
Quoted 10 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, March 12, 2019 2:16 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device nameDo 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.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
v1 - previously sent as RFClib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)(quoted diff) +0
-0
b/lib/librte_ethdev/rte_ethdev.cindex85c1794968dd..0b81980ff71c100644lib/librte_ethdev/rte_ethdev.c +0
-0@@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)uint16_t port_id;struct rte_eth_dev *eth_dev =NULL ;
Quoted 6 lines
Quoted 3 lines
lib/librte_ethdev/rte_ethdev.c rte_eth_dev_allocate(const char *name) · line 442
Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1
-0+if (*name) {Is above check same as "strlen(name) == 0"?
Yes, but checking for first null byte is slightly quicker. Alternative would be to call
strnlen()once.
But you are checking the not null byte here right? should it be if (!(*name))?
Hi Stephen,
I see failures in performance tests caused by this patch:
http://mails.dpdk.org/archives/test-report/2019-March/076705.html
http://mails.dpdk.org/archives/test-report/2019-March/076704.html
After applying your patch, the devices will not be probed:
'''
Zero length Ethernet device namenet_mlx5: can not allocate rte ethdevnet_mlx5: probe of PCI device 0000:12:00.1 aborted after encountering an error: Cannot allocate memory
EAL: Requested device 0000:12:00.1 cannot be used
testpmd: No probed ethernet devices
'''
Testpmd command:
./x86_64-native-linuxapp-gcc/build/app/test-pmd/testpmd -c 0x3 -n 4 -w 12:00.0 -w 12:00.1 -- --txd=256 --rxd=256 -i
Quoted 43 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Monday, March 11, 2019 8:16 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device nameDo 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.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
v1 - previously sent as RFClib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)lib/librte_ethdev/rte_ethdev.c +10
-0@@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name)uint16_t port_id;struct rte_eth_dev *eth_dev =NULL ; +if (*name) { +RTE_ETHDEV_LOG (ERR ,"Zero length Ethernet device name\n"); +return NULL ; + } + +if (strnlen (name,RTE_ETH_NAME_MAX_LEN ) >=RTE_ETH_NAME_MAX_LEN ) { +RTE_ETHDEV_LOG (ERR ,"Ethernet device name is too long\n"); +return NULL ; + } +lib/librte_ethdev/rte_ethdev.c +0
-0rte_eth_dev_shared_data_prepare ();/* Synchronize port creation between primary and secondary
Quoted 3 lines
threads. */
--
2.17.1
Regards,
Ali