From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V8VwQ-00016E-TE for qemu-devel@nongnu.org; Sun, 11 Aug 2013 09:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V8VwH-0004dy-Gp for qemu-devel@nongnu.org; Sun, 11 Aug 2013 09:44:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V8VwH-0004dB-8x for qemu-devel@nongnu.org; Sun, 11 Aug 2013 09:44:09 -0400 Date: Sun, 11 Aug 2013 16:45:31 +0300 From: "Michael S. Tsirkin" Message-ID: <20130811134531.GA15442@redhat.com> References: <1374853288-9912-1-git-send-email-peter.maydell@linaro.org> <1374853288-9912-2-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1374853288-9912-2-git-send-email-peter.maydell@linaro.org> Subject: Re: [Qemu-devel] [PATCH v2 for-1.6 1/2] hw/virtio/virtio: Don't allow guests to add/remove queues List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Anthony Liguori , KONRAD Frederic , kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org, patches@linaro.org On Fri, Jul 26, 2013 at 04:41:27PM +0100, Peter Maydell wrote: > A queue size of 0 is used to indicate a nonexistent queue, so > don't allow the guest to flip a queue between zero-size and > non-zero-size. Don't permit setting of negative queue sizes > either. > > Signed-off-by: Peter Maydell Reviewed-by: Michael S. Tsirkin > --- > hw/virtio/virtio.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 09f62c6..60653f7 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -673,10 +673,16 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) > > void virtio_queue_set_num(VirtIODevice *vdev, int n, int num) > { > - if (num <= VIRTQUEUE_MAX_SIZE) { > - vdev->vq[n].vring.num = num; > - virtqueue_init(&vdev->vq[n]); > + /* Don't allow guest to flip queue between existent and > + * nonexistent states, or to set it to an invalid size. > + */ > + if (!!num != !!vdev->vq[n].vring.num || > + num > VIRTQUEUE_MAX_SIZE || > + num < 0) { > + return; > } > + vdev->vq[n].vring.num = num; > + virtqueue_init(&vdev->vq[n]); > } > > int virtio_queue_get_num(VirtIODevice *vdev, int n) > -- > 1.7.9.5