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 BF01D45BDF; Sat, 26 Oct 2024 12:26:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E63DB40696; Sat, 26 Oct 2024 12:26:06 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 419C4402DA for ; Sat, 26 Oct 2024 12:25:51 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XbG035Mc8z1HKdD; Sat, 26 Oct 2024 18:21:23 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id E48311A0188; Sat, 26 Oct 2024 18:25:47 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) 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; Sat, 26 Oct 2024 18:25:47 +0800 From: Jie Hai To: , , , Hemant Agrawal , Sachin Saxena , Nipun Gupta , Ferruh Yigit , Shreyansh Jain , Santosh Shukla CC: , , , Subject: [PATCH v4 07/13] bus/fslmc: replace strtok with reentrant version Date: Sat, 26 Oct 2024 18:14:45 +0800 Message-ID: <20241026101451.29135-8-haijie1@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20241026101451.29135-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20241026101451.29135-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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. 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 Acked-by: Sachin Saxena Acked-by: Morten Brørup --- drivers/bus/fslmc/fslmc_bus.c | 5 +++-- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 097d6dca08b5..42b6b270a419 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -132,6 +132,7 @@ scan_one_fslmc_device(char *dev_name) { char *dup_dev_name, *t_ptr; struct rte_dpaa2_device *dev = NULL; + char *sp = NULL; int ret = -1; if (!dev_name) @@ -169,7 +170,7 @@ scan_one_fslmc_device(char *dev_name) } /* Parse the device name and ID */ - t_ptr = strtok(dup_dev_name, "."); + t_ptr = strtok_r(dup_dev_name, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name); ret = -EINVAL; @@ -200,7 +201,7 @@ scan_one_fslmc_device(char *dev_name) else dev->dev_type = DPAA2_UNKNOWN; - t_ptr = strtok(NULL, "."); + t_ptr = strtok_r(NULL, ".", &sp); if (!t_ptr) { DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name); ret = 0; diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c index d8a98326d9de..204662ad9eaf 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -128,7 +128,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) #define AFFINITY_LEN 128 uint32_t cpu_mask = 1; size_t len = 0; - char *temp = NULL, *token = NULL; + char *temp = NULL, *token = NULL, *sp = NULL; char string[STRING_LEN]; char smp_affinity[AFFINITY_LEN]; FILE *file; @@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id) } while (getline(&temp, &len, file) != -1) { if ((strstr(temp, string)) != NULL) { - token = strtok(temp, ":"); + token = strtok_r(temp, ":", &sp); break; } } -- 2.22.0