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 6D4F743329; Tue, 14 Nov 2023 12:28:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F55A42C24; Tue, 14 Nov 2023 12:24:58 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 31061402F2 for ; Tue, 14 Nov 2023 12:24:15 +0100 (CET) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SV3jR0x2QzMmqt; Tue, 14 Nov 2023 19:19:39 +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 19:24:13 +0800 From: Dengdui Huang To: CC: , , , , Subject: [PATCH v2 39/43] net/virtio: use rte strerror Date: Tue, 14 Nov 2023 19:24:03 +0800 Message-ID: <20231114112407.3496460-40-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114112407.3496460-1-huangdengdui@huawei.com> References: <20231114082539.1858594-44-huangdengdui@huawei.com> <20231114112407.3496460-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: dggems705-chm.china.huawei.com (10.3.19.182) 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/virtio/virtio_user/vhost_kernel.c | 8 +++--- .../net/virtio/virtio_user/vhost_kernel_tap.c | 25 ++++++++++--------- drivers/net/virtio/virtio_user/vhost_user.c | 20 +++++++-------- drivers/net/virtio/virtio_user/vhost_vdpa.c | 12 ++++----- .../net/virtio/virtio_user/virtio_user_dev.c | 8 +++--- drivers/net/virtio/virtio_user_ethdev.c | 6 ++--- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index e42bb35935..b1dec119fc 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -92,7 +92,7 @@ vhost_kernel_ioctl(int fd, uint64_t request, void *arg) ret = ioctl(fd, request, arg); if (ret) { PMD_DRV_LOG(ERR, "Vhost-kernel ioctl %"PRIu64" failed (%s)", - request, strerror(errno)); + request, rte_strerror(errno)); return -1; } @@ -428,7 +428,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) for (i = 0; i < dev->max_queue_pairs; ++i) { vhostfd = open(dev->path, O_RDWR); if (vhostfd < 0) { - PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path, strerror(errno)); + PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path, rte_strerror(errno)); goto err_tapfds; } data->vhostfds[i] = vhostfd; @@ -511,14 +511,14 @@ vhost_kernel_set_backend(int vhostfd, int tapfd) f.index = 0; if (ioctl(vhostfd, VHOST_NET_SET_BACKEND, &f) < 0) { PMD_DRV_LOG(ERR, "VHOST_NET_SET_BACKEND fails, %s", - strerror(errno)); + rte_strerror(errno)); return -1; } f.index = 1; if (ioctl(vhostfd, VHOST_NET_SET_BACKEND, &f) < 0) { PMD_DRV_LOG(ERR, "VHOST_NET_SET_BACKEND fails, %s", - strerror(errno)); + rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index 611e2e25ec..4542ccbf04 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -13,6 +13,7 @@ #include #include +#include #include "vhost_kernel_tap.h" #include "../virtio_logs.h" @@ -27,12 +28,12 @@ tap_support_features(unsigned int *tap_features) tapfd = open(PATH_NET_TUN, O_RDWR); if (tapfd < 0) { PMD_DRV_LOG(ERR, "fail to open %s: %s", - PATH_NET_TUN, strerror(errno)); + PATH_NET_TUN, rte_strerror(errno)); return -1; } if (ioctl(tapfd, TUNGETFEATURES, tap_features) == -1) { - PMD_DRV_LOG(ERR, "TUNGETFEATURES failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETFEATURES failed: %s", rte_strerror(errno)); close(tapfd); return -1; } @@ -49,11 +50,11 @@ tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) tapfd = open(PATH_NET_TUN, O_RDWR); if (tapfd < 0) { - PMD_DRV_LOG(ERR, "fail to open %s: %s", PATH_NET_TUN, strerror(errno)); + PMD_DRV_LOG(ERR, "fail to open %s: %s", PATH_NET_TUN, rte_strerror(errno)); return -1; } if (fcntl(tapfd, F_SETFL, O_NONBLOCK) < 0) { - PMD_DRV_LOG(ERR, "fcntl tapfd failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "fcntl tapfd failed: %s", rte_strerror(errno)); close(tapfd); return -1; } @@ -68,12 +69,12 @@ tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) if (multi_queue) { PMD_DRV_LOG(DEBUG, "TUNSETIFF failed (will retry without IFF_MULTI_QUEUE): %s", - strerror(errno)); + rte_strerror(errno)); multi_queue = false; goto retry_mono_q; } - PMD_DRV_LOG(ERR, "TUNSETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETIFF failed: %s", rte_strerror(errno)); close(tapfd); tapfd = -1; } @@ -88,7 +89,7 @@ tap_get_name(int tapfd, char **name) memset(&ifr, 0, sizeof(ifr)); if (ioctl(tapfd, TUNGETIFF, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", rte_strerror(errno)); return -1; } ret = asprintf(name, "%s", ifr.ifr_name); @@ -104,7 +105,7 @@ tap_get_flags(int tapfd, unsigned int *tap_flags) memset(&ifr, 0, sizeof(ifr)); if (ioctl(tapfd, TUNGETIFF, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", rte_strerror(errno)); return -1; } *tap_flags = ifr.ifr_flags; @@ -120,7 +121,7 @@ tap_set_mac(int tapfd, uint8_t *mac) ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; memcpy(ifr.ifr_hwaddr.sa_data, mac, RTE_ETHER_ADDR_LEN); if (ioctl(tapfd, SIOCSIFHWADDR, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "SIOCSIFHWADDR failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "SIOCSIFHWADDR failed: %s", rte_strerror(errno)); return -1; } return 0; @@ -155,7 +156,7 @@ vhost_kernel_tap_set_offload(int fd, uint64_t features) offload &= ~TUN_F_UFO; if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) { PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s", - strerror(errno)); + rte_strerror(errno)); return -1; } } @@ -175,12 +176,12 @@ vhost_kernel_tap_setup(int tapfd, int hdr_size, uint64_t features) * max_mem_regions, supported in newer version linux kernel */ if (ioctl(tapfd, TUNSETVNETHDRSZ, &hdr_size) < 0) { - PMD_DRV_LOG(ERR, "TUNSETVNETHDRSZ failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETVNETHDRSZ failed: %s", rte_strerror(errno)); return -1; } if (ioctl(tapfd, TUNSETSNDBUF, &sndbuf) < 0) { - PMD_DRV_LOG(ERR, "TUNSETSNDBUF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETSNDBUF failed: %s", rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 3c05ac9cc0..e079c726da 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -135,7 +135,7 @@ vhost_user_write(int fd, struct vhost_user_msg *msg, int *fds, int fd_num) } while (r < 0 && errno == EINTR); if (r < 0) - PMD_DRV_LOG(ERR, "Failed to send msg: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to send msg: %s", rte_strerror(errno)); return r; } @@ -148,7 +148,7 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) ret = recv(fd, (void *)msg, sz_hdr, 0); if (ret < 0) { - PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", rte_strerror(errno)); return -1; } else if (ret < sz_hdr) { PMD_DRV_LOG(ERR, "Failed to recv msg hdr: %d instead of %d.", @@ -174,7 +174,7 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) if (sz_payload) { ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0); if (ret < 0) { - PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", rte_strerror(errno)); return -1; } else if (ret < sz_payload) { PMD_DRV_LOG(ERR, "Failed to recv msg payload: %d instead of %u.", @@ -749,7 +749,7 @@ vhost_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un) ret = bind(fd, (struct sockaddr *)un, sizeof(*un)); if (ret < 0) { PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try again", - dev->path, strerror(errno)); + dev->path, rte_strerror(errno)); return -1; } ret = listen(fd, MAX_VIRTIO_USER_BACKLOG); @@ -760,13 +760,13 @@ vhost_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un) data->vhostfd = accept(fd, NULL, NULL); if (data->vhostfd < 0) { PMD_DRV_LOG(ERR, "Failed to accept initial client connection (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } flag = fcntl(fd, F_GETFL); if (fcntl(fd, F_SETFL, flag | O_NONBLOCK) < 0) { - PMD_DRV_LOG(ERR, "fcntl failed, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "fcntl failed, %s", rte_strerror(errno)); return -1; } @@ -834,15 +834,15 @@ vhost_user_setup(struct virtio_user_dev *dev) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { - PMD_DRV_LOG(ERR, "socket() error, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "socket() error, %s", rte_strerror(errno)); goto err_data; } flag = fcntl(fd, F_GETFD); if (flag == -1) - PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", strerror(errno)); + PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", rte_strerror(errno)); else if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0) - PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", strerror(errno)); + PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", rte_strerror(errno)); memset(&un, 0, sizeof(un)); un.sun_family = AF_UNIX; @@ -856,7 +856,7 @@ vhost_user_setup(struct virtio_user_dev *dev) } } else { if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) { - PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "connect error, %s", rte_strerror(errno)); goto err_socket; } data->vhostfd = fd; diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c index 2c36b26224..ac0ef2c3f9 100644 --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c @@ -92,7 +92,7 @@ vhost_vdpa_ioctl(int fd, uint64_t request, void *arg) ret = ioctl(fd, request, arg); if (ret) { PMD_DRV_LOG(ERR, "Vhost-vDPA ioctl %"PRIu64" failed (%s)", - request, strerror(errno)); + request, rte_strerror(errno)); return -1; } @@ -186,7 +186,7 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev) if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch begin (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -212,7 +212,7 @@ vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev) if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch end (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -243,7 +243,7 @@ vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr, if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB update (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -272,7 +272,7 @@ vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr, if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB invalidate (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -530,7 +530,7 @@ vhost_vdpa_setup(struct virtio_user_dev *dev) data->vhostfd = open(dev->path, O_RDWR); if (data->vhostfd < 0) { PMD_DRV_LOG(ERR, "Failed to open %s: %s", - dev->path, strerror(errno)); + dev->path, rte_strerror(errno)); free(data); return -1; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index af1f8c8237..ad7537a746 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -401,13 +401,13 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev) */ callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (callfd < 0) { - PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path, strerror(errno)); + PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path, rte_strerror(errno)); goto err; } kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (kickfd < 0) { close(callfd); - PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path, strerror(errno)); + PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path, rte_strerror(errno)); goto err; } dev->callfds[i] = callfd; @@ -1043,7 +1043,7 @@ virtio_user_control_queue_notify(struct virtqueue *vq, void *cookie) if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s", - strerror(errno)); + rte_strerror(errno)); } int @@ -1264,7 +1264,7 @@ virtio_user_dev_server_reconnect(struct virtio_user_dev *dev) if (dev->ops->get_features(dev, &dev->device_features) < 0) { PMD_INIT_LOG(ERR, "get_features failed: %s", - strerror(errno)); + rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 3a31642899..908afde4fc 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -273,7 +273,7 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s", - strerror(errno)); + rte_strerror(errno)); } static int @@ -382,7 +382,7 @@ vdpa_dynamic_major_num(void) fp = fopen("/proc/devices", "r"); if (fp == NULL) { PMD_INIT_LOG(ERR, "Cannot open /proc/devices: %s", - strerror(errno)); + rte_strerror(errno)); return UNNAMED_MAJOR; } @@ -409,7 +409,7 @@ virtio_user_backend_type(const char *path) return VIRTIO_USER_BACKEND_VHOST_USER; PMD_INIT_LOG(ERR, "Stat fails: %s (%s)", path, - strerror(errno)); + rte_strerror(errno)); return VIRTIO_USER_BACKEND_UNKNOWN; } -- 2.33.0