From patchwork Mon Nov 13 10:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134132 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CFD65430AB; Mon, 13 Nov 2023 11:50:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F386C402F1; Mon, 13 Nov 2023 11:50:52 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id A9B414021F for ; Mon, 13 Nov 2023 11:50:50 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STR6L0w6zzvQYF; Mon, 13 Nov 2023 18:50:34 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:48 +0800 From: Jie Hai To: , Sunil Kumar Kori , Rakesh Kudurumalla CC: , , Subject: [PATCH 01/21] app/graph: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:30 +0800 Message-ID: <20231113104550.2138654-2-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; } From patchwork Mon Nov 13 10:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134134 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 933DE430AB; Mon, 13 Nov 2023 11:51:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 526CE40685; Mon, 13 Nov 2023 11:50:55 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id F25A54026C for ; Mon, 13 Nov 2023 11:50:50 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6F0FYRzQkBD for ; Mon, 13 Nov 2023 18:50:29 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:48 +0800 From: Jie Hai To: , Nicolas Chautru CC: , , Subject: [PATCH 02/21] app/test-bbdev: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:31 +0800 Message-ID: <20231113104550.2138654-3-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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); From patchwork Mon Nov 13 10:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134133 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 17C96430AB; Mon, 13 Nov 2023 11:51:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 26B7A4067A; Mon, 13 Nov 2023 11:50:54 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 39AE74021F for ; Mon, 13 Nov 2023 11:50:51 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1M5PCwzMmpD for ; Mon, 13 Nov 2023 18:46:15 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:49 +0800 From: Jie Hai To: CC: , , Subject: [PATCH 03/21] app/test-compress-perf: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:32 +0800 Message-ID: <20231113104550.2138654-4-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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) From patchwork Mon Nov 13 10:45:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134135 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2FD41430AB; Mon, 13 Nov 2023 11:51:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C85F40697; Mon, 13 Nov 2023 11:50:56 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 4B160402B7 for ; Mon, 13 Nov 2023 11:50:51 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STR6M4x0QzvQYR for ; Mon, 13 Nov 2023 18:50:35 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:49 +0800 From: Jie Hai To: , Ciara Power CC: , , Subject: [PATCH 04/21] app/test-crypto-perf: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:33 +0800 Message-ID: <20231113104550.2138654-5-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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); From patchwork Mon Nov 13 10:45:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134136 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CFE0B430AB; Mon, 13 Nov 2023 11:51:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C7F8406A2; Mon, 13 Nov 2023 11:51:00 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 506344064C for ; Mon, 13 Nov 2023 11:50:58 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR1x1JCqzPpFQ; Mon, 13 Nov 2023 18:46:45 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:50 +0800 From: Jie Hai To: , Cheng Jiang CC: , , Subject: [PATCH 05/21] app/test-dma-perf: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:34 +0800 Message-ID: <20231113104550.2138654-6-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134137 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D5BF0430AB; Mon, 13 Nov 2023 11:51:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD91C40A67; Mon, 13 Nov 2023 11:51:01 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 729F14067E for ; Mon, 13 Nov 2023 11:50:58 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6P1M4CzWhCW for ; Mon, 13 Nov 2023 18:50:37 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:56 +0800 From: Jie Hai To: , Vladimir Medvedkin CC: , , Subject: [PATCH 06/21] app/test-fib: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:35 +0800 Message-ID: <20231113104550.2138654-7-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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]); From patchwork Mon Nov 13 10:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134138 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB2EA430AB; Mon, 13 Nov 2023 11:51:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 550EF40A7A; Mon, 13 Nov 2023 11:51:03 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 0B7EF4064C for ; Mon, 13 Nov 2023 11:50:59 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1W6h8LzMmn1; Mon, 13 Nov 2023 18:46:23 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:57 +0800 From: Jie Hai To: , Wisam Jaddo CC: , , Subject: [PATCH 07/21] app/dpdk-test-flow-perf: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:36 +0800 Message-ID: <20231113104550.2138654-8-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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) { From patchwork Mon Nov 13 10:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134139 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D964430AB; Mon, 13 Nov 2023 11:51:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73F5240A81; Mon, 13 Nov 2023 11:51:04 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 734B54067E for ; Mon, 13 Nov 2023 11:50:59 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1X3CpNzMmnp; Mon, 13 Nov 2023 18:46:24 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:57 +0800 From: Jie Hai To: , Srikanth Yalavarthi CC: , , Subject: [PATCH 08/21] app/test-mldev: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:37 +0800 Message-ID: <20231113104550.2138654-9-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134140 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95515430AB; Mon, 13 Nov 2023 11:51:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A60D440A8A; Mon, 13 Nov 2023 11:51:05 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 239F34064C for ; Mon, 13 Nov 2023 11:51:00 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STR6X2bmHzvQbl for ; Mon, 13 Nov 2023 18:50:44 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:58 +0800 From: Jie Hai To: , Chengwen Feng , Kevin Laatz , Bruce Richardson CC: , Subject: [PATCH 09/21] lib/dmadev: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:38 +0800 Message-ID: <20231113104550.2138654-10-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134141 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6A82D430AB; Mon, 13 Nov 2023 11:51:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D44E240DC9; Mon, 13 Nov 2023 11:51:06 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 56E524067E for ; Mon, 13 Nov 2023 11:51:00 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6R1qk6zWhCW for ; Mon, 13 Nov 2023 18:50:39 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:58 +0800 From: Jie Hai To: , Anatoly Burakov CC: , , Subject: [PATCH 10/21] lib/eal: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:39 +0800 Message-ID: <20231113104550.2138654-11-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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); From patchwork Mon Nov 13 10:45:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134142 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95E52430AB; Mon, 13 Nov 2023 11:52:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25BFD40DCA; Mon, 13 Nov 2023 11:51:08 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 135904067E for ; Mon, 13 Nov 2023 11:51:01 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6R5hvZzWhKS; Mon, 13 Nov 2023 18:50:39 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:59 +0800 From: Jie Hai To: , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , , Subject: [PATCH 11/21] lib/ethdev: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:40 +0800 Message-ID: <20231113104550.2138654-12-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134143 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 15D5B430AB; Mon, 13 Nov 2023 11:52:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4D3BC40DDB; Mon, 13 Nov 2023 11:51:09 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id AA07F406FF for ; Mon, 13 Nov 2023 11:51:01 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STR324WhXzrTbB; Mon, 13 Nov 2023 18:47:42 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:50:59 +0800 From: Jie Hai To: , Naga Harish K S V , Jerin Jacob CC: , , Subject: [PATCH 12/21] lib/eventdev: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:41 +0800 Message-ID: <20231113104550.2138654-13-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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"); From patchwork Mon Nov 13 10:45:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134144 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 63FF4430AB; Mon, 13 Nov 2023 11:52:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5927740DFB; Mon, 13 Nov 2023 11:51:10 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 4FF32406BC for ; Mon, 13 Nov 2023 11:51:02 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STR3368YFz1P8CH; Mon, 13 Nov 2023 18:47:43 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:00 +0800 From: Jie Hai To: , Akhil Goyal CC: , , Subject: [PATCH 13/21] lib/telemetry: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:42 +0800 Message-ID: <20231113104550.2138654-14-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134145 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8E063430AB; Mon, 13 Nov 2023 11:52:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B566940E54; Mon, 13 Nov 2023 11:51:11 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id BBD40406FF for ; Mon, 13 Nov 2023 11:51:02 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6T2p2gzWhHh for ; Mon, 13 Nov 2023 18:50:41 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:00 +0800 From: Jie Hai To: , Ciara Power CC: , , Subject: [PATCH 14/21] lib/telemetry: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:43 +0800 Message-ID: <20231113104550.2138654-15-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134146 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B445E430AB; Mon, 13 Nov 2023 11:52:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C37A040E72; Mon, 13 Nov 2023 11:51:12 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 340D940A75 for ; Mon, 13 Nov 2023 11:51:03 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6T6Z6tzWh6l; Mon, 13 Nov 2023 18:50:41 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:01 +0800 From: Jie Hai To: , Hemant Agrawal , Sachin Saxena CC: , , Subject: [PATCH 15/21] bus/fslmc: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:44 +0800 Message-ID: <20231113104550.2138654-16-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Acked-by: Sachin Saxena --- 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; } } From patchwork Mon Nov 13 10:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134147 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D39F6430AB; Mon, 13 Nov 2023 11:52:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D295940E8A; Mon, 13 Nov 2023 11:51:13 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id F130340A75 for ; Mon, 13 Nov 2023 11:51:03 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STR6c0spnzvQYL; Mon, 13 Nov 2023 18:50:48 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:02 +0800 From: Jie Hai To: , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao CC: , , Subject: [PATCH 16/21] common/cnxk: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:45 +0800 Message-ID: <20231113104550.2138654-17-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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) From patchwork Mon Nov 13 10:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134148 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C2967430AB; Mon, 13 Nov 2023 11:52:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F02FA40ED3; Mon, 13 Nov 2023 11:51:15 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id E04CD40A7F for ; Mon, 13 Nov 2023 11:51:04 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1d59ZNzMmn1; Mon, 13 Nov 2023 18:46:29 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:02 +0800 From: Jie Hai To: , Pavan Nikhilesh , Shijith Thotton CC: , , Subject: [PATCH 17/21] event/cnxk: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:46 +0800 Message-ID: <20231113104550.2138654-18-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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++; } From patchwork Mon Nov 13 10:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134149 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9775A430AB; Mon, 13 Nov 2023 11:52:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 077D140EDC; Mon, 13 Nov 2023 11:51:17 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 578D540A6D for ; Mon, 13 Nov 2023 11:51:05 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR243jHnzPpDq; Mon, 13 Nov 2023 18:46:52 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:03 +0800 From: Jie Hai To: , Shepard Siegel , Ed Czeck , John Miller CC: , , Subject: [PATCH 18/21] net/ark: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:47 +0800 Message-ID: <20231113104550.2138654-19-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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); } } From patchwork Mon Nov 13 10:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134150 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4C03C430AB; Mon, 13 Nov 2023 11:52:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2117540EDF; Mon, 13 Nov 2023 11:51:18 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id BA0C640A75 for ; Mon, 13 Nov 2023 11:51:05 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STR374409z1P8C8; Mon, 13 Nov 2023 18:47:47 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:04 +0800 From: Jie Hai To: , Jakub Palider , Tomasz Duszynski CC: , , Subject: [PATCH 19/21] raw/cnxk_gpio: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:48 +0800 Message-ID: <20231113104550.2138654-20-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; From patchwork Mon Nov 13 10:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134151 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12477430AB; Mon, 13 Nov 2023 11:52:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D08A40EE4; Mon, 13 Nov 2023 11:51:19 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 5294640A8B for ; Mon, 13 Nov 2023 11:51:06 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STR6Y1FPtzWhCW; Mon, 13 Nov 2023 18:50:45 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:04 +0800 From: Jie Hai To: , Akhil Goyal , Fan Zhang CC: , , Subject: [PATCH 20/21] examples/l2fwd-crypto: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:49 +0800 Message-ID: <20231113104550.2138654-21-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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); From patchwork Mon Nov 13 10:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134152 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AD65A430AB; Mon, 13 Nov 2023 11:53:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C2CC40F16; Mon, 13 Nov 2023 11:51:20 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 1B85B40A8B for ; Mon, 13 Nov 2023 11:51:07 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STR1g6M8VzMmnp; Mon, 13 Nov 2023 18:46:31 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 13 Nov 2023 18:51:05 +0800 From: Jie Hai To: , Maxime Coquelin , Chenbo Xia CC: , , Subject: [PATCH 21/21] examples/vhost: replace strtok with strtok_r Date: Mon, 13 Nov 2023 18:45:50 +0800 Message-ID: <20231113104550.2138654-22-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231113104550.2138654-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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;