* [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 ` (28 more replies) 0 siblings, 29 replies; 152+ 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] 152+ 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 ` (27 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (26 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (25 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (24 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (23 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (22 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (21 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (20 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (19 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (18 subsequent siblings) 28 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (17 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (16 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (15 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (14 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (13 subsequent siblings) 28 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (12 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (11 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (10 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (9 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (8 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (7 subsequent siblings) 28 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (6 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (5 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (4 subsequent siblings) 28 siblings, 0 replies; 152+ 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] 152+ 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 ` (3 subsequent siblings) 28 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (2 subsequent siblings) 28 siblings, 22 replies; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (22 more replies) 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai 28 siblings, 23 replies; 152+ 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] 152+ 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 ` (21 subsequent siblings) 22 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (20 subsequent siblings) 22 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (19 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (18 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (17 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (16 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (15 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (14 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (13 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (12 subsequent siblings) 22 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (11 subsequent siblings) 22 siblings, 1 reply; 152+ 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] 152+ 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; 152+ 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] 152+ 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 ` (10 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (9 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (8 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (7 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (6 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (5 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (4 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (3 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 ` (2 subsequent siblings) 22 siblings, 0 replies; 152+ 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] 152+ 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 2024-10-22 10:46 ` [PATCH v3 00/22] replace strtok with reentrant version Morten Brørup 22 siblings, 0 replies; 152+ 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] 152+ 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 2024-10-22 10:46 ` [PATCH v3 00/22] replace strtok with reentrant version Morten Brørup 22 siblings, 0 replies; 152+ 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] 152+ messages in thread
* RE: [PATCH v3 00/22] replace strtok with reentrant version 2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai ` (21 preceding siblings ...) 2023-11-14 11:00 ` [PATCH v3 22/22] devtools: check for some reentrant function Jie Hai @ 2024-10-22 10:46 ` Morten Brørup 22 siblings, 0 replies; 152+ messages in thread From: Morten Brørup @ 2024-10-22 10:46 UTC (permalink / raw) To: Jie Hai, dev; +Cc: lihuisong, fengchengwen > From: Jie Hai [mailto:haijie1@huawei.com] > Sent: Tuesday, 14 November 2023 12.00 > > 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 Typo: strtok_s -> strtok_r > 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. > -- +1 to doing this, also in functions that are supposed to be single threaded; because it allows the addition to checkpatches. Acked-by: Morten Brørup <mb@smartsharesystems.com> ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 00/13] replace strtok with reentrant version 2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai ` (26 preceding siblings ...) 2023-11-14 10:59 ` [PATCH v3 00/22] replace strtok with reentrant version Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-26 10:14 ` [PATCH v4 01/13] dmadev: " Jie Hai ` (14 more replies) 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai 28 siblings, 15 replies; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit; +Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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_r in app, example, lib and drivers. And adds check for use of strtok in checkpatches.sh. -- v4: 1. fix mispellings. 2. add Acked-bys and Reviewd-bys. 3. remove some patch and add new. 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 (13): 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 net/cnxk: replace strtok with reentrant version devtools: check for some reentrant function 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/net/cnxk/cnxk_ethdev_sec_telemetry.c | 5 +-- drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 ++-- lib/dmadev/rte_dmadev.c | 4 +-- lib/eal/common/eal_common_memory.c | 8 ++--- lib/ethdev/rte_ethdev_telemetry.c | 9 +++-- 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 +-- 17 files changed, 92 insertions(+), 74 deletions(-) -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 01/13] dmadev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:00 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 02/13] eal: " Jie Hai ` (13 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson, Conor Walsh, Sean Morrissey Cc: lihuisong, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 8bb7824aa129..5c5ac78ae9c4 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -1016,7 +1016,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)) @@ -1035,7 +1035,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 01/13] dmadev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 01/13] dmadev: " Jie Hai @ 2024-10-27 3:00 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:00 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson, Conor Walsh, Sean Morrissey, lihuisong, huangdengdui On Sat, 26 Oct 2024 18:14: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. > > 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> > Acked-by: Morten Brørup <mb@smartsharesystems.com> No reason to bother stable with this one. That function is only called from RTE_INIT() which is a constructor. ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai 2024-10-26 10:14 ` [PATCH v4 01/13] dmadev: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:00 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 03/13] ethdev: " Jie Hai ` (12 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> Acked-by: Morten Brørup <mb@smartsharesystems.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 a185e0b580c7..ace63313ea75 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -1275,22 +1275,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 02/13] eal: " Jie Hai @ 2024-10-27 3:00 ` Stephen Hemminger 2024-10-28 13:04 ` fengchengwen 0 siblings, 1 reply; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:00 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:40 +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: 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> > Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> > Acked-by: Morten Brørup <mb@smartsharesystems.com> This doesn't need to go to stable. parse_params is always single threaded. ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-27 3:00 ` Stephen Hemminger @ 2024-10-28 13:04 ` fengchengwen 2024-10-28 15:31 ` Stephen Hemminger 0 siblings, 1 reply; 152+ messages in thread From: fengchengwen @ 2024-10-28 13:04 UTC (permalink / raw) To: Stephen Hemminger, Jie Hai Cc: dev, thomas, ferruh.yigit, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, huangdengdui On 2024/10/27 11:00, Stephen Hemminger wrote: > On Sat, 26 Oct 2024 18:14:40 +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: 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> >> Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> >> Acked-by: Morten Brørup <mb@smartsharesystems.com> > > This doesn't need to go to stable. parse_params is always single threaded. I recommend replacing all, based on: 1\ almost at no cost. 2\ reduce analysis costs, if don't we have to analyze the callers of strtok when you encounter it. ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-28 13:04 ` fengchengwen @ 2024-10-28 15:31 ` Stephen Hemminger 2024-10-29 0:56 ` fengchengwen 0 siblings, 1 reply; 152+ messages in thread From: Stephen Hemminger @ 2024-10-28 15:31 UTC (permalink / raw) To: fengchengwen Cc: Jie Hai, dev, thomas, ferruh.yigit, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, huangdengdui On Mon, 28 Oct 2024 21:04:08 +0800 fengchengwen <fengchengwen@huawei.com> wrote: > On 2024/10/27 11:00, Stephen Hemminger wrote: > > On Sat, 26 Oct 2024 18:14:40 +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: 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> > >> Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> > >> Acked-by: Morten Brørup <mb@smartsharesystems.com> > > > > This doesn't need to go to stable. parse_params is always single threaded. > > I recommend replacing all, based on: > 1\ almost at no cost. > 2\ reduce analysis costs, if don't we have to analyze the callers of strtok when you encounter it. > Yes but. The replacement should not go to stable. One of the rules of stable is that changes should be minimized, and fixes should not be accepted for things that can not ever happen with current code. ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-28 15:31 ` Stephen Hemminger @ 2024-10-29 0:56 ` fengchengwen 2024-10-29 2:51 ` Stephen Hemminger 0 siblings, 1 reply; 152+ messages in thread From: fengchengwen @ 2024-10-29 0:56 UTC (permalink / raw) To: Stephen Hemminger, Ferruh Yigit, Thomas Monjalon Cc: Jie Hai, dev, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, huangdengdui On 2024/10/28 23:31, Stephen Hemminger wrote: > On Mon, 28 Oct 2024 21:04:08 +0800 > fengchengwen <fengchengwen@huawei.com> wrote: > >> On 2024/10/27 11:00, Stephen Hemminger wrote: >>> On Sat, 26 Oct 2024 18:14:40 +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: 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> >>>> Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> >>>> Acked-by: Morten Brørup <mb@smartsharesystems.com> >>> >>> This doesn't need to go to stable. parse_params is always single threaded. >> >> I recommend replacing all, based on: >> 1\ almost at no cost. >> 2\ reduce analysis costs, if don't we have to analyze the callers of strtok when you encounter it. >> > > Yes but. The replacement should not go to stable. > One of the rules of stable is that changes should be minimized, and fixes should > not be accepted for things that can not ever happen with current code. Hope more opinion from TB members. ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-29 0:56 ` fengchengwen @ 2024-10-29 2:51 ` Stephen Hemminger 2024-11-07 12:29 ` Jie Hai 0 siblings, 1 reply; 152+ messages in thread From: Stephen Hemminger @ 2024-10-29 2:51 UTC (permalink / raw) To: fengchengwen Cc: Ferruh Yigit, Thomas Monjalon, Jie Hai, dev, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, huangdengdui On Tue, 29 Oct 2024 08:56:20 +0800 fengchengwen <fengchengwen@huawei.com> wrote: > >>> > >>> This doesn't need to go to stable. parse_params is always single threaded. > >> > >> I recommend replacing all, based on: > >> 1\ almost at no cost. > >> 2\ reduce analysis costs, if don't we have to analyze the callers of strtok when you encounter it. > >> > > > > Yes but. The replacement should not go to stable. > > One of the rules of stable is that changes should be minimized, and fixes should > > not be accepted for things that can not ever happen with current code. > > Hope more opinion from TB members. My assumption is that DPDK operates under similar rules as the Linux kernel. Linux kernel rules are: Rules on what kind of patches are accepted, and which ones are not, into the “-stable” tree: • It or an equivalent fix must already exist in Linux mainline (upstream). • It must be obviously correct and tested. • It cannot be bigger than 100 lines, with context. • It must follow the Documentation/process/submitting-patches.rst rules. • It must either fix a real bug that bothers people or just add a device ID. To elaborate on the former: ◦ It fixes a problem like an oops, a hang, data corruption, a real security issue, a hardware quirk, a build error (but not for things marked CONFIG_BROKEN), or some “oh, that’s not good” issue. ◦ Serious issues as reported by a user of a distribution kernel may also be considered if they fix a notable performance or interactivity issue. As these fixes are not as obvious and have a higher risk of a subtle regression they should only be submitted by a distribution kernel maintainer and include an addendum linking to a bugzilla entry if it exists and additional information on the user-visible impact. ◦ No “This could be a problem...” type of things like a “theoretical race condition”, unless an explanation of how the bug can be exploited is also provided. ◦ No “trivial” fixes without benefit for users (spelling changes, whitespace cleanups, etc). ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 02/13] eal: replace strtok with reentrant version 2024-10-29 2:51 ` Stephen Hemminger @ 2024-11-07 12:29 ` Jie Hai 0 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-07 12:29 UTC (permalink / raw) To: Stephen Hemminger, fengchengwen Cc: Ferruh Yigit, Thomas Monjalon, dev, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla, lihuisong, huangdengdui Hi, Stephen Hemminger, Thanks for your reviews. I'll replace all strtok with strtok_r, and Cc to stable only the necessary ones. Best regards, Jie Hai On 2024/10/29 10:51, Stephen Hemminger wrote: > On Tue, 29 Oct 2024 08:56:20 +0800 > fengchengwen <fengchengwen@huawei.com> wrote: > >>>>> >>>>> This doesn't need to go to stable. parse_params is always single threaded. >>>> >>>> I recommend replacing all, based on: >>>> 1\ almost at no cost. >>>> 2\ reduce analysis costs, if don't we have to analyze the callers of strtok when you encounter it. >>>> >>> >>> Yes but. The replacement should not go to stable. >>> One of the rules of stable is that changes should be minimized, and fixes should >>> not be accepted for things that can not ever happen with current code. >> >> Hope more opinion from TB members. > > My assumption is that DPDK operates under similar rules as the Linux kernel. > Linux kernel rules are: > > Rules on what kind of patches are accepted, and which ones are not, into the “-stable” tree: > • It or an equivalent fix must already exist in Linux mainline (upstream). > • It must be obviously correct and tested. > • It cannot be bigger than 100 lines, with context. > • It must follow the Documentation/process/submitting-patches.rst rules. > • It must either fix a real bug that bothers people or just add a device ID. To elaborate on the former: > ◦ It fixes a problem like an oops, a hang, data corruption, a real security issue, a hardware quirk, a build error (but not for things marked CONFIG_BROKEN), or some “oh, that’s not good” issue. > ◦ Serious issues as reported by a user of a distribution kernel may also be considered if they fix a notable performance or interactivity issue. As these fixes are not as obvious and have a higher risk of a subtle regression they should only be submitted by a distribution kernel maintainer and include an addendum linking to a bugzilla entry if it exists and additional information on the user-visible impact. > ◦ No “This could be a problem...” type of things like a “theoretical race condition”, unless an explanation of how the bug can be exploited is also provided. > ◦ No “trivial” fixes without benefit for users (spelling changes, whitespace cleanups, etc). > . ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 03/13] ethdev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai 2024-10-26 10:14 ` [PATCH v4 01/13] dmadev: " Jie Hai 2024-10-26 10:14 ` [PATCH v4 02/13] eal: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:01 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 04/13] eventdev: " Jie Hai ` (11 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Andrew Rybchenko Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- lib/ethdev/rte_ethdev_telemetry.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index 5e6c4172d3be..0362b1b46d4a 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; @@ -1510,13 +1512,14 @@ eth_dev_handle_port_regs(const char *cmd __rte_unused, { char *filter, *end_param; uint16_t port_id; + char *sp = NULL; int ret; ret = eth_dev_parse_port_params(params, &port_id, &end_param, true); if (ret != 0) return ret; - filter = strtok(end_param, ","); + filter = strtok_r(end_param, ",", &sp); if (filter != NULL && strlen(filter) == 0) filter = NULL; -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 03/13] ethdev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 03/13] ethdev: " Jie Hai @ 2024-10-27 3:01 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:01 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Andrew Rybchenko, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:41 +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: 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> > Acked-by: Morten Brørup <mb@smartsharesystems.com> Only called from RTE_INIT() so naturally single threaded. No need for this one in stable. ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 04/13] eventdev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (2 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 03/13] ethdev: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:02 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 05/13] security: " Jie Hai ` (10 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Naga Harish K S V, Jerin Jacob Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 3ee20d95f372..da864a8e1593 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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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 ca295c87c47d..d3dacffdfab2 100644 --- a/lib/eventdev/rte_eventdev.c +++ b/lib/eventdev/rte_eventdev.c @@ -1787,7 +1787,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]; @@ -1800,12 +1800,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"); @@ -1925,7 +1925,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)) @@ -1935,7 +1935,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)) @@ -1943,7 +1943,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"); @@ -1959,7 +1959,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)) @@ -1969,7 +1969,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)) @@ -1977,7 +1977,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 04/13] eventdev: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 04/13] eventdev: " Jie Hai @ 2024-10-27 3:02 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:02 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Naga Harish K S V, Jerin Jacob, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:42 +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. > > Cc: stable@dpdk.org > > Signed-off-by: Jie Hai <haijie1@huawei.com> > Acked-by: Chengwen Feng <fengchengwen@huawei.com> > Acked-by: Morten Brørup <mb@smartsharesystems.com> Yet another function only called from RTE_INIT() ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 05/13] security: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (3 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 04/13] eventdev: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:03 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 06/13] telemetry: " Jie Hai ` (9 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Akhil Goyal, Anoob Joseph, Gowrishankar Muthukrishnan Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 e5c862f5f570..c34b09bedd6a 100644 --- a/lib/security/rte_security.c +++ b/lib/security/rte_security.c @@ -497,13 +497,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 05/13] security: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 05/13] security: " Jie Hai @ 2024-10-27 3:03 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:03 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Akhil Goyal, Anoob Joseph, Gowrishankar Muthukrishnan, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:43 +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: 259ca6d1617f ("security: add telemetry endpoint for capabilities") > Cc: stable@dpdk.org Another patch that is not needed in stable. ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 06/13] telemetry: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (4 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 05/13] security: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:05 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 07/13] bus/fslmc: " Jie Hai ` (8 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Bruce Richardson, Keith Wiles, Ciara Power Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 31a2c91c0657..000b0f9f80df 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -398,6 +398,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), @@ -412,8 +413,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); struct cmd_callback cb = {.fn = unknown_command}; int i; -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 06/13] telemetry: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 06/13] telemetry: " Jie Hai @ 2024-10-27 3:05 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:05 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Bruce Richardson, Keith Wiles, Ciara Power, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:44 +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: 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> > Acked-by: Morten Brørup <mb@smartsharesystems.com> > --- > lib/telemetry/telemetry.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) This one could be hit while application is running. Acked-by: Stephen Hemminger <stephen@networkplumber.org> ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 07/13] bus/fslmc: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (5 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 06/13] telemetry: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:06 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 08/13] common/cnxk: " Jie Hai ` (7 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Hemant Agrawal, Sachin Saxena, Nipun Gupta, Ferruh Yigit, Shreyansh Jain, Santosh Shukla Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Sachin Saxena <sachin.saxena@nxp.com> Acked-by: Morten Brørup <mb@smartsharesystems.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 097d6dca08b5..42b6b270a419 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -132,6 +132,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) @@ -169,7 +170,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; @@ -200,7 +201,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 d8a98326d9de..204662ad9eaf 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -128,7 +128,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) #define AFFINITY_LEN 128 uint32_t cpu_mask = 1; size_t len = 0; - char *temp = NULL, *token = NULL; + char *temp = NULL, *token = NULL, *sp = NULL; char string[STRING_LEN]; char smp_affinity[AFFINITY_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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 07/13] bus/fslmc: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 07/13] bus/fslmc: " Jie Hai @ 2024-10-27 3:06 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:06 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Hemant Agrawal, Sachin Saxena, Nipun Gupta, Ferruh Yigit, Shreyansh Jain, Santosh Shukla, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14: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: 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> > Acked-by: Sachin Saxena <sachin.saxena@nxp.com> > Acked-by: Morten Brørup <mb@smartsharesystems.com> > --- > drivers/bus/fslmc/fslmc_bus.c | 5 +++-- > drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++-- > 2 files changed, 5 insertions(+), 4 deletions(-) Only called during bus scan so single threaded. Not needed for stable. ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 08/13] common/cnxk: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (6 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 07/13] bus/fslmc: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:07 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 09/13] event/cnxk: " Jie Hai ` (6 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Harman Kalra, Jerin Jacob, Gowrishankar Muthukrishnan Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 abeefafe1e19..00b8ab9e5c18 100644 --- a/drivers/common/cnxk/cnxk_telemetry_nix.c +++ b/drivers/common/cnxk/cnxk_telemetry_nix.c @@ -1015,7 +1015,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; @@ -1023,11 +1023,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) @@ -1036,7 +1036,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) @@ -1052,7 +1052,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) @@ -1068,7 +1068,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 08/13] common/cnxk: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 08/13] common/cnxk: " Jie Hai @ 2024-10-27 3:07 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:07 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Harman Kalra, Jerin Jacob, Gowrishankar Muthukrishnan, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14: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: 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> > Acked-by: Morten Brørup <mb@smartsharesystems.com> > --- These info functions can be called when running. Acked-by: Stephen Hemminger <stephen@networkplumber.org> ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 09/13] event/cnxk: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (7 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 08/13] common/cnxk: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:08 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 10/13] net/ark: " Jie Hai ` (5 subsequent siblings) 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Pavan Nikhilesh, Shijith Thotton Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 8a3d58c189fd ("event/cnxk: add option to control timer adapters") Fixes: 8bdbae66b299 ("event/cnxk: add external clock support for timer") Cc: stable@dpdk.org Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.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 84a55511a328..feb23e0b2177 100644 --- a/drivers/event/cnxk/cnxk_eventdev.c +++ b/drivers/event/cnxk/cnxk_eventdev.c @@ -482,7 +482,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)) @@ -490,7 +491,7 @@ parse_queue_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_r(NULL, "-", &sp); val++; } @@ -518,7 +519,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)) @@ -527,7 +529,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 bba70646fa16..63f868bdb33d 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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 09/13] event/cnxk: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 09/13] event/cnxk: " Jie Hai @ 2024-10-27 3:08 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:08 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, Pavan Nikhilesh, Shijith Thotton, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:47 +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: 8a3d58c189fd ("event/cnxk: add option to control timer adapters") > Fixes: 8bdbae66b299 ("event/cnxk: add external clock support for timer") > Cc: stable@dpdk.org > > Signed-off-by: Jie Hai <haijie1@huawei.com> > Acked-by: Chengwen Feng <fengchengwen@huawei.com> > Acked-by: Morten Brørup <mb@smartsharesystems.com> Another set of parse routines only called during startup. Patch is unnecessary for stable. ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 10/13] net/ark: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (8 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 09/13] event/cnxk: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-26 10:14 ` [PATCH v4 11/13] raw/cnxk_gpio: " Jie Hai ` (4 subsequent siblings) 14 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Shepard Siegel, Ed Czeck, John Miller Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 11/13] raw/cnxk_gpio: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (9 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 10/13] net/ark: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-26 10:14 ` [PATCH v4 12/13] net/cnxk: " Jie Hai ` (3 subsequent siblings) 14 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Jakub Palider, Tomasz Duszynski, Jerin Jacob Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.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 329ac28a2736..bad70ecb1985 100644 --- a/drivers/raw/cnxk_gpio/cnxk_gpio.c +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c @@ -192,7 +192,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); @@ -210,7 +210,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); @@ -236,7 +236,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 12/13] net/cnxk: replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (10 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 11/13] raw/cnxk_gpio: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-26 10:14 ` [PATCH v4 13/13] devtools: check for some reentrant function Jie Hai ` (2 subsequent siblings) 14 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Harman Kalra, Chengwen Feng Cc: lihuisong, haijie1, huangdengdui 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: c8f91985331c ("raw/cnxk_gpio: replace strtok with reentrant version") Cc: stable@dpdk.org Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c index 86c2453c0983..fa1d7c063536 100644 --- a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c +++ b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c @@ -214,6 +214,7 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) char dlim[2] = ","; char *params_args; size_t count = 0; + char *sp = NULL; char *token; if (vals == NULL || params == NULL || strlen(params) == 0) @@ -226,10 +227,10 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) 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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v4 13/13] devtools: check for some reentrant function 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (11 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 12/13] net/cnxk: " Jie Hai @ 2024-10-26 10:14 ` Jie Hai 2024-10-27 3:11 ` Stephen Hemminger 2024-11-05 16:28 ` [PATCH v4 00/13] replace strtok with reentrant version Stephen Hemminger 2024-11-06 20:11 ` David Marchand 14 siblings, 1 reply; 152+ messages in thread From: Jie Hai @ 2024-10-26 10:14 UTC (permalink / raw) To: dev, thomas, ferruh.yigit; +Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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. Cc: stable@dpdk.org Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index d860f190457e..8c3d32d8e552 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -145,6 +145,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 13/13] devtools: check for some reentrant function 2024-10-26 10:14 ` [PATCH v4 13/13] devtools: check for some reentrant function Jie Hai @ 2024-10-27 3:11 ` Stephen Hemminger 0 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-10-27 3:11 UTC (permalink / raw) To: Jie Hai; +Cc: dev, thomas, ferruh.yigit, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:51 +0800 Jie Hai <haijie1@huawei.com> wrote: > diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh > index d860f190457e..8c3d32d8e552 100755 > --- a/devtools/checkpatches.sh > +++ b/devtools/checkpatches.sh > @@ -145,6 +145,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))\\\(" \ Ok, but checkpatch keeps getting slower and slower with all this copy baset. Could someone make it into a python script without so much copy/paste? ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 00/13] replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (12 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 13/13] devtools: check for some reentrant function Jie Hai @ 2024-11-05 16:28 ` Stephen Hemminger 2024-11-06 20:11 ` David Marchand 14 siblings, 0 replies; 152+ messages in thread From: Stephen Hemminger @ 2024-11-05 16:28 UTC (permalink / raw) To: Jie Hai; +Cc: dev, thomas, ferruh.yigit, lihuisong, fengchengwen, huangdengdui On Sat, 26 Oct 2024 18:14:38 +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 patchset replaces strtok with strtok_r in app, example, lib > and drivers. And adds check for use of strtok in checkpatches.sh. > > -- > v4: > 1. fix mispellings. > 2. add Acked-bys and Reviewd-bys. > 3. remove some patch and add new. > 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 (13): > 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 > net/cnxk: replace strtok with reentrant version > devtools: check for some reentrant function > > 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/net/cnxk/cnxk_ethdev_sec_telemetry.c | 5 +-- > drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 ++-- > lib/dmadev/rte_dmadev.c | 4 +-- > lib/eal/common/eal_common_memory.c | 8 ++--- > lib/ethdev/rte_ethdev_telemetry.c | 9 +++-- > 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 +-- > 17 files changed, 92 insertions(+), 74 deletions(-) > This should go into main (for 24.11) but not be backported to stable. Series-Acked-by: Stephen Hemminger <stephen@networkplumber.org> ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 00/13] replace strtok with reentrant version 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai ` (13 preceding siblings ...) 2024-11-05 16:28 ` [PATCH v4 00/13] replace strtok with reentrant version Stephen Hemminger @ 2024-11-06 20:11 ` David Marchand 2024-11-07 12:23 ` Jie Hai 14 siblings, 1 reply; 152+ messages in thread From: David Marchand @ 2024-11-06 20:11 UTC (permalink / raw) To: Jie Hai Cc: dev, thomas, ferruh.yigit, lihuisong, fengchengwen, huangdengdui, Stephen Hemminger, Tyler Retzlaff Hello, On Sat, Oct 26, 2024 at 12:26 PM 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 patchset replaces strtok with strtok_r in app, example, lib > and drivers. And adds check for use of strtok in checkpatches.sh. - The current v4 series breaks compilation on Windows with clang. http://mails.dpdk.org/archives/test-report/2024-November/819978.html The reason is that some include of rte_os_shim.h are missing. ==== 20 line log output for Windows Server 2022 (dpdk_win_llvm_compile): ==== vchan_param = strtok_r(end_param, ",", &sp); ^ ../lib/dmadev/rte_dmadev.c:1038:17: note: did you mean 'strtok_s'? C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\string.h:68:29: note: 'strtok_s' declared here _ACRTIMP char* __cdecl strtok_s( ^ ../lib/dmadev/rte_dmadev.c:1038:15: error: incompatible integer to pointer conversion assigning to 'const char *' from 'int' [-Wint-conversion] vchan_param = strtok_r(end_param, ",", &sp); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 errors generated. [10/836] Linking static target lib/librte_gpudev.a [11/836] Compiling C object lib/librte_mldev.a.p/mldev_mldev_utils_scalar_bfloat16.c.obj [12/836] Compiling C object lib/librte_gro.a.p/gro_gro_udp4.c.obj [13/836] Compiling C object lib/librte_mldev.a.p/mldev_mldev_utils_scalar.c.obj [14/836] Compiling C object lib/librte_gro.a.p/gro_rte_gro.c.obj [15/836] Compiling C object lib/librte_gro.a.p/gro_gro_tcp6.c.obj [16/836] Compiling C object lib/librte_gro.a.p/gro_gro_tcp4.c.obj [17/836] Compiling C object lib/librte_gro.a.p/gro_gro_vxlan_tcp4.c.obj [18/836] Compiling C object lib/librte_cryptodev.a.p/cryptodev_rte_cryptodev.c.obj ninja: build stopped: subcommand failed. - grep shows that there are a number of missed places in drivers and app, which contradicts the commitlog. I don't like leaving some places with strtok while checkpatches.sh warn on the rest. And I think others were expecting too that the whole tree is fixed after this series. Re-reading the thread, were the changes on app/ dropped, following comments from Stephen? I understand his request was to remove the backport request (iow no Cc: stable@dpdk.org in the commitlogs), not to drop the changes. -- David Marchand ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v4 00/13] replace strtok with reentrant version 2024-11-06 20:11 ` David Marchand @ 2024-11-07 12:23 ` Jie Hai 0 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-07 12:23 UTC (permalink / raw) To: David Marchand Cc: dev, thomas, ferruh.yigit, lihuisong, fengchengwen, huangdengdui, Stephen Hemminger, Tyler Retzlaff Hi, David Marchand , Thank you very much for your reminder and comments. I will correct it in the next version. Best Regards, Jie Hai On 2024/11/7 4:11, David Marchand wrote: > Hello, > > On Sat, Oct 26, 2024 at 12:26 PM 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 patchset replaces strtok with strtok_r in app, example, lib >> and drivers. And adds check for use of strtok in checkpatches.sh. > > - The current v4 series breaks compilation on Windows with clang. > http://mails.dpdk.org/archives/test-report/2024-November/819978.html > > The reason is that some include of rte_os_shim.h are missing. > > ==== 20 line log output for Windows Server 2022 (dpdk_win_llvm_compile): ==== > vchan_param = strtok_r(end_param, ",", &sp); > ^ > ../lib/dmadev/rte_dmadev.c:1038:17: note: did you mean 'strtok_s'? > C:\Program Files (x86)\Windows > Kits\10\Include\10.0.22621.0\ucrt\string.h:68:29: note: 'strtok_s' > declared here > _ACRTIMP char* __cdecl strtok_s( > ^ > ../lib/dmadev/rte_dmadev.c:1038:15: error: incompatible integer to > pointer conversion assigning to 'const char *' from 'int' > [-Wint-conversion] > vchan_param = strtok_r(end_param, ",", &sp); > ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 2 errors generated. > [10/836] Linking static target lib/librte_gpudev.a > [11/836] Compiling C object > lib/librte_mldev.a.p/mldev_mldev_utils_scalar_bfloat16.c.obj > [12/836] Compiling C object lib/librte_gro.a.p/gro_gro_udp4.c.obj > [13/836] Compiling C object lib/librte_mldev.a.p/mldev_mldev_utils_scalar.c.obj > [14/836] Compiling C object lib/librte_gro.a.p/gro_rte_gro.c.obj > [15/836] Compiling C object lib/librte_gro.a.p/gro_gro_tcp6.c.obj > [16/836] Compiling C object lib/librte_gro.a.p/gro_gro_tcp4.c.obj > [17/836] Compiling C object lib/librte_gro.a.p/gro_gro_vxlan_tcp4.c.obj > [18/836] Compiling C object > lib/librte_cryptodev.a.p/cryptodev_rte_cryptodev.c.obj > ninja: build stopped: subcommand failed. > > > - grep shows that there are a number of missed places in drivers and > app, which contradicts the commitlog. > I don't like leaving some places with strtok while checkpatches.sh > warn on the rest. > And I think others were expecting too that the whole tree is fixed > after this series. > > Re-reading the thread, were the changes on app/ dropped, following > comments from Stephen? > I understand his request was to remove the backport request (iow no > Cc: stable@dpdk.org in the commitlogs), not to drop the changes. > > ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 00/25] 2023-11-13 10:45 [PATCH 00/21] replace strtok with strtok_r Jie Hai ` (27 preceding siblings ...) 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 01/25] app/graph: replace strtok with reentrant version Jie Hai ` (25 more replies) 28 siblings, 26 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit; +Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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_r in app, example, lib and drivers. And adds check for use of strtok in checkpatches.sh. -- v5: 1. remove CC stable for some patch. 2. replace strtok for all files. v4: 1. fix mispellings. 2. add Acked-bys and Reviewd-bys. 3. remove some patch and add new. 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 (25): 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/flow-perf: replace strtok with reentrant version app/test-mldev: replace strtok with reentrant version app/test-fib: 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 net/cnxk: replace strtok with reentrant version common/qat: replace strtok with reentrant version net/mlx5: 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 | 6 ++- app/graph/utils.c | 16 ++++--- app/test-bbdev/test_bbdev_vector.c | 42 +++++++++++-------- .../comp_perf_options_parse.c | 17 ++++---- app/test-crypto-perf/cperf_options_parsing.c | 17 ++++---- .../cperf_test_vector_parsing.c | 11 +++-- app/test-dma-perf/main.c | 14 ++++--- app/test-fib/main.c | 11 ++--- app/test-flow-perf/main.c | 23 +++++----- app/test-mldev/ml_options.c | 19 +++++---- devtools/checkpatches.sh | 8 ++++ drivers/bus/fslmc/fslmc_bus.c | 6 ++- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 ++- drivers/common/cnxk/cnxk_telemetry_nix.c | 13 +++--- drivers/common/qat/qat_device.c | 6 ++- drivers/event/cnxk/cnxk_eventdev.c | 11 +++-- drivers/event/cnxk/cnxk_tim_evdev.c | 12 +++--- drivers/net/ark/ark_pktchkr.c | 11 ++--- drivers/net/ark/ark_pktgen.c | 11 ++--- drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c | 6 ++- drivers/net/mlx5/mlx5_testpmd.c | 5 ++- drivers/raw/cnxk_gpio/cnxk_gpio.c | 7 ++-- examples/l2fwd-crypto/main.c | 7 ++-- examples/vhost/main.c | 4 +- lib/dmadev/rte_dmadev.c | 5 ++- lib/eal/common/eal_common_memory.c | 8 ++-- lib/ethdev/rte_ethdev_telemetry.c | 10 +++-- lib/eventdev/rte_event_eth_rx_adapter.c | 39 ++++++++--------- lib/eventdev/rte_eventdev.c | 18 ++++---- lib/security/rte_security.c | 4 +- lib/telemetry/telemetry.c | 6 ++- 31 files changed, 223 insertions(+), 155 deletions(-) -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 01/25] app/graph: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 02/25] app/bbdev: " Jie Hai ` (24 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Sunil Kumar Kori, Rakesh Kudurumalla, Nithin Dabilpuram, Jerin Jacob Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/graph/graph.c | 6 ++++-- app/graph/utils.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/graph/graph.c b/app/graph/graph.c index 17717738d7d9..6849b8da5da4 100644 --- a/app/graph/graph.c +++ b/app/graph/graph.c @@ -13,6 +13,7 @@ #include <rte_ethdev.h> #include <rte_graph_worker.h> #include <rte_log.h> +#include <rte_os_shim.h> #include "graph_priv.h" #include "module_api.h" @@ -103,9 +104,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 +118,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 3e8099ea8821..6c53948aa277 100644 --- a/app/graph/utils.c +++ b/app/graph/utils.c @@ -10,6 +10,7 @@ #include <rte_common.h> #include <rte_string_fns.h> +#include <rte_os_shim.h> #include "module_api.h" @@ -94,13 +95,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; } @@ -113,13 +115,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; } @@ -132,13 +135,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 02/25] app/bbdev: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai 2024-11-08 11:03 ` [PATCH v5 01/25] app/graph: replace strtok with reentrant version Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 03/25] app/compress-perf: " Jie Hai ` (23 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Nicolas Chautru, Maxime Coquelin, Amr Mokhtar Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/test-bbdev/test_bbdev_vector.c | 42 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c index 8b32850982c3..fbbdde70bdfc 100644 --- a/app/test-bbdev/test_bbdev_vector.c +++ b/app/test-bbdev/test_bbdev_vector.c @@ -10,6 +10,7 @@ #include <stdlib.h> #include <stdbool.h> #include <rte_malloc.h> +#include <rte_os_shim.h> #include "test_bbdev_vector.h" @@ -63,8 +64,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 +100,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; @@ -324,8 +326,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; @@ -359,7 +362,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; } @@ -399,9 +402,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; @@ -432,7 +436,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; } @@ -932,6 +936,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; @@ -964,7 +969,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++) { @@ -972,7 +977,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; } @@ -1016,53 +1021,53 @@ parse_fft_params(const char *key_token, char *token, fft->output_depadded_size = (uint32_t) strtoul(token, &err, 0); ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "cs_theta_0")) { - 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++) { fft->cs_theta_0[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "cs_theta_d")) { - 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++) { fft->cs_theta_d[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "time_offset")) { - 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++) { fft->time_offset[i] = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } } ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "fft_window_width")) { - 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++) { if (i == 0) vector->fft_window_width_vec = (uint32_t) strtoul(tok, &err, 0); if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -1163,6 +1168,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; @@ -1172,10 +1178,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 03/25] app/compress-perf: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai 2024-11-08 11:03 ` [PATCH v5 01/25] app/graph: replace strtok with reentrant version Jie Hai 2024-11-08 11:03 ` [PATCH v5 02/25] app/bbdev: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 04/25] app/crypto-perf: " Jie Hai ` (22 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Fiona Trahe, Pablo de Lara, Shally Verma, Tomasz Jozwiak, Lee Daly Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- .../comp_perf_options_parse.c | 17 ++++++++++------- 1 file changed, 10 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..6f3f907162e6 100644 --- a/app/test-compress-perf/comp_perf_options_parse.c +++ b/app/test-compress-perf/comp_perf_options_parse.c @@ -12,6 +12,7 @@ #include <rte_string_fns.h> #include <rte_comp.h> +#include <rte_os_shim.h> #include "comp_perf_options.h" @@ -177,6 +178,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 +186,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 +199,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 +213,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 +227,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 +246,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 +254,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 +269,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 +291,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 04/25] app/crypto-perf: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (2 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 03/25] app/compress-perf: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 05/25] app/dma-perf: " Jie Hai ` (21 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Brian Dooley, Pablo de Lara, Sergio Gonzalez Monroy, Declan Doherty, Piotr Azarewicz, Michal Kobylinski, Marcin Kerlin, Slawomir Mrozowicz Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Ciara Power <ciara.power@intel.com> --- app/test-crypto-perf/cperf_options_parsing.c | 17 ++++++++++------- .../cperf_test_vector_parsing.c | 11 +++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 8abee2d68826..07130e2c27f7 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -9,6 +9,7 @@ #include <rte_cryptodev.h> #include <rte_malloc.h> #include <rte_ether.h> +#include <rte_os_shim.h> #include "cperf_options.h" #include "cperf_test_common.h" @@ -166,6 +167,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); @@ -173,7 +175,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) { @@ -187,7 +189,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) { @@ -201,7 +203,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) { @@ -216,7 +218,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); @@ -235,6 +237,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); @@ -242,7 +245,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) { @@ -258,7 +261,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) { @@ -280,7 +283,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..b1cc1ef3c91d 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <rte_malloc.h> +#include <rte_os_shim.h> #include "cperf_options.h" #include "cperf_test_vectors.h" @@ -220,8 +221,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 +254,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 +285,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 +293,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 05/25] app/dma-perf: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (3 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 04/25] app/crypto-perf: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 06/25] app/flow-perf: " Jie Hai ` (20 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Cheng Jiang, Chengwen Feng, Chenbo Xia, Jiayu Hu, Morten Brørup, Yuan Wang Cc: lihuisong, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/test-dma-perf/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c index 18219918ccab..25d8397ebe5c 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -18,6 +18,7 @@ #include <rte_lcore.h> #include <rte_dmadev.h> #include <rte_kvargs.h> +#include <rte_os_shim.h> #include "main.h" @@ -183,6 +184,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; @@ -194,7 +196,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_WORKER_NB) { free(input); @@ -204,7 +206,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); @@ -220,6 +222,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; @@ -237,7 +240,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; @@ -279,7 +282,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: @@ -625,6 +628,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)); @@ -643,7 +647,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 06/25] app/flow-perf: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (4 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 05/25] app/dma-perf: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 07/25] app/test-mldev: " Jie Hai ` (19 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Wisam Jaddo, Alexander Kozyrev, Rongwei Liu, Jiawei Wang, Haifei Luo, Sean Zhang Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/test-flow-perf/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c index 07ddfe0e46df..7e68146c16d7 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -36,6 +36,7 @@ #include <rte_ethdev.h> #include <rte_flow.h> #include <rte_mtr.h> +#include <rte_os_shim.h> #include "config.h" #include "actions_gen.h" @@ -602,6 +603,7 @@ read_meter_policy(char *prog, char *arg) { char *token; size_t i, j, k; + char *sp = NULL; j = 0; k = 0; @@ -612,9 +614,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 +630,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 +643,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 +807,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 +820,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 +831,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 +844,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 +913,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 07/25] app/test-mldev: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (5 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 06/25] app/flow-perf: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 08/25] app/test-fib: " Jie Hai ` (18 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Srikanth Yalavarthi, Anup Prabhu Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: bbd272edcb14 ("app/mldev: add ordered inferences") Fixes: 28a4a819c850 ("app/mldev: improve checks for invalid options") Fixes: da6793390596 ("app/mldev: support inference validation") Fixes: f6661e6d9a3a ("app/mldev: validate model operations") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/test-mldev/ml_options.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 320f6325ae67..1033444de0e1 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -9,6 +9,7 @@ #include <rte_memory.h> #include <rte_mldev.h> #include <rte_string_fns.h> +#include <rte_os_shim.h> #include "ml_common.h" #include "ml_test.h" @@ -76,12 +77,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) { if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { ml_err("Exceeded model count, max = %d\n", ML_TEST_MAX_MODELS); @@ -92,7 +93,7 @@ ml_parse_models(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); opt->nb_filelist++; - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); } if (opt->nb_filelist == 0) { @@ -108,7 +109,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); @@ -118,7 +119,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; @@ -126,7 +127,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; @@ -134,7 +135,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; @@ -142,14 +143,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 08/25] app/test-fib: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (6 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 07/25] app/test-mldev: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 09/25] dmadev: " Jie Hai ` (17 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Vladimir Medvedkin Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- app/test-fib/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/test-fib/main.c b/app/test-fib/main.c index 6479f48cdf6c..11810a1a80a8 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -17,6 +17,7 @@ #include <rte_lpm6.h> #include <rte_fib.h> #include <rte_fib6.h> +#include <rte_os_shim.h> #define PRINT_USAGE_START "%s [EAL options] --\n" @@ -204,9 +205,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) { @@ -246,7 +247,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) { @@ -522,10 +523,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 09/25] dmadev: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (7 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 08/25] app/test-fib: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 10/25] eal: " Jie Hai ` (16 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson, Conor Walsh, Sean Morrissey Cc: lihuisong, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- lib/dmadev/rte_dmadev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c index 8bb7824aa129..eaf649e7d982 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -14,6 +14,7 @@ #include <rte_memzone.h> #include <rte_string_fns.h> #include <rte_telemetry.h> +#include <rte_os_shim.h> #include "rte_dmadev.h" #include "rte_dmadev_pmd.h" @@ -1016,7 +1017,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)) @@ -1035,7 +1036,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 10/25] eal: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (8 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 09/25] dmadev: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 11/25] ethdev: " Jie Hai ` (15 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Anatoly Burakov, Tyler Retzlaff, Amit Prakash Shukla Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Amit Prakash Shukla <amitprakashs@marvell.com> Acked-by: Morten Brørup <mb@smartsharesystems.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 a185e0b580c7..ace63313ea75 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -1275,22 +1275,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 11/25] ethdev: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (9 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 10/25] eal: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 12/25] eventdev: " Jie Hai ` (14 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Andrew Rybchenko Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- lib/ethdev/rte_ethdev_telemetry.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index 5e6c4172d3be..e589032dd368 100644 --- a/lib/ethdev/rte_ethdev_telemetry.c +++ b/lib/ethdev/rte_ethdev_telemetry.c @@ -7,6 +7,7 @@ #include <rte_kvargs.h> #include <rte_telemetry.h> +#include <rte_os_shim.h> #include "rte_ethdev.h" #include "ethdev_driver.h" @@ -477,6 +478,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 +491,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 +1223,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; @@ -1510,13 +1513,14 @@ eth_dev_handle_port_regs(const char *cmd __rte_unused, { char *filter, *end_param; uint16_t port_id; + char *sp = NULL; int ret; ret = eth_dev_parse_port_params(params, &port_id, &end_param, true); if (ret != 0) return ret; - filter = strtok(end_param, ","); + filter = strtok_r(end_param, ",", &sp); if (filter != NULL && strlen(filter) == 0) filter = NULL; -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 12/25] eventdev: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (10 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 11/25] ethdev: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 13/25] security: " Jie Hai ` (13 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Naga Harish K S V, Jerin Jacob Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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. Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- lib/eventdev/rte_event_eth_rx_adapter.c | 39 +++++++++++++------------ lib/eventdev/rte_eventdev.c | 18 ++++++------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 3ee20d95f372..96af9c0c8b65 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -23,6 +23,7 @@ #include <rte_interrupts.h> #include <rte_mbuf_dyn.h> #include <rte_telemetry.h> +#include <rte_os_shim.h> #include "rte_eventdev.h" #include "eventdev_pmd.h" @@ -3651,7 +3652,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 +3662,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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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 +3685,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 +3724,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 +3734,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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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 +3757,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 +3795,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 +3804,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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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 +3827,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 +3856,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 +3864,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_EVENT_ETH_RX_ADAPTER_PORTID_VALID_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 +3882,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 ca295c87c47d..d3dacffdfab2 100644 --- a/lib/eventdev/rte_eventdev.c +++ b/lib/eventdev/rte_eventdev.c @@ -1787,7 +1787,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]; @@ -1800,12 +1800,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"); @@ -1925,7 +1925,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)) @@ -1935,7 +1935,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)) @@ -1943,7 +1943,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"); @@ -1959,7 +1959,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)) @@ -1969,7 +1969,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)) @@ -1977,7 +1977,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 13/25] security: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (11 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 12/25] eventdev: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 14/25] telemetry: " Jie Hai ` (12 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Akhil Goyal, Anoob Joseph, Gowrishankar Muthukrishnan Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- lib/security/rte_security.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c index e5c862f5f570..669888ef0807 100644 --- a/lib/security/rte_security.c +++ b/lib/security/rte_security.c @@ -11,6 +11,7 @@ #include <rte_cryptodev.h> #include <dev_driver.h> #include <rte_telemetry.h> +#include <rte_os_shim.h> #include "rte_security.h" #include "rte_security_driver.h" @@ -497,13 +498,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 14/25] telemetry: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (12 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 13/25] security: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 15/25] bus/fslmc: " Jie Hai ` (11 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Bruce Richardson, Keith Wiles, Ciara Power Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Stephen Hemminger <stephen@networkplumber.org> --- lib/telemetry/telemetry.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 31a2c91c0657..cd1eddc5609c 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -19,6 +19,7 @@ #include <rte_common.h> #include <rte_spinlock.h> #include <rte_log.h> +#include <rte_os_shim.h> #include "rte_telemetry.h" #include "telemetry_json.h" @@ -398,6 +399,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), @@ -412,8 +414,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); struct cmd_callback cb = {.fn = unknown_command}; int i; -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 15/25] bus/fslmc: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (13 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 14/25] telemetry: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 16/25] common/cnxk: " Jie Hai ` (10 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Hemant Agrawal, Sachin Saxena, Nipun Gupta, Shreyansh Jain, Santosh Shukla, Ferruh Yigit Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Sachin Saxena <sachin.saxena@nxp.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- drivers/bus/fslmc/fslmc_bus.c | 6 ++++-- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 097d6dca08b5..fe7eb26940cb 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -16,6 +16,7 @@ #include <rte_memcpy.h> #include <ethdev_driver.h> #include <rte_mbuf_dyn.h> +#include <rte_os_shim.h> #include "private.h" #include <fslmc_vfio.h> @@ -132,6 +133,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) @@ -169,7 +171,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; @@ -200,7 +202,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 d8a98326d9de..8b863af010da 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -31,6 +31,7 @@ #include <rte_cycles.h> #include <rte_kvargs.h> #include <dev_driver.h> +#include <rte_os_shim.h> #include <fslmc_logs.h> #include <bus_fslmc_driver.h> @@ -128,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) #define AFFINITY_LEN 128 uint32_t cpu_mask = 1; size_t len = 0; - char *temp = NULL, *token = NULL; + char *temp = NULL, *token = NULL, *sp = NULL; char string[STRING_LEN]; char smp_affinity[AFFINITY_LEN]; FILE *file; @@ -141,7 +142,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 16/25] common/cnxk: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (14 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 15/25] bus/fslmc: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 17/25] event/cnxk: " Jie Hai ` (9 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Harman Kalra, Jerin Jacob, Gowrishankar Muthukrishnan Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Stephen Hemminger <stephen@networkplumber.org> --- drivers/common/cnxk/cnxk_telemetry_nix.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c index abeefafe1e19..a0b587c97c63 100644 --- a/drivers/common/cnxk/cnxk_telemetry_nix.c +++ b/drivers/common/cnxk/cnxk_telemetry_nix.c @@ -3,6 +3,7 @@ */ #include <ctype.h> +#include <rte_os_shim.h> #include "cnxk_telemetry.h" #include "roc_api.h" #include "roc_priv.h" @@ -1015,7 +1016,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; @@ -1023,11 +1024,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) @@ -1036,7 +1037,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) @@ -1052,7 +1053,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) @@ -1068,7 +1069,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 17/25] event/cnxk: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (15 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 16/25] common/cnxk: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 18/25] net/ark: " Jie Hai ` (8 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Pavan Nikhilesh, Shijith Thotton Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 8a3d58c189fd ("event/cnxk: add option to control timer adapters") Fixes: 8bdbae66b299 ("event/cnxk: add external clock support for timer") Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- drivers/event/cnxk/cnxk_eventdev.c | 11 +++++++---- drivers/event/cnxk/cnxk_tim_evdev.c | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c index 84a55511a328..facbe7fa0928 100644 --- a/drivers/event/cnxk/cnxk_eventdev.c +++ b/drivers/event/cnxk/cnxk_eventdev.c @@ -2,6 +2,7 @@ * Copyright(C) 2021 Marvell. */ +#include <rte_os_shim.h> #include "roc_npa.h" #include "cnxk_eventdev.h" @@ -482,7 +483,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)) @@ -490,7 +492,7 @@ parse_queue_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_r(NULL, "-", &sp); val++; } @@ -518,7 +520,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)) @@ -527,7 +530,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 bba70646fa16..82d4a1878dd5 100644 --- a/drivers/event/cnxk/cnxk_tim_evdev.c +++ b/drivers/event/cnxk/cnxk_tim_evdev.c @@ -3,6 +3,7 @@ */ #include <math.h> +#include <rte_os_shim.h> #include "roc_npa.h" @@ -420,7 +421,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 +433,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 +509,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 18/25] net/ark: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (16 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 17/25] event/cnxk: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 19/25] raw/cnxk_gpio: " Jie Hai ` (7 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Shepard Siegel, Ed Czeck, John Miller Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- drivers/net/ark/ark_pktchkr.c | 11 ++++++----- drivers/net/ark/ark_pktgen.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c index e1f336c73c2a..2bb3dd7b5f36 100644 --- a/drivers/net/ark/ark_pktchkr.c +++ b/drivers/net/ark/ark_pktchkr.c @@ -7,6 +7,7 @@ #include <rte_string_fns.h> #include <rte_malloc.h> +#include <rte_os_shim.h> #include "ark_pktchkr.h" #include "ark_logs.h" @@ -359,14 +360,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..4765b8f0992a 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -8,6 +8,7 @@ #include <rte_string_fns.h> #include <rte_malloc.h> #include <rte_thread.h> +#include <rte_os_shim.h> #include "ark_pktgen.h" #include "ark_logs.h" @@ -340,14 +341,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 19/25] raw/cnxk_gpio: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (17 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 18/25] net/ark: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 20/25] net/cnxk: " Jie Hai ` (6 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Jakub Palider, Tomasz Duszynski, Jerin Jacob Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- drivers/raw/cnxk_gpio/cnxk_gpio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c index 329ac28a2736..e6408db824de 100644 --- a/drivers/raw/cnxk_gpio/cnxk_gpio.c +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c @@ -11,6 +11,7 @@ #include <rte_kvargs.h> #include <rte_lcore.h> #include <rte_rawdev_pmd.h> +#include <rte_os_shim.h> #include <roc_api.h> @@ -192,7 +193,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); @@ -210,7 +211,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); @@ -236,7 +237,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 20/25] net/cnxk: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (18 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 19/25] raw/cnxk_gpio: " Jie Hai @ 2024-11-08 11:03 ` Jie Hai 2024-11-08 11:04 ` [PATCH v5 21/25] common/qat: " Jie Hai ` (5 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:03 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Harman Kalra, Chengwen Feng Cc: lihuisong, haijie1, huangdengdui 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: c8f91985331c ("raw/cnxk_gpio: replace strtok with reentrant version") Cc: stable@dpdk.org Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> --- drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c index 86c2453c0983..0b766be11a17 100644 --- a/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c +++ b/drivers/net/cnxk/cnxk_ethdev_sec_telemetry.c @@ -5,6 +5,7 @@ #include <ctype.h> #include <rte_telemetry.h> +#include <rte_os_shim.h> #include <roc_api.h> @@ -214,6 +215,7 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) char dlim[2] = ","; char *params_args; size_t count = 0; + char *sp = NULL; char *token; if (vals == NULL || params == NULL || strlen(params) == 0) @@ -226,10 +228,10 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) 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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 21/25] common/qat: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (19 preceding siblings ...) 2024-11-08 11:03 ` [PATCH v5 20/25] net/cnxk: " Jie Hai @ 2024-11-08 11:04 ` Jie Hai 2024-11-08 11:04 ` [PATCH v5 22/25] net/mlx5: " Jie Hai ` (4 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:04 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Kai Ji, Arkadiusz Kusztal, Brian Dooley Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 99ab2806687b ("common/qat: isolate parser arguments configuration") Signed-off-by: Jie Hai <haijie1@huawei.com> --- drivers/common/qat/qat_device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/common/qat/qat_device.c b/drivers/common/qat/qat_device.c index bca88fd9bded..99153775d883 100644 --- a/drivers/common/qat/qat_device.c +++ b/drivers/common/qat/qat_device.c @@ -4,6 +4,7 @@ #include <rte_string_fns.h> #include <rte_devargs.h> +#include <rte_os_shim.h> #include <ctype.h> #include "qat_device.h" @@ -222,6 +223,7 @@ qat_dev_parse_command_line(struct qat_pci_device *qat_dev, { int len = 0; char *token = NULL; + char *sp = NULL; if (!devargs) return 0; @@ -236,14 +238,14 @@ qat_dev_parse_command_line(struct qat_pci_device *qat_dev, return -1; } strcpy(qat_dev->command_line, devargs->drv_str); - token = strtok(qat_dev->command_line, ","); + token = strtok_r(qat_dev->command_line, ",", &sp); while (token != NULL) { if (!cmdline_validate(token)) { QAT_LOG(ERR, "Incorrect command line argument: %s", token); return -1; } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } /* Copy once againe the entire string, strtok already altered the contents */ strcpy(qat_dev->command_line, devargs->drv_str); -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 22/25] net/mlx5: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (20 preceding siblings ...) 2024-11-08 11:04 ` [PATCH v5 21/25] common/qat: " Jie Hai @ 2024-11-08 11:04 ` Jie Hai 2024-11-08 11:04 ` [PATCH v5 23/25] examples/l2fwd-crypto: " Jie Hai ` (3 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:04 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao, Ori Kam, Suanming Mou, Matan Azrad, Michael Baum Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 0683c002f7f5 ("net/mlx5: add testpmd commands for GENEVE TLV parser") Signed-off-by: Jie Hai <haijie1@huawei.com> --- drivers/net/mlx5/mlx5_testpmd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5_testpmd.c b/drivers/net/mlx5/mlx5_testpmd.c index 1bb5a89559fe..7bd220fafa46 100644 --- a/drivers/net/mlx5/mlx5_testpmd.c +++ b/drivers/net/mlx5/mlx5_testpmd.c @@ -353,6 +353,7 @@ mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len, rte_be32_t **match_data_mask) { rte_be32_t *data; + char *sp = NULL; char *buff2; char *token; uint8_t i = 0; @@ -377,7 +378,7 @@ mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len, return -ENOMEM; } - token = strtok(buff2, SPACE_DELIMITER); + token = strtok_r(buff2, SPACE_DELIMITER, &sp); while (token != NULL) { if (i == data_len) { TESTPMD_LOG(ERR, @@ -393,7 +394,7 @@ mlx5_test_parse_geneve_option_data(const char *buff, uint8_t data_len, else data[i] = 0x0; - token = strtok(NULL, SPACE_DELIMITER); + token = strtok_r(NULL, SPACE_DELIMITER, &sp); i++; } -- 2.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 23/25] examples/l2fwd-crypto: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (21 preceding siblings ...) 2024-11-08 11:04 ` [PATCH v5 22/25] net/mlx5: " Jie Hai @ 2024-11-08 11:04 ` Jie Hai 2024-11-08 11:04 ` [PATCH v5 24/25] examples/vhost: " Jie Hai ` (2 subsequent siblings) 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:04 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Akhil Goyal, Fan Zhang, Sergio Gonzalez Monroy, Pablo de Lara Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 1df9c0109f4c ("examples/l2fwd-crypto: parse key parameters") Signed-off-by: Jie Hai <haijie1@huawei.com> --- examples/l2fwd-crypto/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index a441312f5524..7128bd2e72cf 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -43,6 +43,7 @@ #include <rte_prefetch.h> #include <rte_random.h> #include <rte_hexdump.h> +#include <rte_os_shim.h> #ifdef RTE_CRYPTO_SCHEDULER #include <rte_cryptodev_scheduler.h> #endif @@ -1105,12 +1106,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 24/25] examples/vhost: replace strtok with reentrant version 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (22 preceding siblings ...) 2024-11-08 11:04 ` [PATCH v5 23/25] examples/l2fwd-crypto: " Jie Hai @ 2024-11-08 11:04 ` Jie Hai 2024-11-08 11:04 ` [PATCH v5 25/25] devtools: check for some reentrant function Jie Hai 2024-11-08 14:39 ` [PATCH v5 00/25] David Marchand 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:04 UTC (permalink / raw) To: dev, thomas, ferruh.yigit, Maxime Coquelin, Chenbo Xia, Sunil Pai G, Jiayu Hu Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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: 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path") Signed-off-by: Jie Hai <haijie1@huawei.com> --- examples/vhost/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 4391d88c3d15..0fbb11b1d4f4 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -29,6 +29,7 @@ #include <rte_dmadev.h> #include <rte_vhost_async.h> #include <rte_thread.h> +#include <rte_os_shim.h> #include "main.h" @@ -259,6 +260,7 @@ open_dma(const char *value) uint16_t i = 0; char *dma_arg[RTE_MAX_VHOST_DEVICE]; int args_nr; + char *sp = NULL; if (input == NULL) return -1; @@ -272,7 +274,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v5 25/25] devtools: check for some reentrant function 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (23 preceding siblings ...) 2024-11-08 11:04 ` [PATCH v5 24/25] examples/vhost: " Jie Hai @ 2024-11-08 11:04 ` Jie Hai 2024-11-08 14:39 ` [PATCH v5 00/25] David Marchand 25 siblings, 0 replies; 152+ messages in thread From: Jie Hai @ 2024-11-08 11:04 UTC (permalink / raw) To: dev, thomas, ferruh.yigit; +Cc: lihuisong, fengchengwen, haijie1, huangdengdui 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. Cc: stable@dpdk.org Signed-off-by: Jie Hai <haijie1@huawei.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 4a8591be225e..80fe41604427 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -145,6 +145,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.22.0 ^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v5 00/25] 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai ` (24 preceding siblings ...) 2024-11-08 11:04 ` [PATCH v5 25/25] devtools: check for some reentrant function Jie Hai @ 2024-11-08 14:39 ` David Marchand 25 siblings, 0 replies; 152+ messages in thread From: David Marchand @ 2024-11-08 14:39 UTC (permalink / raw) To: Jie Hai; +Cc: dev, thomas, ferruh.yigit, lihuisong, fengchengwen, huangdengdui On Fri, Nov 8, 2024 at 12:15 PM 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 patchset replaces strtok with strtok_r in app, example, lib > and drivers. And adds check for use of strtok in checkpatches.sh. > > -- > v5: > 1. remove CC stable for some patch. > 2. replace strtok for all files. In case you did not notice, including rte_os_shim.h in examples breaks compilation. Too late for taking in rc2, I may consider in rc3 if the series is fixed by then. Thanks. -- David Marchand ^ permalink raw reply [flat|nested] 152+ messages in thread
end of thread, other threads:[~2024-11-08 14:39 UTC | newest] Thread overview: 152+ 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 2024-10-22 10:46 ` [PATCH v3 00/22] replace strtok with reentrant version Morten Brørup 2024-10-26 10:14 ` [PATCH v4 00/13] " Jie Hai 2024-10-26 10:14 ` [PATCH v4 01/13] dmadev: " Jie Hai 2024-10-27 3:00 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 02/13] eal: " Jie Hai 2024-10-27 3:00 ` Stephen Hemminger 2024-10-28 13:04 ` fengchengwen 2024-10-28 15:31 ` Stephen Hemminger 2024-10-29 0:56 ` fengchengwen 2024-10-29 2:51 ` Stephen Hemminger 2024-11-07 12:29 ` Jie Hai 2024-10-26 10:14 ` [PATCH v4 03/13] ethdev: " Jie Hai 2024-10-27 3:01 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 04/13] eventdev: " Jie Hai 2024-10-27 3:02 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 05/13] security: " Jie Hai 2024-10-27 3:03 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 06/13] telemetry: " Jie Hai 2024-10-27 3:05 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 07/13] bus/fslmc: " Jie Hai 2024-10-27 3:06 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 08/13] common/cnxk: " Jie Hai 2024-10-27 3:07 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 09/13] event/cnxk: " Jie Hai 2024-10-27 3:08 ` Stephen Hemminger 2024-10-26 10:14 ` [PATCH v4 10/13] net/ark: " Jie Hai 2024-10-26 10:14 ` [PATCH v4 11/13] raw/cnxk_gpio: " Jie Hai 2024-10-26 10:14 ` [PATCH v4 12/13] net/cnxk: " Jie Hai 2024-10-26 10:14 ` [PATCH v4 13/13] devtools: check for some reentrant function Jie Hai 2024-10-27 3:11 ` Stephen Hemminger 2024-11-05 16:28 ` [PATCH v4 00/13] replace strtok with reentrant version Stephen Hemminger 2024-11-06 20:11 ` David Marchand 2024-11-07 12:23 ` Jie Hai 2024-11-08 11:03 ` [PATCH v5 00/25] Jie Hai 2024-11-08 11:03 ` [PATCH v5 01/25] app/graph: replace strtok with reentrant version Jie Hai 2024-11-08 11:03 ` [PATCH v5 02/25] app/bbdev: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 03/25] app/compress-perf: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 04/25] app/crypto-perf: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 05/25] app/dma-perf: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 06/25] app/flow-perf: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 07/25] app/test-mldev: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 08/25] app/test-fib: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 09/25] dmadev: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 10/25] eal: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 11/25] ethdev: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 12/25] eventdev: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 13/25] security: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 14/25] telemetry: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 15/25] bus/fslmc: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 16/25] common/cnxk: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 17/25] event/cnxk: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 18/25] net/ark: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 19/25] raw/cnxk_gpio: " Jie Hai 2024-11-08 11:03 ` [PATCH v5 20/25] net/cnxk: " Jie Hai 2024-11-08 11:04 ` [PATCH v5 21/25] common/qat: " Jie Hai 2024-11-08 11:04 ` [PATCH v5 22/25] net/mlx5: " Jie Hai 2024-11-08 11:04 ` [PATCH v5 23/25] examples/l2fwd-crypto: " Jie Hai 2024-11-08 11:04 ` [PATCH v5 24/25] examples/vhost: " Jie Hai 2024-11-08 11:04 ` [PATCH v5 25/25] devtools: check for some reentrant function Jie Hai 2024-11-08 14:39 ` [PATCH v5 00/25] David Marchand
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).