From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [PATCH 1/6] vhost: fix vduse device creation error handling
Date: Wed, 23 Oct 2024 17:15:47 +0200 [thread overview]
Message-ID: <20241023151552.2863387-2-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20241023151552.2863387-1-maxime.coquelin@redhat.com>
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 <maxime.coquelin@redhat.com>
---
lib/vhost/vduse.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index f9ac317438..89bc29a33f 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -488,7 +488,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags)
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 +530,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 +584,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,7 +592,7 @@ 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 {
reco_fd = open(reconnect_file, O_CREAT | O_EXCL | O_RDWR, 0600);
@@ -633,7 +633,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 +649,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 +693,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 +769,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
next prev parent reply other threads:[~2024-10-23 15:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 15:15 [PATCH 0/6] VDUSE reconnection fixes and cleanup Maxime Coquelin
2024-10-23 15:15 ` Maxime Coquelin [this message]
2024-10-23 16:06 ` [PATCH 1/6] vhost: fix vduse device creation error handling David Marchand
2024-10-23 18:55 ` Maxime Coquelin
2024-10-23 15:15 ` [PATCH 2/6] vhost: fix possible TOCTOU in VDUSE dev creation Maxime Coquelin
2024-10-23 16:06 ` David Marchand
2024-10-23 15:15 ` [PATCH 3/6] vhost: fix VDUSE reconnect device start failure Maxime Coquelin
2024-10-23 16:06 ` David Marchand
2024-10-23 18:57 ` Maxime Coquelin
2024-10-23 15:15 ` [PATCH 4/6] vhost: refactor VDUSE reconnection log mapping Maxime Coquelin
2024-10-23 16:07 ` David Marchand
2024-10-23 19:04 ` Maxime Coquelin
2024-10-23 15:15 ` [PATCH 5/6] vhost: fix and refactor VDUSE reconnect log check Maxime Coquelin
2024-10-23 16:08 ` David Marchand
2024-10-23 15:15 ` [PATCH 6/6] vhost: move VDUSE reconnection after device is created Maxime Coquelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241023151552.2863387-2-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).