Skip to content

Commit

Permalink
net/bonding: fix socket ID check
Browse files Browse the repository at this point in the history
[ upstream commit f294e04 ]

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: 2efb58c ("bond: new link bonding library")

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
  • Loading branch information
Chengchang Tang authored and steevenlee committed Jun 8, 2021
1 parent 8d04d02 commit adefa69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions drivers/net/bonding/rte_eth_bond_args.c
Expand Up @@ -200,20 +200,20 @@ int
bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
const char *value, void *extra_args)
{
int socket_id;
long socket_id;
char *endptr;

if (value == NULL || extra_args == NULL)
return -1;

errno = 0;
socket_id = (uint8_t)strtol(value, &endptr, 10);
socket_id = 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 = (int)socket_id;
return 0;
}
return -1;
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/bonding/rte_eth_bond_pmd.c
Expand Up @@ -3325,8 +3325,9 @@ 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;
int arg_count, port_id;
int socket_id;
uint8_t agg_mode;
struct rte_eth_dev *eth_dev;

Expand Down

0 comments on commit adefa69

Please sign in to comment.