DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 00/21] replace strtok with strtok_r
@ 2023-11-13 10:45 Jie Hai
  2023-11-13 10:45 ` [PATCH 01/21] app/graph: " Jie Hai
                   ` (26 more replies)
  0 siblings, 27 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Jie Hai (21):
  app/graph: replace strtok with strtok_r
  app/test-bbdev: replace strtok with strtok_r
  app/test-compress-perf: replace strtok with strtok_r
  app/test-crypto-perf: replace strtok with strtok_r
  app/test-dma-perf: replace strtok with strtok_r
  app/test-fib: replace strtok with strtok_r
  app/dpdk-test-flow-perf: replace strtok with strtok_r
  app/test-mldev: replace strtok with strtok_r
  lib/dmadev: replace strtok with strtok_r
  lib/eal: replace strtok with strtok_r
  lib/ethdev: replace strtok with strtok_r
  lib/eventdev: replace strtok with strtok_r
  lib/telemetry: replace strtok with strtok_r
  lib/telemetry: replace strtok with strtok_r
  bus/fslmc: replace strtok with strtok_r
  common/cnxk: replace strtok with strtok_r
  event/cnxk: replace strtok with strtok_r
  net/ark: replace strtok with strtok_r
  raw/cnxk_gpio: replace strtok with strtok_r
  examples/l2fwd-crypto: replace strtok with strtok_r
  examples/vhost: replace strtok with strtok_r

 app/graph/graph.c                             |  5 ++-
 app/graph/utils.c                             | 15 +++++---
 app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
 .../comp_perf_options_parse.c                 | 16 ++++----
 app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
 .../cperf_test_vector_parsing.c               | 10 +++--
 app/test-dma-perf/main.c                      | 13 ++++---
 app/test-fib/main.c                           | 10 ++---
 app/test-flow-perf/main.c                     | 22 ++++++-----
 app/test-mldev/ml_options.c                   | 18 ++++-----
 drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
 drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
 drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
 drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
 drivers/net/ark/ark_pktchkr.c                 | 10 ++---
 drivers/net/ark/ark_pktgen.c                  | 10 ++---
 drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
 examples/l2fwd-crypto/main.c                  |  6 +--
 examples/vhost/main.c                         |  3 +-
 lib/dmadev/rte_dmadev.c                       |  4 +-
 lib/eal/common/eal_common_memory.c            |  8 ++--
 lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
 lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
 lib/eventdev/rte_eventdev.c                   | 18 ++++-----
 lib/security/rte_security.c                   |  3 +-
 lib/telemetry/telemetry.c                     |  5 ++-
 27 files changed, 169 insertions(+), 140 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 01/21] app/graph: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 02/21] app/test-bbdev: " Jie Hai
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Sunil Kumar Kori, Rakesh Kudurumalla
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/graph/graph.c |  5 +++--
 app/graph/utils.c | 15 +++++++++------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/app/graph/graph.c b/app/graph/graph.c
index a65723a196da..316950948160 100644
--- a/app/graph/graph.c
+++ b/app/graph/graph.c
@@ -103,9 +103,10 @@ parser_usecases_read(char *usecases)
 {
 	bool valid = false;
 	uint32_t i, j = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(usecases, ",");
+	token = strtok_r(usecases, ",", &sp);
 	while (token != NULL) {
 		for (i = 0; i < RTE_DIM(supported_usecases); i++) {
 			if (strcmp(supported_usecases[i], token) == 0) {
@@ -116,7 +117,7 @@ parser_usecases_read(char *usecases)
 				break;
 			}
 		}
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	return valid;
diff --git a/app/graph/utils.c b/app/graph/utils.c
index c7b6ae83cf1f..ae2ff225c394 100644
--- a/app/graph/utils.c
+++ b/app/graph/utils.c
@@ -101,13 +101,14 @@ int
 parser_ip4_read(uint32_t *value, char *p)
 {
 	uint8_t shift = 24;
+	char *sp = NULL;
 	uint32_t ip = 0;
 	char *token;
 
-	token = strtok(p, ".");
+	token = strtok_r(p, ".", &sp);
 	while (token != NULL) {
 		ip |= (((uint32_t)strtoul(token, NULL, 10)) << shift);
-		token = strtok(NULL, ".");
+		token = strtok_r(NULL, ".", &sp);
 		shift -= 8;
 	}
 
@@ -120,13 +121,14 @@ int
 parser_ip6_read(uint8_t *value, char *p)
 {
 	uint64_t val = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_r(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		*value = val;
-		token = strtok(NULL, ":");
+		token = strtok_r(NULL, ":", &sp);
 		value++;
 		val = 0;
 	}
@@ -139,13 +141,14 @@ parser_mac_read(uint64_t *value, char *p)
 {
 	uint64_t mac = 0, val = 0;
 	uint8_t shift = 40;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_r(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		mac |= val << shift;
-		token = strtok(NULL, ":");
+		token = strtok_r(NULL, ":", &sp);
 		shift -= 8;
 		val = 0;
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 02/21] app/test-bbdev: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
  2023-11-13 10:45 ` [PATCH 01/21] app/graph: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 03/21] app/test-compress-perf: " Jie Hai
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Nicolas Chautru; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-bbdev/test_bbdev_vector.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index c26727cd35c4..5c966e79645e 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 	uint32_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 		*data_length = *data_length + (strlen(tok) - strlen("0x"))/2;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 {
 	char *tok = NULL;
 	uint32_t op_flag_value = 0;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 
 		*op_flags = *op_flags | op_flag_value;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -368,9 +370,10 @@ static int
 parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 {
 	char *tok = NULL;
+	char *sp = NULL;
 	bool status_ok = false;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 			return -1;
 		}
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token,
 	int ret = 0, status = 0, i, shift;
 	uint32_t op_flags = 0;
 	char *tok, *err = NULL;
+	char *sp = NULL;
 
 	struct rte_bbdev_op_fft *fft = &vector->fft;
 
@@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token,
 		fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0);
 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
 	} else if (!strcmp(key_token, "window_index")) {
-		tok = strtok(token, VALUE_DELIMITER);
+		tok = strtok_r(token, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			return -1;
 		for (i = 0; i < FFT_WIN_SIZE; i++) {
@@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token,
 			fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0)
 					<< shift;
 			if (i < (FFT_WIN_SIZE - 1)) {
-				tok = strtok(NULL, VALUE_DELIMITER);
+				tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 				if (tok == NULL)
 					return -1;
 			}
@@ -995,6 +999,7 @@ static int
 parse_entry(char *entry, struct test_bbdev_vector *vector)
 {
 	int ret = 0;
+	char *sp = NULL;
 	char *token, *key_token;
 	enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE;
 
@@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector)
 	}
 
 	/* get key */
-	token = strtok(entry, ENTRY_DELIMITER);
+	token = strtok_r(entry, ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, ENTRY_DELIMITER);
+	token = strtok_r(NULL, ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 03/21] app/test-compress-perf: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
  2023-11-13 10:45 ` [PATCH 01/21] app/graph: " Jie Hai
  2023-11-13 10:45 ` [PATCH 02/21] app/test-bbdev: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 04/21] app/test-crypto-perf: " Jie Hai
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-compress-perf/comp_perf_options_parse.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 6d8c370fc2ea..d997fa667a94 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -177,6 +177,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 {
 	char *token;
 	uint8_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -184,7 +185,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_r(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -197,7 +198,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -225,7 +226,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_r(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -244,6 +245,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -251,7 +253,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_r(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -266,7 +268,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -288,7 +290,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	if (min)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 04/21] app/test-crypto-perf: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (2 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 03/21] app/test-compress-perf: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 05/21] app/test-dma-perf: " Jie Hai
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Ciara Power; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-crypto-perf/cperf_options_parsing.c     | 16 +++++++++-------
 app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++----
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 75afedc7fd6e..77cda0eb8e6f 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 {
 	char *token;
 	uint32_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_r(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_r(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_r(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	if (min)
diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index 737d61d4af6b..4d2e6053e745 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 
 	uint8_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, CPERF_VALUE_DELIMITER);
+	tok = strtok_r(tokens, CPERF_VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 			return -1;
 		}
 
-		tok = strtok(NULL, CPERF_VALUE_DELIMITER);
+		tok = strtok_r(NULL, CPERF_VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 
 	uint8_t *data = NULL;
 	char *token, *key_token;
+	char *sp = NULL;
 
 	if (entry == NULL) {
 		printf("Expected entry value\n");
@@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 	}
 
 	/* get key */
-	token = strtok(entry, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(entry, CPERF_ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(NULL, CPERF_ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 05/21] app/test-dma-perf: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (3 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 04/21] app/test-crypto-perf: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 06/21] app/test-fib: " Jie Hai
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Cheng Jiang; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-dma-perf/main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index e5bccc27da5e..38780939578e 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -164,6 +164,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 	uint16_t len;
 	char *input;
 	struct lcore_dma_map_t *lcore_dma_map;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -175,7 +176,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 
 	memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t));
 
-	char *token = strtok(input, ", ");
+	char *token = strtok_r(input, ", ", &sp);
 	while (token != NULL) {
 		if (lcore_dma_map->cnt >= MAX_LCORE_NB) {
 			free(input);
@@ -185,7 +186,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 		uint16_t lcore_id = atoi(token);
 		lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id;
 
-		token = strtok(NULL, ", ");
+		token = strtok_r(NULL, ", ", &sp);
 	}
 
 	free(input);
@@ -201,6 +202,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	char *start, *end, *substr;
 	uint16_t lcore_id;
 	int ret = 0;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -216,7 +218,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &sp);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
@@ -258,7 +260,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1],
 				RTE_DEV_NAME_MAX_LEN);
 		lcore_dma_map->cnt++;
-		substr = strtok(NULL, ",");
+		substr = strtok_r(NULL, ",", &sp);
 	} while (substr != NULL);
 
 out:
@@ -486,6 +488,7 @@ main(int argc, char *argv[])
 	char *rst_path_ptr = NULL;
 	char rst_path[PATH_MAX];
 	int new_argc;
+	char *sp = NULL;
 
 	memset(args, 0, sizeof(args));
 
@@ -504,7 +507,7 @@ main(int argc, char *argv[])
 	}
 	if (rst_path_ptr == NULL) {
 		strlcpy(rst_path, cfg_path_ptr, PATH_MAX);
-		char *token = strtok(basename(rst_path), ".");
+		char *token = strtok_r(basename(rst_path), ".", &sp);
 		if (token == NULL) {
 			printf("Config file error.\n");
 			return -1;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 06/21] app/test-fib: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (4 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 05/21] app/test-dma-perf: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 07/21] app/dpdk-test-flow-perf: " Jie Hai
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Vladimir Medvedkin; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-fib/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index 75a56135f212..8e5d17b13028 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 	uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */
 	uint32_t n_routes;
 	uint8_t depth, ratio, ratio_acc = 0;
-	char *in;
+	char *in, *sp = NULL;
 
-	in = strtok(distrib_string, ",");
+	in = strtok_r(distrib_string, ",", &sp);
 
 	/*parse configures routes percentage ratios*/
 	while (in != NULL) {
@@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 		}
 
 		/*number of configured depths in*/
-		in = strtok(NULL, ",");
+		in = strtok_r(NULL, ",", &sp);
 	}
 
 	if (ratio_acc > 100) {
@@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af)
 	int ret, i = 0;
 	uint8_t *tbl = (uint8_t *)config.lookup_tbl;
 	int step = (af == AF_INET) ? 4 : 16;
-	char *s;
+	char *s, *sp = NULL;
 
 	while (fgets(line, sizeof(line), f) != NULL) {
-		s = strtok(line, " \t\n");
+		s = strtok_r(line, " \t\n", &sp);
 		if (s == NULL)
 			return -EINVAL;
 		ret = inet_pton(af, s, &tbl[i]);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 07/21] app/dpdk-test-flow-perf: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (5 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 06/21] app/test-fib: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 08/21] app/test-mldev: " Jie Hai
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Wisam Jaddo; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-flow-perf/main.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index e224ef67983d..36e7c1d72019 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg)
 {
 	char *token;
 	size_t i, j, k;
+	char *sp = NULL;
 
 	j = 0;
 	k = 0;
@@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg)
 		token = strsep(&arg, ":\0");
 	}
 	j = 0;
-	token = strtok(actions_str[0], ",\0");
+	token = strtok_r(actions_str[0], ",\0", &sp);
 	while (token == NULL && j < RTE_COLORS - 1)
-		token = strtok(actions_str[++j], ",\0");
+		token = strtok_r(actions_str[++j], ",\0", &sp);
 	while (j < RTE_COLORS && token != NULL) {
 		for (i = 0; i < RTE_DIM(flow_options); i++) {
 			if (!strcmp(token, flow_options[i].str)) {
@@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg)
 			usage(prog);
 			rte_exit(EXIT_SUCCESS, "Invalid colored actions\n");
 		}
-		token = strtok(NULL, ",\0");
+		token = strtok_r(NULL, ",\0", &sp);
 		while (!token && j < RTE_COLORS - 1) {
-			token = strtok(actions_str[++j], ",\0");
+			token = strtok_r(actions_str[++j], ",\0", &sp);
 			k = 0;
 		}
 	}
@@ -641,6 +642,7 @@ args_parse(int argc, char **argv)
 {
 	uint64_t pm, seed;
 	uint64_t hp_conf;
+	char *sp = NULL;
 	char **argvopt;
 	uint32_t prio;
 	char *token;
@@ -804,7 +806,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_ENCAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -817,7 +819,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid encap item: %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -828,7 +830,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_DECAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -841,7 +843,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid decap item %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -910,10 +912,10 @@ args_parse(int argc, char **argv)
 				uint16_t port_idx = 0;
 				char *token;
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					dst_ports[port_idx++] = atoi(token);
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name, "rxq") == 0) {
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 08/21] app/test-mldev: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (6 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 07/21] app/dpdk-test-flow-perf: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 09/21] lib/dmadev: " Jie Hai
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Srikanth Yalavarthi; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 app/test-mldev/ml_options.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c
index 72357c1c393d..3f3dc8f69890 100644
--- a/app/test-mldev/ml_options.c
+++ b/app/test-mldev/ml_options.c
@@ -75,12 +75,12 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char models[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 	int ret = 0;
 
 	strlcpy(models, arg, PATH_MAX);
 
-	token = strtok(models, delim);
+	token = strtok_r(models, delim, &sp);
 	while (token != NULL) {
 		strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 		opt->nb_filelist++;
@@ -90,7 +90,7 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 			ret = -EINVAL;
 			break;
 		}
-		token = strtok(NULL, delim);
+		token = strtok_r(NULL, delim, &sp);
 	}
 
 	if (opt->nb_filelist == 0) {
@@ -106,7 +106,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char filelist[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 
 	if (opt->nb_filelist >= ML_TEST_MAX_MODELS) {
 		ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS);
@@ -116,7 +116,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(filelist, arg, PATH_MAX);
 
 	/* model */
-	token = strtok(filelist, delim);
+	token = strtok_r(filelist, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, model not specified = %s\n", arg);
 		return -EINVAL;
@@ -124,7 +124,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 
 	/* input */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, input not specified = %s\n", arg);
 		return -EINVAL;
@@ -132,7 +132,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX);
 
 	/* output */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, output not specified = %s\n", arg);
 		return -EINVAL;
@@ -140,14 +140,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX);
 
 	/* reference - optional */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token != NULL)
 		strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX);
 	else
 		memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX);
 
 	/* check for extra tokens */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token != NULL) {
 		ml_err("Invalid filelist. Entries > 4\n.");
 		return -EINVAL;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 09/21] lib/dmadev: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (7 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 08/21] app/test-mldev: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 10/21] lib/eal: " Jie Hai
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Chengwen Feng, Kevin Laatz, Bruce Richardson; +Cc: haijie1, lihuisong

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/dmadev/rte_dmadev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 4e5e420c82a5..f856cc7d0905 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -971,7 +971,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	struct rte_dma_info dma_info;
 	struct rte_dma_stats dma_stats;
 	int dev_id, ret, vchan_id;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *vchan_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -990,7 +990,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	if (dma_info.nb_vchans == 1 && *end_param == '\0')
 		vchan_id = 0;
 	else {
-		vchan_param = strtok(end_param, ",");
+		vchan_param = strtok_r(end_param, ",", &sp);
 		if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param))
 			return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 10/21] lib/eal: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (8 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 09/21] lib/dmadev: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 16:27   ` Stephen Hemminger
  2023-11-13 10:45 ` [PATCH 11/21] lib/ethdev: " Jie Hai
                   ` (16 subsequent siblings)
  26 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Anatoly Burakov; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/eal/common/eal_common_memory.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index d9433db62345..a05eb0442b0b 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals)
 	char dlim[2] = ",";
 	char *params_args;
 	size_t count = 0;
-	char *token;
+	char *token, *sp = NULL;
 
 	if (vals == NULL || params == NULL || strlen(params) == 0)
 		return -1;
 
-	/* strtok expects char * and param is const char *. Hence on using
+	/* strtok_r expects char * and param is const char *. Hence on using
 	 * params as "const char *" compiler throws warning.
 	 */
 	params_args = strdup(params);
 	if (params_args == NULL)
 		return -1;
 
-	token = strtok(params_args, dlim);
+	token = strtok_r(params_args, dlim, &sp);
 	while (token && isdigit(*token) && count < n_vals) {
 		vals[count++] = strtoul(token, NULL, 10);
-		token = strtok(NULL, dlim);
+		token = strtok_r(NULL, dlim, &sp);
 	}
 
 	free(params_args);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 11/21] lib/ethdev: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (9 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 10/21] lib/eal: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 12/21] lib/eventdev: " Jie Hai
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/ethdev/rte_ethdev_telemetry.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
index b01028ce9b60..6810c54109a5 100644
--- a/lib/ethdev/rte_ethdev_telemetry.c
+++ b/lib/ethdev/rte_ethdev_telemetry.c
@@ -477,6 +477,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	const char *qid_param;
 	uint16_t nb_queues;
 	char *end_param;
+	char *sp = NULL;
 	uint64_t qid;
 	int ret;
 
@@ -489,7 +490,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	if (nb_queues == 1 && *end_param == '\0')
 		qid = 0;
 	else {
-		qid_param = strtok(end_param, ",");
+		qid_param = strtok_r(end_param, ",", &sp);
 		if (!qid_param || strlen(qid_param) == 0 || !isdigit(*qid_param))
 			return -EINVAL;
 
@@ -1221,9 +1222,10 @@ static int
 eth_dev_parse_tm_params(char *params, uint32_t *result)
 {
 	const char *splited_param;
+	char *sp = NULL;
 	uint64_t ret;
 
-	splited_param = strtok(params, ",");
+	splited_param = strtok_r(params, ",", &sp);
 	if (!splited_param || strlen(splited_param) == 0 || !isdigit(*splited_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 12/21] lib/eventdev: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (10 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 11/21] lib/ethdev: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 13/21] lib/telemetry: " Jie Hai
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Naga Harish K S V, Jerin Jacob; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/eventdev/rte_event_eth_rx_adapter.c | 38 ++++++++++++-------------
 lib/eventdev/rte_eventdev.c             | 18 ++++++------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index 6db03adf0463..4107d600dfb7 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -3651,7 +3651,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp;
 	struct rte_event_eth_rx_adapter_queue_conf queue_conf;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3661,19 +3661,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3684,7 +3684,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3723,7 +3723,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 	struct rte_event_eth_rx_adapter_queue_stats q_stats;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3733,19 +3733,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3756,7 +3756,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3794,7 +3794,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3803,19 +3803,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3826,7 +3826,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3855,7 +3855,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	uint8_t instance_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3863,14 +3863,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3881,7 +3881,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c
index 0ca32d672175..fabba0228672 100644
--- a/lib/eventdev/rte_eventdev.c
+++ b/lib/eventdev/rte_eventdev.c
@@ -1784,7 +1784,7 @@ handle_queue_links(const char *cmd __rte_unused,
 		   struct rte_tel_data *d)
 {
 	int i, ret, port_id = 0;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	uint8_t dev_id;
 	uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
 	uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
@@ -1797,12 +1797,12 @@ handle_queue_links(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
 		return -1;
 
 	port_id = strtoul(p_param, &end_param, 10);
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1922,7 +1922,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1932,7 +1932,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_PORT;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1940,7 +1940,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1956,7 +1956,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1966,7 +1966,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_QUEUE;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1974,7 +1974,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 13/21] lib/telemetry: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (11 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 12/21] lib/eventdev: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 14/21] " Jie Hai
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Akhil Goyal; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/security/rte_security.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c
index b082a290296b..e20d610172ef 100644
--- a/lib/security/rte_security.c
+++ b/lib/security/rte_security.c
@@ -496,13 +496,14 @@ security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char *
 	int dev_id, capa_id;
 	int crypto_caps_n;
 	char *end_param;
+	char *sp = NULL;
 	int rc;
 
 	if (!params || strlen(params) == 0 || !isdigit(*params))
 		return -EINVAL;
 
 	dev_id = strtoul(params, &end_param, 0);
-	capa_param = strtok(end_param, ",");
+	capa_param = strtok_r(end_param, ",", &sp);
 	if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 14/21] lib/telemetry: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (12 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 13/21] lib/telemetry: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 15/21] bus/fslmc: " Jie Hai
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Ciara Power; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/telemetry/telemetry.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 92982842a860..bb028d9381f7 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -371,6 +371,7 @@ static void *
 client_handler(void *sock_id)
 {
 	int s = (int)(uintptr_t)sock_id;
+	char *sp = NULL;
 	char buffer[1024];
 	char info_str[1024];
 	snprintf(info_str, sizeof(info_str),
@@ -385,8 +386,8 @@ client_handler(void *sock_id)
 	int bytes = read(s, buffer, sizeof(buffer) - 1);
 	while (bytes > 0) {
 		buffer[bytes] = 0;
-		const char *cmd = strtok(buffer, ",");
-		const char *param = strtok(NULL, "\0");
+		const char *cmd = strtok_r(buffer, ",", &sp);
+		const char *param = strtok_r(NULL, "\0", &sp);
 		telemetry_cb fn = unknown_command;
 		int i;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 15/21] bus/fslmc: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (13 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 14/21] " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-15  2:41   ` Sachin Saxena
  2023-11-13 10:45 ` [PATCH 16/21] common/cnxk: " Jie Hai
                   ` (11 subsequent siblings)
  26 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Hemant Agrawal, Sachin Saxena; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/bus/fslmc/fslmc_bus.c            | 5 +++--
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 57bfb5111a97..7960ad3979ef 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name)
 {
 	char *dup_dev_name, *t_ptr;
 	struct rte_dpaa2_device *dev = NULL;
+	char *sp = NULL;
 	int ret = -1;
 
 	if (!dev_name)
@@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name)
 	}
 
 	/* Parse the device name and ID */
-	t_ptr = strtok(dup_dev_name, ".");
+	t_ptr = strtok_r(dup_dev_name, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
 		ret = -EINVAL;
@@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name)
 	else
 		dev->dev_type = DPAA2_UNKNOWN;
 
-	t_ptr = strtok(NULL, ".");
+	t_ptr = strtok_r(NULL, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
 		ret = 0;
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 4aec7b2cd8ba..09a1a2b23787 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	uint32_t cpu_mask = 1;
 	int ret;
 	size_t len = 0;
-	char *temp = NULL, *token = NULL;
+	char *temp = NULL, *token = NULL, *sp = NULL;
 	char string[STRING_LEN], command[COMMAND_LEN];
 	FILE *file;
 
@@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	}
 	while (getline(&temp, &len, file) != -1) {
 		if ((strstr(temp, string)) != NULL) {
-			token = strtok(temp, ":");
+			token = strtok_r(temp, ":", &sp);
 			break;
 		}
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 16/21] common/cnxk: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (14 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 15/21] bus/fslmc: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 17/21] event/cnxk: " Jie Hai
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/common/cnxk/cnxk_telemetry_nix.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index ccae5d7853af..8054c3cf910c 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			   struct plt_tel_data *d)
 {
 	struct nix_tel_node *node;
-	char *name, *param;
+	char *name, *param, *sp = NULL;
 	char buf[1024];
 	int rc = -1;
 
@@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 		goto exit;
 
 	plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
-	name = strtok(buf, ",");
+	name = strtok_r(buf, ",", &sp);
 	if (name == NULL)
 		goto exit;
 
-	param = strtok(NULL, "\0");
+	param = strtok_r(NULL, "\0", &sp);
 
 	node = nix_tel_node_get_by_pcidev_name(name);
 	if (!node)
@@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 	plt_tel_data_start_dict(d);
 
 	if (strstr(cmd, "rq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int rq;
 
 		if (!tok)
@@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_rq(node->rqs[rq], d);
 
 	} else if (strstr(cmd, "cq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int cq;
 
 		if (!tok)
@@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_cq(node->cqs[cq], d);
 
 	} else if (strstr(cmd, "sq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int sq;
 
 		if (!tok)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 17/21] event/cnxk: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (15 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 16/21] common/cnxk: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 18/21] net/ark: " Jie Hai
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Pavan Nikhilesh, Shijith Thotton; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/event/cnxk/cnxk_eventdev.c  | 10 ++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c
index 0c61f4c20eec..fe7a86797c25 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -478,7 +478,8 @@ parse_queue_param(char *value, void *opaque)
 	struct cnxk_sso_qos queue_qos = {0};
 	uint16_t *val = (uint16_t *)&queue_qos;
 	struct cnxk_sso_evdev *dev = opaque;
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "-", &sp);
 	struct cnxk_sso_qos *old_ptr;
 
 	if (!strlen(value))
@@ -486,7 +487,7 @@ parse_queue_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		val++;
 	}
 
@@ -514,7 +515,8 @@ parse_stash_param(char *value, void *opaque)
 	struct cnxk_sso_stash queue_stash = {0};
 	struct cnxk_sso_evdev *dev = opaque;
 	struct cnxk_sso_stash *old_ptr;
-	char *tok = strtok(value, "|");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "|", &sp);
 	uint16_t *val;
 
 	if (!strlen(value))
