From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, yliu@fridaylinux.org, tiwei.bie@intel.com,
jianfeng.tan@intel.com, vkaplans@redhat.com
Cc: stable@dpdk.org, jfreiman@redhat.com,
Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [dpdk-dev] [PATCH 1/3] vhost: fix fd leak in VHOST_USER_SET_LOG_BASE
Date: Fri, 24 Nov 2017 18:48:23 +0100 [thread overview]
Message-ID: <20171124174825.15567-2-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20171124174825.15567-1-maxime.coquelin@redhat.com>
If VHOST_USER_SET_LOG_BASE request's message size is invalid,
the fd is leaked.
Fix this by closing the fd systematically as long as it is valid.
Fixes: 53af5b1e0ace ("vhost: fix leak of file descriptor")
Cc: stable@dpdk.org
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/librte_vhost/vhost_user.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index f4c7ce462..f06d9bb65 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -895,6 +895,7 @@ static int
vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg)
{
int fd = msg->fds[0];
+ int ret = 0;
uint64_t size, off;
void *addr;
@@ -907,7 +908,8 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg)
RTE_LOG(ERR, VHOST_CONFIG,
"invalid log base msg size: %"PRId32" != %d\n",
msg->size, (int)sizeof(VhostUserLog));
- return -1;
+ ret = -1;
+ goto out;
}
size = msg->payload.log.mmap_size;
@@ -921,10 +923,10 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg)
* fail when offset is not page size aligned.
*/
addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- close(fd);
if (addr == MAP_FAILED) {
RTE_LOG(ERR, VHOST_CONFIG, "mmap log base failed!\n");
- return -1;
+ ret = -1;
+ goto out;
}
/*
@@ -938,7 +940,10 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg)
dev->log_base = dev->log_addr + off;
dev->log_size = size;
- return 0;
+out:
+ close(fd);
+
+ return ret;
}
/*
--
2.14.3
next prev parent reply other threads:[~2017-11-24 17:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-24 17:48 [dpdk-dev] [PATCH 0/3] vhost: MQ live-migration fixes Maxime Coquelin
2017-11-24 17:48 ` Maxime Coquelin [this message]
2017-11-24 17:48 ` [dpdk-dev] [PATCH 2/3] vhost: protect dirty logging against logging base change Maxime Coquelin
2017-11-24 17:48 ` [dpdk-dev] [PATCH 3/3] vhost: don't invalidate vrings if new addresses are identical 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=20171124174825.15567-2-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=dev@dpdk.org \
--cc=jfreiman@redhat.com \
--cc=jianfeng.tan@intel.com \
--cc=stable@dpdk.org \
--cc=tiwei.bie@intel.com \
--cc=vkaplans@redhat.com \
--cc=yliu@fridaylinux.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).