net/bonding: fix socket id check
Subsystems (2)
PATCH v3 1/1 net/bonding: fix socket id check
From: Chengchang Tang <[email protected]>
The socket ID entered by user is cast to an unsigned integer. However, the value may be an illegal negative value, which may cause some problems. In this case, an error should be returned.
In addition, the socket ID may be an invalid positive number, which is also processed in this patch.
---
v3:
* changed type of socket id.
v2:
* fixed socket id type.
--- drivers/net/bonding/rte_eth_bond_args.c | 6 +++--- drivers/net/bonding/rte_eth_bond_pmd.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/bonding/rte_eth_bond_args.c +3 -3
@@ -207,13 +207,13 @@ bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,return -1 ; errno =0 ; - socket_id = (uint8_t )strtol (value, &endptr,10 ); + socket_id = (int )strtol (value, &endptr,10 );if (*endptr !=0 || errno !=0 )return -1 ;/* validate socket id value */ -if (socket_id >=0 ) { - *(uint8_t *)extra_args = (uint8_t )socket_id; +if (socket_id >=0 && socket_id <RTE_MAX_NUMA_NODES ) { + *(int *)extra_args = socket_id;return 0 ; }return -1 ;
drivers/net/bonding/rte_eth_bond_pmd.c +2 -2
@@ -3333,8 +3333,8 @@ bond_probe(struct rte_vdev_device *dev)const char *name;struct bond_dev_private *internals;struct rte_kvargs *kvlist; -uint8_t bonding_mode, socket_id/*, agg_mode*/ ; -int arg_count, port_id; +uint8_t bonding_mode/*, agg_mode*/ ; +int arg_count, port_id, socket_id;uint8_t agg_mode;struct rte_eth_dev *eth_dev;
Signature · 1 line
2.7.4
Quoted 33 lines · Min Hu (Connor)
From: Chengchang Tang <[email protected]>
The socket ID entered by user is cast to an unsigned integer. However, the value may be an illegal negative value, which may cause some problems. In this case, an error should be returned.
In addition, the socket ID may be an invalid positive number, which is also processed in this patch.
Fixes 2efb58cbab6e ("bond: new link bonding library")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v3:
* changed type of socket id.v2:
* fixed socket id type.--- drivers/net/bonding/rte_eth_bond_args.c | 6 +++--- drivers/net/bonding/rte_eth_bond_pmd.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/net/bonding/rte_eth_bond_args.c +0
-0@@ -207,13 +207,13 @@ bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,return -1 ; errno =0 ;
drivers/net/bonding/rte_eth_bond_args.c bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused, · line 216
Quoted 10 lines
drivers/net/bonding/rte_eth_bond_args.c +3
-3- socket_id = (uint8_t )strtol (value, &endptr,10 ); + socket_id = (int )strtol (value, &endptr,10 );if (*endptr !=0 || errno !=0 )return -1 ;/* validate socket id value */ -if (socket_id >=0 ) { - *(uint8_t *)extra_args = (uint8_t )socket_id; +if (socket_id >=0 && socket_id <RTE_MAX_NUMA_NODES ) { + *(int *)extra_args = socket_id;
What do you think to keep this local 'socket_id' variable as "long int" as reasons commented on previous versions.
Quoted 8 lines
drivers/net/bonding/rte_eth_bond_args.c +0
-0return 0 ; }return -1 ;drivers/net/bonding/rte_eth_bond_pmd.c +0
-0
drivers/net/bonding/rte_eth_bond_pmd.c bond_probe(struct rte_vdev_device *dev) · line 3336
Quoted 6 lines
drivers/net/bonding/rte_eth_bond_pmd.c +1
-2@@ -3333,8 +3333,8 @@ bond_probe(struct rte_vdev_device *dev)const char *name;struct bond_dev_private *internals;struct rte_kvargs *kvlist; -uint8_t bonding_mode, socket_id/*, agg_mode*/ ; -int arg_count, port_id; +uint8_t bonding_mode/*, agg_mode*/ ;
Can you please cleanup the 'agg_mode' while you are touching this.
drivers/net/bonding/rte_eth_bond_pmd.c bond_probe(struct rte_vdev_device *dev) · line 3337
Quoted 1 line
drivers/net/bonding/rte_eth_bond_pmd.c +1
-0+int arg_count, port_id, socket_id;
Can you add it into new line, instead of appending?
Quoted 4 lines
drivers/net/bonding/rte_eth_bond_pmd.c +0
-0uint8_t agg_mode;struct rte_eth_dev *eth_dev;