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 8AA9145CA6; Fri, 8 Nov 2024 12:17:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C7834433A1; Fri, 8 Nov 2024 12:16:02 +0100 (CET) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by mails.dpdk.org (Postfix) with ESMTP id D60EE4336F for ; Fri, 8 Nov 2024 12:15:48 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XlGb162BZz1ypKZ; Fri, 8 Nov 2024 19:15:57 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 4F5CA1A0188; Fri, 8 Nov 2024 19:15: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; Fri, 8 Nov 2024 19:15:46 +0800 From: Jie Hai To: , , , Hemant Agrawal , Sachin Saxena , Nipun Gupta , Shreyansh Jain , Santosh Shukla , Ferruh Yigit CC: , , , Subject: [PATCH v5 15/25] bus/fslmc: replace strtok with reentrant version Date: Fri, 8 Nov 2024 19:03:54 +0800 Message-ID: <20241108110404.18317-16-haijie1@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20241108110404.18317-1-haijie1@huawei.com> References: <20231113104550.2138654-1-haijie1@huawei.com> <20241108110404.18317-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: 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. 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 | 6 ++++-- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 097d6dca08b5..fe7eb26940cb 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "private.h" #include @@ -132,6 +133,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 +171,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 +202,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..8b863af010da 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -128,7 +129,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 +142,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