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 8CF6045BAE; Wed, 23 Oct 2024 10:32:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81C4C42D66; Wed, 23 Oct 2024 10:29:42 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id A6D2F41156 for ; Wed, 23 Oct 2024 10:29:00 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4XYMcl5D7qzQs7b; Wed, 23 Oct 2024 16:28:07 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 96F751402E2; Wed, 23 Oct 2024 16:28:59 +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; Wed, 23 Oct 2024 16:28:59 +0800 From: Dengdui Huang To: CC: , , , , , , , , Subject: [PATCH v4 36/42] net/tap: use rte strerror Date: Wed, 23 Oct 2024 16:28:46 +0800 Message-ID: <20241023082852.2780488-37-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241023082852.2780488-1-huangdengdui@huawei.com> References: <20231114082539.1858594-44-huangdengdui@huawei.com> <20241023082852.2780488-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: dggems705-chm.china.huawei.com (10.3.19.182) 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 rte_strerror() to replace it. Cc: stable@dpdk.org Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup --- drivers/net/tap/rte_eth_tap.c | 28 ++++++++++++++-------------- drivers/net/tap/tap_flow.c | 14 +++++++------- drivers/net/tap/tap_netlink.c | 5 +++-- drivers/net/tap/tap_tcmsgs.c | 6 ++++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 36b06b3ac5..629f577f7b 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -198,7 +198,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) /* Set the TUN/TAP configuration and set the name if needed */ if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) { TAP_LOG(WARNING, "Unable to set TUNSETIFF for %s: %s", - ifr.ifr_name, strerror(errno)); + ifr.ifr_name, rte_strerror(errno)); goto error; } @@ -206,7 +206,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) if (persistent && ioctl(fd, TUNSETPERSIST, 1) < 0) { TAP_LOG(WARNING, "Unable to set persist %s: %s", - ifr.ifr_name, strerror(errno)); + ifr.ifr_name, rte_strerror(errno)); goto error; } @@ -226,7 +226,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) if (ioctl(fd, TUNSETQUEUE, (void *)&ifr) < 0) { TAP_LOG(WARNING, "Unable to detach keep-alive queue for %s: %s", - ifr.ifr_name, strerror(errno)); + ifr.ifr_name, rte_strerror(errno)); goto error; } } @@ -234,7 +234,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) flags = fcntl(fd, F_GETFL); if (flags == -1) { TAP_LOG(WARNING, "Unable to get %s current flags: %s", - ifr.ifr_name, strerror(errno)); + ifr.ifr_name, rte_strerror(errno)); goto error; } @@ -243,7 +243,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) if (fcntl(fd, F_SETFL, flags) < 0) { TAP_LOG(WARNING, "Unable to set %s to nonblocking: %s", - ifr.ifr_name, strerror(errno)); + ifr.ifr_name, rte_strerror(errno)); goto error; } @@ -296,18 +296,18 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) /* Enable signal on file descriptor */ if (fcntl(fd, F_SETSIG, signo) < 0) { TAP_LOG(WARNING, "Unable to set signo %d for fd %d: %s", - signo, fd, strerror(errno)); + signo, fd, rte_strerror(errno)); goto error; } if (fcntl(fd, F_SETFL, flags | O_ASYNC) < 0) { TAP_LOG(WARNING, "Unable to set fcntl flags: %s", - strerror(errno)); + rte_strerror(errno)); goto error; } if (fcntl(fd, F_SETOWN, getpid()) < 0) { TAP_LOG(WARNING, "Unable to set fcntl owner: %s", - strerror(errno)); + rte_strerror(errno)); goto error; } } @@ -822,7 +822,7 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request, error: TAP_LOG(DEBUG, "%s(%s) failed: %s(%d)", ifr->ifr_name, - tap_ioctl_req2str(request), strerror(errno), errno); + tap_ioctl_req2str(request), rte_strerror(errno), errno); return -errno; } @@ -1946,7 +1946,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, if (pmd->ioctl_sock == -1) { TAP_LOG(ERR, "%s Unable to get a socket for management: %s", - tuntap_name, strerror(errno)); + tuntap_name, rte_strerror(errno)); goto error_exit; } @@ -2109,7 +2109,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, disable_rte_flow: TAP_LOG(ERR, " Disabling rte flow support: %s(%d)", - strerror(errno), errno); + rte_strerror(errno), errno); if (strlen(remote_iface)) { TAP_LOG(ERR, "Remote feature requires flow support."); goto error_exit; @@ -2120,7 +2120,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, #ifdef HAVE_TCA_FLOWER error_remote: TAP_LOG(ERR, " Can't set up remote feature: %s(%d)", - strerror(errno), errno); + rte_strerror(errno), errno); tap_flow_implicit_flush(pmd, NULL); #endif @@ -2454,7 +2454,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) ret = rte_mp_action_register(TAP_MP_REQ_START_RXTX, tap_mp_req_start_rxtx); if (ret < 0 && rte_errno != ENOTSUP) { TAP_LOG(ERR, "tap: Failed to register IPC callback: %s", - strerror(rte_errno)); + rte_strerror(rte_errno)); return -1; } } @@ -2514,7 +2514,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) ret = rte_mp_action_register(TAP_MP_KEY, tap_mp_sync_queues); if (ret < 0 && rte_errno != ENOTSUP) { TAP_LOG(ERR, "tap: Failed to register IPC callback: %s", - strerror(rte_errno)); + rte_strerror(rte_errno)); goto leave; } } diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c index 51ec07eb5a..0c9a643492 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -1317,7 +1317,7 @@ tap_flow_create(struct rte_eth_dev *dev, if (err < 0) { TAP_LOG(ERR, "Kernel refused TC filter rule creation (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); rte_flow_error_set(error, EEXIST, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "overlapping rules or Kernel too old for flower support"); @@ -1362,7 +1362,7 @@ tap_flow_create(struct rte_eth_dev *dev, if (err < 0) { TAP_LOG(ERR, "Kernel refused TC filter rule creation (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); rte_flow_error_set( error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -1416,7 +1416,7 @@ tap_flow_destroy_pmd(struct pmd_internals *pmd, if (ret < 0) { TAP_LOG(ERR, "Kernel refused TC filter rule deletion (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "couldn't receive kernel ack to our request"); @@ -1440,7 +1440,7 @@ tap_flow_destroy_pmd(struct pmd_internals *pmd, if (ret < 0) { TAP_LOG(ERR, "Kernel refused TC filter rule deletion (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); rte_flow_error_set( error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Failure trying to receive nl ack"); @@ -1664,7 +1664,7 @@ int tap_flow_implicit_create(struct pmd_internals *pmd, goto success; TAP_LOG(ERR, "Kernel refused TC filter rule creation (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); goto fail; } LIST_INSERT_HEAD(&pmd->implicit_flows, remote_flow, next); @@ -1754,7 +1754,7 @@ static int rss_enable(struct pmd_internals *pmd, struct rte_flow_error *error) /* Load the BPF program (defined in tap_bpf.h from skeleton) */ pmd->rss = tap_rss__open_and_load(); if (pmd->rss == NULL) { - TAP_LOG(ERR, "Failed to load BPF object: %s", strerror(errno)); + TAP_LOG(ERR, "Failed to load BPF object: %s", rte_strerror(errno)); rte_flow_error_set(error, errno, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "BPF object could not be loaded"); return -errno; @@ -1885,7 +1885,7 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, if (err) { TAP_LOG(ERR, "Failed to update BPF map entry %#x (%d): %s", - handle, errno, strerror(errno)); + handle, errno, rte_strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Kernel too old or not configured " diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c index 35c491ac37..6011f6c61d 100644 --- a/drivers/net/tap/tap_netlink.c +++ b/drivers/net/tap/tap_netlink.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "tap_log.h" @@ -98,7 +99,7 @@ tap_nl_final(int nlsk_fd) { if (close(nlsk_fd)) { TAP_LOG(ERR, "Failed to close netlink socket: %s (%d)", - strerror(errno), errno); + rte_strerror(errno), errno); return -1; } return 0; @@ -130,7 +131,7 @@ tap_nl_send(int nlsk_fd, struct nlmsghdr *nh) goto retry; TAP_LOG(ERR, "Failed to send netlink message: %s (%d)", - strerror(errno), errno); + rte_strerror(errno), errno); return -1; } return send_bytes; diff --git a/drivers/net/tap/tap_tcmsgs.c b/drivers/net/tap/tap_tcmsgs.c index a3aae3c814..28d4809360 100644 --- a/drivers/net/tap/tap_tcmsgs.c +++ b/drivers/net/tap/tap_tcmsgs.c @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include "tap_log.h" @@ -263,7 +265,7 @@ qdisc_create_multiq(int nlsk_fd, unsigned int ifindex) err = qdisc_add_multiq(nlsk_fd, ifindex); if (err < 0 && errno != -EEXIST) { TAP_LOG(ERR, "Could not add multiq qdisc (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } return 0; @@ -289,7 +291,7 @@ qdisc_create_ingress(int nlsk_fd, unsigned int ifindex) err = qdisc_add_ingress(nlsk_fd, ifindex); if (err < 0 && errno != -EEXIST) { TAP_LOG(ERR, "Could not add ingress qdisc (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } return 0; -- 2.33.0