From patchwork Thu Jul 25 13:37:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18575 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DA22E25E19 for ; Thu, 25 Jul 2013 13:38:05 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ht10sf220497vcb.5 for ; Thu, 25 Jul 2013 06:38:05 -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=s6kvniJfIqNW8nSysmOYUZND3ozMbpnNzm8pxKh0b4g=; b=o6AGM3CM81xMg+N2WaozsipedNuCEZP1dvRqv4fzlsujQtKW2WeCUWy4cNS4gcBjAJ K0/ZSux/V2OcsoWfc2xCPyg949WrYOHvP55p1AefMDxz23RTwVS66MWncQisRYRUbLuY g6+ZGdhsPGrHDkKreHRN0EVEaJ/GZXXk7q6JJGSqrCRtByxpQ0i+Dxr0HDHHXxS3Mnrd 9w2oLZqHPAySNqgdZwbOMtBeKfRwv/HLzDStHWu0CjeqAKAFt3OjbNvi5Jf90qzpiSU1 VlZqsSukvAWMnUFFJANLs02dDcozXVvAoRmQM7cT204E0kerGr9UpTP3YhNOp7OJlgvD 3wWA== X-Received: by 10.236.220.5 with SMTP id n5mr22774464yhp.21.1374759485240; Thu, 25 Jul 2013 06:38:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.86.7 with SMTP id l7ls617992qez.51.gmail; Thu, 25 Jul 2013 06:38:05 -0700 (PDT) X-Received: by 10.58.80.38 with SMTP id o6mr17922091vex.69.1374759485149; Thu, 25 Jul 2013 06:38:05 -0700 (PDT) Received: from mail-vb0-f47.google.com (mail-vb0-f47.google.com [209.85.212.47]) by mx.google.com with ESMTPS id f8si12362919vec.85.2013.07.25.06.38.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Jul 2013 06:38:05 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.47 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.47; Received: by mail-vb0-f47.google.com with SMTP id h10so410401vbh.20 for ; Thu, 25 Jul 2013 06:38:05 -0700 (PDT) X-Received: by 10.220.83.69 with SMTP id e5mr577377vcl.53.1374759485068; Thu, 25 Jul 2013 06:38:05 -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 yu8csp78028veb; Thu, 25 Jul 2013 06:38:03 -0700 (PDT) X-Received: by 10.204.175.10 with SMTP id v10mr987422bkz.86.1374759469850; Thu, 25 Jul 2013 06:37:49 -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 u7si5819454bkh.260.2013.07.25.06.37.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Jul 2013 06:37:49 -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 1V2Ljk-0001ey-1l; Thu, 25 Jul 2013 14:37:44 +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 1/2] hw/virtio/virtio: Don't allow guests to add/remove queues Date: Thu, 25 Jul 2013 14:37:42 +0100 Message-Id: <1374759463-6351-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1374759463-6351-1-git-send-email-peter.maydell@linaro.org> References: <1374759463-6351-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQm+xYeh6S0+nxRpFM1UwKB7T8qYHzuleOojk0wSWK1alzWXdyHSjPY3ac5+ZEZRv7N3VVAe X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.47 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 --- hw/virtio/virtio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 09f62c6..d5b0502 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -673,10 +673,14 @@ 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]); + if ((num == 0 && vdev->vq[n].vring.num != 0) || + (num != 0 && vdev->vq[n].vring.num == 0) || + (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)