From patchwork Tue Nov 14 08:41:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134232 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 7EDAE43325; Tue, 14 Nov 2023 09:47:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BFB35402DC; Tue, 14 Nov 2023 09:47:13 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 0A5EC402B0 for ; Tue, 14 Nov 2023 09:47:12 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fg6nL7z1P87P; Tue, 14 Nov 2023 16:43:51 +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; Tue, 14 Nov 2023 16:47:09 +0800 From: Jie Hai To: , Sunil Kumar Kori , Rakesh Kudurumalla , Nithin Dabilpuram , Jerin Jacob CC: , , Subject: [PATCH v2 01/22] app/graph: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:12 +0800 Message-ID: <20231114084133.3573959-2-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 5c59002a34f3 ("app/graph: add graph commands") Fixes: 984a315a5804 ("app/graph: add parser utility") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/graph/graph.c | 5 +++-- app/graph/utils.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/graph/graph.c b/app/graph/graph.c index a65723a196da..ed9405ea4bac 100644 --- a/app/graph/graph.c +++ b/app/graph/graph.c @@ -103,9 +103,10 @@ parser_usecases_read(char *usecases) { bool valid = false; uint32_t i, j = 0; + char *sp = NULL; char *token; - token = strtok(usecases, ","); + token = strtok_s(usecases, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(supported_usecases); i++) { if (strcmp(supported_usecases[i], token) == 0) { @@ -116,7 +117,7 @@ parser_usecases_read(char *usecases) break; } } - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } return valid; diff --git a/app/graph/utils.c b/app/graph/utils.c index c7b6ae83cf1f..f7525f0b70af 100644 --- a/app/graph/utils.c +++ b/app/graph/utils.c @@ -101,13 +101,14 @@ int parser_ip4_read(uint32_t *value, char *p) { uint8_t shift = 24; + char *sp = NULL; uint32_t ip = 0; char *token; - token = strtok(p, "."); + token = strtok_s(p, ".", &sp); while (token != NULL) { ip |= (((uint32_t)strtoul(token, NULL, 10)) << shift); - token = strtok(NULL, "."); + token = strtok_s(NULL, ".", &sp); shift -= 8; } @@ -120,13 +121,14 @@ int parser_ip6_read(uint8_t *value, char *p) { uint64_t val = 0; + char *sp = NULL; char *token; - token = strtok(p, ":"); + token = strtok_s(p, ":", &sp); while (token != NULL) { hex_string_to_uint64(&val, token); *value = val; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); value++; val = 0; } @@ -139,13 +141,14 @@ parser_mac_read(uint64_t *value, char *p) { uint64_t mac = 0, val = 0; uint8_t shift = 40; + char *sp = NULL; char *token; - token = strtok(p, ":"); + token = strtok_s(p, ":", &sp); while (token != NULL) { hex_string_to_uint64(&val, token); mac |= val << shift; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); shift -= 8; val = 0; } From patchwork Tue Nov 14 08:41:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134233 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 9C1CC43325; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36FC840648; Tue, 14 Nov 2023 09:47:16 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 5D6B6402D6 for ; Tue, 14 Nov 2023 09:47:12 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0K52gHPzWgy6; Tue, 14 Nov 2023 16:46:49 +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; Tue, 14 Nov 2023 16:47:10 +0800 From: Jie Hai To: , Nicolas Chautru , Maxime Coquelin , Amr Mokhtar CC: , , Subject: [PATCH v2 02/22] app/bbdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:13 +0800 Message-ID: <20231114084133.3573959-3-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 0acdb9866756 ("test/bbdev: add FFT operations cases") Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-bbdev/test_bbdev_vector.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c index c26727cd35c4..00a0f99801b7 100644 --- a/app/test-bbdev/test_bbdev_vector.c +++ b/app/test-bbdev/test_bbdev_vector.c @@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) uint32_t *values, *values_resized; char *tok, *error = NULL; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) *data_length = *data_length + (strlen(tok) - strlen("0x"))/2; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, { char *tok = NULL; uint32_t op_flag_value = 0; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, *op_flags = *op_flags | op_flag_value; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -368,9 +370,10 @@ static int parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) { char *tok = NULL; + char *sp = NULL; bool status_ok = false; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_s(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) return -1; } - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token, int ret = 0, status = 0, i, shift; uint32_t op_flags = 0; char *tok, *err = NULL; + char *sp = NULL; struct rte_bbdev_op_fft *fft = &vector->fft; @@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token, fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0); ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "window_index")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_s(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { @@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token, fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0) << shift; if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_s(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -995,6 +999,7 @@ static int parse_entry(char *entry, struct test_bbdev_vector *vector) { int ret = 0; + char *sp = NULL; char *token, *key_token; enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE; @@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector) } /* get key */ - token = strtok(entry, ENTRY_DELIMITER); + token = strtok_s(entry, ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, ENTRY_DELIMITER); + token = strtok_s(NULL, ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); From patchwork Tue Nov 14 08:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134234 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 1994843325; Tue, 14 Nov 2023 09:47:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 535BE4067C; Tue, 14 Nov 2023 09:47:17 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 0CBB24027B for ; Tue, 14 Nov 2023 09:47:13 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fh2wt0zrV4m; Tue, 14 Nov 2023 16:43: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; Tue, 14 Nov 2023 16:47:10 +0800 From: Jie Hai To: , Tomasz Jozwiak , Fiona Trahe , Pablo de Lara , Lee Daly , Shally Verma CC: , , Subject: [PATCH v2 03/22] app/compress-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:14 +0800 Message-ID: <20231114084133.3573959-4-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: e0b6287c035d ("app/compress-perf: add parser") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-compress-perf/comp_perf_options_parse.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c index 6d8c370fc2ea..a390fa36c56c 100644 --- a/app/test-compress-perf/comp_perf_options_parse.c +++ b/app/test-compress-perf/comp_perf_options_parse.c @@ -177,6 +177,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) { char *token; uint8_t number; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -184,7 +185,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) return -1; errno = 0; - token = strtok(copy_arg, ":"); + token = strtok_s(copy_arg, ":", &sp); /* Parse minimum value */ if (token != NULL) { @@ -197,7 +198,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); /* Parse increment value */ if (token != NULL) { @@ -211,7 +212,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); /* Parse maximum value */ if (token != NULL) { @@ -225,7 +226,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - if (strtok(NULL, ":") != NULL) + if (strtok_s(NULL, ":", &sp) != NULL) goto err_range; free(copy_arg); @@ -244,6 +245,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) uint8_t count = 0; uint32_t temp_min; uint32_t temp_max; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -251,7 +253,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) return -1; errno = 0; - token = strtok(copy_arg, ","); + token = strtok_s(copy_arg, ",", &sp); /* Parse first value */ if (token != NULL) { @@ -266,7 +268,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) } else goto err_list; - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); while (token != NULL) { if (count == MAX_LIST) { @@ -288,7 +290,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) if (number > temp_max) temp_max = number; - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } if (min) From patchwork Tue Nov 14 08:41:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134235 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 D618543325; Tue, 14 Nov 2023 09:47:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 874D94068E; Tue, 14 Nov 2023 09:47:18 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 73191402B0 for ; Tue, 14 Nov 2023 09:47:13 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fj13g2zrVDF for ; Tue, 14 Nov 2023 16:43:53 +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; Tue, 14 Nov 2023 16:47:11 +0800 From: Jie Hai To: , Ciara Power , Sergio Gonzalez Monroy , Pablo de Lara , Piotr Azarewicz , Michal Kobylinski , Slawomir Mrozowicz , Marcin Kerlin , Declan Doherty CC: , , Subject: [PATCH v2 04/22] app/crypto-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:15 +0800 Message-ID: <20231114084133.3573959-5-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: f6cefe253cc8 ("app/crypto-perf: add range/list of sizes") Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng Acked-by: Ciara Power --- app/test-crypto-perf/cperf_options_parsing.c | 16 +++++++++------- app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 75afedc7fd6e..81fa4a925291 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) { char *token; uint32_t number; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) return -1; errno = 0; - token = strtok(copy_arg, ":"); + token = strtok_s(copy_arg, ":", &sp); /* Parse minimum value */ if (token != NULL) { @@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); /* Parse increment value */ if (token != NULL) { @@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_s(NULL, ":", &sp); /* Parse maximum value */ if (token != NULL) { @@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - if (strtok(NULL, ":") != NULL) + if (strtok_s(NULL, ":", &sp) != NULL) goto err_range; free(copy_arg); @@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) uint8_t count = 0; uint32_t temp_min; uint32_t temp_max; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) return -1; errno = 0; - token = strtok(copy_arg, ","); + token = strtok_s(copy_arg, ",", &sp); /* Parse first value */ if (token != NULL) { @@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) } else goto err_list; - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); while (token != NULL) { if (count == MAX_LIST) { @@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) if (number > temp_max) temp_max = number; - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } if (min) diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c index 737d61d4af6b..3557d767b55c 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length) uint8_t *values, *values_resized; char *tok, *error = NULL; + char *sp = NULL; - tok = strtok(tokens, CPERF_VALUE_DELIMITER); + tok = strtok_s(tokens, CPERF_VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length) return -1; } - tok = strtok(NULL, CPERF_VALUE_DELIMITER); + tok = strtok_s(NULL, CPERF_VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector, uint8_t *data = NULL; char *token, *key_token; + char *sp = NULL; if (entry == NULL) { printf("Expected entry value\n"); @@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector, } /* get key */ - token = strtok(entry, CPERF_ENTRY_DELIMITER); + token = strtok_s(entry, CPERF_ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, CPERF_ENTRY_DELIMITER); + token = strtok_s(NULL, CPERF_ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); From patchwork Tue Nov 14 08:41:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134237 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 394B343325; Tue, 14 Nov 2023 09:47:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FB9040A4B; Tue, 14 Nov 2023 09:47:21 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 16CE54027B for ; Tue, 14 Nov 2023 09:47:14 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0K727JPzWh1N; Tue, 14 Nov 2023 16:46:51 +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; Tue, 14 Nov 2023 16:47:12 +0800 From: Jie Hai To: , Cheng Jiang , Anoob Joseph , =?utf-8?q?Morten_Br=C3=B8rup?= , Chengwen Feng , Chenbo Xia CC: , Subject: [PATCH v2 05/22] app/dma-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:16 +0800 Message-ID: <20231114084133.3573959-6-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-dma-perf/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c index e5bccc27da5e..e34f9f8aaa7c 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -164,6 +164,7 @@ parse_lcore(struct test_configure *test_case, const char *value) uint16_t len; char *input; struct lcore_dma_map_t *lcore_dma_map; + char *sp = NULL; if (test_case == NULL || value == NULL) return -1; @@ -175,7 +176,7 @@ parse_lcore(struct test_configure *test_case, const char *value) memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t)); - char *token = strtok(input, ", "); + char *token = strtok_s(input, ", ", &sp); while (token != NULL) { if (lcore_dma_map->cnt >= MAX_LCORE_NB) { free(input); @@ -185,7 +186,7 @@ parse_lcore(struct test_configure *test_case, const char *value) uint16_t lcore_id = atoi(token); lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id; - token = strtok(NULL, ", "); + token = strtok_s(NULL, ", ", &sp); } free(input); @@ -201,6 +202,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) char *start, *end, *substr; uint16_t lcore_id; int ret = 0; + char *sp = NULL; if (test_case == NULL || value == NULL) return -1; @@ -216,7 +218,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) goto out; } - substr = strtok(addrs, ","); + substr = strtok_s(addrs, ",", &sp); if (substr == NULL) { fprintf(stderr, "No input DMA address\n"); ret = -1; @@ -258,7 +260,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1], RTE_DEV_NAME_MAX_LEN); lcore_dma_map->cnt++; - substr = strtok(NULL, ","); + substr = strtok_s(NULL, ",", &sp); } while (substr != NULL); out: @@ -486,6 +488,7 @@ main(int argc, char *argv[]) char *rst_path_ptr = NULL; char rst_path[PATH_MAX]; int new_argc; + char *sp = NULL; memset(args, 0, sizeof(args)); @@ -504,7 +507,7 @@ main(int argc, char *argv[]) } if (rst_path_ptr == NULL) { strlcpy(rst_path, cfg_path_ptr, PATH_MAX); - char *token = strtok(basename(rst_path), "."); + char *token = strtok_s(basename(rst_path), ".", &sp); if (token == NULL) { printf("Config file error.\n"); return -1; From patchwork Tue Nov 14 08:41:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134236 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 401EA43325; Tue, 14 Nov 2023 09:47:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CAE5A4069D; Tue, 14 Nov 2023 09:47:19 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 5DC53402E6 for ; Tue, 14 Nov 2023 09:47:14 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fk1cl5zrVDq for ; Tue, 14 Nov 2023 16:43:54 +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; Tue, 14 Nov 2023 16:47:12 +0800 From: Jie Hai To: , Vladimir Medvedkin CC: , , Subject: [PATCH v2 06/22] app/test-fib: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:17 +0800 Message-ID: <20231114084133.3573959-7-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 103809d032cd ("app/test-fib: add test application for FIB") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-fib/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/test-fib/main.c b/app/test-fib/main.c index 75a56135f212..95f6bd467b49 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n) uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */ uint32_t n_routes; uint8_t depth, ratio, ratio_acc = 0; - char *in; + char *in, *sp = NULL; - in = strtok(distrib_string, ","); + in = strtok_s(distrib_string, ",", &sp); /*parse configures routes percentage ratios*/ while (in != NULL) { @@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n) } /*number of configured depths in*/ - in = strtok(NULL, ","); + in = strtok_s(NULL, ",", &sp); } if (ratio_acc > 100) { @@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af) int ret, i = 0; uint8_t *tbl = (uint8_t *)config.lookup_tbl; int step = (af == AF_INET) ? 4 : 16; - char *s; + char *s, *sp = NULL; while (fgets(line, sizeof(line), f) != NULL) { - s = strtok(line, " \t\n"); + s = strtok_s(line, " \t\n", &sp); if (s == NULL) return -EINVAL; ret = inet_pton(af, s, &tbl[i]); From patchwork Tue Nov 14 08:41:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134238 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 5437F43325; Tue, 14 Nov 2023 09:47:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B92A40698; Tue, 14 Nov 2023 09:47:22 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 100BC402EF for ; Tue, 14 Nov 2023 09:47:15 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0K837ZDzWhBR; Tue, 14 Nov 2023 16: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; Tue, 14 Nov 2023 16:47:13 +0800 From: Jie Hai To: , Wisam Jaddo , Alexander Kozyrev , Rongwei Liu , Haifei Luo , Jiawei Wang , Sean Zhang CC: , , Subject: [PATCH v2 07/22] app/flow-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:18 +0800 Message-ID: <20231114084133.3573959-8-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 0c8f1f4ab90e ("app/flow-perf: support raw encap/decap actions") Fixes: 7f37f0936a19 ("app/flow-perf: support meter policy API") Fixes: 80a323319745 ("app/flow-perf: add destination ports parameter") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-flow-perf/main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c index e224ef67983d..04ce7e38a539 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg) { char *token; size_t i, j, k; + char *sp = NULL; j = 0; k = 0; @@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg) token = strsep(&arg, ":\0"); } j = 0; - token = strtok(actions_str[0], ",\0"); + token = strtok_s(actions_str[0], ",\0", &sp); while (token == NULL && j < RTE_COLORS - 1) - token = strtok(actions_str[++j], ",\0"); + token = strtok_s(actions_str[++j], ",\0", &sp); while (j < RTE_COLORS && token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (!strcmp(token, flow_options[i].str)) { @@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg) usage(prog); rte_exit(EXIT_SUCCESS, "Invalid colored actions\n"); } - token = strtok(NULL, ",\0"); + token = strtok_s(NULL, ",\0", &sp); while (!token && j < RTE_COLORS - 1) { - token = strtok(actions_str[++j], ",\0"); + token = strtok_s(actions_str[++j], ",\0", &sp); k = 0; } } @@ -641,6 +642,7 @@ args_parse(int argc, char **argv) { uint64_t pm, seed; uint64_t hp_conf; + char *sp = NULL; char **argvopt; uint32_t prio; char *token; @@ -804,7 +806,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_ENCAP ); - token = strtok(optarg, ","); + token = strtok_s(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -817,7 +819,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid encap item: %s\n", token); } - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } printf(" / "); } @@ -828,7 +830,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_DECAP ); - token = strtok(optarg, ","); + token = strtok_s(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -841,7 +843,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid decap item %s\n", token); } - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } printf(" / "); } @@ -910,10 +912,10 @@ args_parse(int argc, char **argv) uint16_t port_idx = 0; char *token; - token = strtok(optarg, ","); + token = strtok_s(optarg, ",", &sp); while (token != NULL) { dst_ports[port_idx++] = atoi(token); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); } } if (strcmp(lgopts[opt_idx].name, "rxq") == 0) { From patchwork Tue Nov 14 08:41:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134240 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 2EC1143325; Tue, 14 Nov 2023 09:48:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ADD2840A79; Tue, 14 Nov 2023 09:47:24 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id B3BF3402F2 for ; Tue, 14 Nov 2023 09:47:15 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0KG6r1KzvQH1; Tue, 14 Nov 2023 16:46:58 +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; Tue, 14 Nov 2023 16:47:13 +0800 From: Jie Hai To: , Srikanth Yalavarthi CC: , , Subject: [PATCH v2 08/22] app/test-mldev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:19 +0800 Message-ID: <20231114084133.3573959-9-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- app/test-mldev/ml_options.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 72357c1c393d..3e93a8b7356c 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -75,12 +75,12 @@ ml_parse_models(struct ml_options *opt, const char *arg) { const char *delim = ","; char models[PATH_MAX]; - char *token; + char *token, *sp = NULL; int ret = 0; strlcpy(models, arg, PATH_MAX); - token = strtok(models, delim); + token = strtok_s(models, delim, &sp); while (token != NULL) { strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); opt->nb_filelist++; @@ -90,7 +90,7 @@ ml_parse_models(struct ml_options *opt, const char *arg) ret = -EINVAL; break; } - token = strtok(NULL, delim); + token = strtok_s(NULL, delim, &sp); } if (opt->nb_filelist == 0) { @@ -106,7 +106,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) { const char *delim = ","; char filelist[PATH_MAX]; - char *token; + char *token, *sp = NULL; if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS); @@ -116,7 +116,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(filelist, arg, PATH_MAX); /* model */ - token = strtok(filelist, delim); + token = strtok_s(filelist, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, model not specified = %s\n", arg); return -EINVAL; @@ -124,7 +124,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); /* input */ - token = strtok(NULL, delim); + token = strtok_s(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, input not specified = %s\n", arg); return -EINVAL; @@ -132,7 +132,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX); /* output */ - token = strtok(NULL, delim); + token = strtok_s(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, output not specified = %s\n", arg); return -EINVAL; @@ -140,14 +140,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX); /* reference - optional */ - token = strtok(NULL, delim); + token = strtok_s(NULL, delim, &sp); if (token != NULL) strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX); else memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX); /* check for extra tokens */ - token = strtok(NULL, delim); + token = strtok_s(NULL, delim, &sp); if (token != NULL) { ml_err("Invalid filelist. Entries > 4\n."); return -EINVAL; From patchwork Tue Nov 14 08:41:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134239 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 F0F6843325; Tue, 14 Nov 2023 09:47:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 89DED40A70; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 00D93402EF for ; Tue, 14 Nov 2023 09:47:16 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0KH3ZxhzvQjq for ; Tue, 14 Nov 2023 16:46:59 +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; Tue, 14 Nov 2023 16:47:14 +0800 From: Jie Hai To: , Chengwen Feng , Kevin Laatz , Bruce Richardson , Sean Morrissey , Conor Walsh CC: , Subject: [PATCH v2 09/22] dmadev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:20 +0800 Message-ID: <20231114084133.3573959-10-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 39b5ab60df30 ("dmadev: add telemetry") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- lib/dmadev/rte_dmadev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c index 4e5e420c82a5..e9c052304393 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -971,7 +971,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused, struct rte_dma_info dma_info; struct rte_dma_stats dma_stats; int dev_id, ret, vchan_id; - char *end_param; + char *end_param, *sp = NULL; const char *vchan_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -990,7 +990,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused, if (dma_info.nb_vchans == 1 && *end_param == '\0') vchan_id = 0; else { - vchan_param = strtok(end_param, ","); + vchan_param = strtok_s(end_param, ",", &sp); if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param)) return -EINVAL; From patchwork Tue Nov 14 08:41:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134241 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 7022243325; Tue, 14 Nov 2023 09:48:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39BA840DCB; Tue, 14 Nov 2023 09:47:26 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 7FD8F402D6 for ; Tue, 14 Nov 2023 09:47:16 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0KJ088yzvQfV; Tue, 14 Nov 2023 16:46:59 +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; Tue, 14 Nov 2023 16:47:15 +0800 From: Jie Hai To: , Anatoly Burakov , Amit Prakash Shukla CC: , , Subject: [PATCH v2 10/22] eal: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:21 +0800 Message-ID: <20231114084133.3573959-11-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 2054f31a1fcd ("mem: add memseg info in telemetry") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- lib/eal/common/eal_common_memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c index d9433db62345..327eb0f65289 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) char dlim[2] = ","; char *params_args; size_t count = 0; - char *token; + char *token, *sp = NULL; if (vals == NULL || params == NULL || strlen(params) == 0) return -1; - /* strtok expects char * and param is const char *. Hence on using + /* strtok_s expects char * and param is const char *. Hence on using * params as "const char *" compiler throws warning. */ params_args = strdup(params); if (params_args == NULL) return -1; - token = strtok(params_args, dlim); + token = strtok_s(params_args, dlim, &sp); while (token && isdigit(*token) && count < n_vals) { vals[count++] = strtoul(token, NULL, 10); - token = strtok(NULL, dlim); + token = strtok_s(NULL, dlim, &sp); } free(params_args); From patchwork Tue Nov 14 08:41:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134242 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 7494243325; Tue, 14 Nov 2023 09:48:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F01440DDB; Tue, 14 Nov 2023 09:47:27 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 2456F402F2 for ; Tue, 14 Nov 2023 09:47:17 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fn09chzrV4m; Tue, 14 Nov 2023 16:43:57 +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; Tue, 14 Nov 2023 16:47:15 +0800 From: Jie Hai To: , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , , Subject: [PATCH v2 11/22] ethdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:22 +0800 Message-ID: <20231114084133.3573959-12-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: f38f62650f7b ("ethdev: add Rx queue telemetry query") Fixes: 9e7533aeb80a ("ethdev: add telemetry command for TM level capabilities") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- lib/ethdev/rte_ethdev_telemetry.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index b01028ce9b60..658f7e54de03 100644 --- a/lib/ethdev/rte_ethdev_telemetry.c +++ b/lib/ethdev/rte_ethdev_telemetry.c @@ -477,6 +477,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx, const char *qid_param; uint16_t nb_queues; char *end_param; + char *sp = NULL; uint64_t qid; int ret; @@ -489,7 +490,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx, if (nb_queues == 1 && *end_param == '\0') qid = 0; else { - qid_param = strtok(end_param, ","); + qid_param = strtok_s(end_param, ",", &sp); if (!qid_param || strlen(qid_param) == 0 || !isdigit(*qid_param)) return -EINVAL; @@ -1221,9 +1222,10 @@ static int eth_dev_parse_tm_params(char *params, uint32_t *result) { const char *splited_param; + char *sp = NULL; uint64_t ret; - splited_param = strtok(params, ","); + splited_param = strtok_s(params, ",", &sp); if (!splited_param || strlen(splited_param) == 0 || !isdigit(*splited_param)) return -EINVAL; From patchwork Tue Nov 14 08:41:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134243 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 B9F0443325; Tue, 14 Nov 2023 09:48:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C95840DF6; Tue, 14 Nov 2023 09:47:28 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id B5948402EE for ; Tue, 14 Nov 2023 09:47:17 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fp2Bm8z1P7mb; Tue, 14 Nov 2023 16:43:58 +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; Tue, 14 Nov 2023 16:47:16 +0800 From: Jie Hai To: , Naga Harish K S V , Jerin Jacob CC: , , Subject: [PATCH v2 12/22] eventdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:23 +0800 Message-ID: <20231114084133.3573959-13-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- lib/eventdev/rte_event_eth_rx_adapter.c | 38 ++++++++++++------------- lib/eventdev/rte_eventdev.c | 18 ++++++------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 6db03adf0463..91e535e983d3 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -3651,7 +3651,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp; struct rte_event_eth_rx_adapter_queue_conf queue_conf; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3661,19 +3661,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_s(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3684,7 +3684,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_s(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3723,7 +3723,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; struct rte_event_eth_rx_adapter_queue_stats q_stats; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3733,19 +3733,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_s(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3756,7 +3756,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_s(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3794,7 +3794,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3803,19 +3803,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_s(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3826,7 +3826,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_s(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3855,7 +3855,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, uint8_t instance_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3863,14 +3863,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_s(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_s(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3881,7 +3881,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_s(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c index 0ca32d672175..9e753c3720c0 100644 --- a/lib/eventdev/rte_eventdev.c +++ b/lib/eventdev/rte_eventdev.c @@ -1784,7 +1784,7 @@ handle_queue_links(const char *cmd __rte_unused, struct rte_tel_data *d) { int i, ret, port_id = 0; - char *end_param; + char *end_param, *sp = NULL; uint8_t dev_id; uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV]; uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV]; @@ -1797,12 +1797,12 @@ handle_queue_links(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_s(end_param, ",", &sp); if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) return -1; port_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_s(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1922,7 +1922,7 @@ handle_port_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1932,7 +1932,7 @@ handle_port_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_s(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_PORT; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1940,7 +1940,7 @@ handle_port_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_s(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1956,7 +1956,7 @@ handle_queue_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1966,7 +1966,7 @@ handle_queue_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_s(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_QUEUE; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1974,7 +1974,7 @@ handle_queue_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_s(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); From patchwork Tue Nov 14 08:41:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134244 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 9513043325; Tue, 14 Nov 2023 09:48:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B459140E0F; Tue, 14 Nov 2023 09:47:29 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 6F0B54068A for ; Tue, 14 Nov 2023 09:47:18 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0Dn0lylzPpCs; Tue, 14 Nov 2023 16:43:05 +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; Tue, 14 Nov 2023 16:47:16 +0800 From: Jie Hai To: , Akhil Goyal , Gowrishankar Muthukrishnan CC: , , Subject: [PATCH v2 13/22] security: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:24 +0800 Message-ID: <20231114084133.3573959-14-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 259ca6d1617f ("security: add telemetry endpoint for capabilities") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- lib/security/rte_security.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c index b082a290296b..51e3a669e6ec 100644 --- a/lib/security/rte_security.c +++ b/lib/security/rte_security.c @@ -496,13 +496,14 @@ security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char * int dev_id, capa_id; int crypto_caps_n; char *end_param; + char *sp = NULL; int rc; if (!params || strlen(params) == 0 || !isdigit(*params)) return -EINVAL; dev_id = strtoul(params, &end_param, 0); - capa_param = strtok(end_param, ","); + capa_param = strtok_s(end_param, ",", &sp); if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param)) return -EINVAL; From patchwork Tue Nov 14 08:41:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134245 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 2333843325; Tue, 14 Nov 2023 09:48:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D801D40E36; Tue, 14 Nov 2023 09:47:30 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id C456240697 for ; Tue, 14 Nov 2023 09:47:18 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fp57zNzrVDF for ; Tue, 14 Nov 2023 16:43:58 +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; Tue, 14 Nov 2023 16:47:17 +0800 From: Jie Hai To: , Ciara Power , Keith Wiles , Bruce Richardson CC: , , Subject: [PATCH v2 14/22] telemetry: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:25 +0800 Message-ID: <20231114084133.3573959-15-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng Acked-by: Ciara Power --- lib/telemetry/telemetry.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 92982842a860..ef5cc87c34d1 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -371,6 +371,7 @@ static void * client_handler(void *sock_id) { int s = (int)(uintptr_t)sock_id; + char *sp = NULL; char buffer[1024]; char info_str[1024]; snprintf(info_str, sizeof(info_str), @@ -385,8 +386,8 @@ client_handler(void *sock_id) int bytes = read(s, buffer, sizeof(buffer) - 1); while (bytes > 0) { buffer[bytes] = 0; - const char *cmd = strtok(buffer, ","); - const char *param = strtok(NULL, "\0"); + const char *cmd = strtok_s(buffer, ",", &sp); + const char *param = strtok_s(NULL, "\0", &sp); telemetry_cb fn = unknown_command; int i; From patchwork Tue Nov 14 08:41:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134246 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 8B3A543325; Tue, 14 Nov 2023 09:48:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D59640E54; Tue, 14 Nov 2023 09:47:32 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id A42314068A for ; Tue, 14 Nov 2023 09:47:19 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0KF0059zWhBk; Tue, 14 Nov 2023 16:46:56 +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; Tue, 14 Nov 2023 16:47:17 +0800 From: Jie Hai To: , Hemant Agrawal , Sachin Saxena , Nipun Gupta , Shreyansh Jain , Santosh Shukla , Ferruh Yigit CC: , , Subject: [PATCH v2 15/22] bus/fslmc: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:26 +0800 Message-ID: <20231114084133.3573959-16-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 9ccb76b24c1d ("bus/fslmc: enable portal interrupt handling") Fixes: 828d51d8fc3e ("bus/fslmc: refactor scan and probe functions") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- drivers/bus/fslmc/fslmc_bus.c | 5 +++-- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 57bfb5111a97..2aa0e45c3d1b 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name) { char *dup_dev_name, *t_ptr; struct rte_dpaa2_device *dev = NULL; + char *sp = NULL; int ret = -1; if (!dev_name) @@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name) } /* Parse the device name and ID */ - t_ptr = strtok(dup_dev_name, "."); + t_ptr = strtok_s(dup_dev_name, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name); ret = -EINVAL; @@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name) else dev->dev_type = DPAA2_UNKNOWN; - t_ptr = strtok(NULL, "."); + t_ptr = strtok_s(NULL, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name); ret = 0; diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c index 4aec7b2cd8ba..b788d7681866 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) uint32_t cpu_mask = 1; int ret; size_t len = 0; - char *temp = NULL, *token = NULL; + char *temp = NULL, *token = NULL, *sp = NULL; char string[STRING_LEN], command[COMMAND_LEN]; FILE *file; @@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) } while (getline(&temp, &len, file) != -1) { if ((strstr(temp, string)) != NULL) { - token = strtok(temp, ":"); + token = strtok_s(temp, ":", &sp); break; } } From patchwork Tue Nov 14 08:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134247 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 A6E3E43325; Tue, 14 Nov 2023 09:48:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 34E7E40E8A; Tue, 14 Nov 2023 09:47:33 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 4B7E74068A for ; Tue, 14 Nov 2023 09:47:20 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0Dq0Y5wzPpLN; Tue, 14 Nov 2023 16:43:07 +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; Tue, 14 Nov 2023 16:47:18 +0800 From: Jie Hai To: , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Jerin Jacob , Gowrishankar Muthukrishnan , Harman Kalra CC: , , Subject: [PATCH v2 16/22] common/cnxk: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:27 +0800 Message-ID: <20231114084133.3573959-17-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: af75aac78978 ("common/cnxk: support telemetry for NIX") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- drivers/common/cnxk/cnxk_telemetry_nix.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c index ccae5d7853af..eff1517951e9 100644 --- a/drivers/common/cnxk/cnxk_telemetry_nix.c +++ b/drivers/common/cnxk/cnxk_telemetry_nix.c @@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, struct plt_tel_data *d) { struct nix_tel_node *node; - char *name, *param; + char *name, *param, *sp = NULL; char buf[1024]; int rc = -1; @@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, goto exit; plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1); - name = strtok(buf, ","); + name = strtok_s(buf, ",", &sp); if (name == NULL) goto exit; - param = strtok(NULL, "\0"); + param = strtok_s(NULL, "\0", &sp); node = nix_tel_node_get_by_pcidev_name(name); if (!node) @@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, plt_tel_data_start_dict(d); if (strstr(cmd, "rq")) { - char *tok = strtok(param, ","); + char *tok = strtok_s(param, ",", &sp); int rq; if (!tok) @@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, rc = cnxk_tel_nix_rq(node->rqs[rq], d); } else if (strstr(cmd, "cq")) { - char *tok = strtok(param, ","); + char *tok = strtok_s(param, ",", &sp); int cq; if (!tok) @@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, rc = cnxk_tel_nix_cq(node->cqs[cq], d); } else if (strstr(cmd, "sq")) { - char *tok = strtok(param, ","); + char *tok = strtok_s(param, ",", &sp); int sq; if (!tok) From patchwork Tue Nov 14 08:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134248 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 F15DE43325; Tue, 14 Nov 2023 09:48:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5229140ED3; Tue, 14 Nov 2023 09:47:34 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id B01C4406BC for ; Tue, 14 Nov 2023 09:47:20 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fs2Zlbz1P7nw; Tue, 14 Nov 2023 16:44:01 +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; Tue, 14 Nov 2023 16:47:19 +0800 From: Jie Hai To: , Pavan Nikhilesh , Shijith Thotton CC: , , Subject: [PATCH v2 17/22] event/cnxk: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:28 +0800 Message-ID: <20231114084133.3573959-18-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- drivers/event/cnxk/cnxk_eventdev.c | 10 ++++++---- drivers/event/cnxk/cnxk_tim_evdev.c | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c index 0c61f4c20eec..1067c403ee02 100644 --- a/drivers/event/cnxk/cnxk_eventdev.c +++ b/drivers/event/cnxk/cnxk_eventdev.c @@ -478,7 +478,8 @@ parse_queue_param(char *value, void *opaque) struct cnxk_sso_qos queue_qos = {0}; uint16_t *val = (uint16_t *)&queue_qos; struct cnxk_sso_evdev *dev = opaque; - char *tok = strtok(value, "-"); + char *sp = NULL; + char *tok = strtok_s(value, "-", &sp); struct cnxk_sso_qos *old_ptr; if (!strlen(value)) @@ -486,7 +487,7 @@ parse_queue_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_s(NULL, "-", &sp); val++; } @@ -514,7 +515,8 @@ parse_stash_param(char *value, void *opaque) struct cnxk_sso_stash queue_stash = {0}; struct cnxk_sso_evdev *dev = opaque; struct cnxk_sso_stash *old_ptr; - char *tok = strtok(value, "|"); + char *sp = NULL; + char *tok = strtok_s(value, "|", &sp); uint16_t *val; if (!strlen(value)) @@ -523,7 +525,7 @@ parse_stash_param(char *value, void *opaque) val = (uint16_t *)&queue_stash; while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "|"); + tok = strtok_s(NULL, "|", &sp); val++; } diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c b/drivers/event/cnxk/cnxk_tim_evdev.c index 6d59fdf90983..82975ec8c6e7 100644 --- a/drivers/event/cnxk/cnxk_tim_evdev.c +++ b/drivers/event/cnxk/cnxk_tim_evdev.c @@ -420,7 +420,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque) { struct cnxk_tim_evdev *dev = opaque; struct cnxk_tim_ctl ring_ctl = {0}; - char *tok = strtok(value, "-"); + char *sp = NULL; + char *tok = strtok_s(value, "-", &sp); struct cnxk_tim_ctl *old_ptr; uint16_t *val; @@ -431,7 +432,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_s(NULL, "-", &sp); val++; } @@ -507,16 +508,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque) ROC_TIM_CLK_SRC_INVALID}; struct cnxk_tim_evdev *dev = opaque; char *str = strdup(value); - char *tok; + char *tok, *sp = NULL; int i = 0; if (str == NULL || !strlen(str)) goto free; - tok = strtok(str, "-"); + tok = strtok_s(str, "-", &sp); while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) { dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10); - tok = strtok(NULL, "-"); + tok = strtok_s(NULL, "-", &sp); i++; } From patchwork Tue Nov 14 08:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134249 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 2CA7C43325; Tue, 14 Nov 2023 09:48:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4041040EDC; Tue, 14 Nov 2023 09:47:35 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 5CC9340A6B for ; Tue, 14 Nov 2023 09:47:21 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Fs1YlmzrVDn; Tue, 14 Nov 2023 16:44:01 +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; Tue, 14 Nov 2023 16:47:19 +0800 From: Jie Hai To: , Shepard Siegel , Ed Czeck , John Miller CC: , , Subject: [PATCH v2 18/22] net/ark: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:29 +0800 Message-ID: <20231114084133.3573959-19-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 9c7188a68d7b ("net/ark: provide API for hardware modules pktchkr and pktgen") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- drivers/net/ark/ark_pktchkr.c | 10 +++++----- drivers/net/ark/ark_pktgen.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c index e1f336c73c2a..c1c1033eb75e 100644 --- a/drivers/net/ark/ark_pktchkr.c +++ b/drivers/net/ark/ark_pktchkr.c @@ -359,14 +359,14 @@ set_arg(char *arg, char *val) void ark_pktchkr_parse(char *args) { - char *argv, *v; + char *argv, *v, *sp = NULL; const char toks[] = "=\n\t\v\f \r"; - argv = strtok(args, toks); - v = strtok(NULL, toks); + argv = strtok_s(args, toks, &sp); + v = strtok_s(NULL, toks, &sp); while (argv && v) { set_arg(argv, v); - argv = strtok(NULL, toks); - v = strtok(NULL, toks); + argv = strtok_s(NULL, toks, &sp); + v = strtok_s(NULL, toks, &sp); } } diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index 69ff7072b2ab..4b564099d2d6 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -340,14 +340,14 @@ pmd_set_arg(char *arg, char *val) void ark_pktgen_parse(char *args) { - char *argv, *v; + char *argv, *v, *sp = NULL; const char toks[] = " =\n\t\v\f \r"; - argv = strtok(args, toks); - v = strtok(NULL, toks); + argv = strtok_s(args, toks, &sp); + v = strtok_s(NULL, toks, &sp); while (argv && v) { pmd_set_arg(argv, v); - argv = strtok(NULL, toks); - v = strtok(NULL, toks); + argv = strtok_s(NULL, toks, &sp); + v = strtok_s(NULL, toks, &sp); } } From patchwork Tue Nov 14 08:41: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: 134250 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 AF7DD43325; Tue, 14 Nov 2023 09:48:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 43CD040DC9; Tue, 14 Nov 2023 09:47:36 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 1A3AE406BC for ; Tue, 14 Nov 2023 09:47:22 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV0Dr56k1zPnZK; Tue, 14 Nov 2023 16:43:08 +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; Tue, 14 Nov 2023 16:47:20 +0800 From: Jie Hai To: , Jakub Palider , Tomasz Duszynski , Jerin Jacob CC: , , Subject: [PATCH v2 19/22] raw/cnxk_gpio: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:30 +0800 Message-ID: <20231114084133.3573959-20-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c index 29c250672646..0e6ee31d35c9 100644 --- a/drivers/raw/cnxk_gpio/cnxk_gpio.c +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c @@ -190,7 +190,7 @@ static int cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) { int i, ret, val, queue = 0; - char *token; + char *token, *sp = NULL; int *list; list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0); @@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) allowlist[strlen(allowlist) - 1] = ' '; /* quiesce -Wcast-qual */ - token = strtok((char *)(uintptr_t)allowlist, ","); + token = strtok_s((char *)(uintptr_t)allowlist, ",", &sp); do { errno = 0; val = strtol(token, NULL, 10); @@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) } if (i == queue) list[queue++] = val; - } while ((token = strtok(NULL, ","))); + } while ((token = strtok_s(NULL, ",", &sp))); free(allowlist); gpiochip->allowlist = list; From patchwork Tue Nov 14 08:41: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: 134252 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 7003B43325; Tue, 14 Nov 2023 09:49:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5A976410FB; Tue, 14 Nov 2023 09:47:39 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 8A88440A77 for ; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0KP6JZ2zvQkc; Tue, 14 Nov 2023 16:47:05 +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; Tue, 14 Nov 2023 16:47:20 +0800 From: Jie Hai To: , Akhil Goyal , Fan Zhang , Pablo de Lara CC: , , Subject: [PATCH v2 20/22] examples/l2fwd-crypto: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:31 +0800 Message-ID: <20231114084133.3573959-21-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: ff5d5b01f8f2 ("examples/l2fwd-crypto: support AES-CCM") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- examples/l2fwd-crypto/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index efe7eea2a768..7327ff1128df 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -1105,12 +1105,12 @@ static int parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size) { unsigned byte_count; - char *token; + char *token, *sp = NULL; errno = 0; - for (byte_count = 0, token = strtok(input_arg, ":"); + for (byte_count = 0, token = strtok_s(input_arg, ":", &sp); (byte_count < max_size) && (token != NULL); - token = strtok(NULL, ":")) { + token = strtok_s(NULL, ":", &sp)) { int number = (int)strtol(token, NULL, 16); From patchwork Tue Nov 14 08:41: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: 134251 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 7AA6943325; Tue, 14 Nov 2023 09:49:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 34E20410F1; Tue, 14 Nov 2023 09:47:38 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 0435E40A70 for ; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV0Ft6F3KzrVDl; Tue, 14 Nov 2023 16:44:02 +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; Tue, 14 Nov 2023 16:47:21 +0800 From: Jie Hai To: , Maxime Coquelin , Chenbo Xia , Cheng Jiang CC: , , Subject: [PATCH v2 21/22] examples/vhost: replace strtok with reentrant version Date: Tue, 14 Nov 2023 16:41:32 +0800 Message-ID: <20231114084133.3573959-22-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 version. Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing") Cc: stable@dpdk.org Signed-off-by: Jie Hai Acked-by: Chengwen Feng --- examples/vhost/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index ce5c1efddf5c..3949d83be212 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -246,6 +246,7 @@ open_dma(const char *value) char *ptrs[2]; char *start, *end, *substr; int64_t socketid, vring_id; + char *sp = NULL; struct rte_dma_info info; struct rte_dma_conf dev_config = { .nb_vchans = 1 }; @@ -269,7 +270,7 @@ open_dma(const char *value) /* process DMA devices within bracket. */ addrs++; - substr = strtok(addrs, ";]"); + substr = strtok_s(addrs, ";]", &sp); if (!substr) { ret = -1; goto out; From patchwork Tue Nov 14 08:41: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: 134253 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 38C8443325; Tue, 14 Nov 2023 09:49:17 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 679BF41101; Tue, 14 Nov 2023 09:47:40 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 8EF3640A79 for ; Tue, 14 Nov 2023 09:47:23 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SV0DR4DcjzMmnS; Tue, 14 Nov 2023 16:42: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; Tue, 14 Nov 2023 16:47:21 +0800 From: Jie Hai To: , Thomas Monjalon CC: , , Subject: [PATCH v2 22/22] devtools: check for some reentrant function Date: Tue, 14 Nov 2023 16:41:33 +0800 Message-ID: <20231114084133.3573959-23-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114084133.3573959-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114084133.3573959-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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. This patch adds check in checkpatches.sh for strtok, which is non-reentrant. Signed-off-by: Jie Hai --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 066449d147e8..0a936219c069 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -119,6 +119,14 @@ check_forbidden_additions() { # -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # refrain from using some non-reentrant functions + awk -v FOLDERS="lib drivers app examples" \ + -v EXPRESSIONS="strtok\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Using non-reentrant function strtok, prefer strtok_s' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # refrain from using some pthread functions awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \