From: Tiwei Bie <tiwei.bie@intel.com>
To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org
Cc: stable@dpdk.org
Subject: [dpdk-dev] [PATCH 2/4] vhost: fix potential use-after-free for zero copy mbuf
Date: Fri, 22 Feb 2019 10:42:07 +0800 [thread overview]
Message-ID: <20190222024209.30879-3-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190222024209.30879-1-tiwei.bie@intel.com>
Don't free the zero copy mbufs before they have been consumed,
otherwise there could be use-after-free.
Fixes: b0a985d1f340 ("vhost: add dequeue zero copy")
Cc: stable@dpdk.org
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
lib/librte_vhost/vhost.h | 12 ++++++++++++
lib/librte_vhost/vhost_user.c | 3 +++
lib/librte_vhost/virtio_net.c | 12 ------------
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index bcfce274b..044651b19 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -757,4 +757,16 @@ restore_mbuf(struct rte_mbuf *m)
}
}
+static __rte_always_inline bool
+mbuf_is_consumed(struct rte_mbuf *m)
+{
+ while (m) {
+ if (rte_mbuf_refcnt_read(m) > 1)
+ return false;
+ m = m->next;
+ }
+
+ return true;
+}
+
#endif /* _VHOST_NET_CDEV_H_ */
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index e3ddf2589..6d8253514 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -1218,6 +1218,9 @@ free_zmbufs(struct vhost_virtqueue *vq)
zmbuf != NULL; zmbuf = next) {
next = TAILQ_NEXT(zmbuf, next);
+ while (!mbuf_is_consumed(zmbuf->mbuf))
+ usleep(1000);
+
restore_mbuf(zmbuf->mbuf);
rte_pktmbuf_free(zmbuf->mbuf);
TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 862ca5e1a..40a292364 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1306,18 +1306,6 @@ get_zmbuf(struct vhost_virtqueue *vq)
return NULL;
}
-static __rte_always_inline bool
-mbuf_is_consumed(struct rte_mbuf *m)
-{
- while (m) {
- if (rte_mbuf_refcnt_read(m) > 1)
- return false;
- m = m->next;
- }
-
- return true;
-}
-
static __rte_always_inline uint16_t
virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
--
2.17.1
next prev parent reply other threads:[~2019-02-22 2:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 2:42 [dpdk-dev] [PATCH 0/4] Some fixes for vhost zero copy Tiwei Bie
2019-02-22 2:42 ` [dpdk-dev] [PATCH 1/4] vhost: restore mbuf first when freeing zmbuf Tiwei Bie
2019-02-26 14:41 ` Maxime Coquelin
2019-02-22 2:42 ` Tiwei Bie [this message]
2019-02-26 14:42 ` [dpdk-dev] [PATCH 2/4] vhost: fix potential use-after-free for zero copy mbuf Maxime Coquelin
2019-02-22 2:42 ` [dpdk-dev] [PATCH 3/4] vhost: fix potential use-after-free for memory region Tiwei Bie
2019-02-26 14:42 ` Maxime Coquelin
2019-02-22 2:42 ` [dpdk-dev] [PATCH 4/4] doc: improve vhost zero copy guide Tiwei Bie
2019-02-26 14:44 ` Maxime Coquelin
2019-02-26 14:46 ` [dpdk-dev] [PATCH 0/4] Some fixes for vhost zero copy Maxime Coquelin
2019-02-27 1:52 ` Tiwei Bie
2019-02-27 8:32 ` Maxime Coquelin
2019-02-27 8:31 ` 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=20190222024209.30879-3-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=stable@dpdk.org \
--cc=zhihong.wang@intel.com \
/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).