DPDK patches and discussions
 help / color / mirror / Atom feed
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 5/6] vhost: fix possible dead loop in vector filling
Date: Fri,  4 Jan 2019 12:06:41 +0800	[thread overview]
Message-ID: <20190104040642.27463-6-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190104040642.27463-1-tiwei.bie@intel.com>

Fix a possible dead loop which may happen, e.g. when driver
created a loop in the desc list and lens in descs are zero.

Fixes: fd68b4739d2c ("vhost: use buffer vectors in dequeue path")
Fixes: 2f3225a7d69b ("vhost: add vector filling support for packed ring")
Cc: stable@dpdk.org

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 lib/librte_vhost/virtio_net.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index d64c355b9..0893a1d04 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -309,6 +309,7 @@ fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	uint16_t vec_id = *vec_idx;
 	uint32_t len    = 0;
 	uint64_t dlen;
+	uint32_t nr_descs = vq->size;
 	struct vring_desc *descs = vq->desc;
 	struct vring_desc *idesc = NULL;
 
@@ -319,6 +320,10 @@ fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	if (vq->desc[idx].flags & VRING_DESC_F_INDIRECT) {
 		dlen = vq->desc[idx].len;
+		nr_descs = dlen / sizeof(struct vring_desc);
+		if (unlikely(nr_descs > vq->size))
+			return -1;
+
 		descs = (struct vring_desc *)(uintptr_t)
 			vhost_iova_to_vva(dev, vq, vq->desc[idx].addr,
 						&dlen,
@@ -348,6 +353,11 @@ fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			return -1;
 		}
 
+		if (unlikely(nr_descs-- == 0)) {
+			free_ind_table(idesc);
+			return -1;
+		}
+
 		len += descs[idx].len;
 
 		if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
@@ -510,6 +520,9 @@ fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(vec_id >= BUF_VECTOR_MAX))
 			return -1;
 
+		if (unlikely(*desc_count >= vq->size))
+			return -1;
+
 		*desc_count += 1;
 		*buf_id = descs[avail_idx].id;
 
-- 
2.17.1

  parent reply	other threads:[~2019-01-04  4:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-04  4:06 [dpdk-dev] [PATCH 0/6] Some fixes for vhost Tiwei Bie
2019-01-04  4:06 ` [dpdk-dev] [PATCH 1/6] vhost: fix desc access in relay helpers Tiwei Bie
2019-01-04  8:16   ` Maxime Coquelin
2019-01-04  4:06 ` [dpdk-dev] [PATCH 2/6] vhost: fix possible out of bound " Tiwei Bie
2019-01-04  8:39   ` Maxime Coquelin
2019-01-04  4:06 ` [dpdk-dev] [PATCH 3/6] vhost: fix possible dead loop " Tiwei Bie
2019-01-04  8:40   ` Maxime Coquelin
2019-01-04  4:06 ` [dpdk-dev] [PATCH 4/6] vhost: fix possible out of bound access in vector filling Tiwei Bie
2019-01-04  8:46   ` Maxime Coquelin
2019-01-04  4:06 ` Tiwei Bie [this message]
2019-01-04  8:46   ` [dpdk-dev] [PATCH 5/6] vhost: fix possible dead loop " Maxime Coquelin
2019-01-04  4:06 ` [dpdk-dev] [PATCH 6/6] vhost: ensure event idx is mapped when negotiated Tiwei Bie
2019-01-04  8:47   ` Maxime Coquelin
2019-01-04 18:00 ` [dpdk-dev] [PATCH 0/6] Some fixes for vhost 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=20190104040642.27463-6-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).