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
Subject: [dpdk-dev] [PATCH 2/6] vhost: fix possible out of bound access in relay helpers
Date: Fri,  4 Jan 2019 12:06:38 +0800	[thread overview]
Message-ID: <20190104040642.27463-3-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190104040642.27463-1-tiwei.bie@intel.com>

Fixes: b13ad2decc83 ("vhost: provide helpers for virtio ring relay")

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

diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c
index 77d92f9ad..407d1c363 100644
--- a/lib/librte_vhost/vdpa.c
+++ b/lib/librte_vhost/vdpa.c
@@ -178,6 +178,9 @@ rte_vdpa_relay_vring_avail(int vid, uint16_t qid, void *vring_m)
 	while (idx_m != idx) {
 		/* avail entry copy */
 		desc_id = vq->avail->ring[idx_m & (vq->size - 1)];
+		if (unlikely(desc_id >= vq->size))
+			return -1;
+
 		s_vring->avail->ring[idx_m & (vq->size - 1)] = desc_id;
 		desc_ring = vq->desc;
 
@@ -205,15 +208,14 @@ rte_vdpa_relay_vring_avail(int vid, uint16_t qid, void *vring_m)
 
 		/* check if the buf addr is within the guest memory */
 		do {
+			if (unlikely(desc_id >= vq->size))
+				goto fail;
 			desc = desc_ring[desc_id];
 			perm = desc.flags & VRING_DESC_F_WRITE ?
 				VHOST_ACCESS_WO : VHOST_ACCESS_RO;
 			if (invalid_desc_check(dev, vq, desc.addr, desc.len,
-						perm)) {
-				if (unlikely(idesc))
-					free_ind_table(idesc);
-				return -1;
-			}
+						perm))
+				goto fail;
 			desc_id = desc.next;
 		} while (desc.flags & VRING_DESC_F_NEXT);
 
@@ -232,6 +234,11 @@ rte_vdpa_relay_vring_avail(int vid, uint16_t qid, void *vring_m)
 		vhost_avail_event(vq) = idx;
 
 	return ret;
+
+fail:
+	if (unlikely(idesc))
+		free_ind_table(idesc);
+	return -1;
 }
 
 int __rte_experimental
@@ -270,6 +277,9 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m)
 		desc_id = vq->used->ring[idx & (vq->size - 1)].id;
 		desc_ring = vq->desc;
 
+		if (unlikely(desc_id >= vq->size))
+			return -1;
+
 		if (vq->desc[desc_id].flags & VRING_DESC_F_INDIRECT) {
 			dlen = vq->desc[desc_id].len;
 			desc_ring = (struct vring_desc *)(uintptr_t)
@@ -294,6 +304,8 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m)
 
 		/* dirty page logging for DMA writeable buffer */
 		do {
+			if (unlikely(desc_id >= vq->size))
+				goto fail;
 			desc = desc_ring[desc_id];
 			if (desc.flags & VRING_DESC_F_WRITE)
 				vhost_log_write(dev, desc.addr, desc.len);
@@ -315,4 +327,9 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m)
 		vring_used_event(s_vring) = idx_m;
 
 	return ret;
+
+fail:
+	if (unlikely(idesc))
+		free_ind_table(idesc);
+	return -1;
 }
-- 
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 ` Tiwei Bie [this message]
2019-01-04  8:39   ` [dpdk-dev] [PATCH 2/6] vhost: fix possible out of bound " 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 ` [dpdk-dev] [PATCH 5/6] vhost: fix possible dead loop " Tiwei Bie
2019-01-04  8:46   ` 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-3-tiwei.bie@intel.com \
    --to=tiwei.bie@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --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).