From patchwork Fri Jul 26 15:41:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18610 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f199.google.com (mail-ye0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ED90F25E59 for ; Fri, 26 Jul 2013 15:41:43 +0000 (UTC) Received: by mail-ye0-f199.google.com with SMTP id l12sf1804497yen.6 for ; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=E8/YCSM1aXhh4RM/WwdG17k5YQpTQcOlOZVcyXfG2zs=; b=gK9ki3vcGNZqeI171dtdlPC1hP+SXQiAmjPGHJtmFyUUkCaqMqqyKPftmdoCjn0Pw9 iVFWxHf47nDPeFUSd+RsqUWxW+aLs9bxyd6EA+i3VKFjATq+WsN1f44df1cWGoMcU55x YhWn8/Kk8v82wRQkoOMxvYHUJBb+nkQbCanhhWDYuX6B4wlhT5mD/UjV+zip4tGA8ENU 2jRAWHfCqd2sN6nDq4Bz676lDOXlzVJ19Y+98tNJ2Wkfmae3mT51jGHPh4AsPJeCoG8V U46ewq7YV/9izupfrXaEPPO25l2YknivW+fYy9rUOZOYqh60o55Jw2ovVWJRU1PK5FLz 6klQ== X-Received: by 10.236.77.166 with SMTP id d26mr24137042yhe.40.1374853302855; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.60.200 with SMTP id j8ls1086573qer.42.gmail; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) X-Received: by 10.58.145.97 with SMTP id st1mr20927630veb.71.1374853302719; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by mx.google.com with ESMTPS id j7si2194721vci.6.2013.07.26.08.41.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Jul 2013 08:41:42 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.46; Received: by mail-vb0-f46.google.com with SMTP id w8so1346993vbf.33 for ; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) X-Received: by 10.58.119.233 with SMTP id kx9mr21098058veb.3.1374853302631; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp29796veb; Fri, 26 Jul 2013 08:41:42 -0700 (PDT) X-Received: by 10.180.20.228 with SMTP id q4mr6236754wie.1.1374853301465; Fri, 26 Jul 2013 08:41:41 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id lm2si2132021wic.68.2013.07.26.08.41.40 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 26 Jul 2013 08:41:41 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1V2k92-0002aP-UX; Fri, 26 Jul 2013 16:41:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, kvmarm@lists.cs.columbia.edu, Anthony Liguori , "Michael S. Tsirkin" , KONRAD Frederic Subject: [PATCH v2 for-1.6 1/2] hw/virtio/virtio: Don't allow guests to add/remove queues Date: Fri, 26 Jul 2013 16:41:27 +0100 Message-Id: <1374853288-9912-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1374853288-9912-1-git-send-email-peter.maydell@linaro.org> References: <1374853288-9912-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQkAjyPOWmqxBXyv9mBZsdYH6KRG9tV9DRka477yq9c54LCXAWIyiZQUA6dyvL5XLpe3C5ix X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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)