Skip to contentSkip to conversation

lib: fix socket id type

PATCH In review Min Hu (Connor) 2 participants 2 messages Apr 27, 2021 – Jun 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: fix socket id type

From: Chengchang Tang <[email protected]>

The variable type of the current socket ID is uint8_t. When traversing all nodes, the socket ID is compared with RTE_MAX_NUMA_NODES. Since RTE_MAX_NUMA_NODES has not been verified, it may be larger than UCHAR_MAX theoretically. This would lead to an infinite loop.

This patch declares the socket ID type as 'int' or 'unsigned int' by referring to the common practice in EAL.

Fixes 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
Fixes f00708c2aa53 ("node: add IPv4 rewrite and lookup control")
---
 lib/efd/rte_efd.c     | 4 ++--
 lib/node/ip4_lookup.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/efd/rte_efd.c +2 -2
index 77f4680..4d354d8 100644
@@ -500,7 +500,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
 	struct rte_efd_table *table = NULL;
 	uint8_t *key_array = NULL;
 	uint32_t num_chunks, num_chunks_shift;
-	uint8_t socket_id;
+	unsigned int socket_id;
 	struct rte_efd_list *efd_list = NULL;
 	struct rte_tailq_entry *te;
 	uint64_t offline_table_size;
@@ -746,7 +746,7 @@ rte_efd_find_existing(const char *name)
 void
 rte_efd_free(struct rte_efd_table *table)
 {
-	uint8_t socket_id;
+	unsigned int socket_id;
 	struct rte_efd_list *efd_list;
 	struct rte_tailq_entry *te, *temp;
 
lib/node/ip4_lookup.c +1 -1
index d083a72..4811378 100644
@@ -129,7 +129,7 @@ rte_node_ip4_route_add(uint32_t ip, uint8_t depth, uint16_t next_hop,
 {
 	char abuf[INET6_ADDRSTRLEN];
 	struct in_addr in;
-	uint8_t socket;
+	int socket;
 	uint32_t val;
 	int ret;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · On Tue, 27 Apr 2021 17:36:32 +0800 "Min Hu (Connor)" <[email protected]> wrote:

From: Chengchang Tang <[email protected]>

The variable type of the current socket ID is uint8_t. When traversing all nodes, the socket ID is compared with RTE_MAX_NUMA_NODES. Since RTE_MAX_NUMA_NODES has not been verified, it may be larger than UCHAR_MAX theoretically. This would lead to an infinite loop.

This patch declares the socket ID type as 'int' or 'unsigned int' by referring to the common practice in EAL.

Quoted 6 lines
Fixes 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
Fixes f00708c2aa53 ("node: add IPv4 rewrite and lookup control")

An alternative way of handling this would be to add a compile time check that user did not exceed 255 for numa nodes.

I.e:

lib/efd/rte_efd.c +2 -0
index dad962ce29bf..8a05909aa4ae 100644
@@ -505,6 +505,8 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
 	struct rte_ring *r = NULL;
 	unsigned int i;
 
+	RTE_BUILD_BUG_ON(RTE_MAX_NUMA_NODES >= UINT8_MAX);
+
 	efd_list = RTE_TAILQ_CAST(rte_efd_tailq.head, rte_efd_list);
 
 	if (online_cpu_socket_bitmask == 0) {
lib/node/ip4_lookup.c +2 -0
index 8bce03d7db9d..0adcd0436b7b 100644
@@ -128,6 +128,8 @@ rte_node_ip4_route_add(uint32_t ip, uint8_t depth, uint16_t next_hop,
 	uint32_t val;
 	int ret;
 
+	RTE_BUILD_BUG_ON(RTE_MAX_NUMA_NODES >= UINT8_MAX);
+
 	in.s_addr = htonl(ip);
 	inet_ntop(AF_INET, &in, abuf, sizeof(abuf));
 	/* Embedded next node id into 24 bit next hop */