From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 96ED03237 for ; Thu, 10 Mar 2016 05:30:15 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP; 09 Mar 2016 20:30:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,314,1455004800"; d="scan'208";a="920667223" Received: from yliu-dev.sh.intel.com ([10.239.66.49]) by fmsmga001.fm.intel.com with ESMTP; 09 Mar 2016 20:30:14 -0800 From: Yuanhan Liu To: dev@dpdk.org Date: Thu, 10 Mar 2016 12:32:45 +0800 Message-Id: <1457584366-3036-8-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1457584366-3036-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1455803352-5518-1-git-send-email-yuanhan.liu@linux.intel.com> <1457584366-3036-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v3 7/8] vhost: do sanity check for desc->next against with vq->size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2016 04:30:16 -0000 A malicious guest may easily forge some illegal vring desc buf. To make our vhost robust, we need make sure desc->next will not go beyond the vq->desc[] array. Suggested-by: Rich Lane Signed-off-by: Yuanhan Liu --- lib/librte_vhost/vhost_rxtx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index 86e4d1a..43db6c7 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -183,6 +183,8 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, /* Room in vring buffer is not enough */ return -1; } + if (unlikely(desc->next >= vq->size)) + return -1; desc = &vq->desc[desc->next]; desc_addr = gpa_to_vva(dev, desc->addr); @@ -345,7 +347,7 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx, uint32_t len = *allocated; while (1) { - if (vec_id >= BUF_VECTOR_MAX) + if (unlikely(vec_id >= BUF_VECTOR_MAX || idx >= vq->size)) return -1; len += vq->desc[idx].len; @@ -759,6 +761,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, while (desc_avail != 0 || (desc->flags & VRING_DESC_F_NEXT) != 0) { /* This desc reaches to its end, get the next one */ if (desc_avail == 0) { + if (unlikely(desc->next >= vq->size)) + return -1; desc = &vq->desc[desc->next]; desc_addr = gpa_to_vva(dev, desc->addr); -- 1.9.0