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 B271043329; Tue, 14 Nov 2023 13:39:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 603FC4161A; Tue, 14 Nov 2023 13:36:38 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id A9AFA402D8 for ; Tue, 14 Nov 2023 13:35:59 +0100 (CET) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SV5PC0df3zvQhC; Tue, 14 Nov 2023 20:35:43 +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_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 20:35:58 +0800 From: Dengdui Huang To: CC: , , , , Subject: [PATCH v3 36/42] net/tap: use rte strerror Date: Tue, 14 Nov 2023 20:35:46 +0800 Message-ID: <20231114123552.398072-37-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114123552.398072-1-huangdengdui@huawei.com> References: <20231114082539.1858594-44-huangdengdui@huawei.com> <20231114123552.398072-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-CFilter-Loop: Reflected 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 --- drivers/net/tap/rte_eth_tap.c | 26 +++++++++++++------------- drivers/net/tap/tap_flow.c | 18 +++++++++--------- drivers/net/tap/tap_netlink.c | 5 +++-- drivers/net/tap/tap_tcmsgs.c | 6 ++++-- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index b41fa971cb..ff290ea5bf 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -196,7 +196,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; } @@ -204,7 +204,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; } @@ -224,7 +224,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; } } @@ -242,7 +242,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; } @@ -295,18 +295,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; } } @@ -821,7 +821,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; } @@ -1966,7 +1966,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; } @@ -2127,7 +2127,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; @@ -2137,7 +2137,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, 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); error_exit: @@ -2475,7 +2475,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; } } @@ -2535,7 +2535,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 ed4d42f92f..9d6b84f5c7 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -1409,7 +1409,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"); @@ -1454,7 +1454,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, @@ -1508,7 +1508,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"); @@ -1532,7 +1532,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"); @@ -1755,7 +1755,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); @@ -1871,7 +1871,7 @@ static int rss_enable(struct pmd_internals *pmd, if (pmd->map_fd < 0) { TAP_LOG(ERR, "Failed to create BPF map (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Kernel too old or not configured " @@ -1946,7 +1946,7 @@ static int rss_enable(struct pmd_internals *pmd, if (err < 0) { TAP_LOG(ERR, "Kernel refused TC filter rule creation (%d): %s", - errno, strerror(errno)); + errno, rte_strerror(errno)); return err; } LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next); @@ -2111,7 +2111,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 #%u (%d): %s", - flow->key_idx, errno, strerror(errno)); + flow->key_idx, errno, rte_strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Kernel too old or not configured " @@ -2130,7 +2130,7 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, if (flow->bpf_fd[SEC_L3_L4] < 0) { TAP_LOG(ERR, "Failed to load BPF section %s (%d): %s", - sec_name[SEC_L3_L4], errno, strerror(errno)); + sec_name[SEC_L3_L4], 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 75af3404b0..354574ba29 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" @@ -97,7 +98,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; @@ -129,7 +130,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