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 5953945C76; Mon, 4 Nov 2024 12:15:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 381EE427D3; Mon, 4 Nov 2024 12:11:34 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id CEAF740E3B for ; Mon, 4 Nov 2024 12:10:47 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4XhpcF0pzJz10PZt; Mon, 4 Nov 2024 19:08:29 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id C447E1800A7; Mon, 4 Nov 2024 19:10:46 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 4 Nov 2024 19:10:46 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 49/52] raw/ifpga: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:34 +0800 Message-ID: <20241104111037.3632161-50-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241104111037.3632161-1-huangdengdui@huawei.com> References: <20231114082539.1858594-1-huangdengdui@huawei.com> <20241104111037.3632161-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) 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 The function strerror() is insecure in a multi-thread environment. This patch uses strerror_r() to replace it. Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup Acked-by: Huisong Li --- drivers/raw/ifpga/afu_pmd_n3000.c | 10 ++++++++-- drivers/raw/ifpga/base/ifpga_fme_rsu.c | 24 +++++++++++++++++++----- drivers/raw/ifpga/ifpga_rawdev.c | 5 ++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/raw/ifpga/afu_pmd_n3000.c b/drivers/raw/ifpga/afu_pmd_n3000.c index 6aae1b224e..d9545a3b5f 100644 --- a/drivers/raw/ifpga/afu_pmd_n3000.c +++ b/drivers/raw/ifpga/afu_pmd_n3000.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "afu_pmd_core.h" #include "afu_pmd_n3000.h" @@ -680,6 +681,7 @@ static void clear_interrupt(struct dma_afu_ctx *ctx) static int poll_interrupt(struct dma_afu_ctx *ctx) { + char errmsg[RTE_STRERR_BUFSIZE]; struct pollfd pfd = {0}; uint64_t count = 0; ssize_t bytes_read = 0; @@ -693,7 +695,9 @@ static int poll_interrupt(struct dma_afu_ctx *ctx) pfd.events = POLLIN; poll_ret = poll(&pfd, 1, DMA_TIMEOUT_MSEC); if (poll_ret < 0) { - IFPGA_RAWDEV_PMD_ERR("Error %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + IFPGA_RAWDEV_PMD_ERR("Error %s", errmsg); ret = -EFAULT; goto out; } else if (poll_ret == 0) { @@ -707,8 +711,10 @@ static int poll_interrupt(struct dma_afu_ctx *ctx) poll_ret, count); ret = 0; } else { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); IFPGA_RAWDEV_PMD_ERR("Failed %s", bytes_read > 0 ? - strerror(errno) : "zero bytes read"); + errmsg : "zero bytes read"); ret = -EIO; } } diff --git a/drivers/raw/ifpga/base/ifpga_fme_rsu.c b/drivers/raw/ifpga/base/ifpga_fme_rsu.c index f147aaa1e8..9f1643c5ee 100644 --- a/drivers/raw/ifpga/base/ifpga_fme_rsu.c +++ b/drivers/raw/ifpga/base/ifpga_fme_rsu.c @@ -7,6 +7,8 @@ #include #include "ifpga_sec_mgr.h" +#include + static struct ifpga_sec_mgr *sec_mgr; static void set_rsu_control(struct ifpga_sec_mgr *smgr, uint32_t ctrl) @@ -91,6 +93,7 @@ static int start_flash_update(struct ifpga_sec_mgr *smgr) static int write_flash_image(struct ifpga_sec_mgr *smgr, const char *image, uint32_t offset) { + char errmsg[RTE_STRERR_BUFSIZE]; void *buf = NULL; int retry = 0; uint32_t length = 0; @@ -110,9 +113,11 @@ static int write_flash_image(struct ifpga_sec_mgr *smgr, const char *image, fd = open(image, O_RDONLY); if (fd < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); dev_err(smgr, "Failed to open \'%s\' for RD [e:%s]\n", - image, strerror(errno)); + image, errmsg); return -EIO; } @@ -129,15 +134,19 @@ static int write_flash_image(struct ifpga_sec_mgr *smgr, const char *image, to_transfer = (length > IFPGA_RSU_DATA_BLK_SIZE) ? IFPGA_RSU_DATA_BLK_SIZE : length; if (lseek(fd, offset, SEEK_SET) < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); dev_err(smgr, "Failed to seek in \'%s\' [e:%s]\n", - image, strerror(errno)); + image, errmsg); ret = -EIO; goto end; } read_size = read(fd, buf, to_transfer); if (read_size < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); dev_err(smgr, "Failed to read from \'%s\' [e:%s]\n", - image, strerror(errno)); + image, errmsg); ret = -EIO; goto end; } @@ -280,6 +289,7 @@ int fpga_update_flash(struct ifpga_fme_hw *fme, const char *image, struct sigaction sa; time_t start; int ret = 0; + char errmsg[RTE_STRERR_BUFSIZE]; if (!fme || !image || !status) { dev_err(fme, "Input parameter of %s is invalid\n", __func__); @@ -314,18 +324,22 @@ int fpga_update_flash(struct ifpga_fme_hw *fme, const char *image, fd = open(image, O_RDONLY); if (fd < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); dev_err(smgr, "Failed to open \'%s\' for RD [e:%s]\n", - image, strerror(errno)); + image, errmsg); return -EIO; } len = lseek(fd, 0, SEEK_END); close(fd); if (len < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); dev_err(smgr, "Failed to get file length of \'%s\' [e:%s]\n", - image, strerror(errno)); + image, errmsg); return -EIO; } if (len == 0) { diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 5b9b596435..d6728079e1 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -834,6 +834,7 @@ static int rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, const char *file_name) { + char errmsg[RTE_STRERR_BUFSIZE]; struct stat file_stat; int file_fd; int ret = 0; @@ -848,7 +849,9 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, if (file_fd < 0) { IFPGA_RAWDEV_PMD_ERR("%s: open file error: %s", __func__, file_name); - IFPGA_RAWDEV_PMD_ERR("Message : %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + IFPGA_RAWDEV_PMD_ERR("Message : %s", errmsg); return -EINVAL; } ret = stat(file_name, &file_stat); -- 2.33.0