From: Rich Lane Subject: [PATCH] vhost: avoid buffer overflow in update_secure_len Date: Thu, 12 Nov 2015 00:02:33 -0800 Message-ID: <1447315353-42152-1-git-send-email-rlane@bigswitch.com> To: dev@dpdk.org Return-path: Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id 63CF18E98 for ; Thu, 12 Nov 2015 09:02:51 +0100 (CET) Received: by padhx2 with SMTP id hx2so57743214pad.1 for ; Thu, 12 Nov 2015 00:02:50 -0800 (PST) List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The guest could trigger this buffer overflow by creating a cycle of descriptors (which would also cause an infinite loop). The more common case is that vq->avail->idx jumps out of the range [last_used_idx, last_used_idx+256). This happens nearly every time when restarting a DPDK app inside a VM connected to a vhost-user vswitch because the virtqueue memory allocated by the previous run is zeroed. Signed-off-by: Rich Lane --- lib/librte_vhost/vhost_rxtx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index 9322ce6..d95b478 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -453,7 +453,7 @@ update_secure_len(struct vhost_virtqueue *vq, uint32_t id, vq->buf_vec[vec_id].desc_idx = idx; vec_id++; - if (vq->desc[idx].flags & VRING_DESC_F_NEXT) { + if (vq->desc[idx].flags & VRING_DESC_F_NEXT && vec_id < BUF_VECTOR_MAX) { idx = vq->desc[idx].next; next_desc = 1; } -- 1.9.1