From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C7D4F5A8B for ; Mon, 15 Jun 2015 09:57:05 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 15 Jun 2015 00:57:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,617,1427785200"; d="scan'208";a="746791495" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga002.jf.intel.com with ESMTP; 15 Jun 2015 00:57:04 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t5F7v1Zj005515; Mon, 15 Jun 2015 15:57:01 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t5F7uwvX030646; Mon, 15 Jun 2015 15:57:00 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t5F7uvNn030642; Mon, 15 Jun 2015 15:56:57 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Mon, 15 Jun 2015 15:56:41 +0800 Message-Id: <1434355006-30583-5-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1434355006-30583-1-git-send-email-changchun.ouyang@intel.com> References: <1433915549-18571-1-git-send-email-changchun.ouyang@intel.com> <1434355006-30583-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v3 4/9] lib_vhost: Check the virtqueue address's validity 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: Mon, 15 Jun 2015 07:57:06 -0000 This is added since v3. Check the virtqueue address's validity. Signed-off-by: Changchun Ouyang --- lib/librte_vhost/vhost_user/vhost-net-user.c | 11 ++++++++++- lib/librte_vhost/virtio-net.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c index b66a653..552b501 100644 --- a/lib/librte_vhost/vhost_user/vhost-net-user.c +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c @@ -398,7 +398,16 @@ vserver_message_handler(int connfd, void *dat, int *remove) ops->set_vring_num(ctx, &msg.payload.state); break; case VHOST_USER_SET_VRING_ADDR: - ops->set_vring_addr(ctx, &msg.payload.addr); + if (ops->set_vring_addr(ctx, &msg.payload.addr) != 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "error found in vhost set vring," + "the vhost device will destroy\n"); + close(connfd); + *remove = 1; + free(cfd_ctx); + user_destroy_device(ctx); + ops->destroy_device(ctx); + } break; case VHOST_USER_SET_VRING_BASE: ops->set_vring_base(ctx, &msg.payload.state); diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 3e24841..80df0ec 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -553,6 +553,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) { struct virtio_net *dev; struct vhost_virtqueue *vq; + uint32_t i; dev = get_device(ctx); if (dev == NULL) @@ -580,6 +581,15 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + for (i = vq->last_used_idx; i < vq->avail->idx; i++) + if (vq->avail->ring[i] >= vq->size) { + RTE_LOG(ERR, VHOST_CONFIG, "%s (%"PRIu64"):" + "Please check virt queue pair idx:%d is " + "enalbed correctly on guest.\n", __func__, + dev->device_fh, addr->index / VIRTIO_QNUM); + return -1; + } + vq->used = (struct vring_used *)(uintptr_t)qva_to_vva(dev, addr->index / VIRTIO_QNUM, addr->used_user_addr); if (vq->used == 0) { -- 1.8.4.2