From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4E57F45D7C; Fri, 22 Nov 2024 12:13:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E175433CB; Fri, 22 Nov 2024 12:11:54 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 3A91B43397 for ; Fri, 22 Nov 2024 12:11:42 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XvsmS5nx1z69Zd; Fri, 22 Nov 2024 19:08:56 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 2098B140154; Fri, 22 Nov 2024 19:11:41 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf500004.china.huawei.com (7.202.181.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Nov 2024 19:11:40 +0800 From: Jie Hai To: , , , Naga Harish K S V , Jerin Jacob CC: , , , Subject: [PATCH v6 11/25] eventdev: replace strtok with reentrant version Date: Fri, 22 Nov 2024 19:04:43 +0800 Message-ID: <20241122110458.2156907-12-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241122110458.2156907-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20241122110458.2156907-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemf500004.china.huawei.com (7.202.181.242) 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. Signed-off-by: Jie Hai Acked-by: Chengwen Feng Acked-by: Morten Brørup --- lib/eventdev/rte_event_eth_rx_adapter.c | 39 +++++++++++++------------ lib/eventdev/rte_eventdev.c | 18 ++++++------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 39674c4604df..89e1b1836d59 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "rte_eventdev.h" #include "eventdev_pmd.h" @@ -3651,7 +3652,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp; struct rte_event_eth_rx_adapter_queue_conf queue_conf; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3661,19 +3662,19 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_PORTID_VALID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3684,7 +3685,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3723,7 +3724,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; struct rte_event_eth_rx_adapter_queue_stats q_stats; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -3733,19 +3734,19 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_PORTID_VALID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3756,7 +3757,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3794,7 +3795,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, uint8_t rx_adapter_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3803,19 +3804,19 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_GOTO_ERR_RET(rx_adapter_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_PORTID_VALID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3826,7 +3827,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); @@ -3855,7 +3856,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, uint8_t instance_id; uint16_t rx_queue_id; int eth_dev_id, ret = -1; - char *token, *l_params; + char *token, *l_params, *sp = NULL; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) return -1; @@ -3863,14 +3864,14 @@ handle_rxa_instance_get(const char *cmd __rte_unused, l_params = strdup(params); if (l_params == NULL) return -ENOMEM; - token = strtok(l_params, ","); + token = strtok_r(l_params, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_PORTID_VALID_OR_GOTO_ERR_RET(eth_dev_id, -EINVAL); - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &sp); RTE_EVENT_ETH_RX_ADAPTER_TOKEN_VALID_OR_GOTO_ERR_RET(token, -1); /* Get Rx queue ID from parameter string */ @@ -3881,7 +3882,7 @@ handle_rxa_instance_get(const char *cmd __rte_unused, goto error; } - token = strtok(NULL, "\0"); + token = strtok_r(NULL, "\0", &sp); if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); diff --git a/lib/eventdev/rte_eventdev.c b/lib/eventdev/rte_eventdev.c index ca295c87c47d..d3dacffdfab2 100644 --- a/lib/eventdev/rte_eventdev.c +++ b/lib/eventdev/rte_eventdev.c @@ -1787,7 +1787,7 @@ handle_queue_links(const char *cmd __rte_unused, struct rte_tel_data *d) { int i, ret, port_id = 0; - char *end_param; + char *end_param, *sp = NULL; uint8_t dev_id; uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV]; uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV]; @@ -1800,12 +1800,12 @@ handle_queue_links(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) return -1; port_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1925,7 +1925,7 @@ handle_port_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1935,7 +1935,7 @@ handle_port_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_PORT; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1943,7 +1943,7 @@ handle_port_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); @@ -1959,7 +1959,7 @@ handle_queue_xstats(const char *cmd __rte_unused, int dev_id; int port_queue_id = 0; enum rte_event_dev_xstats_mode mode; - char *end_param; + char *end_param, *sp = NULL; const char *p_param; if (params == NULL || strlen(params) == 0 || !isdigit(*params)) @@ -1969,7 +1969,7 @@ handle_queue_xstats(const char *cmd __rte_unused, dev_id = strtoul(params, &end_param, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL); - p_param = strtok(end_param, ","); + p_param = strtok_r(end_param, ",", &sp); mode = RTE_EVENT_DEV_XSTATS_QUEUE; if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param)) @@ -1977,7 +1977,7 @@ handle_queue_xstats(const char *cmd __rte_unused, port_queue_id = strtoul(p_param, &end_param, 10); - p_param = strtok(NULL, "\0"); + p_param = strtok_r(NULL, "\0", &sp); if (p_param != NULL) RTE_EDEV_LOG_DEBUG( "Extra parameters passed to eventdev telemetry command, ignoring"); -- 2.33.0