@@ -523,7 +525,7 @@ parse_stash_param(char *value, void *opaque)
 	val = (uint16_t *)&queue_stash;
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "|");
+		tok = strtok_r(NULL, "|", &sp);
 		val++;
 	}
 
diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c b/drivers/event/cnxk/cnxk_tim_evdev.c
index 6d59fdf90983..86ef7dc3d578 100644
--- a/drivers/event/cnxk/cnxk_tim_evdev.c
+++ b/drivers/event/cnxk/cnxk_tim_evdev.c
@@ -420,7 +420,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 {
 	struct cnxk_tim_evdev *dev = opaque;
 	struct cnxk_tim_ctl ring_ctl = {0};
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "-", &sp);
 	struct cnxk_tim_ctl *old_ptr;
 	uint16_t *val;
 
@@ -431,7 +432,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		val++;
 	}
 
@@ -507,16 +508,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque)
 				      ROC_TIM_CLK_SRC_INVALID};
 	struct cnxk_tim_evdev *dev = opaque;
 	char *str = strdup(value);
-	char *tok;
+	char *tok, *sp = NULL;
 	int i = 0;
 
 	if (str == NULL || !strlen(str))
 		goto free;
 
-	tok = strtok(str, "-");
+	tok = strtok_r(str, "-", &sp);
 	while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
 		dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		i++;
 	}
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 18/21] net/ark: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (16 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 17/21] event/cnxk: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 19/21] raw/cnxk_gpio: " Jie Hai
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Shepard Siegel, Ed Czeck, John Miller
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/ark/ark_pktchkr.c | 10 +++++-----
 drivers/net/ark/ark_pktgen.c  | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c2a..6e8e5339607b 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -359,14 +359,14 @@ set_arg(char *arg, char *val)
 void
 ark_pktchkr_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = "=\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }
 
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2ab..d611406a1b46 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -340,14 +340,14 @@ pmd_set_arg(char *arg, char *val)
 void
 ark_pktgen_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = " =\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		pmd_set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 19/21] raw/cnxk_gpio: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (17 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 18/21] net/ark: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 20/21] examples/l2fwd-crypto: " Jie Hai
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 29c250672646..a499a258f315 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -190,7 +190,7 @@ static int
 cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 {
 	int i, ret, val, queue = 0;
-	char *token;
+	char *token, *sp = NULL;
 	int *list;
 
 	list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0);
@@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 	allowlist[strlen(allowlist) - 1] = ' ';
 
 	/* quiesce -Wcast-qual */
-	token = strtok((char *)(uintptr_t)allowlist, ",");
+	token = strtok_r((char *)(uintptr_t)allowlist, ",", &sp);
 	do {
 		errno = 0;
 		val = strtol(token, NULL, 10);
@@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 		}
 		if (i == queue)
 			list[queue++] = val;
-	} while ((token = strtok(NULL, ",")));
+	} while ((token = strtok_r(NULL, ",", &sp)));
 
 	free(allowlist);
 	gpiochip->allowlist = list;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 20/21] examples/l2fwd-crypto: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (18 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 19/21] raw/cnxk_gpio: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 10:45 ` [PATCH 21/21] examples/vhost: " Jie Hai
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 examples/l2fwd-crypto/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index efe7eea2a768..06e296776b95 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -1105,12 +1105,12 @@ static int
 parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size)
 {
 	unsigned byte_count;
-	char *token;
+	char *token, *sp = NULL;
 
 	errno = 0;
-	for (byte_count = 0, token = strtok(input_arg, ":");
+	for (byte_count = 0, token = strtok_r(input_arg, ":", &sp);
 			(byte_count < max_size) && (token != NULL);
-			token = strtok(NULL, ":")) {
+			token = strtok_r(NULL, ":", &sp)) {
 
 		int number = (int)strtol(token, NULL, 16);
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH 21/21] examples/vhost: replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (19 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 20/21] examples/l2fwd-crypto: " Jie Hai
@ 2023-11-13 10:45 ` Jie Hai
  2023-11-13 16:26   ` Stephen Hemminger
  2023-11-13 11:00 ` [PATCH 00/21] " Thomas Monjalon
                   ` (5 subsequent siblings)
  26 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-13 10:45 UTC (permalink / raw)
  To: dev, Maxime Coquelin, Chenbo Xia; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant function.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 examples/vhost/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ce5c1efddf5c..e8b3a97c48a4 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -246,6 +246,7 @@ open_dma(const char *value)
 	char *ptrs[2];
 	char *start, *end, *substr;
 	int64_t socketid, vring_id;
+	char *sp = NULL;
 
 	struct rte_dma_info info;
 	struct rte_dma_conf dev_config = { .nb_vchans = 1 };
@@ -269,7 +270,7 @@ open_dma(const char *value)
 
 	/* process DMA devices within bracket. */
 	addrs++;
-	substr = strtok(addrs, ";]");
+	substr = strtok_r(addrs, ";]", &sp);
 	if (!substr) {
 		ret = -1;
 		goto out;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (20 preceding siblings ...)
  2023-11-13 10:45 ` [PATCH 21/21] examples/vhost: " Jie Hai
@ 2023-11-13 11:00 ` Thomas Monjalon
  2023-11-13 11:33 ` fengchengwen
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Thomas Monjalon @ 2023-11-13 11:00 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen, david.marchand

13/11/2023 11:45, Jie Hai:
> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant function.

You should add a check in checkpatches.sh so we won't add more in future.




^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (21 preceding siblings ...)
  2023-11-13 11:00 ` [PATCH 00/21] " Thomas Monjalon
@ 2023-11-13 11:33 ` fengchengwen
  2023-11-13 16:25 ` Stephen Hemminger
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: fengchengwen @ 2023-11-13 11:33 UTC (permalink / raw)
  To: Jie Hai, dev; +Cc: lihuisong

Hi Jie,

Good fix

There are two minor I think need to modify:
1. The [PATCH 13/21] lib/telemetry should be lib/security
2. All commits should add Cc because it's potential bug.

The other LGTM, with above fixed
Series-acked-by: Chengwen Feng <fengchengwen@huawei.com>

Thanks
Chengwen

On 2023/11/13 18:45, Jie Hai wrote:
> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant function.
> 
> Jie Hai (21):
>   app/graph: replace strtok with strtok_r
>   app/test-bbdev: replace strtok with strtok_r
>   app/test-compress-perf: replace strtok with strtok_r
>   app/test-crypto-perf: replace strtok with strtok_r
>   app/test-dma-perf: replace strtok with strtok_r
>   app/test-fib: replace strtok with strtok_r
>   app/dpdk-test-flow-perf: replace strtok with strtok_r
>   app/test-mldev: replace strtok with strtok_r
>   lib/dmadev: replace strtok with strtok_r
>   lib/eal: replace strtok with strtok_r
>   lib/ethdev: replace strtok with strtok_r
>   lib/eventdev: replace strtok with strtok_r
>   lib/telemetry: replace strtok with strtok_r
>   lib/telemetry: replace strtok with strtok_r
>   bus/fslmc: replace strtok with strtok_r
>   common/cnxk: replace strtok with strtok_r
>   event/cnxk: replace strtok with strtok_r
>   net/ark: replace strtok with strtok_r
>   raw/cnxk_gpio: replace strtok with strtok_r
>   examples/l2fwd-crypto: replace strtok with strtok_r
>   examples/vhost: replace strtok with strtok_r
> 
>  app/graph/graph.c                             |  5 ++-
>  app/graph/utils.c                             | 15 +++++---
>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
>  .../comp_perf_options_parse.c                 | 16 ++++----
>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
>  .../cperf_test_vector_parsing.c               | 10 +++--
>  app/test-dma-perf/main.c                      | 13 ++++---
>  app/test-fib/main.c                           | 10 ++---
>  app/test-flow-perf/main.c                     | 22 ++++++-----
>  app/test-mldev/ml_options.c                   | 18 ++++-----
>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
>  examples/l2fwd-crypto/main.c                  |  6 +--
>  examples/vhost/main.c                         |  3 +-
>  lib/dmadev/rte_dmadev.c                       |  4 +-
>  lib/eal/common/eal_common_memory.c            |  8 ++--
>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
>  lib/security/rte_security.c                   |  3 +-
>  lib/telemetry/telemetry.c                     |  5 ++-
>  27 files changed, 169 insertions(+), 140 deletions(-)
> 

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (22 preceding siblings ...)
  2023-11-13 11:33 ` fengchengwen
@ 2023-11-13 16:25 ` Stephen Hemminger
  2023-11-13 17:09 ` Tyler Retzlaff
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-13 16:25 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen

On Mon, 13 Nov 2023 18:45:29 +0800
Jie Hai <haijie1@huawei.com> wrote:

> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant function.

Lots of churn. And most of these places are never callable from
multiple threads.

It does indicate that some better  arg handling is needed.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 21/21] examples/vhost: replace strtok with strtok_r
  2023-11-13 10:45 ` [PATCH 21/21] examples/vhost: " Jie Hai
@ 2023-11-13 16:26   ` Stephen Hemminger
  0 siblings, 0 replies; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-13 16:26 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, Maxime Coquelin, Chenbo Xia, lihuisong, fengchengwen

On Mon, 13 Nov 2023 18:45:50 +0800
Jie Hai <haijie1@huawei.com> wrote:

> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant function.
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>

This is in initialization code, can not be called by multiple threads.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 10/21] lib/eal: replace strtok with strtok_r
  2023-11-13 10:45 ` [PATCH 10/21] lib/eal: " Jie Hai
@ 2023-11-13 16:27   ` Stephen Hemminger
  2023-11-14  1:05     ` fengchengwen
  0 siblings, 1 reply; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-13 16:27 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, Anatoly Burakov, lihuisong, fengchengwen

On Mon, 13 Nov 2023 18:45:39 +0800
Jie Hai <haijie1@huawei.com> wrote:

> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.

This code is only called in startup and can not be called by
multiple threads.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (23 preceding siblings ...)
  2023-11-13 16:25 ` Stephen Hemminger
@ 2023-11-13 17:09 ` Tyler Retzlaff
  2023-11-14 12:50   ` Jie Hai
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
  26 siblings, 1 reply; 92+ messages in thread
From: Tyler Retzlaff @ 2023-11-13 17:09 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen

On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant function.

could you please use strtok_s instead of strtok_r the former is part of
the C11 standard the latter is not.

thanks!

> 
> Jie Hai (21):
>   app/graph: replace strtok with strtok_r
>   app/test-bbdev: replace strtok with strtok_r
>   app/test-compress-perf: replace strtok with strtok_r
>   app/test-crypto-perf: replace strtok with strtok_r
>   app/test-dma-perf: replace strtok with strtok_r
>   app/test-fib: replace strtok with strtok_r
>   app/dpdk-test-flow-perf: replace strtok with strtok_r
>   app/test-mldev: replace strtok with strtok_r
>   lib/dmadev: replace strtok with strtok_r
>   lib/eal: replace strtok with strtok_r
>   lib/ethdev: replace strtok with strtok_r
>   lib/eventdev: replace strtok with strtok_r
>   lib/telemetry: replace strtok with strtok_r
>   lib/telemetry: replace strtok with strtok_r
>   bus/fslmc: replace strtok with strtok_r
>   common/cnxk: replace strtok with strtok_r
>   event/cnxk: replace strtok with strtok_r
>   net/ark: replace strtok with strtok_r
>   raw/cnxk_gpio: replace strtok with strtok_r
>   examples/l2fwd-crypto: replace strtok with strtok_r
>   examples/vhost: replace strtok with strtok_r
> 
>  app/graph/graph.c                             |  5 ++-
>  app/graph/utils.c                             | 15 +++++---
>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
>  .../comp_perf_options_parse.c                 | 16 ++++----
>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
>  .../cperf_test_vector_parsing.c               | 10 +++--
>  app/test-dma-perf/main.c                      | 13 ++++---
>  app/test-fib/main.c                           | 10 ++---
>  app/test-flow-perf/main.c                     | 22 ++++++-----
>  app/test-mldev/ml_options.c                   | 18 ++++-----
>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
>  examples/l2fwd-crypto/main.c                  |  6 +--
>  examples/vhost/main.c                         |  3 +-
>  lib/dmadev/rte_dmadev.c                       |  4 +-
>  lib/eal/common/eal_common_memory.c            |  8 ++--
>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
>  lib/security/rte_security.c                   |  3 +-
>  lib/telemetry/telemetry.c                     |  5 ++-
>  27 files changed, 169 insertions(+), 140 deletions(-)
> 
> -- 
> 2.30.0

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 10/21] lib/eal: replace strtok with strtok_r
  2023-11-13 16:27   ` Stephen Hemminger
@ 2023-11-14  1:05     ` fengchengwen
  2023-11-14  1:08       ` Stephen Hemminger
  0 siblings, 1 reply; 92+ messages in thread
From: fengchengwen @ 2023-11-14  1:05 UTC (permalink / raw)
  To: Stephen Hemminger, Jie Hai; +Cc: dev, Anatoly Burakov, lihuisong

Hi Stephen,

On 2023/11/14 0:27, Stephen Hemminger wrote:
> On Mon, 13 Nov 2023 18:45:39 +0800
> Jie Hai <haijie1@huawei.com> wrote:
> 
>> Multiple threads calling the same function may cause condition
>> race issues, which often leads to abnormal behavior and can cause
>> more serious vulnerabilities such as abnormal termination, denial
>> of service, and compromised data integrity.
> 
> This code is only called in startup and can not be called by
> multiple threads.

For the DPDK examples and apps, I think it's OK if it called in startup then may not need replace.

But as for lib and drivers, I think we shouldn't make such an assumption.

At last I also recommend fix the examples and apps, because people may refer it.

Thanks
Chengwen

> 
> .
> 

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 10/21] lib/eal: replace strtok with strtok_r
  2023-11-14  1:05     ` fengchengwen
@ 2023-11-14  1:08       ` Stephen Hemminger
  0 siblings, 0 replies; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-14  1:08 UTC (permalink / raw)
  To: fengchengwen; +Cc: Jie Hai, dev, Anatoly Burakov, lihuisong

On Tue, 14 Nov 2023 09:05:10 +0800
fengchengwen <fengchengwen@huawei.com> wrote:

> Hi Stephen,
> 
> On 2023/11/14 0:27, Stephen Hemminger wrote:
> > On Mon, 13 Nov 2023 18:45:39 +0800
> > Jie Hai <haijie1@huawei.com> wrote:
> >   
> >> Multiple threads calling the same function may cause condition
> >> race issues, which often leads to abnormal behavior and can cause
> >> more serious vulnerabilities such as abnormal termination, denial
> >> of service, and compromised data integrity.  
> > 
> > This code is only called in startup and can not be called by
> > multiple threads.  
> 
> For the DPDK examples and apps, I think it's OK if it called in startup then may not need replace.
> 
> But as for lib and drivers, I think we shouldn't make such an assumption.
> 
> At last I also recommend fix the examples and apps, because people may refer it.

For startup of libs and driver initialization the code is always single threaded.
If not many, many other things would break.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 00/22] replace strtok with reentrant version
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (24 preceding siblings ...)
  2023-11-13 17:09 ` Tyler Retzlaff
@ 2023-11-14  8:41 ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 01/22] app/graph: " Jie Hai
                     ` (21 more replies)
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
  26 siblings, 22 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patchset replaces strtok with strtok_s in app, example, lib
and drivers. And adds check for use of strtok in checkpatches.sh.

--
v2:
1. fix commit log.
2. add check in checkpatches.sh.
3. replace strtok_r with strtok_s.
4. add Acked-by.
--

Jie Hai (22):
  app/graph: replace strtok with reentrant version
  app/bbdev: replace strtok with reentrant version
  app/compress-perf: replace strtok with reentrant version
  app/crypto-perf: replace strtok with reentrant version
  app/dma-perf: replace strtok with reentrant version
  app/test-fib: replace strtok with reentrant version
  app/flow-perf: replace strtok with reentrant version
  app/test-mldev: replace strtok with reentrant version
  dmadev: replace strtok with reentrant version
  eal: replace strtok with reentrant version
  ethdev: replace strtok with reentrant version
  eventdev: replace strtok with reentrant version
  security: replace strtok with reentrant version
  telemetry: replace strtok with reentrant version
  bus/fslmc: replace strtok with reentrant version
  common/cnxk: replace strtok with reentrant version
  event/cnxk: replace strtok with reentrant version
  net/ark: replace strtok with reentrant version
  raw/cnxk_gpio: replace strtok with reentrant version
  examples/l2fwd-crypto: replace strtok with reentrant version
  examples/vhost: replace strtok with reentrant version
  devtools: check for some reentrant function

 app/graph/graph.c                             |  5 ++-
 app/graph/utils.c                             | 15 +++++---
 app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
 .../comp_perf_options_parse.c                 | 16 ++++----
 app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
 .../cperf_test_vector_parsing.c               | 10 +++--
 app/test-dma-perf/main.c                      | 13 ++++---
 app/test-fib/main.c                           | 10 ++---
 app/test-flow-perf/main.c                     | 22 ++++++-----
 app/test-mldev/ml_options.c                   | 18 ++++-----
 devtools/checkpatches.sh                      |  8 ++++
 drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
 drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
 drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
 drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
 drivers/net/ark/ark_pktchkr.c                 | 10 ++---
 drivers/net/ark/ark_pktgen.c                  | 10 ++---
 drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
 examples/l2fwd-crypto/main.c                  |  6 +--
 examples/vhost/main.c                         |  3 +-
 lib/dmadev/rte_dmadev.c                       |  4 +-
 lib/eal/common/eal_common_memory.c            |  8 ++--
 lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
 lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
 lib/eventdev/rte_eventdev.c                   | 18 ++++-----
 lib/security/rte_security.c                   |  3 +-
 lib/telemetry/telemetry.c                     |  5 ++-
 28 files changed, 177 insertions(+), 140 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 01/22] app/graph: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 02/22] app/bbdev: " Jie Hai
                     ` (20 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Sunil Kumar Kori, Rakesh Kudurumalla, Nithin Dabilpuram,
	Jerin Jacob
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 5c59002a34f3 ("app/graph: add graph commands")
Fixes: 984a315a5804 ("app/graph: add parser utility")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/graph/graph.c |  5 +++--
 app/graph/utils.c | 15 +++++++++------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/app/graph/graph.c b/app/graph/graph.c
index a65723a196da..ed9405ea4bac 100644
--- a/app/graph/graph.c
+++ b/app/graph/graph.c
@@ -103,9 +103,10 @@ parser_usecases_read(char *usecases)
 {
 	bool valid = false;
 	uint32_t i, j = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(usecases, ",");
+	token = strtok_s(usecases, ",", &sp);
 	while (token != NULL) {
 		for (i = 0; i < RTE_DIM(supported_usecases); i++) {
 			if (strcmp(supported_usecases[i], token) == 0) {
@@ -116,7 +117,7 @@ parser_usecases_read(char *usecases)
 				break;
 			}
 		}
-		token = strtok(NULL, ",");
+		token = strtok_s(NULL, ",", &sp);
 	}
 
 	return valid;
diff --git a/app/graph/utils.c b/app/graph/utils.c
index c7b6ae83cf1f..f7525f0b70af 100644
--- a/app/graph/utils.c
+++ b/app/graph/utils.c
@@ -101,13 +101,14 @@ int
 parser_ip4_read(uint32_t *value, char *p)
 {
 	uint8_t shift = 24;
+	char *sp = NULL;
 	uint32_t ip = 0;
 	char *token;
 
-	token = strtok(p, ".");
+	token = strtok_s(p, ".", &sp);
 	while (token != NULL) {
 		ip |= (((uint32_t)strtoul(token, NULL, 10)) << shift);
-		token = strtok(NULL, ".");
+		token = strtok_s(NULL, ".", &sp);
 		shift -= 8;
 	}
 
@@ -120,13 +121,14 @@ int
 parser_ip6_read(uint8_t *value, char *p)
 {
 	uint64_t val = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_s(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		*value = val;
-		token = strtok(NULL, ":");
+		token = strtok_s(NULL, ":", &sp);
 		value++;
 		val = 0;
 	}
@@ -139,13 +141,14 @@ parser_mac_read(uint64_t *value, char *p)
 {
 	uint64_t mac = 0, val = 0;
 	uint8_t shift = 40;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_s(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		mac |= val << shift;
-		token = strtok(NULL, ":");
+		token = strtok_s(NULL, ":", &sp);
 		shift -= 8;
 		val = 0;
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 02/22] app/bbdev: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
  2023-11-14  8:41   ` [PATCH v2 01/22] app/graph: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 03/22] app/compress-perf: " Jie Hai
                     ` (19 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Nicolas Chautru, Maxime Coquelin, Amr Mokhtar
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 0acdb9866756 ("test/bbdev: add FFT operations cases")
Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-bbdev/test_bbdev_vector.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index c26727cd35c4..00a0f99801b7 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 	uint32_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_s(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 		*data_length = *data_length + (strlen(tok) - strlen("0x"))/2;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_s(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 {
 	char *tok = NULL;
 	uint32_t op_flag_value = 0;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_s(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 
 		*op_flags = *op_flags | op_flag_value;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_s(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -368,9 +370,10 @@ static int
 parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 {
 	char *tok = NULL;
+	char *sp = NULL;
 	bool status_ok = false;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_s(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 			return -1;
 		}
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_s(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token,
 	int ret = 0, status = 0, i, shift;
 	uint32_t op_flags = 0;
 	char *tok, *err = NULL;
+	char *sp = NULL;
 
 	struct rte_bbdev_op_fft *fft = &vector->fft;
 
@@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token,
 		fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0);
 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
 	} else if (!strcmp(key_token, "window_index")) {
-		tok = strtok(token, VALUE_DELIMITER);
+		tok = strtok_s(token, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			return -1;
 		for (i = 0; i < FFT_WIN_SIZE; i++) {
@@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token,
 			fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0)
 					<< shift;
 			if (i < (FFT_WIN_SIZE - 1)) {
-				tok = strtok(NULL, VALUE_DELIMITER);
+				tok = strtok_s(NULL, VALUE_DELIMITER, &sp);
 				if (tok == NULL)
 					return -1;
 			}
@@ -995,6 +999,7 @@ static int
 parse_entry(char *entry, struct test_bbdev_vector *vector)
 {
 	int ret = 0;
+	char *sp = NULL;
 	char *token, *key_token;
 	enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE;
 
@@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector)
 	}
 
 	/* get key */
-	token = strtok(entry, ENTRY_DELIMITER);
+	token = strtok_s(entry, ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, ENTRY_DELIMITER);
+	token = strtok_s(NULL, ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 03/22] app/compress-perf: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
  2023-11-14  8:41   ` [PATCH v2 01/22] app/graph: " Jie Hai
  2023-11-14  8:41   ` [PATCH v2 02/22] app/bbdev: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 04/22] app/crypto-perf: " Jie Hai
                     ` (18 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Tomasz Jozwiak, Fiona Trahe, Pablo de Lara, Lee Daly, Shally Verma
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: e0b6287c035d ("app/compress-perf: add parser")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-compress-perf/comp_perf_options_parse.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 6d8c370fc2ea..a390fa36c56c 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -177,6 +177,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 {
 	char *token;
 	uint8_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -184,7 +185,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_s(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -197,7 +198,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_s(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_s(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -225,7 +226,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_s(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -244,6 +245,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -251,7 +253,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_s(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -266,7 +268,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -288,7 +290,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_s(NULL, ",", &sp);
 	}
 
 	if (min)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 04/22] app/crypto-perf: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (2 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 03/22] app/compress-perf: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2024-01-11 17:10     ` Power, Ciara
  2023-11-14  8:41   ` [PATCH v2 05/22] app/dma-perf: " Jie Hai
                     ` (17 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Ciara Power, Sergio Gonzalez Monroy, Pablo de Lara,
	Piotr Azarewicz, Michal Kobylinski, Slawomir Mrozowicz,
	Marcin Kerlin, Declan Doherty
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: f6cefe253cc8 ("app/crypto-perf: add range/list of sizes")
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-crypto-perf/cperf_options_parsing.c     | 16 +++++++++-------
 app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++----
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 75afedc7fd6e..81fa4a925291 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 {
 	char *token;
 	uint32_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_s(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_s(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_s(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_s(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_s(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_s(NULL, ",", &sp);
 	}
 
 	if (min)
diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index 737d61d4af6b..3557d767b55c 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 
 	uint8_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, CPERF_VALUE_DELIMITER);
+	tok = strtok_s(tokens, CPERF_VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 			return -1;
 		}
 
-		tok = strtok(NULL, CPERF_VALUE_DELIMITER);
+		tok = strtok_s(NULL, CPERF_VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 
 	uint8_t *data = NULL;
 	char *token, *key_token;
+	char *sp = NULL;
 
 	if (entry == NULL) {
 		printf("Expected entry value\n");
@@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 	}
 
 	/* get key */
-	token = strtok(entry, CPERF_ENTRY_DELIMITER);
+	token = strtok_s(entry, CPERF_ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
+	token = strtok_s(NULL, CPERF_ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 05/22] app/dma-perf: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (3 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 04/22] app/crypto-perf: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 06/22] app/test-fib: " Jie Hai
                     ` (16 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Cheng Jiang, Anoob Joseph, Morten Brørup,
	Chengwen Feng, Chenbo Xia
  Cc: haijie1, lihuisong

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-dma-perf/main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index e5bccc27da5e..e34f9f8aaa7c 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -164,6 +164,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 	uint16_t len;
 	char *input;
 	struct lcore_dma_map_t *lcore_dma_map;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -175,7 +176,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 
 	memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t));
 
-	char *token = strtok(input, ", ");
+	char *token = strtok_s(input, ", ", &sp);
 	while (token != NULL) {
 		if (lcore_dma_map->cnt >= MAX_LCORE_NB) {
 			free(input);
@@ -185,7 +186,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 		uint16_t lcore_id = atoi(token);
 		lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id;
 
-		token = strtok(NULL, ", ");
+		token = strtok_s(NULL, ", ", &sp);
 	}
 
 	free(input);
@@ -201,6 +202,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	char *start, *end, *substr;
 	uint16_t lcore_id;
 	int ret = 0;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -216,7 +218,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_s(addrs, ",", &sp);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
@@ -258,7 +260,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1],
 				RTE_DEV_NAME_MAX_LEN);
 		lcore_dma_map->cnt++;
-		substr = strtok(NULL, ",");
+		substr = strtok_s(NULL, ",", &sp);
 	} while (substr != NULL);
 
 out:
@@ -486,6 +488,7 @@ main(int argc, char *argv[])
 	char *rst_path_ptr = NULL;
 	char rst_path[PATH_MAX];
 	int new_argc;
+	char *sp = NULL;
 
 	memset(args, 0, sizeof(args));
 
@@ -504,7 +507,7 @@ main(int argc, char *argv[])
 	}
 	if (rst_path_ptr == NULL) {
 		strlcpy(rst_path, cfg_path_ptr, PATH_MAX);
-		char *token = strtok(basename(rst_path), ".");
+		char *token = strtok_s(basename(rst_path), ".", &sp);
 		if (token == NULL) {
 			printf("Config file error.\n");
 			return -1;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 06/22] app/test-fib: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (4 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 05/22] app/dma-perf: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 07/22] app/flow-perf: " Jie Hai
                     ` (15 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Vladimir Medvedkin; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-fib/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index 75a56135f212..95f6bd467b49 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 	uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */
 	uint32_t n_routes;
 	uint8_t depth, ratio, ratio_acc = 0;
-	char *in;
+	char *in, *sp = NULL;
 
-	in = strtok(distrib_string, ",");
+	in = strtok_s(distrib_string, ",", &sp);
 
 	/*parse configures routes percentage ratios*/
 	while (in != NULL) {
@@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 		}
 
 		/*number of configured depths in*/
-		in = strtok(NULL, ",");
+		in = strtok_s(NULL, ",", &sp);
 	}
 
 	if (ratio_acc > 100) {
@@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af)
 	int ret, i = 0;
 	uint8_t *tbl = (uint8_t *)config.lookup_tbl;
 	int step = (af == AF_INET) ? 4 : 16;
-	char *s;
+	char *s, *sp = NULL;
 
 	while (fgets(line, sizeof(line), f) != NULL) {
-		s = strtok(line, " \t\n");
+		s = strtok_s(line, " \t\n", &sp);
 		if (s == NULL)
 			return -EINVAL;
 		ret = inet_pton(af, s, &tbl[i]);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 07/22] app/flow-perf: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (5 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 06/22] app/test-fib: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 08/22] app/test-mldev: " Jie Hai
                     ` (14 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Wisam Jaddo, Alexander Kozyrev, Rongwei Liu, Haifei Luo,
	Jiawei Wang, Sean Zhang
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 0c8f1f4ab90e ("app/flow-perf: support raw encap/decap actions")
Fixes: 7f37f0936a19 ("app/flow-perf: support meter policy API")
Fixes: 80a323319745 ("app/flow-perf: add destination ports parameter")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-flow-perf/main.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index e224ef67983d..04ce7e38a539 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg)
 {
 	char *token;
 	size_t i, j, k;
+	char *sp = NULL;
 
 	j = 0;
 	k = 0;
@@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg)
 		token = strsep(&arg, ":\0");
 	}
 	j = 0;
-	token = strtok(actions_str[0], ",\0");
+	token = strtok_s(actions_str[0], ",\0", &sp);
 	while (token == NULL && j < RTE_COLORS - 1)
-		token = strtok(actions_str[++j], ",\0");
+		token = strtok_s(actions_str[++j], ",\0", &sp);
 	while (j < RTE_COLORS && token != NULL) {
 		for (i = 0; i < RTE_DIM(flow_options); i++) {
 			if (!strcmp(token, flow_options[i].str)) {
@@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg)
 			usage(prog);
 			rte_exit(EXIT_SUCCESS, "Invalid colored actions\n");
 		}
-		token = strtok(NULL, ",\0");
+		token = strtok_s(NULL, ",\0", &sp);
 		while (!token && j < RTE_COLORS - 1) {
-			token = strtok(actions_str[++j], ",\0");
+			token = strtok_s(actions_str[++j], ",\0", &sp);
 			k = 0;
 		}
 	}
@@ -641,6 +642,7 @@ args_parse(int argc, char **argv)
 {
 	uint64_t pm, seed;
 	uint64_t hp_conf;
+	char *sp = NULL;
 	char **argvopt;
 	uint32_t prio;
 	char *token;
@@ -804,7 +806,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_ENCAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_s(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -817,7 +819,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid encap item: %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_s(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -828,7 +830,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_DECAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_s(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -841,7 +843,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid decap item %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_s(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -910,10 +912,10 @@ args_parse(int argc, char **argv)
 				uint16_t port_idx = 0;
 				char *token;
 
-				token = strtok(optarg, ",");
+				token = strtok_s(optarg, ",", &sp);
 				while (token != NULL) {
 					dst_ports[port_idx++] = atoi(token);
-					token = strtok(NULL, ",");
+					token = strtok_s(NULL, ",", &sp);
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name, "rxq") == 0) {
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 08/22] app/test-mldev: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (6 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 07/22] app/flow-perf: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 09/22] dmadev: " Jie Hai
                     ` (13 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Srikanth Yalavarthi; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-mldev/ml_options.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c
index 72357c1c393d..3e93a8b7356c 100644
--- a/app/test-mldev/ml_options.c
+++ b/app/test-mldev/ml_options.c
@@ -75,12 +75,12 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char models[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 	int ret = 0;
 
 	strlcpy(models, arg, PATH_MAX);
 
-	token = strtok(models, delim);
+	token = strtok_s(models, delim, &sp);
 	while (token != NULL) {
 		strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 		opt->nb_filelist++;
@@ -90,7 +90,7 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 			ret = -EINVAL;
 			break;
 		}
-		token = strtok(NULL, delim);
+		token = strtok_s(NULL, delim, &sp);
 	}
 
 	if (opt->nb_filelist == 0) {
@@ -106,7 +106,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char filelist[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 
 	if (opt->nb_filelist >= ML_TEST_MAX_MODELS) {
 		ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS);
@@ -116,7 +116,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(filelist, arg, PATH_MAX);
 
 	/* model */
-	token = strtok(filelist, delim);
+	token = strtok_s(filelist, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, model not specified = %s\n", arg);
 		return -EINVAL;
@@ -124,7 +124,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 
 	/* input */
-	token = strtok(NULL, delim);
+	token = strtok_s(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, input not specified = %s\n", arg);
 		return -EINVAL;
@@ -132,7 +132,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX);
 
 	/* output */
-	token = strtok(NULL, delim);
+	token = strtok_s(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, output not specified = %s\n", arg);
 		return -EINVAL;
@@ -140,14 +140,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX);
 
 	/* reference - optional */
-	token = strtok(NULL, delim);
+	token = strtok_s(NULL, delim, &sp);
 	if (token != NULL)
 		strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX);
 	else
 		memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX);
 
 	/* check for extra tokens */
-	token = strtok(NULL, delim);
+	token = strtok_s(NULL, delim, &sp);
 	if (token != NULL) {
 		ml_err("Invalid filelist. Entries > 4\n.");
 		return -EINVAL;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 09/22] dmadev: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (7 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 08/22] app/test-mldev: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 10/22] eal: " Jie Hai
                     ` (12 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Chengwen Feng, Kevin Laatz, Bruce Richardson,
	Sean Morrissey, Conor Walsh
  Cc: haijie1, lihuisong

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 39b5ab60df30 ("dmadev: add telemetry")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/dmadev/rte_dmadev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 4e5e420c82a5..e9c052304393 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -971,7 +971,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	struct rte_dma_info dma_info;
 	struct rte_dma_stats dma_stats;
 	int dev_id, ret, vchan_id;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *vchan_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -990,7 +990,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	if (dma_info.nb_vchans == 1 && *end_param == '\0')
 		vchan_id = 0;
 	else {
-		vchan_param = strtok(end_param, ",");
+		vchan_param = strtok_s(end_param, ",", &sp);
 		if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param))
 			return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 10/22] eal: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (8 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 09/22] dmadev: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 11/22] ethdev: " Jie Hai
                     ` (11 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Anatoly Burakov, Amit Prakash Shukla
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 2054f31a1fcd ("mem: add memseg info in telemetry")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eal/common/eal_common_memory.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index d9433db62345..327eb0f65289 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals)
 	char dlim[2] = ",";
 	char *params_args;
 	size_t count = 0;
-	char *token;
+	char *token, *sp = NULL;
 
 	if (vals == NULL || params == NULL || strlen(params) == 0)
 		return -1;
 
-	/* strtok expects char * and param is const char *. Hence on using
+	/* strtok_s expects char * and param is const char *. Hence on using
 	 * params as "const char *" compiler throws warning.
 	 */
 	params_args = strdup(params);
 	if (params_args == NULL)
 		return -1;
 
-	token = strtok(params_args, dlim);
+	token = strtok_s(params_args, dlim, &sp);
 	while (token && isdigit(*token) && count < n_vals) {
 		vals[count++] = strtoul(token, NULL, 10);
-		token = strtok(NULL, dlim);
+		token = strtok_s(NULL, dlim, &sp);
 	}
 
 	free(params_args);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 11/22] ethdev: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (9 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 10/22] eal: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 12/22] eventdev: " Jie Hai
                     ` (10 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: f38f62650f7b ("ethdev: add Rx queue telemetry query")
Fixes: 9e7533aeb80a ("ethdev: add telemetry command for TM level capabilities")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/ethdev/rte_ethdev_telemetry.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
index b01028ce9b60..658f7e54de03 100644
--- a/lib/ethdev/rte_ethdev_telemetry.c
+++ b/lib/ethdev/rte_ethdev_telemetry.c
@@ -477,6 +477,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	const char *qid_param;
 	uint16_t nb_queues;
 	char *end_param;
+	char *sp = NULL;
 	uint64_t qid;
 	int ret;
 
@@ -489,7 +490,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	if (nb_queues == 1 && *end_param == '\0')
 		qid = 0;
 	else {
-		qid_param = strtok(end_param, ",");
+		qid_param = strtok_s(end_param, ",", &sp);
 		if (!qid_param || strlen(qid_param) == 0 || !isdigit(*qid_param))
 			return -EINVAL;
 
@@ -1221,9 +1222,10 @@ static int
 eth_dev_parse_tm_params(char *params, uint32_t *result)
 {
 	const char *splited_param;
+	char *sp = NULL;
 	uint64_t ret;
 
-	splited_param = strtok(params, ",");
+	splited_param = strtok_s(params, ",", &sp);
 	if (!splited_param || strlen(splited_param) == 0 || !isdigit(*splited_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 12/22] eventdev: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (10 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 11/22] ethdev: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 13/22] security: " Jie Hai
                     ` (9 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Naga Harish K S V, Jerin Jacob; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eventdev/rte_event_eth_rx_adapter.c | 38 ++++++++++++-------------
 lib/eventdev/rte_eventdev.c             | 18 ++++++------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index 6db03adf0463..91e535e983d3 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -3651,7 +3651,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp;
 	struct rte_event_eth_rx_adapter_queue_conf queue_conf;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3661,19 +3661,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_s(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3684,7 +3684,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_s(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3723,7 +3723,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 	struct rte_event_eth_rx_adapter_queue_stats q_stats;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3733,19 +3733,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_s(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3756,7 +3756,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_s(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3794,7 +3794,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3803,19 +3803,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_s(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3826,7 +3826,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_s(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3855,7 +3855,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	uint8_t instance_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3863,14 +3863,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_s(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_s(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3881,7 +3881,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_s(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c
index 0ca32d672175..9e753c3720c0 100644
--- a/lib/eventdev/rte_eventdev.c
+++ b/lib/eventdev/rte_eventdev.c
@@ -1784,7 +1784,7 @@ handle_queue_links(const char *cmd __rte_unused,
 		   struct rte_tel_data *d)
 {
 	int i, ret, port_id = 0;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	uint8_t dev_id;
 	uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
 	uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
@@ -1797,12 +1797,12 @@ handle_queue_links(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_s(end_param, ",", &sp);
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
 		return -1;
 
 	port_id = strtoul(p_param, &end_param, 10);
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_s(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1922,7 +1922,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1932,7 +1932,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_s(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_PORT;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1940,7 +1940,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_s(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1956,7 +1956,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1966,7 +1966,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_s(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_QUEUE;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1974,7 +1974,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_s(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 13/22] security: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (11 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 12/22] eventdev: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 14/22] telemetry: " Jie Hai
                     ` (8 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Akhil Goyal, Gowrishankar Muthukrishnan
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 259ca6d1617f ("security: add telemetry endpoint for capabilities")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/security/rte_security.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c
index b082a290296b..51e3a669e6ec 100644
--- a/lib/security/rte_security.c
+++ b/lib/security/rte_security.c
@@ -496,13 +496,14 @@ security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char *
 	int dev_id, capa_id;
 	int crypto_caps_n;
 	char *end_param;
+	char *sp = NULL;
 	int rc;
 
 	if (!params || strlen(params) == 0 || !isdigit(*params))
 		return -EINVAL;
 
 	dev_id = strtoul(params, &end_param, 0);
-	capa_param = strtok(end_param, ",");
+	capa_param = strtok_s(end_param, ",", &sp);
 	if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 14/22] telemetry: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (12 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 13/22] security: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2024-01-11 17:13     ` Power, Ciara
  2023-11-14  8:41   ` [PATCH v2 15/22] bus/fslmc: " Jie Hai
                     ` (7 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Ciara Power, Keith Wiles, Bruce Richardson
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/telemetry/telemetry.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 92982842a860..ef5cc87c34d1 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -371,6 +371,7 @@ static void *
 client_handler(void *sock_id)
 {
 	int s = (int)(uintptr_t)sock_id;
+	char *sp = NULL;
 	char buffer[1024];
 	char info_str[1024];
 	snprintf(info_str, sizeof(info_str),
@@ -385,8 +386,8 @@ client_handler(void *sock_id)
 	int bytes = read(s, buffer, sizeof(buffer) - 1);
 	while (bytes > 0) {
 		buffer[bytes] = 0;
-		const char *cmd = strtok(buffer, ",");
-		const char *param = strtok(NULL, "\0");
+		const char *cmd = strtok_s(buffer, ",", &sp);
+		const char *param = strtok_s(NULL, "\0", &sp);
 		telemetry_cb fn = unknown_command;
 		int i;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 15/22] bus/fslmc: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (13 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 14/22] telemetry: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 16/22] common/cnxk: " Jie Hai
                     ` (6 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Hemant Agrawal, Sachin Saxena, Nipun Gupta, Shreyansh Jain,
	Santosh Shukla, Ferruh Yigit
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 9ccb76b24c1d ("bus/fslmc: enable portal interrupt handling")
Fixes: 828d51d8fc3e ("bus/fslmc: refactor scan and probe functions")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/bus/fslmc/fslmc_bus.c            | 5 +++--
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 57bfb5111a97..2aa0e45c3d1b 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name)
 {
 	char *dup_dev_name, *t_ptr;
 	struct rte_dpaa2_device *dev = NULL;
+	char *sp = NULL;
 	int ret = -1;
 
 	if (!dev_name)
@@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name)
 	}
 
 	/* Parse the device name and ID */
-	t_ptr = strtok(dup_dev_name, ".");
+	t_ptr = strtok_s(dup_dev_name, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
 		ret = -EINVAL;
@@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name)
 	else
 		dev->dev_type = DPAA2_UNKNOWN;
 
-	t_ptr = strtok(NULL, ".");
+	t_ptr = strtok_s(NULL, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
 		ret = 0;
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 4aec7b2cd8ba..b788d7681866 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	uint32_t cpu_mask = 1;
 	int ret;
 	size_t len = 0;
-	char *temp = NULL, *token = NULL;
+	char *temp = NULL, *token = NULL, *sp = NULL;
 	char string[STRING_LEN], command[COMMAND_LEN];
 	FILE *file;
 
@@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	}
 	while (getline(&temp, &len, file) != -1) {
 		if ((strstr(temp, string)) != NULL) {
-			token = strtok(temp, ":");
+			token = strtok_s(temp, ":", &sp);
 			break;
 		}
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 16/22] common/cnxk: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (14 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 15/22] bus/fslmc: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 17/22] event/cnxk: " Jie Hai
                     ` (5 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori,
	Satha Rao, Jerin Jacob, Gowrishankar Muthukrishnan, Harman Kalra
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: af75aac78978 ("common/cnxk: support telemetry for NIX")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/common/cnxk/cnxk_telemetry_nix.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index ccae5d7853af..eff1517951e9 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			   struct plt_tel_data *d)
 {
 	struct nix_tel_node *node;
-	char *name, *param;
+	char *name, *param, *sp = NULL;
 	char buf[1024];
 	int rc = -1;
 
@@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 		goto exit;
 
 	plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
-	name = strtok(buf, ",");
+	name = strtok_s(buf, ",", &sp);
 	if (name == NULL)
 		goto exit;
 
-	param = strtok(NULL, "\0");
+	param = strtok_s(NULL, "\0", &sp);
 
 	node = nix_tel_node_get_by_pcidev_name(name);
 	if (!node)
@@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 	plt_tel_data_start_dict(d);
 
 	if (strstr(cmd, "rq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_s(param, ",", &sp);
 		int rq;
 
 		if (!tok)
@@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_rq(node->rqs[rq], d);
 
 	} else if (strstr(cmd, "cq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_s(param, ",", &sp);
 		int cq;
 
 		if (!tok)
@@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_cq(node->cqs[cq], d);
 
 	} else if (strstr(cmd, "sq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_s(param, ",", &sp);
 		int sq;
 
 		if (!tok)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 17/22] event/cnxk: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (15 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 16/22] common/cnxk: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 18/22] net/ark: " Jie Hai
                     ` (4 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Pavan Nikhilesh, Shijith Thotton; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/event/cnxk/cnxk_eventdev.c  | 10 ++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c
index 0c61f4c20eec..1067c403ee02 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -478,7 +478,8 @@ parse_queue_param(char *value, void *opaque)
 	struct cnxk_sso_qos queue_qos = {0};
 	uint16_t *val = (uint16_t *)&queue_qos;
 	struct cnxk_sso_evdev *dev = opaque;
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_s(value, "-", &sp);
 	struct cnxk_sso_qos *old_ptr;
 
 	if (!strlen(value))
@@ -486,7 +487,7 @@ parse_queue_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_s(NULL, "-", &sp);
 		val++;
 	}
 
@@ -514,7 +515,8 @@ parse_stash_param(char *value, void *opaque)
 	struct cnxk_sso_stash queue_stash = {0};
 	struct cnxk_sso_evdev *dev = opaque;
 	struct cnxk_sso_stash *old_ptr;
-	char *tok = strtok(value, "|");
+	char *sp = NULL;
+	char *tok = strtok_s(value, "|", &sp);
 	uint16_t *val;
 
 	if (!strlen(value))
@@ -523,7 +525,7 @@ parse_stash_param(char *value, void *opaque)
 	val = (uint16_t *)&queue_stash;
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "|");
+		tok = strtok_s(NULL, "|", &sp);
 		val++;
 	}
 
diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c b/drivers/event/cnxk/cnxk_tim_evdev.c
index 6d59fdf90983..82975ec8c6e7 100644
--- a/drivers/event/cnxk/cnxk_tim_evdev.c
+++ b/drivers/event/cnxk/cnxk_tim_evdev.c
@@ -420,7 +420,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 {
 	struct cnxk_tim_evdev *dev = opaque;
 	struct cnxk_tim_ctl ring_ctl = {0};
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_s(value, "-", &sp);
 	struct cnxk_tim_ctl *old_ptr;
 	uint16_t *val;
 
@@ -431,7 +432,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_s(NULL, "-", &sp);
 		val++;
 	}
 
@@ -507,16 +508,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque)
 				      ROC_TIM_CLK_SRC_INVALID};
 	struct cnxk_tim_evdev *dev = opaque;
 	char *str = strdup(value);
-	char *tok;
+	char *tok, *sp = NULL;
 	int i = 0;
 
 	if (str == NULL || !strlen(str))
 		goto free;
 
-	tok = strtok(str, "-");
+	tok = strtok_s(str, "-", &sp);
 	while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
 		dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
-		tok = strtok(NULL, "-");
+		tok = strtok_s(NULL, "-", &sp);
 		i++;
 	}
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 18/22] net/ark: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (16 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 17/22] event/cnxk: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 19/22] raw/cnxk_gpio: " Jie Hai
                     ` (3 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Shepard Siegel, Ed Czeck, John Miller
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 9c7188a68d7b ("net/ark: provide API for hardware modules pktchkr and pktgen")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/ark/ark_pktchkr.c | 10 +++++-----
 drivers/net/ark/ark_pktgen.c  | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c2a..c1c1033eb75e 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -359,14 +359,14 @@ set_arg(char *arg, char *val)
 void
 ark_pktchkr_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = "=\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_s(args, toks, &sp);
+	v = strtok_s(NULL, toks, &sp);
 	while (argv && v) {
 		set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_s(NULL, toks, &sp);
+		v = strtok_s(NULL, toks, &sp);
 	}
 }
 
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2ab..4b564099d2d6 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -340,14 +340,14 @@ pmd_set_arg(char *arg, char *val)
 void
 ark_pktgen_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = " =\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_s(args, toks, &sp);
+	v = strtok_s(NULL, toks, &sp);
 	while (argv && v) {
 		pmd_set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_s(NULL, toks, &sp);
+		v = strtok_s(NULL, toks, &sp);
 	}
 }
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 19/22] raw/cnxk_gpio: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (17 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 18/22] net/ark: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 20/22] examples/l2fwd-crypto: " Jie Hai
                     ` (2 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski, Jerin Jacob
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 29c250672646..0e6ee31d35c9 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -190,7 +190,7 @@ static int
 cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 {
 	int i, ret, val, queue = 0;
-	char *token;
+	char *token, *sp = NULL;
 	int *list;
 
 	list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0);
@@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 	allowlist[strlen(allowlist) - 1] = ' ';
 
 	/* quiesce -Wcast-qual */
-	token = strtok((char *)(uintptr_t)allowlist, ",");
+	token = strtok_s((char *)(uintptr_t)allowlist, ",", &sp);
 	do {
 		errno = 0;
 		val = strtol(token, NULL, 10);
@@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 		}
 		if (i == queue)
 			list[queue++] = val;
-	} while ((token = strtok(NULL, ",")));
+	} while ((token = strtok_s(NULL, ",", &sp)));
 
 	free(allowlist);
 	gpiochip->allowlist = list;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 20/22] examples/l2fwd-crypto: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (18 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 19/22] raw/cnxk_gpio: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 21/22] examples/vhost: " Jie Hai
  2023-11-14  8:41   ` [PATCH v2 22/22] devtools: check for some reentrant function Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang, Pablo de Lara
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: ff5d5b01f8f2 ("examples/l2fwd-crypto: support AES-CCM")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/l2fwd-crypto/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index efe7eea2a768..7327ff1128df 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -1105,12 +1105,12 @@ static int
 parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size)
 {
 	unsigned byte_count;
-	char *token;
+	char *token, *sp = NULL;
 
 	errno = 0;
-	for (byte_count = 0, token = strtok(input_arg, ":");
+	for (byte_count = 0, token = strtok_s(input_arg, ":", &sp);
 			(byte_count < max_size) && (token != NULL);
-			token = strtok(NULL, ":")) {
+			token = strtok_s(NULL, ":", &sp)) {
 
 		int number = (int)strtol(token, NULL, 16);
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 21/22] examples/vhost: replace strtok with reentrant version
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (19 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 20/22] examples/l2fwd-crypto: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  2023-11-14  8:41   ` [PATCH v2 22/22] devtools: check for some reentrant function Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Maxime Coquelin, Chenbo Xia, Cheng Jiang
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/vhost/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ce5c1efddf5c..3949d83be212 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -246,6 +246,7 @@ open_dma(const char *value)
 	char *ptrs[2];
 	char *start, *end, *substr;
 	int64_t socketid, vring_id;
+	char *sp = NULL;
 
 	struct rte_dma_info info;
 	struct rte_dma_conf dev_config = { .nb_vchans = 1 };
@@ -269,7 +270,7 @@ open_dma(const char *value)
 
 	/* process DMA devices within bracket. */
 	addrs++;
-	substr = strtok(addrs, ";]");
+	substr = strtok_s(addrs, ";]", &sp);
 	if (!substr) {
 		ret = -1;
 		goto out;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v2 22/22] devtools: check for some reentrant function
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
                     ` (20 preceding siblings ...)
  2023-11-14  8:41   ` [PATCH v2 21/22] examples/vhost: " Jie Hai
@ 2023-11-14  8:41   ` Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14  8:41 UTC (permalink / raw)
  To: dev, Thomas Monjalon; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patch adds check in checkpatches.sh for strtok, which is
non-reentrant.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 066449d147e8..0a936219c069 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# refrain from using some non-reentrant functions
+	awk -v FOLDERS="lib drivers app examples" \
+		-v EXPRESSIONS="strtok\\\(" \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using non-reentrant function strtok, prefer strtok_s' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# refrain from using some pthread functions
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 00/22] replace strtok with reentrant version
  2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
                   ` (25 preceding siblings ...)
  2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
@ 2023-11-14 10:59 ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
                     ` (21 more replies)
  26 siblings, 22 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patchset replaces strtok with strtok_s in app, example, lib
and drivers. And adds check for use of strtok in checkpatches.sh.

--
v3:
1. fix compile error.
2. use strtok_r instead.
v2:
1. fix commit log.
2. add check in checkpatches.sh.
3. replace strtok_r with strtok_s.
4. add Acked-by.
--

Jie Hai (22):
  app/graph: replace strtok with reentrant version
  app/bbdev: replace strtok with reentrant version
  app/compress-perf: replace strtok with reentrant version
  app/crypto-perf: replace strtok with reentrant version
  app/dma-perf: replace strtok with reentrant version
  app/test-fib: replace strtok with reentrant version
  app/flow-perf: replace strtok with reentrant version
  app/test-mldev: replace strtok with reentrant version
  dmadev: replace strtok with reentrant version
  eal: replace strtok with reentrant version
  ethdev: replace strtok with reentrant version
  eventdev: replace strtok with reentrant version
  security: replace strtok with reentrant version
  telemetry: replace strtok with reentrant version
  bus/fslmc: replace strtok with reentrant version
  common/cnxk: replace strtok with reentrant version
  event/cnxk: replace strtok with reentrant version
  net/ark: replace strtok with reentrant version
  raw/cnxk_gpio: replace strtok with reentrant version
  examples/l2fwd-crypto: replace strtok with reentrant version
  examples/vhost: replace strtok with reentrant version
  devtools: check for some reentrant function

 app/graph/graph.c                             |  5 ++-
 app/graph/utils.c                             | 15 +++++---
 app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
 .../comp_perf_options_parse.c                 | 16 ++++----
 app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
 .../cperf_test_vector_parsing.c               | 10 +++--
 app/test-dma-perf/main.c                      | 13 ++++---
 app/test-fib/main.c                           | 10 ++---
 app/test-flow-perf/main.c                     | 22 ++++++-----
 app/test-mldev/ml_options.c                   | 18 ++++-----
 devtools/checkpatches.sh                      |  8 ++++
 drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
 drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
 drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
 drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
 drivers/net/ark/ark_pktchkr.c                 | 10 ++---
 drivers/net/ark/ark_pktgen.c                  | 10 ++---
 drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
 examples/l2fwd-crypto/main.c                  |  6 +--
 examples/vhost/main.c                         |  3 +-
 lib/dmadev/rte_dmadev.c                       |  4 +-
 lib/eal/common/eal_common_memory.c            |  8 ++--
 lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
 lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
 lib/eventdev/rte_eventdev.c                   | 18 ++++-----
 lib/security/rte_security.c                   |  3 +-
 lib/telemetry/telemetry.c                     |  5 ++-
 28 files changed, 177 insertions(+), 140 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 01/22] app/graph: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-15  0:07     ` Stephen Hemminger
  2023-11-14 10:59   ` [PATCH v3 02/22] app/bbdev: " Jie Hai
                     ` (20 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Sunil Kumar Kori, Rakesh Kudurumalla, Nithin Dabilpuram,
	Jerin Jacob
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 5c59002a34f3 ("app/graph: add graph commands")
Fixes: 984a315a5804 ("app/graph: add parser utility")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/graph/graph.c |  5 +++--
 app/graph/utils.c | 15 +++++++++------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/app/graph/graph.c b/app/graph/graph.c
index a65723a196da..316950948160 100644
--- a/app/graph/graph.c
+++ b/app/graph/graph.c
@@ -103,9 +103,10 @@ parser_usecases_read(char *usecases)
 {
 	bool valid = false;
 	uint32_t i, j = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(usecases, ",");
+	token = strtok_r(usecases, ",", &sp);
 	while (token != NULL) {
 		for (i = 0; i < RTE_DIM(supported_usecases); i++) {
 			if (strcmp(supported_usecases[i], token) == 0) {
@@ -116,7 +117,7 @@ parser_usecases_read(char *usecases)
 				break;
 			}
 		}
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	return valid;
diff --git a/app/graph/utils.c b/app/graph/utils.c
index c7b6ae83cf1f..ae2ff225c394 100644
--- a/app/graph/utils.c
+++ b/app/graph/utils.c
@@ -101,13 +101,14 @@ int
 parser_ip4_read(uint32_t *value, char *p)
 {
 	uint8_t shift = 24;
+	char *sp = NULL;
 	uint32_t ip = 0;
 	char *token;
 
-	token = strtok(p, ".");
+	token = strtok_r(p, ".", &sp);
 	while (token != NULL) {
 		ip |= (((uint32_t)strtoul(token, NULL, 10)) << shift);
-		token = strtok(NULL, ".");
+		token = strtok_r(NULL, ".", &sp);
 		shift -= 8;
 	}
 
@@ -120,13 +121,14 @@ int
 parser_ip6_read(uint8_t *value, char *p)
 {
 	uint64_t val = 0;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_r(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		*value = val;
-		token = strtok(NULL, ":");
+		token = strtok_r(NULL, ":", &sp);
 		value++;
 		val = 0;
 	}
@@ -139,13 +141,14 @@ parser_mac_read(uint64_t *value, char *p)
 {
 	uint64_t mac = 0, val = 0;
 	uint8_t shift = 40;
+	char *sp = NULL;
 	char *token;
 
-	token = strtok(p, ":");
+	token = strtok_r(p, ":", &sp);
 	while (token != NULL) {
 		hex_string_to_uint64(&val, token);
 		mac |= val << shift;
-		token = strtok(NULL, ":");
+		token = strtok_r(NULL, ":", &sp);
 		shift -= 8;
 		val = 0;
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 02/22] app/bbdev: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
  2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-15  0:09     ` Stephen Hemminger
  2023-11-14 10:59   ` [PATCH v3 03/22] app/compress-perf: " Jie Hai
                     ` (19 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Nicolas Chautru, Maxime Coquelin, Amr Mokhtar
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 0acdb9866756 ("test/bbdev: add FFT operations cases")
Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-bbdev/test_bbdev_vector.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index c26727cd35c4..5c966e79645e 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 	uint32_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
 
 		*data_length = *data_length + (strlen(tok) - strlen("0x"))/2;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 {
 	char *tok = NULL;
 	uint32_t op_flag_value = 0;
+	char *sp = NULL;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags,
 
 		*op_flags = *op_flags | op_flag_value;
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -368,9 +370,10 @@ static int
 parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 {
 	char *tok = NULL;
+	char *sp = NULL;
 	bool status_ok = false;
 
-	tok = strtok(tokens, VALUE_DELIMITER);
+	tok = strtok_r(tokens, VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
 			return -1;
 		}
 
-		tok = strtok(NULL, VALUE_DELIMITER);
+		tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 	}
@@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token,
 	int ret = 0, status = 0, i, shift;
 	uint32_t op_flags = 0;
 	char *tok, *err = NULL;
+	char *sp = NULL;
 
 	struct rte_bbdev_op_fft *fft = &vector->fft;
 
@@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token,
 		fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0);
 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
 	} else if (!strcmp(key_token, "window_index")) {
-		tok = strtok(token, VALUE_DELIMITER);
+		tok = strtok_r(token, VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			return -1;
 		for (i = 0; i < FFT_WIN_SIZE; i++) {
@@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token,
 			fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0)
 					<< shift;
 			if (i < (FFT_WIN_SIZE - 1)) {
-				tok = strtok(NULL, VALUE_DELIMITER);
+				tok = strtok_r(NULL, VALUE_DELIMITER, &sp);
 				if (tok == NULL)
 					return -1;
 			}
@@ -995,6 +999,7 @@ static int
 parse_entry(char *entry, struct test_bbdev_vector *vector)
 {
 	int ret = 0;
+	char *sp = NULL;
 	char *token, *key_token;
 	enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE;
 
@@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector)
 	}
 
 	/* get key */
-	token = strtok(entry, ENTRY_DELIMITER);
+	token = strtok_r(entry, ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, ENTRY_DELIMITER);
+	token = strtok_r(NULL, ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 03/22] app/compress-perf: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
  2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
  2023-11-14 10:59   ` [PATCH v3 02/22] app/bbdev: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 04/22] app/crypto-perf: " Jie Hai
                     ` (18 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Pablo de Lara, Shally Verma, Lee Daly, Tomasz Jozwiak, Fiona Trahe
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: e0b6287c035d ("app/compress-perf: add parser")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-compress-perf/comp_perf_options_parse.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 6d8c370fc2ea..d997fa667a94 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -177,6 +177,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 {
 	char *token;
 	uint8_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -184,7 +185,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_r(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -197,7 +198,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -225,7 +226,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_r(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -244,6 +245,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -251,7 +253,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_r(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -266,7 +268,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -288,7 +290,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	if (min)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 04/22] app/crypto-perf: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (2 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 03/22] app/compress-perf: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 05/22] app/dma-perf: " Jie Hai
                     ` (17 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Ciara Power, Sergio Gonzalez Monroy, Pablo de Lara,
	Piotr Azarewicz, Michal Kobylinski, Declan Doherty,
	Slawomir Mrozowicz, Marcin Kerlin
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: f6cefe253cc8 ("app/crypto-perf: add range/list of sizes")
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-crypto-perf/cperf_options_parsing.c     | 16 +++++++++-------
 app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++----
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 75afedc7fd6e..77cda0eb8e6f 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 {
 	char *token;
 	uint32_t number;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ":");
+	token = strtok_r(copy_arg, ":", &sp);
 
 	/* Parse minimum value */
 	if (token != NULL) {
@@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse increment value */
 	if (token != NULL) {
@@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	token = strtok(NULL, ":");
+	token = strtok_r(NULL, ":", &sp);
 
 	/* Parse maximum value */
 	if (token != NULL) {
@@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
 	} else
 		goto err_range;
 
-	if (strtok(NULL, ":") != NULL)
+	if (strtok_r(NULL, ":", &sp) != NULL)
 		goto err_range;
 
 	free(copy_arg);
@@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	uint8_t count = 0;
 	uint32_t temp_min;
 	uint32_t temp_max;
+	char *sp = NULL;
 
 	char *copy_arg = strdup(arg);
 
@@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		return -1;
 
 	errno = 0;
-	token = strtok(copy_arg, ",");
+	token = strtok_r(copy_arg, ",", &sp);
 
 	/* Parse first value */
 	if (token != NULL) {
@@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 	} else
 		goto err_list;
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 
 	while (token != NULL) {
 		if (count == MAX_LIST) {
@@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 		if (number > temp_max)
 			temp_max = number;
 
-		token = strtok(NULL, ",");
+		token = strtok_r(NULL, ",", &sp);
 	}
 
 	if (min)
diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index 737d61d4af6b..4d2e6053e745 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 
 	uint8_t *values, *values_resized;
 	char *tok, *error = NULL;
+	char *sp = NULL;
 
-	tok = strtok(tokens, CPERF_VALUE_DELIMITER);
+	tok = strtok_r(tokens, CPERF_VALUE_DELIMITER, &sp);
 	if (tok == NULL)
 		return -1;
 
@@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length)
 			return -1;
 		}
 
-		tok = strtok(NULL, CPERF_VALUE_DELIMITER);
+		tok = strtok_r(NULL, CPERF_VALUE_DELIMITER, &sp);
 		if (tok == NULL)
 			break;
 
@@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 
 	uint8_t *data = NULL;
 	char *token, *key_token;
+	char *sp = NULL;
 
 	if (entry == NULL) {
 		printf("Expected entry value\n");
@@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector,
 	}
 
 	/* get key */
-	token = strtok(entry, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(entry, CPERF_ENTRY_DELIMITER, &sp);
 	key_token = token;
 	/* get values for key */
-	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
+	token = strtok_r(NULL, CPERF_ENTRY_DELIMITER, &sp);
 
 	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 05/22] app/dma-perf: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (3 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 04/22] app/crypto-perf: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 06/22] app/test-fib: " Jie Hai
                     ` (16 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Cheng Jiang, Chenbo Xia, Chengwen Feng, Morten Brørup,
	Jiayu Hu
  Cc: haijie1, lihuisong

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-dma-perf/main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index e5bccc27da5e..38780939578e 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -164,6 +164,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 	uint16_t len;
 	char *input;
 	struct lcore_dma_map_t *lcore_dma_map;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -175,7 +176,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 
 	memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t));
 
-	char *token = strtok(input, ", ");
+	char *token = strtok_r(input, ", ", &sp);
 	while (token != NULL) {
 		if (lcore_dma_map->cnt >= MAX_LCORE_NB) {
 			free(input);
@@ -185,7 +186,7 @@ parse_lcore(struct test_configure *test_case, const char *value)
 		uint16_t lcore_id = atoi(token);
 		lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id;
 
-		token = strtok(NULL, ", ");
+		token = strtok_r(NULL, ", ", &sp);
 	}
 
 	free(input);
@@ -201,6 +202,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	char *start, *end, *substr;
 	uint16_t lcore_id;
 	int ret = 0;
+	char *sp = NULL;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
@@ -216,7 +218,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &sp);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
@@ -258,7 +260,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1],
 				RTE_DEV_NAME_MAX_LEN);
 		lcore_dma_map->cnt++;
-		substr = strtok(NULL, ",");
+		substr = strtok_r(NULL, ",", &sp);
 	} while (substr != NULL);
 
 out:
@@ -486,6 +488,7 @@ main(int argc, char *argv[])
 	char *rst_path_ptr = NULL;
 	char rst_path[PATH_MAX];
 	int new_argc;
+	char *sp = NULL;
 
 	memset(args, 0, sizeof(args));
 
@@ -504,7 +507,7 @@ main(int argc, char *argv[])
 	}
 	if (rst_path_ptr == NULL) {
 		strlcpy(rst_path, cfg_path_ptr, PATH_MAX);
-		char *token = strtok(basename(rst_path), ".");
+		char *token = strtok_r(basename(rst_path), ".", &sp);
 		if (token == NULL) {
 			printf("Config file error.\n");
 			return -1;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 06/22] app/test-fib: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (4 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 05/22] app/dma-perf: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 07/22] app/flow-perf: " Jie Hai
                     ` (15 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Vladimir Medvedkin; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-fib/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index 75a56135f212..8e5d17b13028 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 	uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */
 	uint32_t n_routes;
 	uint8_t depth, ratio, ratio_acc = 0;
-	char *in;
+	char *in, *sp = NULL;
 
-	in = strtok(distrib_string, ",");
+	in = strtok_r(distrib_string, ",", &sp);
 
 	/*parse configures routes percentage ratios*/
 	while (in != NULL) {
@@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n)
 		}
 
 		/*number of configured depths in*/
-		in = strtok(NULL, ",");
+		in = strtok_r(NULL, ",", &sp);
 	}
 
 	if (ratio_acc > 100) {
@@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af)
 	int ret, i = 0;
 	uint8_t *tbl = (uint8_t *)config.lookup_tbl;
 	int step = (af == AF_INET) ? 4 : 16;
-	char *s;
+	char *s, *sp = NULL;
 
 	while (fgets(line, sizeof(line), f) != NULL) {
-		s = strtok(line, " \t\n");
+		s = strtok_r(line, " \t\n", &sp);
 		if (s == NULL)
 			return -EINVAL;
 		ret = inet_pton(af, s, &tbl[i]);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 07/22] app/flow-perf: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (5 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 06/22] app/test-fib: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 08/22] app/test-mldev: " Jie Hai
                     ` (14 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Wisam Jaddo, Alexander Kozyrev, Rongwei Liu, Jiawei Wang,
	Haifei Luo, Sean Zhang
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 0c8f1f4ab90e ("app/flow-perf: support raw encap/decap actions")
Fixes: 7f37f0936a19 ("app/flow-perf: support meter policy API")
Fixes: 80a323319745 ("app/flow-perf: add destination ports parameter")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-flow-perf/main.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index e224ef67983d..36e7c1d72019 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg)
 {
 	char *token;
 	size_t i, j, k;
+	char *sp = NULL;
 
 	j = 0;
 	k = 0;
@@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg)
 		token = strsep(&arg, ":\0");
 	}
 	j = 0;
-	token = strtok(actions_str[0], ",\0");
+	token = strtok_r(actions_str[0], ",\0", &sp);
 	while (token == NULL && j < RTE_COLORS - 1)
-		token = strtok(actions_str[++j], ",\0");
+		token = strtok_r(actions_str[++j], ",\0", &sp);
 	while (j < RTE_COLORS && token != NULL) {
 		for (i = 0; i < RTE_DIM(flow_options); i++) {
 			if (!strcmp(token, flow_options[i].str)) {
@@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg)
 			usage(prog);
 			rte_exit(EXIT_SUCCESS, "Invalid colored actions\n");
 		}
-		token = strtok(NULL, ",\0");
+		token = strtok_r(NULL, ",\0", &sp);
 		while (!token && j < RTE_COLORS - 1) {
-			token = strtok(actions_str[++j], ",\0");
+			token = strtok_r(actions_str[++j], ",\0", &sp);
 			k = 0;
 		}
 	}
@@ -641,6 +642,7 @@ args_parse(int argc, char **argv)
 {
 	uint64_t pm, seed;
 	uint64_t hp_conf;
+	char *sp = NULL;
 	char **argvopt;
 	uint32_t prio;
 	char *token;
@@ -804,7 +806,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_ENCAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -817,7 +819,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid encap item: %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -828,7 +830,7 @@ args_parse(int argc, char **argv)
 						RTE_FLOW_ACTION_TYPE_RAW_DECAP
 					);
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					for (i = 0; i < RTE_DIM(flow_options); i++) {
 						if (strcmp(flow_options[i].str, token) == 0) {
@@ -841,7 +843,7 @@ args_parse(int argc, char **argv)
 							rte_exit(EXIT_FAILURE,
 								"Invalid decap item %s\n", token);
 					}
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 				printf(" / ");
 			}
@@ -910,10 +912,10 @@ args_parse(int argc, char **argv)
 				uint16_t port_idx = 0;
 				char *token;
 
-				token = strtok(optarg, ",");
+				token = strtok_r(optarg, ",", &sp);
 				while (token != NULL) {
 					dst_ports[port_idx++] = atoi(token);
-					token = strtok(NULL, ",");
+					token = strtok_r(NULL, ",", &sp);
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name, "rxq") == 0) {
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 08/22] app/test-mldev: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (6 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 07/22] app/flow-perf: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 09/22] dmadev: " Jie Hai
                     ` (13 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Srikanth Yalavarthi; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-mldev/ml_options.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c
index 72357c1c393d..3f3dc8f69890 100644
--- a/app/test-mldev/ml_options.c
+++ b/app/test-mldev/ml_options.c
@@ -75,12 +75,12 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char models[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 	int ret = 0;
 
 	strlcpy(models, arg, PATH_MAX);
 
-	token = strtok(models, delim);
+	token = strtok_r(models, delim, &sp);
 	while (token != NULL) {
 		strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 		opt->nb_filelist++;
@@ -90,7 +90,7 @@ ml_parse_models(struct ml_options *opt, const char *arg)
 			ret = -EINVAL;
 			break;
 		}
-		token = strtok(NULL, delim);
+		token = strtok_r(NULL, delim, &sp);
 	}
 
 	if (opt->nb_filelist == 0) {
@@ -106,7 +106,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 {
 	const char *delim = ",";
 	char filelist[PATH_MAX];
-	char *token;
+	char *token, *sp = NULL;
 
 	if (opt->nb_filelist >= ML_TEST_MAX_MODELS) {
 		ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS);
@@ -116,7 +116,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(filelist, arg, PATH_MAX);
 
 	/* model */
-	token = strtok(filelist, delim);
+	token = strtok_r(filelist, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, model not specified = %s\n", arg);
 		return -EINVAL;
@@ -124,7 +124,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX);
 
 	/* input */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, input not specified = %s\n", arg);
 		return -EINVAL;
@@ -132,7 +132,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX);
 
 	/* output */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token == NULL) {
 		ml_err("Invalid filelist, output not specified = %s\n", arg);
 		return -EINVAL;
@@ -140,14 +140,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg)
 	strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX);
 
 	/* reference - optional */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token != NULL)
 		strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX);
 	else
 		memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX);
 
 	/* check for extra tokens */
-	token = strtok(NULL, delim);
+	token = strtok_r(NULL, delim, &sp);
 	if (token != NULL) {
 		ml_err("Invalid filelist. Entries > 4\n.");
 		return -EINVAL;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 09/22] dmadev: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (7 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 08/22] app/test-mldev: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 10/22] eal: " Jie Hai
                     ` (12 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Chengwen Feng, Kevin Laatz, Bruce Richardson, Conor Walsh,
	Sean Morrissey
  Cc: haijie1, lihuisong

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 39b5ab60df30 ("dmadev: add telemetry")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/dmadev/rte_dmadev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 4e5e420c82a5..f856cc7d0905 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -971,7 +971,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	struct rte_dma_info dma_info;
 	struct rte_dma_stats dma_stats;
 	int dev_id, ret, vchan_id;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *vchan_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -990,7 +990,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused,
 	if (dma_info.nb_vchans == 1 && *end_param == '\0')
 		vchan_id = 0;
 	else {
-		vchan_param = strtok(end_param, ",");
+		vchan_param = strtok_r(end_param, ",", &sp);
 		if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param))
 			return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 10/22] eal: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (8 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 09/22] dmadev: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-15  7:17     ` [EXT] " Amit Prakash Shukla
  2023-11-14 10:59   ` [PATCH v3 11/22] ethdev: " Jie Hai
                     ` (11 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Anatoly Burakov, Amit Prakash Shukla
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 2054f31a1fcd ("mem: add memseg info in telemetry")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eal/common/eal_common_memory.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index d9433db62345..a05eb0442b0b 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals)
 	char dlim[2] = ",";
 	char *params_args;
 	size_t count = 0;
-	char *token;
+	char *token, *sp = NULL;
 
 	if (vals == NULL || params == NULL || strlen(params) == 0)
 		return -1;
 
-	/* strtok expects char * and param is const char *. Hence on using
+	/* strtok_r expects char * and param is const char *. Hence on using
 	 * params as "const char *" compiler throws warning.
 	 */
 	params_args = strdup(params);
 	if (params_args == NULL)
 		return -1;
 
-	token = strtok(params_args, dlim);
+	token = strtok_r(params_args, dlim, &sp);
 	while (token && isdigit(*token) && count < n_vals) {
 		vals[count++] = strtoul(token, NULL, 10);
-		token = strtok(NULL, dlim);
+		token = strtok_r(NULL, dlim, &sp);
 	}
 
 	free(params_args);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 11/22] ethdev: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (9 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 10/22] eal: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-12-16 10:01     ` Andrew Rybchenko
  2023-11-14 10:59   ` [PATCH v3 12/22] eventdev: " Jie Hai
                     ` (10 subsequent siblings)
  21 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: f38f62650f7b ("ethdev: add Rx queue telemetry query")
Fixes: 9e7533aeb80a ("ethdev: add telemetry command for TM level capabilities")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/ethdev/rte_ethdev_telemetry.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
index b01028ce9b60..6810c54109a5 100644
--- a/lib/ethdev/rte_ethdev_telemetry.c
+++ b/lib/ethdev/rte_ethdev_telemetry.c
@@ -477,6 +477,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	const char *qid_param;
 	uint16_t nb_queues;
 	char *end_param;
+	char *sp = NULL;
 	uint64_t qid;
 	int ret;
 
@@ -489,7 +490,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx,
 	if (nb_queues == 1 && *end_param == '\0')
 		qid = 0;
 	else {
-		qid_param = strtok(end_param, ",");
+		qid_param = strtok_r(end_param, ",", &sp);
 		if (!qid_param || strlen(qid_param) == 0 || !isdigit(*qid_param))
 			return -EINVAL;
 
@@ -1221,9 +1222,10 @@ static int
 eth_dev_parse_tm_params(char *params, uint32_t *result)
 {
 	const char *splited_param;
+	char *sp = NULL;
 	uint64_t ret;
 
-	splited_param = strtok(params, ",");
+	splited_param = strtok_r(params, ",", &sp);
 	if (!splited_param || strlen(splited_param) == 0 || !isdigit(*splited_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 12/22] eventdev: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (10 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 11/22] ethdev: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 13/22] security: " Jie Hai
                     ` (9 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Naga Harish K S V, Jerin Jacob; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eventdev/rte_event_eth_rx_adapter.c | 38 ++++++++++++-------------
 lib/eventdev/rte_eventdev.c             | 18 ++++++------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index 6db03adf0463..4107d600dfb7 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -3651,7 +3651,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp;
 	struct rte_event_eth_rx_adapter_queue_conf queue_conf;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3661,19 +3661,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3684,7 +3684,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3723,7 +3723,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 	struct rte_event_eth_rx_adapter_queue_stats q_stats;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -3733,19 +3733,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3756,7 +3756,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3794,7 +3794,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	uint8_t rx_adapter_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3803,19 +3803,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 	rx_adapter_id = strtoul(token, NULL, 10);
 	RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3826,7 +3826,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
@@ -3855,7 +3855,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	uint8_t instance_id;
 	uint16_t rx_queue_id;
 	int eth_dev_id, ret = -1;
-	char *token, *l_params;
+	char *token, *l_params, *sp = NULL;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
@@ -3863,14 +3863,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 	l_params = strdup(params);
 	if (l_params == NULL)
 		return -ENOMEM;
-	token = strtok(l_params, ",");
+	token = strtok_r(l_params, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get device ID from parameter string */
 	eth_dev_id = strtoul(token, NULL, 10);
 	RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL);
 
-	token = strtok(NULL, ",");
+	token = strtok_r(NULL, ",", &sp);
 	RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1);
 
 	/* Get Rx queue ID from parameter string */
@@ -3881,7 +3881,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused,
 		goto error;
 	}
 
-	token = strtok(NULL, "\0");
+	token = strtok_r(NULL, "\0", &sp);
 	if (token != NULL)
 		RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev"
 				 " telemetry command, ignoring");
diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c
index 0ca32d672175..fabba0228672 100644
--- a/lib/eventdev/rte_eventdev.c
+++ b/lib/eventdev/rte_eventdev.c
@@ -1784,7 +1784,7 @@ handle_queue_links(const char *cmd __rte_unused,
 		   struct rte_tel_data *d)
 {
 	int i, ret, port_id = 0;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	uint8_t dev_id;
 	uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
 	uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
@@ -1797,12 +1797,12 @@ handle_queue_links(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
 		return -1;
 
 	port_id = strtoul(p_param, &end_param, 10);
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1922,7 +1922,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1932,7 +1932,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_PORT;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1940,7 +1940,7 @@ handle_port_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
@@ -1956,7 +1956,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	int dev_id;
 	int port_queue_id = 0;
 	enum rte_event_dev_xstats_mode mode;
-	char *end_param;
+	char *end_param, *sp = NULL;
 	const char *p_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
@@ -1966,7 +1966,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 	dev_id = strtoul(params, &end_param, 10);
 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
-	p_param = strtok(end_param, ",");
+	p_param = strtok_r(end_param, ",", &sp);
 	mode = RTE_EVENT_DEV_XSTATS_QUEUE;
 
 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
@@ -1974,7 +1974,7 @@ handle_queue_xstats(const char *cmd __rte_unused,
 
 	port_queue_id = strtoul(p_param, &end_param, 10);
 
-	p_param = strtok(NULL, "\0");
+	p_param = strtok_r(NULL, "\0", &sp);
 	if (p_param != NULL)
 		RTE_EDEV_LOG_DEBUG(
 			"Extra parameters passed to eventdev telemetry command, ignoring");
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 13/22] security: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (11 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 12/22] eventdev: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 14/22] telemetry: " Jie Hai
                     ` (8 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Akhil Goyal, Gowrishankar Muthukrishnan
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 259ca6d1617f ("security: add telemetry endpoint for capabilities")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/security/rte_security.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c
index b082a290296b..e20d610172ef 100644
--- a/lib/security/rte_security.c
+++ b/lib/security/rte_security.c
@@ -496,13 +496,14 @@ security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char *
 	int dev_id, capa_id;
 	int crypto_caps_n;
 	char *end_param;
+	char *sp = NULL;
 	int rc;
 
 	if (!params || strlen(params) == 0 || !isdigit(*params))
 		return -EINVAL;
 
 	dev_id = strtoul(params, &end_param, 0);
-	capa_param = strtok(end_param, ",");
+	capa_param = strtok_r(end_param, ",", &sp);
 	if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param))
 		return -EINVAL;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 14/22] telemetry: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (12 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 13/22] security: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 10:59   ` [PATCH v3 15/22] bus/fslmc: " Jie Hai
                     ` (7 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Ciara Power, Bruce Richardson, Keith Wiles
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/telemetry/telemetry.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 92982842a860..bb028d9381f7 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -371,6 +371,7 @@ static void *
 client_handler(void *sock_id)
 {
 	int s = (int)(uintptr_t)sock_id;
+	char *sp = NULL;
 	char buffer[1024];
 	char info_str[1024];
 	snprintf(info_str, sizeof(info_str),
@@ -385,8 +386,8 @@ client_handler(void *sock_id)
 	int bytes = read(s, buffer, sizeof(buffer) - 1);
 	while (bytes > 0) {
 		buffer[bytes] = 0;
-		const char *cmd = strtok(buffer, ",");
-		const char *param = strtok(NULL, "\0");
+		const char *cmd = strtok_r(buffer, ",", &sp);
+		const char *param = strtok_r(NULL, "\0", &sp);
 		telemetry_cb fn = unknown_command;
 		int i;
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 15/22] bus/fslmc: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (13 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 14/22] telemetry: " Jie Hai
@ 2023-11-14 10:59   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 16/22] common/cnxk: " Jie Hai
                     ` (6 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 10:59 UTC (permalink / raw)
  To: dev, Hemant Agrawal, Sachin Saxena, Nipun Gupta, Santosh Shukla,
	Shreyansh Jain, Ferruh Yigit
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 9ccb76b24c1d ("bus/fslmc: enable portal interrupt handling")
Fixes: 828d51d8fc3e ("bus/fslmc: refactor scan and probe functions")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/bus/fslmc/fslmc_bus.c            | 5 +++--
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 57bfb5111a97..7960ad3979ef 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name)
 {
 	char *dup_dev_name, *t_ptr;
 	struct rte_dpaa2_device *dev = NULL;
+	char *sp = NULL;
 	int ret = -1;
 
 	if (!dev_name)
@@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name)
 	}
 
 	/* Parse the device name and ID */
-	t_ptr = strtok(dup_dev_name, ".");
+	t_ptr = strtok_r(dup_dev_name, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
 		ret = -EINVAL;
@@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name)
 	else
 		dev->dev_type = DPAA2_UNKNOWN;
 
-	t_ptr = strtok(NULL, ".");
+	t_ptr = strtok_r(NULL, ".", &sp);
 	if (!t_ptr) {
 		DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
 		ret = 0;
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 4aec7b2cd8ba..09a1a2b23787 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	uint32_t cpu_mask = 1;
 	int ret;
 	size_t len = 0;
-	char *temp = NULL, *token = NULL;
+	char *temp = NULL, *token = NULL, *sp = NULL;
 	char string[STRING_LEN], command[COMMAND_LEN];
 	FILE *file;
 
@@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	}
 	while (getline(&temp, &len, file) != -1) {
 		if ((strstr(temp, string)) != NULL) {
-			token = strtok(temp, ":");
+			token = strtok_r(temp, ":", &sp);
 			break;
 		}
 	}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 16/22] common/cnxk: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (14 preceding siblings ...)
  2023-11-14 10:59   ` [PATCH v3 15/22] bus/fslmc: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 17/22] event/cnxk: " Jie Hai
                     ` (5 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori,
	Satha Rao, Gowrishankar Muthukrishnan, Jerin Jacob, Harman Kalra
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: af75aac78978 ("common/cnxk: support telemetry for NIX")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/common/cnxk/cnxk_telemetry_nix.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index ccae5d7853af..8054c3cf910c 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			   struct plt_tel_data *d)
 {
 	struct nix_tel_node *node;
-	char *name, *param;
+	char *name, *param, *sp = NULL;
 	char buf[1024];
 	int rc = -1;
 
@@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 		goto exit;
 
 	plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
-	name = strtok(buf, ",");
+	name = strtok_r(buf, ",", &sp);
 	if (name == NULL)
 		goto exit;
 
-	param = strtok(NULL, "\0");
+	param = strtok_r(NULL, "\0", &sp);
 
 	node = nix_tel_node_get_by_pcidev_name(name);
 	if (!node)
@@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 	plt_tel_data_start_dict(d);
 
 	if (strstr(cmd, "rq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int rq;
 
 		if (!tok)
@@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_rq(node->rqs[rq], d);
 
 	} else if (strstr(cmd, "cq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int cq;
 
 		if (!tok)
@@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 			rc = cnxk_tel_nix_cq(node->cqs[cq], d);
 
 	} else if (strstr(cmd, "sq")) {
-		char *tok = strtok(param, ",");
+		char *tok = strtok_r(param, ",", &sp);
 		int sq;
 
 		if (!tok)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 17/22] event/cnxk: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (15 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 16/22] common/cnxk: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 18/22] net/ark: " Jie Hai
                     ` (4 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Pavan Nikhilesh, Shijith Thotton; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/event/cnxk/cnxk_eventdev.c  | 10 ++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c
index 0c61f4c20eec..fe7a86797c25 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -478,7 +478,8 @@ parse_queue_param(char *value, void *opaque)
 	struct cnxk_sso_qos queue_qos = {0};
 	uint16_t *val = (uint16_t *)&queue_qos;
 	struct cnxk_sso_evdev *dev = opaque;
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "-", &sp);
 	struct cnxk_sso_qos *old_ptr;
 
 	if (!strlen(value))
@@ -486,7 +487,7 @@ parse_queue_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		val++;
 	}
 
@@ -514,7 +515,8 @@ parse_stash_param(char *value, void *opaque)
 	struct cnxk_sso_stash queue_stash = {0};
 	struct cnxk_sso_evdev *dev = opaque;
 	struct cnxk_sso_stash *old_ptr;
-	char *tok = strtok(value, "|");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "|", &sp);
 	uint16_t *val;
 
 	if (!strlen(value))
@@ -523,7 +525,7 @@ parse_stash_param(char *value, void *opaque)
 	val = (uint16_t *)&queue_stash;
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "|");
+		tok = strtok_r(NULL, "|", &sp);
 		val++;
 	}
 
diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c b/drivers/event/cnxk/cnxk_tim_evdev.c
index 6d59fdf90983..86ef7dc3d578 100644
--- a/drivers/event/cnxk/cnxk_tim_evdev.c
+++ b/drivers/event/cnxk/cnxk_tim_evdev.c
@@ -420,7 +420,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 {
 	struct cnxk_tim_evdev *dev = opaque;
 	struct cnxk_tim_ctl ring_ctl = {0};
-	char *tok = strtok(value, "-");
+	char *sp = NULL;
+	char *tok = strtok_r(value, "-", &sp);
 	struct cnxk_tim_ctl *old_ptr;
 	uint16_t *val;
 
@@ -431,7 +432,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 
 	while (tok != NULL) {
 		*val = atoi(tok);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		val++;
 	}
 
@@ -507,16 +508,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque)
 				      ROC_TIM_CLK_SRC_INVALID};
 	struct cnxk_tim_evdev *dev = opaque;
 	char *str = strdup(value);
-	char *tok;
+	char *tok, *sp = NULL;
 	int i = 0;
 
 	if (str == NULL || !strlen(str))
 		goto free;
 
-	tok = strtok(str, "-");
+	tok = strtok_r(str, "-", &sp);
 	while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
 		dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
-		tok = strtok(NULL, "-");
+		tok = strtok_r(NULL, "-", &sp);
 		i++;
 	}
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 18/22] net/ark: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (16 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 17/22] event/cnxk: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 19/22] raw/cnxk_gpio: " Jie Hai
                     ` (3 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Shepard Siegel, Ed Czeck, John Miller
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 9c7188a68d7b ("net/ark: provide API for hardware modules pktchkr and pktgen")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/ark/ark_pktchkr.c | 10 +++++-----
 drivers/net/ark/ark_pktgen.c  | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c2a..6e8e5339607b 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -359,14 +359,14 @@ set_arg(char *arg, char *val)
 void
 ark_pktchkr_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = "=\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }
 
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2ab..d611406a1b46 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -340,14 +340,14 @@ pmd_set_arg(char *arg, char *val)
 void
 ark_pktgen_parse(char *args)
 {
-	char *argv, *v;
+	char *argv, *v, *sp = NULL;
 	const char toks[] = " =\n\t\v\f \r";
-	argv = strtok(args, toks);
-	v = strtok(NULL, toks);
+	argv = strtok_r(args, toks, &sp);
+	v = strtok_r(NULL, toks, &sp);
 	while (argv && v) {
 		pmd_set_arg(argv, v);
-		argv = strtok(NULL, toks);
-		v = strtok(NULL, toks);
+		argv = strtok_r(NULL, toks, &sp);
+		v = strtok_r(NULL, toks, &sp);
 	}
 }
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 19/22] raw/cnxk_gpio: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (17 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 18/22] net/ark: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 20/22] examples/l2fwd-crypto: " Jie Hai
                     ` (2 subsequent siblings)
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski, Jerin Jacob
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 29c250672646..a499a258f315 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -190,7 +190,7 @@ static int
 cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 {
 	int i, ret, val, queue = 0;
-	char *token;
+	char *token, *sp = NULL;
 	int *list;
 
 	list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0);
@@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 	allowlist[strlen(allowlist) - 1] = ' ';
 
 	/* quiesce -Wcast-qual */
-	token = strtok((char *)(uintptr_t)allowlist, ",");
+	token = strtok_r((char *)(uintptr_t)allowlist, ",", &sp);
 	do {
 		errno = 0;
 		val = strtol(token, NULL, 10);
@@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 		}
 		if (i == queue)
 			list[queue++] = val;
-	} while ((token = strtok(NULL, ",")));
+	} while ((token = strtok_r(NULL, ",", &sp)));
 
 	free(allowlist);
 	gpiochip->allowlist = list;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 20/22] examples/l2fwd-crypto: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (18 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 19/22] raw/cnxk_gpio: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 21/22] examples/vhost: " Jie Hai
  2023-11-14 11:00   ` [PATCH v3 22/22] devtools: check for some reentrant function Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang, Pablo de Lara
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: ff5d5b01f8f2 ("examples/l2fwd-crypto: support AES-CCM")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/l2fwd-crypto/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index efe7eea2a768..06e296776b95 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -1105,12 +1105,12 @@ static int
 parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size)
 {
 	unsigned byte_count;
-	char *token;
+	char *token, *sp = NULL;
 
 	errno = 0;
-	for (byte_count = 0, token = strtok(input_arg, ":");
+	for (byte_count = 0, token = strtok_r(input_arg, ":", &sp);
 			(byte_count < max_size) && (token != NULL);
-			token = strtok(NULL, ":")) {
+			token = strtok_r(NULL, ":", &sp)) {
 
 		int number = (int)strtol(token, NULL, 16);
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 21/22] examples/vhost: replace strtok with reentrant version
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (19 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 20/22] examples/l2fwd-crypto: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  2023-11-14 11:00   ` [PATCH v3 22/22] devtools: check for some reentrant function Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Maxime Coquelin, Chenbo Xia, Cheng Jiang
  Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 examples/vhost/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ce5c1efddf5c..e8b3a97c48a4 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -246,6 +246,7 @@ open_dma(const char *value)
 	char *ptrs[2];
 	char *start, *end, *substr;
 	int64_t socketid, vring_id;
+	char *sp = NULL;
 
 	struct rte_dma_info info;
 	struct rte_dma_conf dev_config = { .nb_vchans = 1 };
@@ -269,7 +270,7 @@ open_dma(const char *value)
 
 	/* process DMA devices within bracket. */
 	addrs++;
-	substr = strtok(addrs, ";]");
+	substr = strtok_r(addrs, ";]", &sp);
 	if (!substr) {
 		ret = -1;
 		goto out;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* [PATCH v3 22/22] devtools: check for some reentrant function
  2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
                     ` (20 preceding siblings ...)
  2023-11-14 11:00   ` [PATCH v3 21/22] examples/vhost: " Jie Hai
@ 2023-11-14 11:00   ` Jie Hai
  21 siblings, 0 replies; 92+ messages in thread
From: Jie Hai @ 2023-11-14 11:00 UTC (permalink / raw)
  To: dev, Thomas Monjalon; +Cc: haijie1, lihuisong, fengchengwen

Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patch adds check in checkpatches.sh for strtok, which is
non-reentrant.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 066449d147e8..e831fc723dfb 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# refrain from using some non-reentrant functions
+	awk -v FOLDERS="lib drivers app examples" \
+		-v EXPRESSIONS="strtok\\\(" \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using non-reentrant function strtok, prefer strtok_r' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# refrain from using some pthread functions
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \
-- 
2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-13 17:09 ` Tyler Retzlaff
@ 2023-11-14 12:50   ` Jie Hai
  2023-11-14 17:32     ` Tyler Retzlaff
  0 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-14 12:50 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, lihuisong, fengchengwen

On 2023/11/14 1:09, Tyler Retzlaff wrote:
> On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
>> Multiple threads calling the same function may cause condition
>> race issues, which often leads to abnormal behavior and can cause
>> more serious vulnerabilities such as abnormal termination, denial
>> of service, and compromised data integrity.
>>
>> The strtok() is non-reentrant, it is better to replace it with a
>> reentrant function.
> 
> could you please use strtok_s instead of strtok_r the former is part of
> the C11 standard the latter is not.
> 
> thanks!
> 
Hi, Tyler Retzlaff

Thanks for your comment.

For the use of strtok_s, I have consulted some documents, see
	https://en.cppreference.com/w/c/string/byte/strtok
It says
"As with all bounds-checked functions, strtok_s only guaranteed to be
available if __STDC_LIB_EXT1__ is defined by the implementation and if
the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
including <string.h>.
"

I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around and 
compiled
locally and found that __STDC_LIB_EXT1__ was not defined, so the related
code  was not called. I'm afraid there's a problem with this
modification.

Am I using strtok_s wrong?

Thanks,
Jie Hai
>>
>> Jie Hai (21):
>>    app/graph: replace strtok with strtok_r
>>    app/test-bbdev: replace strtok with strtok_r
>>    app/test-compress-perf: replace strtok with strtok_r
>>    app/test-crypto-perf: replace strtok with strtok_r
>>    app/test-dma-perf: replace strtok with strtok_r
>>    app/test-fib: replace strtok with strtok_r
>>    app/dpdk-test-flow-perf: replace strtok with strtok_r
>>    app/test-mldev: replace strtok with strtok_r
>>    lib/dmadev: replace strtok with strtok_r
>>    lib/eal: replace strtok with strtok_r
>>    lib/ethdev: replace strtok with strtok_r
>>    lib/eventdev: replace strtok with strtok_r
>>    lib/telemetry: replace strtok with strtok_r
>>    lib/telemetry: replace strtok with strtok_r
>>    bus/fslmc: replace strtok with strtok_r
>>    common/cnxk: replace strtok with strtok_r
>>    event/cnxk: replace strtok with strtok_r
>>    net/ark: replace strtok with strtok_r
>>    raw/cnxk_gpio: replace strtok with strtok_r
>>    examples/l2fwd-crypto: replace strtok with strtok_r
>>    examples/vhost: replace strtok with strtok_r
>>
>>   app/graph/graph.c                             |  5 ++-
>>   app/graph/utils.c                             | 15 +++++---
>>   app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
>>   .../comp_perf_options_parse.c                 | 16 ++++----
>>   app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
>>   .../cperf_test_vector_parsing.c               | 10 +++--
>>   app/test-dma-perf/main.c                      | 13 ++++---
>>   app/test-fib/main.c                           | 10 ++---
>>   app/test-flow-perf/main.c                     | 22 ++++++-----
>>   app/test-mldev/ml_options.c                   | 18 ++++-----
>>   drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
>>   drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
>>   drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
>>   drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
>>   drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
>>   drivers/net/ark/ark_pktchkr.c                 | 10 ++---
>>   drivers/net/ark/ark_pktgen.c                  | 10 ++---
>>   drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
>>   examples/l2fwd-crypto/main.c                  |  6 +--
>>   examples/vhost/main.c                         |  3 +-
>>   lib/dmadev/rte_dmadev.c                       |  4 +-
>>   lib/eal/common/eal_common_memory.c            |  8 ++--
>>   lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
>>   lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
>>   lib/eventdev/rte_eventdev.c                   | 18 ++++-----
>>   lib/security/rte_security.c                   |  3 +-
>>   lib/telemetry/telemetry.c                     |  5 ++-
>>   27 files changed, 169 insertions(+), 140 deletions(-)
>>
>> -- 
>> 2.30.0
> .

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-14 12:50   ` Jie Hai
@ 2023-11-14 17:32     ` Tyler Retzlaff
  2023-11-14 17:34       ` Tyler Retzlaff
  0 siblings, 1 reply; 92+ messages in thread
From: Tyler Retzlaff @ 2023-11-14 17:32 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen

On Tue, Nov 14, 2023 at 08:50:17PM +0800, Jie Hai wrote:
> On 2023/11/14 1:09, Tyler Retzlaff wrote:
> >On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
> >>Multiple threads calling the same function may cause condition
> >>race issues, which often leads to abnormal behavior and can cause
> >>more serious vulnerabilities such as abnormal termination, denial
> >>of service, and compromised data integrity.
> >>
> >>The strtok() is non-reentrant, it is better to replace it with a
> >>reentrant function.
> >
> >could you please use strtok_s instead of strtok_r the former is part of
> >the C11 standard the latter is not.
> >
> >thanks!
> >
> Hi, Tyler Retzlaff
> 
> Thanks for your comment.
> 
> For the use of strtok_s, I have consulted some documents, see
> 	https://en.cppreference.com/w/c/string/byte/strtok
> It says
> "As with all bounds-checked functions, strtok_s only guaranteed to be
> available if __STDC_LIB_EXT1__ is defined by the implementation and if
> the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
> including <string.h>.
> "
> 
> I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around and
> compiled
> locally and found that __STDC_LIB_EXT1__ was not defined, so the related
> code  was not called. I'm afraid there's a problem with this
> modification.
> 
> Am I using strtok_s wrong?

no i overlooked that it is optional my fault sorry.

since there is no portable strtok_r i'm going to have to agree with others
that only places where you actually need reentrant strtok be converted to
strtok_r.

for windows i think we'll either need to introduce an abstracted strtok_r
name for portability or something in the rte_ namespace (dependent on
what other revieweres would prefer)

thanks!

> 
> Thanks,
> Jie Hai
> >>
> >>Jie Hai (21):
> >>   app/graph: replace strtok with strtok_r
> >>   app/test-bbdev: replace strtok with strtok_r
> >>   app/test-compress-perf: replace strtok with strtok_r
> >>   app/test-crypto-perf: replace strtok with strtok_r
> >>   app/test-dma-perf: replace strtok with strtok_r
> >>   app/test-fib: replace strtok with strtok_r
> >>   app/dpdk-test-flow-perf: replace strtok with strtok_r
> >>   app/test-mldev: replace strtok with strtok_r
> >>   lib/dmadev: replace strtok with strtok_r
> >>   lib/eal: replace strtok with strtok_r
> >>   lib/ethdev: replace strtok with strtok_r
> >>   lib/eventdev: replace strtok with strtok_r
> >>   lib/telemetry: replace strtok with strtok_r
> >>   lib/telemetry: replace strtok with strtok_r
> >>   bus/fslmc: replace strtok with strtok_r
> >>   common/cnxk: replace strtok with strtok_r
> >>   event/cnxk: replace strtok with strtok_r
> >>   net/ark: replace strtok with strtok_r
> >>   raw/cnxk_gpio: replace strtok with strtok_r
> >>   examples/l2fwd-crypto: replace strtok with strtok_r
> >>   examples/vhost: replace strtok with strtok_r
> >>
> >>  app/graph/graph.c                             |  5 ++-
> >>  app/graph/utils.c                             | 15 +++++---
> >>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
> >>  .../comp_perf_options_parse.c                 | 16 ++++----
> >>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
> >>  .../cperf_test_vector_parsing.c               | 10 +++--
> >>  app/test-dma-perf/main.c                      | 13 ++++---
> >>  app/test-fib/main.c                           | 10 ++---
> >>  app/test-flow-perf/main.c                     | 22 ++++++-----
> >>  app/test-mldev/ml_options.c                   | 18 ++++-----
> >>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
> >>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
> >>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
> >>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
> >>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
> >>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
> >>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
> >>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
> >>  examples/l2fwd-crypto/main.c                  |  6 +--
> >>  examples/vhost/main.c                         |  3 +-
> >>  lib/dmadev/rte_dmadev.c                       |  4 +-
> >>  lib/eal/common/eal_common_memory.c            |  8 ++--
> >>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
> >>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
> >>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
> >>  lib/security/rte_security.c                   |  3 +-
> >>  lib/telemetry/telemetry.c                     |  5 ++-
> >>  27 files changed, 169 insertions(+), 140 deletions(-)
> >>
> >>-- 
> >>2.30.0
> >.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-14 17:32     ` Tyler Retzlaff
@ 2023-11-14 17:34       ` Tyler Retzlaff
  2023-11-14 17:49         ` Tyler Retzlaff
  0 siblings, 1 reply; 92+ messages in thread
From: Tyler Retzlaff @ 2023-11-14 17:34 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen

On Tue, Nov 14, 2023 at 09:32:48AM -0800, Tyler Retzlaff wrote:
> On Tue, Nov 14, 2023 at 08:50:17PM +0800, Jie Hai wrote:
> > On 2023/11/14 1:09, Tyler Retzlaff wrote:
> > >On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
> > >>Multiple threads calling the same function may cause condition
> > >>race issues, which often leads to abnormal behavior and can cause
> > >>more serious vulnerabilities such as abnormal termination, denial
> > >>of service, and compromised data integrity.
> > >>
> > >>The strtok() is non-reentrant, it is better to replace it with a
> > >>reentrant function.
> > >
> > >could you please use strtok_s instead of strtok_r the former is part of
> > >the C11 standard the latter is not.
> > >
> > >thanks!
> > >
> > Hi, Tyler Retzlaff
> > 
> > Thanks for your comment.
> > 
> > For the use of strtok_s, I have consulted some documents, see
> > 	https://en.cppreference.com/w/c/string/byte/strtok
> > It says
> > "As with all bounds-checked functions, strtok_s only guaranteed to be
> > available if __STDC_LIB_EXT1__ is defined by the implementation and if
> > the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
> > including <string.h>.
> > "
> > 
> > I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around and
> > compiled
> > locally and found that __STDC_LIB_EXT1__ was not defined, so the related
> > code  was not called. I'm afraid there's a problem with this
> > modification.
> > 
> > Am I using strtok_s wrong?
> 
> no i overlooked that it is optional my fault sorry.
> 
> since there is no portable strtok_r i'm going to have to agree with others
> that only places where you actually need reentrant strtok be converted to
> strtok_r.
> 
> for windows i think we'll either need to introduce an abstracted strtok_r
> name for portability or something in the rte_ namespace (dependent on
> what other revieweres would prefer)

just as a follow up here maybe it would be optimal if we could use
strtok_s *if* we test that the toolchain makes it available and if not
provide a mapping of strtok_s -> strtok_r.

what do others think?

> 
> thanks!
> 
> > 
> > Thanks,
> > Jie Hai
> > >>
> > >>Jie Hai (21):
> > >>   app/graph: replace strtok with strtok_r
> > >>   app/test-bbdev: replace strtok with strtok_r
> > >>   app/test-compress-perf: replace strtok with strtok_r
> > >>   app/test-crypto-perf: replace strtok with strtok_r
> > >>   app/test-dma-perf: replace strtok with strtok_r
> > >>   app/test-fib: replace strtok with strtok_r
> > >>   app/dpdk-test-flow-perf: replace strtok with strtok_r
> > >>   app/test-mldev: replace strtok with strtok_r
> > >>   lib/dmadev: replace strtok with strtok_r
> > >>   lib/eal: replace strtok with strtok_r
> > >>   lib/ethdev: replace strtok with strtok_r
> > >>   lib/eventdev: replace strtok with strtok_r
> > >>   lib/telemetry: replace strtok with strtok_r
> > >>   lib/telemetry: replace strtok with strtok_r
> > >>   bus/fslmc: replace strtok with strtok_r
> > >>   common/cnxk: replace strtok with strtok_r
> > >>   event/cnxk: replace strtok with strtok_r
> > >>   net/ark: replace strtok with strtok_r
> > >>   raw/cnxk_gpio: replace strtok with strtok_r
> > >>   examples/l2fwd-crypto: replace strtok with strtok_r
> > >>   examples/vhost: replace strtok with strtok_r
> > >>
> > >>  app/graph/graph.c                             |  5 ++-
> > >>  app/graph/utils.c                             | 15 +++++---
> > >>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
> > >>  .../comp_perf_options_parse.c                 | 16 ++++----
> > >>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
> > >>  .../cperf_test_vector_parsing.c               | 10 +++--
> > >>  app/test-dma-perf/main.c                      | 13 ++++---
> > >>  app/test-fib/main.c                           | 10 ++---
> > >>  app/test-flow-perf/main.c                     | 22 ++++++-----
> > >>  app/test-mldev/ml_options.c                   | 18 ++++-----
> > >>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
> > >>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
> > >>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
> > >>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
> > >>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
> > >>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
> > >>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
> > >>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
> > >>  examples/l2fwd-crypto/main.c                  |  6 +--
> > >>  examples/vhost/main.c                         |  3 +-
> > >>  lib/dmadev/rte_dmadev.c                       |  4 +-
> > >>  lib/eal/common/eal_common_memory.c            |  8 ++--
> > >>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
> > >>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
> > >>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
> > >>  lib/security/rte_security.c                   |  3 +-
> > >>  lib/telemetry/telemetry.c                     |  5 ++-
> > >>  27 files changed, 169 insertions(+), 140 deletions(-)
> > >>
> > >>-- 
> > >>2.30.0
> > >.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-14 17:34       ` Tyler Retzlaff
@ 2023-11-14 17:49         ` Tyler Retzlaff
  2023-11-15  3:02           ` fengchengwen
  0 siblings, 1 reply; 92+ messages in thread
From: Tyler Retzlaff @ 2023-11-14 17:49 UTC (permalink / raw)
  To: Jie Hai; +Cc: dev, lihuisong, fengchengwen

On Tue, Nov 14, 2023 at 09:34:33AM -0800, Tyler Retzlaff wrote:
> On Tue, Nov 14, 2023 at 09:32:48AM -0800, Tyler Retzlaff wrote:
> > On Tue, Nov 14, 2023 at 08:50:17PM +0800, Jie Hai wrote:
> > > On 2023/11/14 1:09, Tyler Retzlaff wrote:
> > > >On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
> > > >>Multiple threads calling the same function may cause condition
> > > >>race issues, which often leads to abnormal behavior and can cause
> > > >>more serious vulnerabilities such as abnormal termination, denial
> > > >>of service, and compromised data integrity.
> > > >>
> > > >>The strtok() is non-reentrant, it is better to replace it with a
> > > >>reentrant function.
> > > >
> > > >could you please use strtok_s instead of strtok_r the former is part of
> > > >the C11 standard the latter is not.
> > > >
> > > >thanks!
> > > >
> > > Hi, Tyler Retzlaff
> > > 
> > > Thanks for your comment.
> > > 
> > > For the use of strtok_s, I have consulted some documents, see
> > > 	https://en.cppreference.com/w/c/string/byte/strtok
> > > It says
> > > "As with all bounds-checked functions, strtok_s only guaranteed to be
> > > available if __STDC_LIB_EXT1__ is defined by the implementation and if
> > > the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
> > > including <string.h>.
> > > "
> > > 
> > > I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around and
> > > compiled
> > > locally and found that __STDC_LIB_EXT1__ was not defined, so the related
> > > code  was not called. I'm afraid there's a problem with this
> > > modification.
> > > 
> > > Am I using strtok_s wrong?
> > 
> > no i overlooked that it is optional my fault sorry.
> > 
> > since there is no portable strtok_r i'm going to have to agree with others
> > that only places where you actually need reentrant strtok be converted to
> > strtok_r.
> > 
> > for windows i think we'll either need to introduce an abstracted strtok_r
> > name for portability or something in the rte_ namespace (dependent on
> > what other revieweres would prefer)
> 
> just as a follow up here maybe it would be optimal if we could use
> strtok_s *if* we test that the toolchain makes it available and if not
> provide a mapping of strtok_s -> strtok_r.

just a final follow up, i can see that we already have a rte_strerror
here to do the replace with reentrant dance. it is probably good to
follow the already established pattern for this and have a rte_strtok.

what do others think?
 
> > 
> > thanks!
> > 
> > > 
> > > Thanks,
> > > Jie Hai
> > > >>
> > > >>Jie Hai (21):
> > > >>   app/graph: replace strtok with strtok_r
> > > >>   app/test-bbdev: replace strtok with strtok_r
> > > >>   app/test-compress-perf: replace strtok with strtok_r
> > > >>   app/test-crypto-perf: replace strtok with strtok_r
> > > >>   app/test-dma-perf: replace strtok with strtok_r
> > > >>   app/test-fib: replace strtok with strtok_r
> > > >>   app/dpdk-test-flow-perf: replace strtok with strtok_r
> > > >>   app/test-mldev: replace strtok with strtok_r
> > > >>   lib/dmadev: replace strtok with strtok_r
> > > >>   lib/eal: replace strtok with strtok_r
> > > >>   lib/ethdev: replace strtok with strtok_r
> > > >>   lib/eventdev: replace strtok with strtok_r
> > > >>   lib/telemetry: replace strtok with strtok_r
> > > >>   lib/telemetry: replace strtok with strtok_r
> > > >>   bus/fslmc: replace strtok with strtok_r
> > > >>   common/cnxk: replace strtok with strtok_r
> > > >>   event/cnxk: replace strtok with strtok_r
> > > >>   net/ark: replace strtok with strtok_r
> > > >>   raw/cnxk_gpio: replace strtok with strtok_r
> > > >>   examples/l2fwd-crypto: replace strtok with strtok_r
> > > >>   examples/vhost: replace strtok with strtok_r
> > > >>
> > > >>  app/graph/graph.c                             |  5 ++-
> > > >>  app/graph/utils.c                             | 15 +++++---
> > > >>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
> > > >>  .../comp_perf_options_parse.c                 | 16 ++++----
> > > >>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
> > > >>  .../cperf_test_vector_parsing.c               | 10 +++--
> > > >>  app/test-dma-perf/main.c                      | 13 ++++---
> > > >>  app/test-fib/main.c                           | 10 ++---
> > > >>  app/test-flow-perf/main.c                     | 22 ++++++-----
> > > >>  app/test-mldev/ml_options.c                   | 18 ++++-----
> > > >>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
> > > >>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
> > > >>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
> > > >>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
> > > >>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
> > > >>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
> > > >>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
> > > >>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
> > > >>  examples/l2fwd-crypto/main.c                  |  6 +--
> > > >>  examples/vhost/main.c                         |  3 +-
> > > >>  lib/dmadev/rte_dmadev.c                       |  4 +-
> > > >>  lib/eal/common/eal_common_memory.c            |  8 ++--
> > > >>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
> > > >>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
> > > >>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
> > > >>  lib/security/rte_security.c                   |  3 +-
> > > >>  lib/telemetry/telemetry.c                     |  5 ++-
> > > >>  27 files changed, 169 insertions(+), 140 deletions(-)
> > > >>
> > > >>-- 
> > > >>2.30.0
> > > >.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH v3 01/22] app/graph: replace strtok with reentrant version
  2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
@ 2023-11-15  0:07     ` Stephen Hemminger
  0 siblings, 0 replies; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-15  0:07 UTC (permalink / raw)
  To: Jie Hai
  Cc: dev, Sunil Kumar Kori, Rakesh Kudurumalla, Nithin Dabilpuram,
	Jerin Jacob, lihuisong, fengchengwen

On Tue, 14 Nov 2023 18:59:45 +0800
Jie Hai <haijie1@huawei.com> wrote:

> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant version.
> 
> Fixes: 5c59002a34f3 ("app/graph: add graph commands")
> Fixes: 984a315a5804 ("app/graph: add parser utility")

NAK
These are only called from graph CLI which must be single threaded



^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH v3 02/22] app/bbdev: replace strtok with reentrant version
  2023-11-14 10:59   ` [PATCH v3 02/22] app/bbdev: " Jie Hai
@ 2023-11-15  0:09     ` Stephen Hemminger
  0 siblings, 0 replies; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-15  0:09 UTC (permalink / raw)
  To: Jie Hai
  Cc: dev, Nicolas Chautru, Maxime Coquelin, Amr Mokhtar, lihuisong,
	fengchengwen

On Tue, 14 Nov 2023 18:59:46 +0800
Jie Hai <haijie1@huawei.com> wrote:

> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant version.
> 
> Fixes: 0acdb9866756 ("test/bbdev: add FFT operations cases")
> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>

NAK
Please don't make wide assertions about multi-threading.
All these are only called from test_bbdev_vector_read which is single
threaded.

Please limit patches to places where you are sure the use is multi-threaded.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* RE: [PATCH 15/21] bus/fslmc: replace strtok with strtok_r
  2023-11-13 10:45 ` [PATCH 15/21] bus/fslmc: " Jie Hai
@ 2023-11-15  2:41   ` Sachin Saxena
  0 siblings, 0 replies; 92+ messages in thread
From: Sachin Saxena @ 2023-11-15  2:41 UTC (permalink / raw)
  To: Jie Hai, dev, Hemant Agrawal; +Cc: lihuisong, fengchengwen

Acked-by: Sachin Saxena <sachin.saxena@nxp.com>

> -----Original Message-----
> From: Jie Hai <haijie1@huawei.com>
> Sent: 13 November 2023 04:16 PM
> To: dev@dpdk.org; Hemant Agrawal <hemant.agrawal@nxp.com>; Sachin
> Saxena <sachin.saxena@nxp.com>
> Cc: haijie1@huawei.com; lihuisong@huawei.com; fengchengwen@huawei.com
> Subject: [PATCH 15/21] bus/fslmc: replace strtok with strtok_r
> 
> Multiple threads calling the same function may cause condition race issues,
> which often leads to abnormal behavior and can cause more serious
> vulnerabilities such as abnormal termination, denial of service, and
> compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a reentrant function.
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> ---
>  drivers/bus/fslmc/fslmc_bus.c            | 5 +++--
>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++--
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
> index 57bfb5111a97..7960ad3979ef 100644
> --- a/drivers/bus/fslmc/fslmc_bus.c
> +++ b/drivers/bus/fslmc/fslmc_bus.c
> @@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name)  {
>  	char *dup_dev_name, *t_ptr;
>  	struct rte_dpaa2_device *dev = NULL;
> +	char *sp = NULL;
>  	int ret = -1;
> 
>  	if (!dev_name)
> @@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name)
>  	}
> 
>  	/* Parse the device name and ID */
> -	t_ptr = strtok(dup_dev_name, ".");
> +	t_ptr = strtok_r(dup_dev_name, ".", &sp);
>  	if (!t_ptr) {
>  		DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
>  		ret = -EINVAL;
> @@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name)
>  	else
>  		dev->dev_type = DPAA2_UNKNOWN;
> 
> -	t_ptr = strtok(NULL, ".");
> +	t_ptr = strtok_r(NULL, ".", &sp);
>  	if (!t_ptr) {
>  		DPAA2_BUS_ERR("Skipping invalid device (%s)",
> dup_dev_name);
>  		ret = 0;
> diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
> b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
> index 4aec7b2cd8ba..09a1a2b23787 100644
> --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
> +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
> @@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t
> dpio_id, int cpu_id)
>  	uint32_t cpu_mask = 1;
>  	int ret;
>  	size_t len = 0;
> -	char *temp = NULL, *token = NULL;
> +	char *temp = NULL, *token = NULL, *sp = NULL;
>  	char string[STRING_LEN], command[COMMAND_LEN];
>  	FILE *file;
> 
> @@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t
> dpio_id, int cpu_id)
>  	}
>  	while (getline(&temp, &len, file) != -1) {
>  		if ((strstr(temp, string)) != NULL) {
> -			token = strtok(temp, ":");
> +			token = strtok_r(temp, ":", &sp);
>  			break;
>  		}
>  	}
> --
> 2.30.0


^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-14 17:49         ` Tyler Retzlaff
@ 2023-11-15  3:02           ` fengchengwen
  2023-11-15 11:27             ` Morten Brørup
  0 siblings, 1 reply; 92+ messages in thread
From: fengchengwen @ 2023-11-15  3:02 UTC (permalink / raw)
  To: Tyler Retzlaff, Jie Hai; +Cc: dev, lihuisong

On 2023/11/15 1:49, Tyler Retzlaff wrote:
> On Tue, Nov 14, 2023 at 09:34:33AM -0800, Tyler Retzlaff wrote:
>> On Tue, Nov 14, 2023 at 09:32:48AM -0800, Tyler Retzlaff wrote:
>>> On Tue, Nov 14, 2023 at 08:50:17PM +0800, Jie Hai wrote:
>>>> On 2023/11/14 1:09, Tyler Retzlaff wrote:
>>>>> On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
>>>>>> Multiple threads calling the same function may cause condition
>>>>>> race issues, which often leads to abnormal behavior and can cause
>>>>>> more serious vulnerabilities such as abnormal termination, denial
>>>>>> of service, and compromised data integrity.
>>>>>>
>>>>>> The strtok() is non-reentrant, it is better to replace it with a
>>>>>> reentrant function.
>>>>>
>>>>> could you please use strtok_s instead of strtok_r the former is part of
>>>>> the C11 standard the latter is not.
>>>>>
>>>>> thanks!
>>>>>
>>>> Hi, Tyler Retzlaff
>>>>
>>>> Thanks for your comment.
>>>>
>>>> For the use of strtok_s, I have consulted some documents, see
>>>> 	https://en.cppreference.com/w/c/string/byte/strtok
>>>> It says
>>>> "As with all bounds-checked functions, strtok_s only guaranteed to be
>>>> available if __STDC_LIB_EXT1__ is defined by the implementation and if
>>>> the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
>>>> including <string.h>.
>>>> "
>>>>
>>>> I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around and
>>>> compiled
>>>> locally and found that __STDC_LIB_EXT1__ was not defined, so the related
>>>> code  was not called. I'm afraid there's a problem with this
>>>> modification.
>>>>
>>>> Am I using strtok_s wrong?
>>>
>>> no i overlooked that it is optional my fault sorry.
>>>
>>> since there is no portable strtok_r i'm going to have to agree with others
>>> that only places where you actually need reentrant strtok be converted to
>>> strtok_r.
>>>
>>> for windows i think we'll either need to introduce an abstracted strtok_r
>>> name for portability or something in the rte_ namespace (dependent on
>>> what other revieweres would prefer)
>>
>> just as a follow up here maybe it would be optimal if we could use
>> strtok_s *if* we test that the toolchain makes it available and if not
>> provide a mapping of strtok_s -> strtok_r.
> 
> just a final follow up, i can see that we already have a rte_strerror
> here to do the replace with reentrant dance. it is probably good to
> follow the already established pattern for this and have a rte_strtok.

+1 for have rte_strtok which could cover different platform.

> 
> what do others think?
>  
>>>
>>> thanks!
>>>
>>>>
>>>> Thanks,
>>>> Jie Hai
>>>>>>
>>>>>> Jie Hai (21):
>>>>>>   app/graph: replace strtok with strtok_r
>>>>>>   app/test-bbdev: replace strtok with strtok_r
>>>>>>   app/test-compress-perf: replace strtok with strtok_r
>>>>>>   app/test-crypto-perf: replace strtok with strtok_r
>>>>>>   app/test-dma-perf: replace strtok with strtok_r
>>>>>>   app/test-fib: replace strtok with strtok_r
>>>>>>   app/dpdk-test-flow-perf: replace strtok with strtok_r
>>>>>>   app/test-mldev: replace strtok with strtok_r
>>>>>>   lib/dmadev: replace strtok with strtok_r
>>>>>>   lib/eal: replace strtok with strtok_r
>>>>>>   lib/ethdev: replace strtok with strtok_r
>>>>>>   lib/eventdev: replace strtok with strtok_r
>>>>>>   lib/telemetry: replace strtok with strtok_r
>>>>>>   lib/telemetry: replace strtok with strtok_r
>>>>>>   bus/fslmc: replace strtok with strtok_r
>>>>>>   common/cnxk: replace strtok with strtok_r
>>>>>>   event/cnxk: replace strtok with strtok_r
>>>>>>   net/ark: replace strtok with strtok_r
>>>>>>   raw/cnxk_gpio: replace strtok with strtok_r
>>>>>>   examples/l2fwd-crypto: replace strtok with strtok_r
>>>>>>   examples/vhost: replace strtok with strtok_r
>>>>>>
>>>>>>  app/graph/graph.c                             |  5 ++-
>>>>>>  app/graph/utils.c                             | 15 +++++---
>>>>>>  app/test-bbdev/test_bbdev_vector.c            | 25 +++++++-----
>>>>>>  .../comp_perf_options_parse.c                 | 16 ++++----
>>>>>>  app/test-crypto-perf/cperf_options_parsing.c  | 16 ++++----
>>>>>>  .../cperf_test_vector_parsing.c               | 10 +++--
>>>>>>  app/test-dma-perf/main.c                      | 13 ++++---
>>>>>>  app/test-fib/main.c                           | 10 ++---
>>>>>>  app/test-flow-perf/main.c                     | 22 ++++++-----
>>>>>>  app/test-mldev/ml_options.c                   | 18 ++++-----
>>>>>>  drivers/bus/fslmc/fslmc_bus.c                 |  5 ++-
>>>>>>  drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  4 +-
>>>>>>  drivers/common/cnxk/cnxk_telemetry_nix.c      | 12 +++---
>>>>>>  drivers/event/cnxk/cnxk_eventdev.c            | 10 +++--
>>>>>>  drivers/event/cnxk/cnxk_tim_evdev.c           | 11 +++---
>>>>>>  drivers/net/ark/ark_pktchkr.c                 | 10 ++---
>>>>>>  drivers/net/ark/ark_pktgen.c                  | 10 ++---
>>>>>>  drivers/raw/cnxk_gpio/cnxk_gpio.c             |  6 +--
>>>>>>  examples/l2fwd-crypto/main.c                  |  6 +--
>>>>>>  examples/vhost/main.c                         |  3 +-
>>>>>>  lib/dmadev/rte_dmadev.c                       |  4 +-
>>>>>>  lib/eal/common/eal_common_memory.c            |  8 ++--
>>>>>>  lib/ethdev/rte_ethdev_telemetry.c             |  6 ++-
>>>>>>  lib/eventdev/rte_event_eth_rx_adapter.c       | 38 +++++++++----------
>>>>>>  lib/eventdev/rte_eventdev.c                   | 18 ++++-----
>>>>>>  lib/security/rte_security.c                   |  3 +-
>>>>>>  lib/telemetry/telemetry.c                     |  5 ++-
>>>>>>  27 files changed, 169 insertions(+), 140 deletions(-)
>>>>>>
>>>>>> -- 
>>>>>> 2.30.0
>>>>> .
> .
> 

^ permalink raw reply	[flat|nested] 92+ messages in thread

* RE: [EXT] [PATCH v3 10/22] eal: replace strtok with reentrant version
  2023-11-14 10:59   ` [PATCH v3 10/22] eal: " Jie Hai
@ 2023-11-15  7:17     ` Amit Prakash Shukla
  0 siblings, 0 replies; 92+ messages in thread
From: Amit Prakash Shukla @ 2023-11-15  7:17 UTC (permalink / raw)
  To: Jie Hai, dev, Anatoly Burakov; +Cc: lihuisong, fengchengwen

> -----Original Message-----
> From: Jie Hai <haijie1@huawei.com>
> Sent: Tuesday, November 14, 2023 4:30 PM
> To: dev@dpdk.org; Anatoly Burakov <anatoly.burakov@intel.com>; Amit
> Prakash Shukla <amitprakashs@marvell.com>
> Cc: haijie1@huawei.com; lihuisong@huawei.com;
> fengchengwen@huawei.com
> Subject: [EXT] [PATCH v3 10/22] eal: replace strtok with reentrant version
> 
> External Email
> 
> ----------------------------------------------------------------------
> Multiple threads calling the same function may cause condition race issues,
> which often leads to abnormal behavior and can cause more serious
> vulnerabilities such as abnormal termination, denial of service, and
> compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a reentrant
> version.
> 
> Fixes: 2054f31a1fcd ("mem: add memseg info in telemetry")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>
> ---
>  lib/eal/common/eal_common_memory.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/eal/common/eal_common_memory.c
> b/lib/eal/common/eal_common_memory.c
> index d9433db62345..a05eb0442b0b 100644
> --- a/lib/eal/common/eal_common_memory.c
> +++ b/lib/eal/common/eal_common_memory.c
> @@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t
> *vals, size_t n_vals)
>  	char dlim[2] = ",";
>  	char *params_args;
>  	size_t count = 0;
> -	char *token;
> +	char *token, *sp = NULL;
> 
>  	if (vals == NULL || params == NULL || strlen(params) == 0)
>  		return -1;
> 
> -	/* strtok expects char * and param is const char *. Hence on using
> +	/* strtok_r expects char * and param is const char *. Hence on using
>  	 * params as "const char *" compiler throws warning.
>  	 */
>  	params_args = strdup(params);
>  	if (params_args == NULL)
>  		return -1;
> 
> -	token = strtok(params_args, dlim);
> +	token = strtok_r(params_args, dlim, &sp);
>  	while (token && isdigit(*token) && count < n_vals) {
>  		vals[count++] = strtoul(token, NULL, 10);
> -		token = strtok(NULL, dlim);
> +		token = strtok_r(NULL, dlim, &sp);
>  	}
> 
>  	free(params_args);
> --
> 2.30.0

Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com>

^ permalink raw reply	[flat|nested] 92+ messages in thread

* RE: [PATCH 00/21] replace strtok with strtok_r
  2023-11-15  3:02           ` fengchengwen
@ 2023-11-15 11:27             ` Morten Brørup
  2023-11-15 15:08               ` Stephen Hemminger
  0 siblings, 1 reply; 92+ messages in thread
From: Morten Brørup @ 2023-11-15 11:27 UTC (permalink / raw)
  To: fengchengwen, Tyler Retzlaff, Jie Hai; +Cc: dev, lihuisong

> From: fengchengwen [mailto:fengchengwen@huawei.com]
> Sent: Wednesday, 15 November 2023 04.03
> 
> On 2023/11/15 1:49, Tyler Retzlaff wrote:
> > On Tue, Nov 14, 2023 at 09:34:33AM -0800, Tyler Retzlaff wrote:
> >> On Tue, Nov 14, 2023 at 09:32:48AM -0800, Tyler Retzlaff wrote:
> >>> On Tue, Nov 14, 2023 at 08:50:17PM +0800, Jie Hai wrote:
> >>>> On 2023/11/14 1:09, Tyler Retzlaff wrote:
> >>>>> On Mon, Nov 13, 2023 at 06:45:29PM +0800, Jie Hai wrote:
> >>>>>> Multiple threads calling the same function may cause condition
> >>>>>> race issues, which often leads to abnormal behavior and can
> cause
> >>>>>> more serious vulnerabilities such as abnormal termination,
> denial
> >>>>>> of service, and compromised data integrity.
> >>>>>>
> >>>>>> The strtok() is non-reentrant, it is better to replace it with a
> >>>>>> reentrant function.
> >>>>>
> >>>>> could you please use strtok_s instead of strtok_r the former is
> part of
> >>>>> the C11 standard the latter is not.
> >>>>>
> >>>>> thanks!
> >>>>>
> >>>> Hi, Tyler Retzlaff
> >>>>
> >>>> Thanks for your comment.
> >>>>
> >>>> For the use of strtok_s, I have consulted some documents, see
> >>>> 	https://en.cppreference.com/w/c/string/byte/strtok
> >>>> It says
> >>>> "As with all bounds-checked functions, strtok_s only guaranteed to
> be
> >>>> available if __STDC_LIB_EXT1__ is defined by the implementation
> and if
> >>>> the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1
> before
> >>>> including <string.h>.
> >>>> "
> >>>>
> >>>> I use strtok_s with "#ifdef __STDC_LIB_EXT1__ ... #endif" around
> and
> >>>> compiled
> >>>> locally and found that __STDC_LIB_EXT1__ was not defined, so the
> related
> >>>> code  was not called. I'm afraid there's a problem with this
> >>>> modification.
> >>>>
> >>>> Am I using strtok_s wrong?
> >>>
> >>> no i overlooked that it is optional my fault sorry.
> >>>
> >>> since there is no portable strtok_r i'm going to have to agree with
> others
> >>> that only places where you actually need reentrant strtok be
> converted to
> >>> strtok_r.
> >>>
> >>> for windows i think we'll either need to introduce an abstracted
> strtok_r
> >>> name for portability or something in the rte_ namespace (dependent
> on
> >>> what other revieweres would prefer)
> >>
> >> just as a follow up here maybe it would be optimal if we could use
> >> strtok_s *if* we test that the toolchain makes it available and if
> not
> >> provide a mapping of strtok_s -> strtok_r.
> >
> > just a final follow up, i can see that we already have a rte_strerror
> > here to do the replace with reentrant dance. it is probably good to
> > follow the already established pattern for this and have a
> rte_strtok.
> 
> +1 for have rte_strtok which could cover different platform.

+1 to rte_strtok doing the reentrant dance for us.

If we had such an rte_strtok(), we could also generally disallow the use of strtok().

> 
> >
> > what do others think?
> >

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-15 11:27             ` Morten Brørup
@ 2023-11-15 15:08               ` Stephen Hemminger
  2023-11-21  3:32                 ` Jie Hai
  0 siblings, 1 reply; 92+ messages in thread
From: Stephen Hemminger @ 2023-11-15 15:08 UTC (permalink / raw)
  To: Morten Brørup; +Cc: fengchengwen, Tyler Retzlaff, Jie Hai, dev, lihuisong

On Wed, 15 Nov 2023 12:27:37 +0100
Morten Brørup <mb@smartsharesystems.com> wrote:

> > > just a final follow up, i can see that we already have a rte_strerror
> > > here to do the replace with reentrant dance. it is probably good to
> > > follow the already established pattern for this and have a  
> > rte_strtok.
> > 
> > +1 for have rte_strtok which could cover different platform.  
> 
> +1 to rte_strtok doing the reentrant dance for us.
> 
> If we had such an rte_strtok(), we could also generally disallow the use of strtok().

Good idea, I like this.
Would be good to have a version on Windows as well.

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-15 15:08               ` Stephen Hemminger
@ 2023-11-21  3:32                 ` Jie Hai
  2024-02-01 11:13                   ` David Marchand
  0 siblings, 1 reply; 92+ messages in thread
From: Jie Hai @ 2023-11-21  3:32 UTC (permalink / raw)
  To: Stephen Hemminger, Morten Brørup
  Cc: fengchengwen, Tyler Retzlaff, dev, lihuisong

On 2023/11/15 23:08, Stephen Hemminger wrote:
> On Wed, 15 Nov 2023 12:27:37 +0100
> Morten Brørup <mb@smartsharesystems.com> wrote:
> 
>>>> just a final follow up, i can see that we already have a rte_strerror
>>>> here to do the replace with reentrant dance. it is probably good to
>>>> follow the already established pattern for this and have a
>>> rte_strtok.
>>>
>>> +1 for have rte_strtok which could cover different platform.
>>
>> +1 to rte_strtok doing the reentrant dance for us.
>>
>> If we had such an rte_strtok(), we could also generally disallow the use of strtok().
> 
> Good idea, I like this.
> Would be good to have a version on Windows as well.
> 
> .
Hi, all maintainers,

Since the map of strtok_r to strtok_s with three patramaters has
been done in "rte_os_shim.h", I just include this file.
And the rte_strtok is defined as below.
My question is whether the
"strtok_s(s, stringlen, delim, save_ptr)" and
"strtok_s(str, delim, saveptr)" are compatible for C11.

And I check the glibc codes here,
https://sourceware.org/git/glibc.git
there is no definition of strtok_s, is strtok_s not in use?

If so, should we delayed processing for the C11 standard strtok_s 
function? That is, delete the "#ifdef __STDC_LIB_EXT1__...
#endif" part, but keep the extension of the four parameters for later 
use. Or keep the following change but never use stringlen as not null
until the function can be used.

What do you think?

diff --git a/lib/eal/include/rte_string_fns.h 
b/lib/eal/include/rte_string_fns.h
index bb43b2cba3eb..6746bfec384b 100644
--- a/lib/eal/include/rte_string_fns.h
+++ b/lib/eal/include/rte_string_fns.h
@@ -15,10 +15,13 @@
  extern "C" {
  #endif

+#define __STDC_WANT_LIB_EXT1__ 1
  #include <stdio.h>
  #include <string.h>

  #include <rte_common.h>
+#include <rte_compat.h>
+#include <rte_os_shim.h>

  /**
   * Takes string "string" parameter and splits it at character "delim"
@@ -115,6 +118,35 @@ rte_strlcat(char *dst, const char *src, size_t size)
  ssize_t
  rte_strscpy(char *dst, const char *src, size_t dsize);

+/*
+ * Divide string s into tokens separated by characters in delim.
+ * Information passed between calls are stored in save_ptr.
+ * The size of the string to be separated is stored in *stringlen.
+ *
+ * @param s
+ *   The string to be separated, it could be NULL.
+ *
+ * @param stringlen
+ *   The pointor to the size of the string to be separated, it could be 
NULL.
+ *
+ * @param delim
+ *   The characters on which the split of the data will be done.
+ *
+ * @param save_ptr
+ *   The internal state of the string separated.
+ */
+static inline char *
+rte_strtok(char *__rte_restrict s, size_t *__rte_restrict stringlen,
+          const char *__rte_restrict delim,
+          char **__rte_restrict save_ptr)
+{
+#ifdef __STDC_LIB_EXT1__
+	if (stringlen != NULL)
+		return strtok_s(s, stringlen, delim, save_ptr);

+#endif
+       (void)stringlen;
+       return strtok_r(s, delim, save_ptr);
+}
+
  #ifdef __cplusplus
  }
  #endif

Thanks,
Jie Hai

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH v3 11/22] ethdev: replace strtok with reentrant version
  2023-11-14 10:59   ` [PATCH v3 11/22] ethdev: " Jie Hai
@ 2023-12-16 10:01     ` Andrew Rybchenko
  0 siblings, 0 replies; 92+ messages in thread
From: Andrew Rybchenko @ 2023-12-16 10:01 UTC (permalink / raw)
  To: Jie Hai, dev, Thomas Monjalon, Ferruh Yigit; +Cc: lihuisong, fengchengwen

On 11/14/23 13:59, Jie Hai wrote:
> Multiple threads calling the same function may cause condition
> race issues, which often leads to abnormal behavior and can cause
> more serious vulnerabilities such as abnormal termination, denial
> of service, and compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a
> reentrant version.
> 
> Fixes: f38f62650f7b ("ethdev: add Rx queue telemetry query")
> Fixes: 9e7533aeb80a ("ethdev: add telemetry command for TM level capabilities")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>

Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>



^ permalink raw reply	[flat|nested] 92+ messages in thread

* RE: [PATCH v2 04/22] app/crypto-perf: replace strtok with reentrant version
  2023-11-14  8:41   ` [PATCH v2 04/22] app/crypto-perf: " Jie Hai
@ 2024-01-11 17:10     ` Power, Ciara
  0 siblings, 0 replies; 92+ messages in thread
From: Power, Ciara @ 2024-01-11 17:10 UTC (permalink / raw)
  To: Jie Hai, dev, Sergio Gonzalez Monroy, De Lara Guarch, Pablo,
	Piotr Azarewicz, Kobylinski, Michal, Mrozowicz, SlawomirX,
	Kerlin, Marcin, Doherty, Declan
  Cc: lihuisong, fengchengwen

Hi Jie Hai,

> -----Original Message-----
> From: Jie Hai <haijie1@huawei.com>
> Sent: Tuesday, November 14, 2023 8:41 AM
> To: dev@dpdk.org; Power, Ciara <ciara.power@intel.com>; Sergio Gonzalez
> Monroy <sergio.gonzalez.monroy@intel.com>; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Piotr Azarewicz
> <piotr.azarewicz@intel.com>; Kobylinski, Michal
> <michal.kobylinski@intel.com>; Mrozowicz, SlawomirX
> <slawomirx.mrozowicz@intel.com>; Kerlin, Marcin <marcin.kerlin@intel.com>;
> Doherty, Declan <declan.doherty@intel.com>
> Cc: haijie1@huawei.com; lihuisong@huawei.com;
> fengchengwen@huawei.com
> Subject: [PATCH v2 04/22] app/crypto-perf: replace strtok with reentrant
> version
> 
> Multiple threads calling the same function may cause condition race issues,
> which often leads to abnormal behavior and can cause more serious
> vulnerabilities such as abnormal termination, denial of service, and
> compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a reentrant version.
> 
> Fixes: f6cefe253cc8 ("app/crypto-perf: add range/list of sizes")
> Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>

Acked-by: Ciara Power <ciara.power@intel.com>

^ permalink raw reply	[flat|nested] 92+ messages in thread

* RE: [PATCH v2 14/22] telemetry: replace strtok with reentrant version
  2023-11-14  8:41   ` [PATCH v2 14/22] telemetry: " Jie Hai
@ 2024-01-11 17:13     ` Power, Ciara
  0 siblings, 0 replies; 92+ messages in thread
From: Power, Ciara @ 2024-01-11 17:13 UTC (permalink / raw)
  To: Jie Hai, dev, Wiles, Keith, Richardson, Bruce; +Cc: lihuisong, fengchengwen



> -----Original Message-----
> From: Jie Hai <haijie1@huawei.com>
> Sent: Tuesday, November 14, 2023 8:41 AM
> To: dev@dpdk.org; Power, Ciara <ciara.power@intel.com>; Wiles, Keith
> <keith.wiles@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
> Cc: haijie1@huawei.com; lihuisong@huawei.com;
> fengchengwen@huawei.com
> Subject: [PATCH v2 14/22] telemetry: replace strtok with reentrant version
> 
> Multiple threads calling the same function may cause condition race issues,
> which often leads to abnormal behavior and can cause more serious
> vulnerabilities such as abnormal termination, denial of service, and
> compromised data integrity.
> 
> The strtok() is non-reentrant, it is better to replace it with a reentrant version.
> 
> Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jie Hai <haijie1@huawei.com>
> Acked-by: Chengwen Feng <fengchengwen@huawei.com>
> ---

Acked-by: Ciara Power <ciara.power@intel.com>

^ permalink raw reply	[flat|nested] 92+ messages in thread

* Re: [PATCH 00/21] replace strtok with strtok_r
  2023-11-21  3:32                 ` Jie Hai
@ 2024-02-01 11:13                   ` David Marchand
  0 siblings, 0 replies; 92+ messages in thread
From: David Marchand @ 2024-02-01 11:13 UTC (permalink / raw)
  To: Jie Hai, Stephen Hemminger, Tyler Retzlaff
  Cc: Morten Brørup, fengchengwen, dev, lihuisong

On Tue, Nov 21, 2023 at 4:33 AM Jie Hai <haijie1@huawei.com> wrote:
>
> On 2023/11/15 23:08, Stephen Hemminger wrote:
> > On Wed, 15 Nov 2023 12:27:37 +0100
> > Morten Brørup <mb@smartsharesystems.com> wrote:
> >
> >>>> just a final follow up, i can see that we already have a rte_strerror
> >>>> here to do the replace with reentrant dance. it is probably good to
> >>>> follow the already established pattern for this and have a
> >>> rte_strtok.
> >>>
> >>> +1 for have rte_strtok which could cover different platform.
> >>
> >> +1 to rte_strtok doing the reentrant dance for us.
> >>
> >> If we had such an rte_strtok(), we could also generally disallow the use of strtok().
> >
> > Good idea, I like this.
> > Would be good to have a version on Windows as well.
> >
> > .
> Hi, all maintainers,
>
> Since the map of strtok_r to strtok_s with three patramaters has
> been done in "rte_os_shim.h", I just include this file.
> And the rte_strtok is defined as below.
> My question is whether the
> "strtok_s(s, stringlen, delim, save_ptr)" and
> "strtok_s(str, delim, saveptr)" are compatible for C11.
>
> And I check the glibc codes here,
> https://sourceware.org/git/glibc.git
> there is no definition of strtok_s, is strtok_s not in use?
>
> If so, should we delayed processing for the C11 standard strtok_s
> function? That is, delete the "#ifdef __STDC_LIB_EXT1__...
> #endif" part, but keep the extension of the four parameters for later
> use. Or keep the following change but never use stringlen as not null
> until the function can be used.
>
> What do you think?

Regardless of how it is done internally, I would not inline this helper.
This will minimise headaches with checks against toolchain/compiler
support in a DPDK header.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 92+ messages in thread

end of thread, other threads:[~2024-02-01 11:13 UTC | newest]

Thread overview: 92+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai
2023-11-13 10:45 ` [PATCH 01/21] app/graph: " Jie Hai
2023-11-13 10:45 ` [PATCH 02/21] app/test-bbdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 03/21] app/test-compress-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 04/21] app/test-crypto-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 05/21] app/test-dma-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 06/21] app/test-fib: " Jie Hai
2023-11-13 10:45 ` [PATCH 07/21] app/dpdk-test-flow-perf: " Jie Hai
2023-11-13 10:45 ` [PATCH 08/21] app/test-mldev: " Jie Hai
2023-11-13 10:45 ` [PATCH 09/21] lib/dmadev: " Jie Hai
2023-11-13 10:45 ` [PATCH 10/21] lib/eal: " Jie Hai
2023-11-13 16:27   ` Stephen Hemminger
2023-11-14  1:05     ` fengchengwen
2023-11-14  1:08       ` Stephen Hemminger
2023-11-13 10:45 ` [PATCH 11/21] lib/ethdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 12/21] lib/eventdev: " Jie Hai
2023-11-13 10:45 ` [PATCH 13/21] lib/telemetry: " Jie Hai
2023-11-13 10:45 ` [PATCH 14/21] " Jie Hai
2023-11-13 10:45 ` [PATCH 15/21] bus/fslmc: " Jie Hai
2023-11-15  2:41   ` Sachin Saxena
2023-11-13 10:45 ` [PATCH 16/21] common/cnxk: " Jie Hai
2023-11-13 10:45 ` [PATCH 17/21] event/cnxk: " Jie Hai
2023-11-13 10:45 ` [PATCH 18/21] net/ark: " Jie Hai
2023-11-13 10:45 ` [PATCH 19/21] raw/cnxk_gpio: " Jie Hai
2023-11-13 10:45 ` [PATCH 20/21] examples/l2fwd-crypto: " Jie Hai
2023-11-13 10:45 ` [PATCH 21/21] examples/vhost: " Jie Hai
2023-11-13 16:26   ` Stephen Hemminger
2023-11-13 11:00 ` [PATCH 00/21] " Thomas Monjalon
2023-11-13 11:33 ` fengchengwen
2023-11-13 16:25 ` Stephen Hemminger
2023-11-13 17:09 ` Tyler Retzlaff
2023-11-14 12:50   ` Jie Hai
2023-11-14 17:32     ` Tyler Retzlaff
2023-11-14 17:34       ` Tyler Retzlaff
2023-11-14 17:49         ` Tyler Retzlaff
2023-11-15  3:02           ` fengchengwen
2023-11-15 11:27             ` Morten Brørup
2023-11-15 15:08               ` Stephen Hemminger
2023-11-21  3:32                 ` Jie Hai
2024-02-01 11:13                   ` David Marchand
2023-11-14  8:41 ` [PATCH v2 00/22] replace strtok with reentrant version Jie Hai
2023-11-14  8:41   ` [PATCH v2 01/22] app/graph: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 02/22] app/bbdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 03/22] app/compress-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 04/22] app/crypto-perf: " Jie Hai
2024-01-11 17:10     ` Power, Ciara
2023-11-14  8:41   ` [PATCH v2 05/22] app/dma-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 06/22] app/test-fib: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 07/22] app/flow-perf: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 08/22] app/test-mldev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 09/22] dmadev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 10/22] eal: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 11/22] ethdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 12/22] eventdev: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 13/22] security: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 14/22] telemetry: " Jie Hai
2024-01-11 17:13     ` Power, Ciara
2023-11-14  8:41   ` [PATCH v2 15/22] bus/fslmc: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 16/22] common/cnxk: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 17/22] event/cnxk: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 18/22] net/ark: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 19/22] raw/cnxk_gpio: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 20/22] examples/l2fwd-crypto: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 21/22] examples/vhost: " Jie Hai
2023-11-14  8:41   ` [PATCH v2 22/22] devtools: check for some reentrant function Jie Hai
2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai
2023-11-14 10:59   ` [PATCH v3 01/22] app/graph: " Jie Hai
2023-11-15  0:07     ` Stephen Hemminger
2023-11-14 10:59   ` [PATCH v3 02/22] app/bbdev: " Jie Hai
2023-11-15  0:09     ` Stephen Hemminger
2023-11-14 10:59   ` [PATCH v3 03/22] app/compress-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 04/22] app/crypto-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 05/22] app/dma-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 06/22] app/test-fib: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 07/22] app/flow-perf: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 08/22] app/test-mldev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 09/22] dmadev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 10/22] eal: " Jie Hai
2023-11-15  7:17     ` [EXT] " Amit Prakash Shukla
2023-11-14 10:59   ` [PATCH v3 11/22] ethdev: " Jie Hai
2023-12-16 10:01     ` Andrew Rybchenko
2023-11-14 10:59   ` [PATCH v3 12/22] eventdev: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 13/22] security: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 14/22] telemetry: " Jie Hai
2023-11-14 10:59   ` [PATCH v3 15/22] bus/fslmc: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 16/22] common/cnxk: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 17/22] event/cnxk: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 18/22] net/ark: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 19/22] raw/cnxk_gpio: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 20/22] examples/l2fwd-crypto: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 21/22] examples/vhost: " Jie Hai
2023-11-14 11:00   ` [PATCH v3 22/22] devtools: check for some reentrant function Jie Hai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).