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 0B8FD45BBE; Thu, 24 Oct 2024 09:54:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 532B9433A4; Thu, 24 Oct 2024 09:54:58 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id DAE8A4339A for ; Thu, 24 Oct 2024 09:54:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729756494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bzg4EDvTym/Ld7udFVVgZsQLcmEtf00zM8gMPDq+9Hk=; b=H1BricugCqumWcm567wM0Ml6dhiuxDZvPyrayZmVRiGvZ75Ivjml9l4cxLmoU8sQx2Azib Wfes9OlzaFCSlZ/6gb6FKx7VmzDxQwXEA9cC75lxS/+hBxBNsvylZf26AlskHQv1eELArn D8K/cswGdEDLEQTnlvJvZVY6JrNVyXY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-rSe7VUimNkq0tpeNH0KB_Q-1; Thu, 24 Oct 2024 03:54:51 -0400 X-MC-Unique: rSe7VUimNkq0tpeNH0KB_Q-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30BAC19560AA; Thu, 24 Oct 2024 07:54:50 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E2EA300018D; Thu, 24 Oct 2024 07:54:48 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v2 1/6] vhost: fix VDUSE device creation error handling Date: Thu, 24 Oct 2024 09:54:36 +0200 Message-ID: <20241024075441.3723352-2-maxime.coquelin@redhat.com> In-Reply-To: <20241024075441.3723352-1-maxime.coquelin@redhat.com> References: <20241024075441.3723352-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 This patch fixes missing reconnection log unmapping miss in the error path at VDUSE creation time. Coverity issue: 445525 Fixes: da79cc7fda76 ("vhost: add reconnection support to VDUSE") Signed-off-by: Maxime Coquelin --- lib/vhost/vduse.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index f9ac317438..4bb309e441 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -485,10 +485,9 @@ vduse_device_create(const char *path, bool compliant_ol_flags) struct virtio_net_config vnet_config = {{ 0 }}; uint64_t ver = VHOST_VDUSE_API_VERSION; uint64_t features; - struct vduse_dev_config *dev_config = NULL; const char *name = path + strlen("/dev/vduse/"); char reconnect_file[PATH_MAX]; - struct vhost_reconnect_data *reconnect_log = NULL; + struct vhost_reconnect_data *reconnect_log = MAP_FAILED; bool reconnect = false; if (vduse.fdset == NULL) { @@ -530,13 +529,13 @@ vduse_device_create(const char *path, bool compliant_ol_flags) ret = rte_vhost_driver_get_features(path, &features); if (ret < 0) { VHOST_CONFIG_LOG(name, ERR, "Failed to get backend features"); - goto out_free; + goto out_ctrl_close; } ret = rte_vhost_driver_get_queue_num(path, &max_queue_pairs); if (ret < 0) { VHOST_CONFIG_LOG(name, ERR, "Failed to get max queue pairs"); - goto out_free; + goto out_ctrl_close; } VHOST_CONFIG_LOG(path, INFO, "VDUSE max queue pairs: %u", max_queue_pairs); @@ -584,7 +583,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) "Features mismatch between backend (0x%" PRIx64 ") & reconnection file (0x%" PRIx64 ")", features, reconnect_log->features); ret = -1; - goto out_ctrl_close; + goto out_log_unmap; } if (reconnect_log->nr_vrings != total_queues) { @@ -592,9 +591,11 @@ vduse_device_create(const char *path, bool compliant_ol_flags) "Queues number mismatch between backend (%u) and reconnection file (%u)", total_queues, reconnect_log->nr_vrings); ret = -1; - goto out_ctrl_close; + goto out_log_unmap; } } else { + struct vduse_dev_config *dev_config; + reco_fd = open(reconnect_file, O_CREAT | O_EXCL | O_RDWR, 0600); if (reco_fd < 0) { if (errno == EEXIST) { @@ -633,7 +634,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) if (!dev_config) { VHOST_CONFIG_LOG(name, ERR, "Failed to allocate VDUSE config"); ret = -1; - goto out_ctrl_close; + goto out_log_unmap; } vnet_config.max_virtqueue_pairs = max_queue_pairs; @@ -649,16 +650,16 @@ vduse_device_create(const char *path, bool compliant_ol_flags) memcpy(dev_config->config, &vnet_config, sizeof(vnet_config)); ret = ioctl(control_fd, VDUSE_CREATE_DEV, dev_config); + free(dev_config); + dev_config = NULL; if (ret < 0) { VHOST_CONFIG_LOG(name, ERR, "Failed to create VDUSE device: %s", strerror(errno)); - goto out_free; + goto out_log_unmap; } memcpy(&reconnect_log->config, &vnet_config, sizeof(vnet_config)); reconnect_log->nr_vrings = total_queues; - free(dev_config); - dev_config = NULL; } dev_fd = open(path, O_RDWR); @@ -693,6 +694,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) dev->vduse_ctrl_fd = control_fd; dev->vduse_dev_fd = dev_fd; dev->reconnect_log = reconnect_log; + reconnect_log = MAP_FAILED; if (reconnect) dev->status = dev->reconnect_log->status; @@ -768,8 +770,9 @@ vduse_device_create(const char *path, bool compliant_ol_flags) if (dev_fd >= 0) close(dev_fd); ioctl(control_fd, VDUSE_DESTROY_DEV, name); -out_free: - free(dev_config); +out_log_unmap: + if (reconnect_log != MAP_FAILED) + munmap(reconnect_log, sizeof(*reconnect_log)); out_ctrl_close: close(control_fd); -- 2.46.2