From patchwork Tue Nov 14 10:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134258 X-Patchwork-Delegate: david.marchand@redhat.com 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 BEA8043329; Tue, 14 Nov 2023 12:10:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 415E1402ED; Tue, 14 Nov 2023 12:09:59 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id BC9C34027D for ; Tue, 14 Nov 2023 12:09:55 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tk4hbBzWhH1; Tue, 14 Nov 2023 19:09:30 +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 19:09:51 +0800 From: Jie Hai To: , Sunil Kumar Kori , Rakesh Kudurumalla , Nithin Dabilpuram , Jerin Jacob CC: , , Subject: [PATCH v3 01/22] app/graph: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:45 +0800 Message-ID: <20231114110006.91148-2-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..316950948160 100644 --- a/app/graph/graph.c +++ b/app/graph/graph.c @@ -103,9 +103,10 @@ parser_usecases_read(char *usecases) { bool valid = false; uint32_t i, j = 0; + char *sp = NULL; char *token; - token = strtok(usecases, ","); + token = strtok_r(usecases, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(supported_usecases); i++) { if (strcmp(supported_usecases[i], token) == 0) { @@ -116,7 +117,7 @@ parser_usecases_read(char *usecases) break; } } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } return valid; diff --git a/app/graph/utils.c b/app/graph/utils.c index c7b6ae83cf1f..ae2ff225c394 100644 --- a/app/graph/utils.c +++ b/app/graph/utils.c @@ -101,13 +101,14 @@ int parser_ip4_read(uint32_t *value, char *p) { uint8_t shift = 24; + char *sp = NULL; uint32_t ip = 0; char *token; - token = strtok(p, "."); + token = strtok_r(p, ".", &sp); while (token != NULL) { ip |= (((uint32_t)strtoul(token, NULL, 10)) << shift); - token = strtok(NULL, "."); + token = strtok_r(NULL, ".", &sp); shift -= 8; } @@ -120,13 +121,14 @@ int parser_ip6_read(uint8_t *value, char *p) { uint64_t val = 0; + char *sp = NULL; char *token; - token = strtok(p, ":"); + token = strtok_r(p, ":", &sp); while (token != NULL) { hex_string_to_uint64(&val, token); *value = val; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); value++; val = 0; } @@ -139,13 +141,14 @@ parser_mac_read(uint64_t *value, char *p) { uint64_t mac = 0, val = 0; uint8_t shift = 40; + char *sp = NULL; char *token; - token = strtok(p, ":"); + token = strtok_r(p, ":", &sp); while (token != NULL) { hex_string_to_uint64(&val, token); mac |= val << shift; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); shift -= 8; val = 0; } From patchwork Tue Nov 14 10:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134262 X-Patchwork-Delegate: david.marchand@redhat.com 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 71E7243329; Tue, 14 Nov 2023 12:10:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0496040698; Tue, 14 Nov 2023 12:10:04 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id E0837402E4 for ; Tue, 14 Nov 2023 12:09:56 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SV3Ns68jzzMmls; Tue, 14 Nov 2023 19:05:17 +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 19:09:52 +0800 From: Jie Hai To: , Nicolas Chautru , Maxime Coquelin , Amr Mokhtar CC: , , Subject: [PATCH v3 02/22] app/bbdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:46 +0800 Message-ID: <20231114110006.91148-3-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..5c966e79645e 100644 --- a/app/test-bbdev/test_bbdev_vector.c +++ b/app/test-bbdev/test_bbdev_vector.c @@ -63,8 +63,9 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) uint32_t *values, *values_resized; char *tok, *error = NULL; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -98,7 +99,7 @@ parse_values(char *tokens, uint32_t **data, uint32_t *data_length) *data_length = *data_length + (strlen(tok) - strlen("0x"))/2; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -299,8 +300,9 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, { char *tok = NULL; uint32_t op_flag_value = 0; + char *sp = NULL; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -330,7 +332,7 @@ parse_turbo_flags(char *tokens, uint32_t *op_flags, *op_flags = *op_flags | op_flag_value; - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -368,9 +370,10 @@ static int parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) { char *tok = NULL; + char *sp = NULL; bool status_ok = false; - tok = strtok(tokens, VALUE_DELIMITER); + tok = strtok_r(tokens, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -401,7 +404,7 @@ parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) return -1; } - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) break; } @@ -894,6 +897,7 @@ parse_fft_params(const char *key_token, char *token, int ret = 0, status = 0, i, shift; uint32_t op_flags = 0; char *tok, *err = NULL; + char *sp = NULL; struct rte_bbdev_op_fft *fft = &vector->fft; @@ -922,7 +926,7 @@ parse_fft_params(const char *key_token, char *token, fft->output_leading_depadding = (uint32_t) strtoul(token, &err, 0); ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; } else if (!strcmp(key_token, "window_index")) { - tok = strtok(token, VALUE_DELIMITER); + tok = strtok_r(token, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; for (i = 0; i < FFT_WIN_SIZE; i++) { @@ -930,7 +934,7 @@ parse_fft_params(const char *key_token, char *token, fft->window_index[i / 2] |= (uint32_t) strtoul(tok, &err, 0) << shift; if (i < (FFT_WIN_SIZE - 1)) { - tok = strtok(NULL, VALUE_DELIMITER); + tok = strtok_r(NULL, VALUE_DELIMITER, &sp); if (tok == NULL) return -1; } @@ -995,6 +999,7 @@ static int parse_entry(char *entry, struct test_bbdev_vector *vector) { int ret = 0; + char *sp = NULL; char *token, *key_token; enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE; @@ -1004,10 +1009,10 @@ parse_entry(char *entry, struct test_bbdev_vector *vector) } /* get key */ - token = strtok(entry, ENTRY_DELIMITER); + token = strtok_r(entry, ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, ENTRY_DELIMITER); + token = strtok_r(NULL, ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); From patchwork Tue Nov 14 10:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134261 X-Patchwork-Delegate: david.marchand@redhat.com 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 F0F4043329; Tue, 14 Nov 2023 12:10:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C211D40693; Tue, 14 Nov 2023 12:10:02 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id A5AE44027D for ; Tue, 14 Nov 2023 12:09:56 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3Ts5m7JzvQWY; Tue, 14 Nov 2023 19:09:37 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:09:52 +0800 From: Jie Hai To: , Pablo de Lara , Shally Verma , Lee Daly , Tomasz Jozwiak , Fiona Trahe CC: , , Subject: [PATCH v3 03/22] app/compress-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:47 +0800 Message-ID: <20231114110006.91148-4-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..d997fa667a94 100644 --- a/app/test-compress-perf/comp_perf_options_parse.c +++ b/app/test-compress-perf/comp_perf_options_parse.c @@ -177,6 +177,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) { char *token; uint8_t number; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -184,7 +185,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) return -1; errno = 0; - token = strtok(copy_arg, ":"); + token = strtok_r(copy_arg, ":", &sp); /* Parse minimum value */ if (token != NULL) { @@ -197,7 +198,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); /* Parse increment value */ if (token != NULL) { @@ -211,7 +212,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); /* Parse maximum value */ if (token != NULL) { @@ -225,7 +226,7 @@ parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) } else goto err_range; - if (strtok(NULL, ":") != NULL) + if (strtok_r(NULL, ":", &sp) != NULL) goto err_range; free(copy_arg); @@ -244,6 +245,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) uint8_t count = 0; uint32_t temp_min; uint32_t temp_max; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -251,7 +253,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) return -1; errno = 0; - token = strtok(copy_arg, ","); + token = strtok_r(copy_arg, ",", &sp); /* Parse first value */ if (token != NULL) { @@ -266,7 +268,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) } else goto err_list; - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); while (token != NULL) { if (count == MAX_LIST) { @@ -288,7 +290,7 @@ parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max) if (number > temp_max) temp_max = number; - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } if (min) From patchwork Tue Nov 14 10:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134263 X-Patchwork-Delegate: david.marchand@redhat.com 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 8756743329; Tue, 14 Nov 2023 12:10:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2B019406BA; Tue, 14 Nov 2023 12:10:05 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id CB3B14027B for ; Tue, 14 Nov 2023 12:09:56 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3QL6Bf0zmXDL for ; Tue, 14 Nov 2023 19:06:34 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:09:53 +0800 From: Jie Hai To: , Ciara Power , Sergio Gonzalez Monroy , Pablo de Lara , Piotr Azarewicz , Michal Kobylinski , Declan Doherty , Slawomir Mrozowicz , Marcin Kerlin CC: , , Subject: [PATCH v3 04/22] app/crypto-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:48 +0800 Message-ID: <20231114110006.91148-5-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 --- app/test-crypto-perf/cperf_options_parsing.c | 16 +++++++++------- app/test-crypto-perf/cperf_test_vector_parsing.c | 10 ++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 75afedc7fd6e..77cda0eb8e6f 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -161,6 +161,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) { char *token; uint32_t number; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -168,7 +169,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) return -1; errno = 0; - token = strtok(copy_arg, ":"); + token = strtok_r(copy_arg, ":", &sp); /* Parse minimum value */ if (token != NULL) { @@ -182,7 +183,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); /* Parse increment value */ if (token != NULL) { @@ -196,7 +197,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - token = strtok(NULL, ":"); + token = strtok_r(NULL, ":", &sp); /* Parse maximum value */ if (token != NULL) { @@ -211,7 +212,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) } else goto err_range; - if (strtok(NULL, ":") != NULL) + if (strtok_r(NULL, ":", &sp) != NULL) goto err_range; free(copy_arg); @@ -230,6 +231,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) uint8_t count = 0; uint32_t temp_min; uint32_t temp_max; + char *sp = NULL; char *copy_arg = strdup(arg); @@ -237,7 +239,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) return -1; errno = 0; - token = strtok(copy_arg, ","); + token = strtok_r(copy_arg, ",", &sp); /* Parse first value */ if (token != NULL) { @@ -253,7 +255,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) } else goto err_list; - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); while (token != NULL) { if (count == MAX_LIST) { @@ -275,7 +277,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) if (number > temp_max) temp_max = number; - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } if (min) diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c index 737d61d4af6b..4d2e6053e745 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -220,8 +220,9 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length) uint8_t *values, *values_resized; char *tok, *error = NULL; + char *sp = NULL; - tok = strtok(tokens, CPERF_VALUE_DELIMITER); + tok = strtok_r(tokens, CPERF_VALUE_DELIMITER, &sp); if (tok == NULL) return -1; @@ -252,7 +253,7 @@ parse_values(char *tokens, uint8_t **data, uint32_t *data_length) return -1; } - tok = strtok(NULL, CPERF_VALUE_DELIMITER); + tok = strtok_r(NULL, CPERF_VALUE_DELIMITER, &sp); if (tok == NULL) break; @@ -283,6 +284,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector, uint8_t *data = NULL; char *token, *key_token; + char *sp = NULL; if (entry == NULL) { printf("Expected entry value\n"); @@ -290,10 +292,10 @@ parse_entry(char *entry, struct cperf_test_vector *vector, } /* get key */ - token = strtok(entry, CPERF_ENTRY_DELIMITER); + token = strtok_r(entry, CPERF_ENTRY_DELIMITER, &sp); key_token = token; /* get values for key */ - token = strtok(NULL, CPERF_ENTRY_DELIMITER); + token = strtok_r(NULL, CPERF_ENTRY_DELIMITER, &sp); if (key_token == NULL || token == NULL) { printf("Expected 'key = values' but was '%.40s'..\n", entry); From patchwork Tue Nov 14 10:59:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134259 X-Patchwork-Delegate: david.marchand@redhat.com 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 868B243329; Tue, 14 Nov 2023 12:10:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 752E540648; Tue, 14 Nov 2023 12:10:00 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 02362402E4 for ; Tue, 14 Nov 2023 12:09:55 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tm6pfFzWhJ8; Tue, 14 Nov 2023 19:09:32 +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 19:09:54 +0800 From: Jie Hai To: , Cheng Jiang , Chenbo Xia , Chengwen Feng , =?utf-8?q?Morten_Br=C3=B8rup?= , Jiayu Hu CC: , Subject: [PATCH v3 05/22] app/dma-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:49 +0800 Message-ID: <20231114110006.91148-6-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..38780939578e 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -164,6 +164,7 @@ parse_lcore(struct test_configure *test_case, const char *value) uint16_t len; char *input; struct lcore_dma_map_t *lcore_dma_map; + char *sp = NULL; if (test_case == NULL || value == NULL) return -1; @@ -175,7 +176,7 @@ parse_lcore(struct test_configure *test_case, const char *value) memset(lcore_dma_map, 0, sizeof(struct lcore_dma_map_t)); - char *token = strtok(input, ", "); + char *token = strtok_r(input, ", ", &sp); while (token != NULL) { if (lcore_dma_map->cnt >= MAX_LCORE_NB) { free(input); @@ -185,7 +186,7 @@ parse_lcore(struct test_configure *test_case, const char *value) uint16_t lcore_id = atoi(token); lcore_dma_map->lcores[lcore_dma_map->cnt++] = lcore_id; - token = strtok(NULL, ", "); + token = strtok_r(NULL, ", ", &sp); } free(input); @@ -201,6 +202,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) char *start, *end, *substr; uint16_t lcore_id; int ret = 0; + char *sp = NULL; if (test_case == NULL || value == NULL) return -1; @@ -216,7 +218,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) goto out; } - substr = strtok(addrs, ","); + substr = strtok_r(addrs, ",", &sp); if (substr == NULL) { fprintf(stderr, "No input DMA address\n"); ret = -1; @@ -258,7 +260,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value) strlcpy(lcore_dma_map->dma_names[lcore_dma_map->cnt], ptrs[1], RTE_DEV_NAME_MAX_LEN); lcore_dma_map->cnt++; - substr = strtok(NULL, ","); + substr = strtok_r(NULL, ",", &sp); } while (substr != NULL); out: @@ -486,6 +488,7 @@ main(int argc, char *argv[]) char *rst_path_ptr = NULL; char rst_path[PATH_MAX]; int new_argc; + char *sp = NULL; memset(args, 0, sizeof(args)); @@ -504,7 +507,7 @@ main(int argc, char *argv[]) } if (rst_path_ptr == NULL) { strlcpy(rst_path, cfg_path_ptr, PATH_MAX); - char *token = strtok(basename(rst_path), "."); + char *token = strtok_r(basename(rst_path), ".", &sp); if (token == NULL) { printf("Config file error.\n"); return -1; From patchwork Tue Nov 14 10:59:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134260 X-Patchwork-Delegate: david.marchand@redhat.com 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 6FE7E43329; Tue, 14 Nov 2023 12:10:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 916884067D; Tue, 14 Nov 2023 12:10:01 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 471CF4027B for ; Tue, 14 Nov 2023 12:09:56 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tn2sYKzWhLp for ; Tue, 14 Nov 2023 19:09:33 +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 19:09:54 +0800 From: Jie Hai To: , Vladimir Medvedkin CC: , , Subject: [PATCH v3 06/22] app/test-fib: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:50 +0800 Message-ID: <20231114110006.91148-7-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..8e5d17b13028 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -223,9 +223,9 @@ parse_distrib(uint8_t depth_lim, const uint32_t n) uint32_t nrpd[128 + 1] = {0}; /* number of routes per depth */ uint32_t n_routes; uint8_t depth, ratio, ratio_acc = 0; - char *in; + char *in, *sp = NULL; - in = strtok(distrib_string, ","); + in = strtok_r(distrib_string, ",", &sp); /*parse configures routes percentage ratios*/ while (in != NULL) { @@ -265,7 +265,7 @@ parse_distrib(uint8_t depth_lim, const uint32_t n) } /*number of configured depths in*/ - in = strtok(NULL, ","); + in = strtok_r(NULL, ",", &sp); } if (ratio_acc > 100) { @@ -542,10 +542,10 @@ parse_lookup(FILE *f, int af) int ret, i = 0; uint8_t *tbl = (uint8_t *)config.lookup_tbl; int step = (af == AF_INET) ? 4 : 16; - char *s; + char *s, *sp = NULL; while (fgets(line, sizeof(line), f) != NULL) { - s = strtok(line, " \t\n"); + s = strtok_r(line, " \t\n", &sp); if (s == NULL) return -EINVAL; ret = inet_pton(af, s, &tbl[i]); From patchwork Tue Nov 14 10:59:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134265 X-Patchwork-Delegate: david.marchand@redhat.com 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 A11C343329; Tue, 14 Nov 2023 12:10:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F1A840A70; Tue, 14 Nov 2023 12:10:07 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 11FDF402E5 for ; Tue, 14 Nov 2023 12:09:57 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tp00QKzWhMg; Tue, 14 Nov 2023 19:09:33 +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 19:09:55 +0800 From: Jie Hai To: , Wisam Jaddo , Alexander Kozyrev , Rongwei Liu , Jiawei Wang , Haifei Luo , Sean Zhang CC: , , Subject: [PATCH v3 07/22] app/flow-perf: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:51 +0800 Message-ID: <20231114110006.91148-8-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..36e7c1d72019 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -602,6 +602,7 @@ read_meter_policy(char *prog, char *arg) { char *token; size_t i, j, k; + char *sp = NULL; j = 0; k = 0; @@ -612,9 +613,9 @@ read_meter_policy(char *prog, char *arg) token = strsep(&arg, ":\0"); } j = 0; - token = strtok(actions_str[0], ",\0"); + token = strtok_r(actions_str[0], ",\0", &sp); while (token == NULL && j < RTE_COLORS - 1) - token = strtok(actions_str[++j], ",\0"); + token = strtok_r(actions_str[++j], ",\0", &sp); while (j < RTE_COLORS && token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (!strcmp(token, flow_options[i].str)) { @@ -628,9 +629,9 @@ read_meter_policy(char *prog, char *arg) usage(prog); rte_exit(EXIT_SUCCESS, "Invalid colored actions\n"); } - token = strtok(NULL, ",\0"); + token = strtok_r(NULL, ",\0", &sp); while (!token && j < RTE_COLORS - 1) { - token = strtok(actions_str[++j], ",\0"); + token = strtok_r(actions_str[++j], ",\0", &sp); k = 0; } } @@ -641,6 +642,7 @@ args_parse(int argc, char **argv) { uint64_t pm, seed; uint64_t hp_conf; + char *sp = NULL; char **argvopt; uint32_t prio; char *token; @@ -804,7 +806,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_ENCAP ); - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -817,7 +819,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid encap item: %s\n", token); } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } printf(" / "); } @@ -828,7 +830,7 @@ args_parse(int argc, char **argv) RTE_FLOW_ACTION_TYPE_RAW_DECAP ); - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { for (i = 0; i < RTE_DIM(flow_options); i++) { if (strcmp(flow_options[i].str, token) == 0) { @@ -841,7 +843,7 @@ args_parse(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid decap item %s\n", token); } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } printf(" / "); } @@ -910,10 +912,10 @@ args_parse(int argc, char **argv) uint16_t port_idx = 0; char *token; - token = strtok(optarg, ","); + token = strtok_r(optarg, ",", &sp); while (token != NULL) { dst_ports[port_idx++] = atoi(token); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); } } if (strcmp(lgopts[opt_idx].name, "rxq") == 0) { From patchwork Tue Nov 14 10:59:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134264 X-Patchwork-Delegate: david.marchand@redhat.com 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 ABBD943329; Tue, 14 Nov 2023 12:10:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6427140A67; Tue, 14 Nov 2023 12:10:06 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 2B789402E6 for ; Tue, 14 Nov 2023 12:09:57 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tw3Z17zvQF5; Tue, 14 Nov 2023 19:09:40 +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 19:09:55 +0800 From: Jie Hai To: , Srikanth Yalavarthi CC: , , Subject: [PATCH v3 08/22] app/test-mldev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:52 +0800 Message-ID: <20231114110006.91148-9-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..3f3dc8f69890 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -75,12 +75,12 @@ ml_parse_models(struct ml_options *opt, const char *arg) { const char *delim = ","; char models[PATH_MAX]; - char *token; + char *token, *sp = NULL; int ret = 0; strlcpy(models, arg, PATH_MAX); - token = strtok(models, delim); + token = strtok_r(models, delim, &sp); while (token != NULL) { strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); opt->nb_filelist++; @@ -90,7 +90,7 @@ ml_parse_models(struct ml_options *opt, const char *arg) ret = -EINVAL; break; } - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); } if (opt->nb_filelist == 0) { @@ -106,7 +106,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) { const char *delim = ","; char filelist[PATH_MAX]; - char *token; + char *token, *sp = NULL; if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS); @@ -116,7 +116,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(filelist, arg, PATH_MAX); /* model */ - token = strtok(filelist, delim); + token = strtok_r(filelist, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, model not specified = %s\n", arg); return -EINVAL; @@ -124,7 +124,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); /* input */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, input not specified = %s\n", arg); return -EINVAL; @@ -132,7 +132,7 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX); /* output */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token == NULL) { ml_err("Invalid filelist, output not specified = %s\n", arg); return -EINVAL; @@ -140,14 +140,14 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX); /* reference - optional */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token != NULL) strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX); else memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX); /* check for extra tokens */ - token = strtok(NULL, delim); + token = strtok_r(NULL, delim, &sp); if (token != NULL) { ml_err("Invalid filelist. Entries > 4\n."); return -EINVAL; From patchwork Tue Nov 14 10:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134266 X-Patchwork-Delegate: david.marchand@redhat.com 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 3C64D43329; Tue, 14 Nov 2023 12:10:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B1D1A4068E; Tue, 14 Nov 2023 12:10:08 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id AA2AC4027B for ; Tue, 14 Nov 2023 12:09:57 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tx0FhczvQTW for ; Tue, 14 Nov 2023 19:09:41 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:09:56 +0800 From: Jie Hai To: , Chengwen Feng , Kevin Laatz , Bruce Richardson , Conor Walsh , Sean Morrissey CC: , Subject: [PATCH v3 09/22] dmadev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:53 +0800 Message-ID: <20231114110006.91148-10-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..f856cc7d0905 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -971,7 +971,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused, struct rte_dma_info dma_info; struct rte_dma_stats dma_stats; int dev_id, ret, vchan_id; - char *end_param; + char *end_param, *sp = NULL; const char *vchan_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -990,7 +990,7 @@ dmadev_handle_dev_stats(const char *cmd __rte_unused, if (dma_info.nb_vchans == 1 && *end_param == '\0') vchan_id = 0; else { - vchan_param = strtok(end_param, ","); + vchan_param = strtok_r(end_param, ",", &sp); if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param)) return -EINVAL; From patchwork Tue Nov 14 10:59:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134267 X-Patchwork-Delegate: david.marchand@redhat.com 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 39BB943329; Tue, 14 Nov 2023 12:11:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D033B40A81; Tue, 14 Nov 2023 12:10:09 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 27715402E4 for ; Tue, 14 Nov 2023 12:09:58 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tx3V16zvQZH; Tue, 14 Nov 2023 19:09:41 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:09:56 +0800 From: Jie Hai To: , Anatoly Burakov , Amit Prakash Shukla CC: , , Subject: [PATCH v3 10/22] eal: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:54 +0800 Message-ID: <20231114110006.91148-11-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 Acked-by: Amit Prakash Shukla --- lib/eal/common/eal_common_memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c index d9433db62345..a05eb0442b0b 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -1273,22 +1273,22 @@ parse_params(const char *params, uint32_t *vals, size_t n_vals) char dlim[2] = ","; char *params_args; size_t count = 0; - char *token; + char *token, *sp = NULL; if (vals == NULL || params == NULL || strlen(params) == 0) return -1; - /* strtok expects char * and param is const char *. Hence on using + /* strtok_r expects char * and param is const char *. Hence on using * params as "const char *" compiler throws warning. */ params_args = strdup(params); if (params_args == NULL) return -1; - token = strtok(params_args, dlim); + token = strtok_r(params_args, dlim, &sp); while (token && isdigit(*token) && count < n_vals) { vals[count++] = strtoul(token, NULL, 10); - token = strtok(NULL, dlim); + token = strtok_r(NULL, dlim, &sp); } free(params_args); From patchwork Tue Nov 14 10:59:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134268 X-Patchwork-Delegate: david.marchand@redhat.com 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 A2F6943329; Tue, 14 Nov 2023 12:11:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E90E5406B8; Tue, 14 Nov 2023 12:10:10 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id C8B4B402E6 for ; Tue, 14 Nov 2023 12:09:58 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3QQ2v2PzmXBn; Tue, 14 Nov 2023 19:06:38 +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 19:09:57 +0800 From: Jie Hai To: , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , , Subject: [PATCH v3 11/22] ethdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:55 +0800 Message-ID: <20231114110006.91148-12-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 Reviewed-by: Andrew Rybchenko --- lib/ethdev/rte_ethdev_telemetry.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index b01028ce9b60..6810c54109a5 100644 --- a/lib/ethdev/rte_ethdev_telemetry.c +++ b/lib/ethdev/rte_ethdev_telemetry.c @@ -477,6 +477,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx, const char *qid_param; uint16_t nb_queues; char *end_param; + char *sp = NULL; uint64_t qid; int ret; @@ -489,7 +490,7 @@ ethdev_parse_queue_params(const char *params, bool is_rx, if (nb_queues == 1 && *end_param == '\0') qid = 0; else { - qid_param = strtok(end_param, ","); + qid_param = strtok_r(end_param, ",", &sp); if (!qid_param || strlen(qid_param) == 0 || !isdigit(*qid_param)) return -EINVAL; @@ -1221,9 +1222,10 @@ static int eth_dev_parse_tm_params(char *params, uint32_t *result) { const char *splited_param; + char *sp = NULL; uint64_t ret; - splited_param = strtok(params, ","); + splited_param = strtok_r(params, ",", &sp); if (!splited_param || strlen(splited_param) == 0 || !isdigit(*splited_param)) return -EINVAL; From patchwork Tue Nov 14 10:59:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134270 X-Patchwork-Delegate: david.marchand@redhat.com 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 4A21643329; Tue, 14 Nov 2023 12:11:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3935640DDA; Tue, 14 Nov 2023 12:10:13 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id D3911402EF for ; Tue, 14 Nov 2023 12:09:59 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3QQ6bF0zmXDL; Tue, 14 Nov 2023 19:06:38 +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 19:09:57 +0800 From: Jie Hai To: , Naga Harish K S V , Jerin Jacob CC: , , Subject: [PATCH v3 12/22] eventdev: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:56 +0800 Message-ID: <20231114110006.91148-13-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..4107d600dfb7 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -3651,7 +3651,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp; struct rte_event_eth_rx_adapter_queue_conf queue_conf; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3661,19 +3661,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3684,7 +3684,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3723,7 +3723,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; struct rte_event_eth_rx_adapter_queue_stats q_stats; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3733,19 +3733,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3756,7 +3756,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3794,7 +3794,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3803,19 +3803,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3826,7 +3826,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3855,7 +3855,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, uint8_t instance_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3863,14 +3863,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_ETH_VALID_PORTID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3881,7 +3881,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c index 0ca32d672175..fabba0228672 100644 --- a/lib/eventdev/rte_eventdev.c +++ b/lib/eventdev/rte_eventdev.c @@ -1784,7 +1784,7 @@ handle_queue_links(const char *cmd __rte_unused, struct rte_tel_data *d) { int i, ret, port_id = 0; - char *end_param; + char *end_param, *sp = NULL; uint8_t dev_id; uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV]; uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV]; @@ -1797,12 +1797,12 @@ handle_queue_links(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) return -1; port_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1922,7 +1922,7 @@ handle_port_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1932,7 +1932,7 @@ handle_port_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_PORT; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1940,7 +1940,7 @@ handle_port_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1956,7 +1956,7 @@ handle_queue_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1966,7 +1966,7 @@ handle_queue_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_QUEUE; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1974,7 +1974,7 @@ handle_queue_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); From patchwork Tue Nov 14 10:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134269 X-Patchwork-Delegate: david.marchand@redhat.com 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 768D543329; Tue, 14 Nov 2023 12:11:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1243A40DCA; Tue, 14 Nov 2023 12:10:12 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id E1EE8402F1 for ; Tue, 14 Nov 2023 12:09:59 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tr6rW6zWhG5; Tue, 14 Nov 2023 19:09:36 +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 19:09:58 +0800 From: Jie Hai To: , Akhil Goyal , Gowrishankar Muthukrishnan CC: , , Subject: [PATCH v3 13/22] security: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:57 +0800 Message-ID: <20231114110006.91148-14-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..e20d610172ef 100644 --- a/lib/security/rte_security.c +++ b/lib/security/rte_security.c @@ -496,13 +496,14 @@ security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char * int dev_id, capa_id; int crypto_caps_n; char *end_param; + char *sp = NULL; int rc; if (!params || strlen(params) == 0 || !isdigit(*params)) return -EINVAL; dev_id = strtoul(params, &end_param, 0); - capa_param = strtok(end_param, ","); + capa_param = strtok_r(end_param, ",", &sp); if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param)) return -EINVAL; From patchwork Tue Nov 14 10:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134271 X-Patchwork-Delegate: david.marchand@redhat.com 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 2FAB443329; Tue, 14 Nov 2023 12:11:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 688A840DFB; Tue, 14 Nov 2023 12:10:14 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 20E81402F2 for ; Tue, 14 Nov 2023 12:10:00 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tz3d6BzvQWY for ; Tue, 14 Nov 2023 19:09:43 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:09:58 +0800 From: Jie Hai To: , Ciara Power , Bruce Richardson , Keith Wiles CC: , , Subject: [PATCH v3 14/22] telemetry: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:58 +0800 Message-ID: <20231114110006.91148-15-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 --- lib/telemetry/telemetry.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 92982842a860..bb028d9381f7 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -371,6 +371,7 @@ static void * client_handler(void *sock_id) { int s = (int)(uintptr_t)sock_id; + char *sp = NULL; char buffer[1024]; char info_str[1024]; snprintf(info_str, sizeof(info_str), @@ -385,8 +386,8 @@ client_handler(void *sock_id) int bytes = read(s, buffer, sizeof(buffer) - 1); while (bytes > 0) { buffer[bytes] = 0; - const char *cmd = strtok(buffer, ","); - const char *param = strtok(NULL, "\0"); + const char *cmd = strtok_r(buffer, ",", &sp); + const char *param = strtok_r(NULL, "\0", &sp); telemetry_cb fn = unknown_command; int i; From patchwork Tue Nov 14 10:59:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134272 X-Patchwork-Delegate: david.marchand@redhat.com 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 81A2043329; Tue, 14 Nov 2023 12:11:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 919FB40E13; Tue, 14 Nov 2023 12:10:15 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id DF251402F2 for ; Tue, 14 Nov 2023 12:10:00 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3PR4HCDzPnZx; Tue, 14 Nov 2023 19:05: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 19:09:59 +0800 From: Jie Hai To: , Hemant Agrawal , Sachin Saxena , Nipun Gupta , Santosh Shukla , Shreyansh Jain , Ferruh Yigit CC: , , Subject: [PATCH v3 15/22] bus/fslmc: replace strtok with reentrant version Date: Tue, 14 Nov 2023 18:59:59 +0800 Message-ID: <20231114110006.91148-16-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..7960ad3979ef 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name) { char *dup_dev_name, *t_ptr; struct rte_dpaa2_device *dev = NULL; + char *sp = NULL; int ret = -1; if (!dev_name) @@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name) } /* Parse the device name and ID */ - t_ptr = strtok(dup_dev_name, "."); + t_ptr = strtok_r(dup_dev_name, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name); ret = -EINVAL; @@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name) else dev->dev_type = DPAA2_UNKNOWN; - t_ptr = strtok(NULL, "."); + t_ptr = strtok_r(NULL, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name); ret = 0; diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c index 4aec7b2cd8ba..09a1a2b23787 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) uint32_t cpu_mask = 1; int ret; size_t len = 0; - char *temp = NULL, *token = NULL; + char *temp = NULL, *token = NULL, *sp = NULL; char string[STRING_LEN], command[COMMAND_LEN]; FILE *file; @@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) } while (getline(&temp, &len, file) != -1) { if ((strstr(temp, string)) != NULL) { - token = strtok(temp, ":"); + token = strtok_r(temp, ":", &sp); break; } } From patchwork Tue Nov 14 11:00:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134273 X-Patchwork-Delegate: david.marchand@redhat.com 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 0EA9443329; Tue, 14 Nov 2023 12:11:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B510D40A79; Tue, 14 Nov 2023 12:10: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 707A3402F2 for ; Tue, 14 Nov 2023 12:10:01 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3Tt4kl1zWhGc; Tue, 14 Nov 2023 19:09:38 +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 19:09:59 +0800 From: Jie Hai To: , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Gowrishankar Muthukrishnan , Jerin Jacob , Harman Kalra CC: , , Subject: [PATCH v3 16/22] common/cnxk: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:00 +0800 Message-ID: <20231114110006.91148-17-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..8054c3cf910c 100644 --- a/drivers/common/cnxk/cnxk_telemetry_nix.c +++ b/drivers/common/cnxk/cnxk_telemetry_nix.c @@ -761,7 +761,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, struct plt_tel_data *d) { struct nix_tel_node *node; - char *name, *param; + char *name, *param, *sp = NULL; char buf[1024]; int rc = -1; @@ -769,11 +769,11 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, goto exit; plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1); - name = strtok(buf, ","); + name = strtok_r(buf, ",", &sp); if (name == NULL) goto exit; - param = strtok(NULL, "\0"); + param = strtok_r(NULL, "\0", &sp); node = nix_tel_node_get_by_pcidev_name(name); if (!node) @@ -782,7 +782,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, plt_tel_data_start_dict(d); if (strstr(cmd, "rq")) { - char *tok = strtok(param, ","); + char *tok = strtok_r(param, ",", &sp); int rq; if (!tok) @@ -798,7 +798,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, rc = cnxk_tel_nix_rq(node->rqs[rq], d); } else if (strstr(cmd, "cq")) { - char *tok = strtok(param, ","); + char *tok = strtok_r(param, ",", &sp); int cq; if (!tok) @@ -814,7 +814,7 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params, rc = cnxk_tel_nix_cq(node->cqs[cq], d); } else if (strstr(cmd, "sq")) { - char *tok = strtok(param, ","); + char *tok = strtok_r(param, ",", &sp); int sq; if (!tok) From patchwork Tue Nov 14 11:00:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134274 X-Patchwork-Delegate: david.marchand@redhat.com 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 177CE43329; Tue, 14 Nov 2023 12:11:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3AE8340E96; Tue, 14 Nov 2023 12:10:18 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id DA6404027D for ; Tue, 14 Nov 2023 12:10:01 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SV3P15zNtzMmjW; Tue, 14 Nov 2023 19:05:25 +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 19:10:00 +0800 From: Jie Hai To: , Pavan Nikhilesh , Shijith Thotton CC: , , Subject: [PATCH v3 17/22] event/cnxk: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:01 +0800 Message-ID: <20231114110006.91148-18-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..fe7a86797c25 100644 --- a/drivers/event/cnxk/cnxk_eventdev.c +++ b/drivers/event/cnxk/cnxk_eventdev.c @@ -478,7 +478,8 @@ parse_queue_param(char *value, void *opaque) struct cnxk_sso_qos queue_qos = {0}; uint16_t *val = (uint16_t *)&queue_qos; struct cnxk_sso_evdev *dev = opaque; - char *tok = strtok(value, "-"); + char *sp = NULL; + char *tok = strtok_r(value, "-", &sp); struct cnxk_sso_qos *old_ptr; if (!strlen(value)) @@ -486,7 +487,7 @@ parse_queue_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_r(NULL, "-", &sp); val++; } @@ -514,7 +515,8 @@ parse_stash_param(char *value, void *opaque) struct cnxk_sso_stash queue_stash = {0}; struct cnxk_sso_evdev *dev = opaque; struct cnxk_sso_stash *old_ptr; - char *tok = strtok(value, "|"); + char *sp = NULL; + char *tok = strtok_r(value, "|", &sp); uint16_t *val; if (!strlen(value)) @@ -523,7 +525,7 @@ parse_stash_param(char *value, void *opaque) val = (uint16_t *)&queue_stash; while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "|"); + tok = strtok_r(NULL, "|", &sp); val++; } diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c b/drivers/event/cnxk/cnxk_tim_evdev.c index 6d59fdf90983..86ef7dc3d578 100644 --- a/drivers/event/cnxk/cnxk_tim_evdev.c +++ b/drivers/event/cnxk/cnxk_tim_evdev.c @@ -420,7 +420,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque) { struct cnxk_tim_evdev *dev = opaque; struct cnxk_tim_ctl ring_ctl = {0}; - char *tok = strtok(value, "-"); + char *sp = NULL; + char *tok = strtok_r(value, "-", &sp); struct cnxk_tim_ctl *old_ptr; uint16_t *val; @@ -431,7 +432,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque) while (tok != NULL) { *val = atoi(tok); - tok = strtok(NULL, "-"); + tok = strtok_r(NULL, "-", &sp); val++; } @@ -507,16 +508,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque) ROC_TIM_CLK_SRC_INVALID}; struct cnxk_tim_evdev *dev = opaque; char *str = strdup(value); - char *tok; + char *tok, *sp = NULL; int i = 0; if (str == NULL || !strlen(str)) goto free; - tok = strtok(str, "-"); + tok = strtok_r(str, "-", &sp); while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) { dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10); - tok = strtok(NULL, "-"); + tok = strtok_r(NULL, "-", &sp); i++; } From patchwork Tue Nov 14 11:00:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134275 X-Patchwork-Delegate: david.marchand@redhat.com 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 9D0EC43329; Tue, 14 Nov 2023 12:11:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C121840EDC; Tue, 14 Nov 2023 12:10: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 8F0764068A for ; Tue, 14 Nov 2023 12:10:02 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3V156z6zvQF5; Tue, 14 Nov 2023 19:09:45 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Tue, 14 Nov 2023 19:10:00 +0800 From: Jie Hai To: , Shepard Siegel , Ed Czeck , John Miller CC: , , Subject: [PATCH v3 18/22] net/ark: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:02 +0800 Message-ID: <20231114110006.91148-19-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..6e8e5339607b 100644 --- a/drivers/net/ark/ark_pktchkr.c +++ b/drivers/net/ark/ark_pktchkr.c @@ -359,14 +359,14 @@ set_arg(char *arg, char *val) void ark_pktchkr_parse(char *args) { - char *argv, *v; + char *argv, *v, *sp = NULL; const char toks[] = "=\n\t\v\f \r"; - argv = strtok(args, toks); - v = strtok(NULL, toks); + argv = strtok_r(args, toks, &sp); + v = strtok_r(NULL, toks, &sp); while (argv && v) { set_arg(argv, v); - argv = strtok(NULL, toks); - v = strtok(NULL, toks); + argv = strtok_r(NULL, toks, &sp); + v = strtok_r(NULL, toks, &sp); } } diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index 69ff7072b2ab..d611406a1b46 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -340,14 +340,14 @@ pmd_set_arg(char *arg, char *val) void ark_pktgen_parse(char *args) { - char *argv, *v; + char *argv, *v, *sp = NULL; const char toks[] = " =\n\t\v\f \r"; - argv = strtok(args, toks); - v = strtok(NULL, toks); + argv = strtok_r(args, toks, &sp); + v = strtok_r(NULL, toks, &sp); while (argv && v) { pmd_set_arg(argv, v); - argv = strtok(NULL, toks); - v = strtok(NULL, toks); + argv = strtok_r(NULL, toks, &sp); + v = strtok_r(NULL, toks, &sp); } } From patchwork Tue Nov 14 11:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134276 X-Patchwork-Delegate: david.marchand@redhat.com 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 7134343329; Tue, 14 Nov 2023 12:11:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1175402EA; Tue, 14 Nov 2023 12:10:20 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 0823240697 for ; Tue, 14 Nov 2023 12:10:03 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3V21fJczvQTW; Tue, 14 Nov 2023 19:09:46 +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 19:10:01 +0800 From: Jie Hai To: , Jakub Palider , Tomasz Duszynski , Jerin Jacob CC: , , Subject: [PATCH v3 19/22] raw/cnxk_gpio: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:03 +0800 Message-ID: <20231114110006.91148-20-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..a499a258f315 100644 --- a/drivers/raw/cnxk_gpio/cnxk_gpio.c +++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c @@ -190,7 +190,7 @@ static int cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) { int i, ret, val, queue = 0; - char *token; + char *token, *sp = NULL; int *list; list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0); @@ -208,7 +208,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) allowlist[strlen(allowlist) - 1] = ' '; /* quiesce -Wcast-qual */ - token = strtok((char *)(uintptr_t)allowlist, ","); + token = strtok_r((char *)(uintptr_t)allowlist, ",", &sp); do { errno = 0; val = strtol(token, NULL, 10); @@ -234,7 +234,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist) } if (i == queue) list[queue++] = val; - } while ((token = strtok(NULL, ","))); + } while ((token = strtok_r(NULL, ",", &sp))); free(allowlist); gpiochip->allowlist = list; From patchwork Tue Nov 14 11:00:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134277 X-Patchwork-Delegate: david.marchand@redhat.com 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 83BD243329; Tue, 14 Nov 2023 12:12:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DD4D440EE7; Tue, 14 Nov 2023 12:10:21 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 68DA840698 for ; Tue, 14 Nov 2023 12:10:03 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV3V25Mm5zvQWY; Tue, 14 Nov 2023 19:09:46 +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 19:10:01 +0800 From: Jie Hai To: , Akhil Goyal , Fan Zhang , Pablo de Lara CC: , , Subject: [PATCH v3 20/22] examples/l2fwd-crypto: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:04 +0800 Message-ID: <20231114110006.91148-21-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..06e296776b95 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -1105,12 +1105,12 @@ static int parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size) { unsigned byte_count; - char *token; + char *token, *sp = NULL; errno = 0; - for (byte_count = 0, token = strtok(input_arg, ":"); + for (byte_count = 0, token = strtok_r(input_arg, ":", &sp); (byte_count < max_size) && (token != NULL); - token = strtok(NULL, ":")) { + token = strtok_r(NULL, ":", &sp)) { int number = (int)strtol(token, NULL, 16); From patchwork Tue Nov 14 11:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134278 X-Patchwork-Delegate: david.marchand@redhat.com 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 62A2E43329; Tue, 14 Nov 2023 12:12:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00C2D41060; Tue, 14 Nov 2023 12:10:23 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 133D3406A2 for ; Tue, 14 Nov 2023 12:10:04 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3PV5VkxzPnhT; Tue, 14 Nov 2023 19:05:50 +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 19:10:02 +0800 From: Jie Hai To: , Maxime Coquelin , Chenbo Xia , Cheng Jiang CC: , , Subject: [PATCH v3 21/22] examples/vhost: replace strtok with reentrant version Date: Tue, 14 Nov 2023 19:00:05 +0800 Message-ID: <20231114110006.91148-22-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..e8b3a97c48a4 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -246,6 +246,7 @@ open_dma(const char *value) char *ptrs[2]; char *start, *end, *substr; int64_t socketid, vring_id; + char *sp = NULL; struct rte_dma_info info; struct rte_dma_conf dev_config = { .nb_vchans = 1 }; @@ -269,7 +270,7 @@ open_dma(const char *value) /* process DMA devices within bracket. */ addrs++; - substr = strtok(addrs, ";]"); + substr = strtok_r(addrs, ";]", &sp); if (!substr) { ret = -1; goto out; From patchwork Tue Nov 14 11:00:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134279 X-Patchwork-Delegate: david.marchand@redhat.com 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 3CF7043329; Tue, 14 Nov 2023 12:12:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1BE3E410D5; Tue, 14 Nov 2023 12:10:24 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 6252E406BA for ; Tue, 14 Nov 2023 12:10:04 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV3PW1lqJzPnjf; Tue, 14 Nov 2023 19:05: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 19:10:02 +0800 From: Jie Hai To: , Thomas Monjalon CC: , , Subject: [PATCH v3 22/22] devtools: check for some reentrant function Date: Tue, 14 Nov 2023 19:00:06 +0800 Message-ID: <20231114110006.91148-23-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231114110006.91148-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20231114110006.91148-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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..e831fc723dfb 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_r' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # refrain from using some pthread functions awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \