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 0860B43325; Tue, 14 Nov 2023 09:26:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DA1D640A79; Tue, 14 Nov 2023 09:25:53 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id C41E6402F0 for ; Tue, 14 Nov 2023 09:25:42 +0100 (CET) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STzls56rzzPpKd; Tue, 14 Nov 2023 16:21:29 +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 16:25:41 +0800 From: Dengdui Huang To: CC: , , , , Subject: [PATCH 09/43] vhost: use rte strerror Date: Tue, 14 Nov 2023 16:25:05 +0800 Message-ID: <20231114082539.1858594-10-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114082539.1858594-1-huangdengdui@huawei.com> References: <20231114082539.1858594-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: dggems703-chm.china.huawei.com (10.3.19.180) 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 --- lib/vhost/socket.c | 13 +++++++------ lib/vhost/vduse.c | 30 +++++++++++++++--------------- lib/vhost/vhost_user.c | 11 ++++++----- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 5882e44176..0b030222d6 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -16,6 +16,7 @@ #include #include +#include #include "fd_man.h" #include "vduse.h" @@ -129,7 +130,7 @@ read_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int m if (ret <= 0) { if (ret) VHOST_LOG_CONFIG(ifname, ERR, "recvmsg failed on fd %d (%s)\n", - sockfd, strerror(errno)); + sockfd, rte_strerror(errno)); return ret; } @@ -200,7 +201,7 @@ send_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int f if (ret < 0) { VHOST_LOG_CONFIG(ifname, ERR, "sendmsg error on fd %d (%s)\n", - sockfd, strerror(errno)); + sockfd, rte_strerror(errno)); return ret; } @@ -358,7 +359,7 @@ create_unix_socket(struct vhost_user_socket *vsocket) if (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) { VHOST_LOG_CONFIG(vsocket->path, ERR, "vhost-user: can't set nonblocking mode for socket, fd: %d (%s)\n", - fd, strerror(errno)); + fd, rte_strerror(errno)); close(fd); return -1; } @@ -392,7 +393,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket) ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un)); if (ret < 0) { VHOST_LOG_CONFIG(path, ERR, "failed to bind: %s; remove it and try again\n", - strerror(errno)); + rte_strerror(errno)); goto err; } VHOST_LOG_CONFIG(path, INFO, "binding succeeded\n"); @@ -445,7 +446,7 @@ vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) flags = fcntl(fd, F_GETFL, 0); if (flags < 0) { VHOST_LOG_CONFIG(path, ERR, "can't get flags for connfd %d (%s)\n", - fd, strerror(errno)); + fd, rte_strerror(errno)); return -2; } if ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) { @@ -539,7 +540,7 @@ vhost_user_start_client(struct vhost_user_socket *vsocket) return 0; } - VHOST_LOG_CONFIG(path, WARNING, "failed to connect: %s\n", strerror(errno)); + VHOST_LOG_CONFIG(path, WARNING, "failed to connect: %s\n", rte_strerror(errno)); if (ret == -2 || !vsocket->reconnect) { close(fd); diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 080b58f7de..12e4b9c891 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -135,7 +135,7 @@ vduse_control_queue_event(int fd, void *arg, int *remove __rte_unused) ret = read(fd, &buf, sizeof(buf)); if (ret < 0) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to read control queue event: %s\n", - strerror(errno)); + rte_strerror(errno)); return; } @@ -157,7 +157,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) ret = ioctl(dev->vduse_dev_fd, VDUSE_VQ_GET_INFO, &vq_info); if (ret) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to get VQ %u info: %s\n", - index, strerror(errno)); + index, rte_strerror(errno)); return; } @@ -183,7 +183,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) vq->kickfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (vq->kickfd < 0) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to init kickfd for VQ %u: %s\n", - index, strerror(errno)); + index, rte_strerror(errno)); vq->kickfd = VIRTIO_INVALID_EVENTFD; return; } @@ -213,7 +213,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) ret = ioctl(dev->vduse_dev_fd, VDUSE_VQ_SETUP_KICKFD, &vq_efd); if (ret) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to setup kickfd for VQ %u: %s\n", - index, strerror(errno)); + index, rte_strerror(errno)); close(vq->kickfd); vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; return; @@ -224,7 +224,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) if (ret) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to setup kickfd handler for VQ %u: %s\n", - index, strerror(errno)); + index, rte_strerror(errno)); vq_efd.fd = VDUSE_EVENTFD_DEASSIGN; ioctl(dev->vduse_dev_fd, VDUSE_VQ_SETUP_KICKFD, &vq_efd); close(vq->kickfd); @@ -254,7 +254,7 @@ vduse_vring_cleanup(struct virtio_net *dev, unsigned int index) ret = ioctl(dev->vduse_dev_fd, VDUSE_VQ_SETUP_KICKFD, &vq_efd); if (ret) VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to cleanup kickfd for VQ %u: %s\n", - index, strerror(errno)); + index, rte_strerror(errno)); close(vq->kickfd); vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; @@ -291,7 +291,7 @@ vduse_device_start(struct virtio_net *dev) ret = ioctl(dev->vduse_dev_fd, VDUSE_DEV_GET_FEATURES, &dev->features); if (ret) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to get features: %s\n", - strerror(errno)); + rte_strerror(errno)); return; } @@ -358,7 +358,7 @@ vduse_events_handler(int fd, void *arg, int *remove __rte_unused) ret = read(fd, &req, sizeof(req)); if (ret < 0) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to read request: %s\n", - strerror(errno)); + rte_strerror(errno)); return; } else if (ret < (int)sizeof(req)) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Incomplete to read request %d\n", ret); @@ -400,7 +400,7 @@ vduse_events_handler(int fd, void *arg, int *remove __rte_unused) ret = write(dev->vduse_dev_fd, &resp, sizeof(resp)); if (ret != sizeof(resp)) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to write response %s\n", - strerror(errno)); + rte_strerror(errno)); return; } @@ -453,13 +453,13 @@ vduse_device_create(const char *path, bool compliant_ol_flags) control_fd = open(VDUSE_CTRL_PATH, O_RDWR); if (control_fd < 0) { VHOST_LOG_CONFIG(name, ERR, "Failed to open %s: %s\n", - VDUSE_CTRL_PATH, strerror(errno)); + VDUSE_CTRL_PATH, rte_strerror(errno)); return -1; } if (ioctl(control_fd, VDUSE_SET_API_VERSION, &ver)) { VHOST_LOG_CONFIG(name, ERR, "Failed to set API version: %" PRIu64 ": %s\n", - ver, strerror(errno)); + ver, rte_strerror(errno)); ret = -1; goto out_ctrl_close; } @@ -507,14 +507,14 @@ vduse_device_create(const char *path, bool compliant_ol_flags) ret = ioctl(control_fd, VDUSE_CREATE_DEV, dev_config); if (ret < 0) { VHOST_LOG_CONFIG(name, ERR, "Failed to create VDUSE device: %s\n", - strerror(errno)); + rte_strerror(errno)); goto out_free; } dev_fd = open(path, O_RDWR); if (dev_fd < 0) { VHOST_LOG_CONFIG(name, ERR, "Failed to open device %s: %s\n", - path, strerror(errno)); + path, rte_strerror(errno)); ret = -1; goto out_dev_close; } @@ -522,7 +522,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) ret = fcntl(dev_fd, F_SETFL, O_NONBLOCK); if (ret < 0) { VHOST_LOG_CONFIG(name, ERR, "Failed to set chardev as non-blocking: %s\n", - strerror(errno)); + rte_strerror(errno)); goto out_dev_close; } @@ -625,7 +625,7 @@ vduse_device_destroy(const char *path) ret = ioctl(dev->vduse_ctrl_fd, VDUSE_DESTROY_DEV, name); if (ret) VHOST_LOG_CONFIG(name, ERR, "Failed to destroy VDUSE device: %s\n", - strerror(errno)); + rte_strerror(errno)); close(dev->vduse_ctrl_fd); dev->vduse_ctrl_fd = -1; } diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index e36312181a..ebf5afe45d 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -772,7 +772,8 @@ mem_set_dump(void *ptr, size_t size, bool enable, uint64_t pagesz) if (madvise(start, len, enable ? MADV_DODUMP : MADV_DONTDUMP) == -1) { rte_log(RTE_LOG_INFO, vhost_config_log_level, - "VHOST_CONFIG: could not set coredump preference (%s).\n", strerror(errno)); + "VHOST_CONFIG: could not set coredump preference (%s).\n", + rte_strerror(errno)); } #endif } @@ -1138,7 +1139,7 @@ vhost_user_postcopy_region_register(struct virtio_net *dev, (uint64_t)reg_struct.range.start + (uint64_t)reg_struct.range.len - 1, dev->postcopy_ufd, - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -1267,7 +1268,7 @@ vhost_user_mmap_region(struct virtio_net *dev, MAP_SHARED | populate, region->fd, 0); if (mmap_addr == MAP_FAILED) { - VHOST_LOG_CONFIG(dev->ifname, ERR, "mmap failed (%s).\n", strerror(errno)); + VHOST_LOG_CONFIG(dev->ifname, ERR, "mmap failed (%s).\n", rte_strerror(errno)); return -1; } @@ -2698,7 +2699,7 @@ vhost_user_set_postcopy_advise(struct virtio_net **pdev, if (dev->postcopy_ufd == -1) { VHOST_LOG_CONFIG(dev->ifname, ERR, "userfaultfd not available: %s\n", - strerror(errno)); + rte_strerror(errno)); return RTE_VHOST_MSG_RESULT_ERR; } api_struct.api = UFFD_API; @@ -2706,7 +2707,7 @@ vhost_user_set_postcopy_advise(struct virtio_net **pdev, if (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) { VHOST_LOG_CONFIG(dev->ifname, ERR, "UFFDIO_API ioctl failure: %s\n", - strerror(errno)); + rte_strerror(errno)); close(dev->postcopy_ufd); dev->postcopy_ufd = -1; return RTE_VHOST_MSG_RESULT_ERR; -- 2.33.0