From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, ehabkost@redhat.com,
qemu-block@nongnu.org, mst@redhat.com, stefanha@redhat.com,
mreitz@redhat.com, den@virtuozzo.com
Subject: [PATCH v1 1/4] virtio: protect non-modern devices from too big virtqueue size setting
Date: Tue, 5 Nov 2019 19:11:02 +0300 [thread overview]
Message-ID: <20191105161105.19016-2-dplotnikov@virtuozzo.com> (raw)
In-Reply-To: <20191105161105.19016-1-dplotnikov@virtuozzo.com>
The patch protects from creating illegal virtio device configuration
via direct virtqueue size property setting.
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
hw/virtio/virtio-blk-pci.c | 9 +++++++++
hw/virtio/virtio-scsi-pci.c | 10 ++++++++++
2 files changed, 19 insertions(+)
diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c
index 60c9185c39..6177ff1df8 100644
--- a/hw/virtio/virtio-blk-pci.c
+++ b/hw/virtio/virtio-blk-pci.c
@@ -48,6 +48,15 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
+ bool modern = virtio_pci_modern(vpci_dev);
+ uint32_t queue_size = dev->vdev.conf.queue_size;
+
+ if (!modern && queue_size > 128) {
+ error_setg(errp,
+ "too big queue size (%u, max: 128) "
+ "for non-modern virtio device", queue_size);
+ return;
+ }
if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
vpci_dev->nvectors = dev->vdev.conf.num_queues + 1;
diff --git a/hw/virtio/virtio-scsi-pci.c b/hw/virtio/virtio-scsi-pci.c
index 2830849729..6e6790fda5 100644
--- a/hw/virtio/virtio-scsi-pci.c
+++ b/hw/virtio/virtio-scsi-pci.c
@@ -17,6 +17,7 @@
#include "hw/virtio/virtio-scsi.h"
#include "virtio-pci.h"
+#include "qapi/error.h"
typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
@@ -47,6 +48,15 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
DeviceState *proxy = DEVICE(vpci_dev);
char *bus_name;
+ bool modern = virtio_pci_modern(vpci_dev);
+ uint32_t virtqueue_size = vs->conf.virtqueue_size;
+
+ if (!modern && virtqueue_size > 128) {
+ error_setg(errp,
+ "too big virtqueue size (%u, max: 128) "
+ "for non-modern virtio device", virtqueue_size);
+ return;
+ }
if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
vpci_dev->nvectors = vs->conf.num_queues + 3;
--
2.17.0
next prev parent reply other threads:[~2019-11-05 16:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-05 16:11 [PATCH v1 0/4] virtio: fix IO request length in virtio SCSI/block Denis Plotnikov
2019-11-05 16:11 ` Denis Plotnikov [this message]
2019-11-05 20:56 ` [PATCH v1 1/4] virtio: protect non-modern devices from too big virtqueue size setting Michael S. Tsirkin
2019-11-06 7:46 ` Denis Plotnikov
2019-11-06 9:01 ` Stefan Hajnoczi
2019-11-06 9:19 ` Stefan Hajnoczi
2019-11-06 11:33 ` Michael S. Tsirkin
2019-11-06 9:18 ` Stefan Hajnoczi
2019-11-06 11:51 ` Michael S. Tsirkin
2019-11-05 16:11 ` [PATCH v1 2/4] virtio: make seg_max virtqueue size dependent Denis Plotnikov
2019-11-05 20:51 ` Michael S. Tsirkin
2019-11-06 10:07 ` Denis Lunev
2019-11-06 11:54 ` Michael S. Tsirkin
2019-11-08 7:43 ` Denis Plotnikov
2019-11-08 9:52 ` Michael S. Tsirkin
2019-11-05 16:11 ` [PATCH v1 3/4] virtio: increase virtuqueue sizes in new machine types Denis Plotnikov
2019-11-05 20:52 ` Michael S. Tsirkin
2019-11-05 16:11 ` [PATCH v1 4/4] iotests: add test for virtio-scsi and virtio-blk machine type settings Denis Plotnikov
2019-11-06 9:24 ` Stefan Hajnoczi
2019-11-06 10:04 ` Max Reitz
2019-11-06 19:26 ` Eduardo Habkost
2019-11-07 16:30 ` Cleber Rosa
2019-11-08 7:08 ` Denis Plotnikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191105161105.19016-2-dplotnikov@virtuozzo.com \
--to=dplotnikov@virtuozzo.com \
--cc=den@virtuozzo.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).