thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From a7db0339ff184a34168de5c1faff523e180fec03 Mon Sep 17 00:00:00 2001
ae23c9
From: Xiao Wang <jasowang@redhat.com>
ae23c9
Date: Fri, 11 Jan 2019 07:59:04 +0000
ae23c9
Subject: [PATCH 09/11] virtio-net-test: add large tx buffer test
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Xiao Wang <jasowang@redhat.com>
ae23c9
Message-id: <20190111075904.2030-10-jasowang@redhat.com>
ae23c9
Patchwork-id: 83980
ae23c9
O-Subject: [RHEL8 qemu-kvm PATCH 9/9] virtio-net-test: add large tx buffer test
ae23c9
Bugzilla: 1636784
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
ae23c9
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
ae23c9
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
ae23c9
This test tries to build a packet whose size is greater than INT_MAX
ae23c9
which tries to trigger integer overflow in qemu_net_queue_append_iov()
ae23c9
which may result OOB.
ae23c9
ae23c9
Signed-off-by: Jason Wang <jasowang@redhat.com>
ae23c9
Reviewed-by: Thomas Huth <thuth@redhat.com>
ae23c9
Message-id: 20181204035347.6148-6-jasowang@redhat.com
ae23c9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
ae23c9
(cherry picked from commit 118cafff251318d16e1cfdef9cbf6b7d1e74cdb5)
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 tests/virtio-net-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
ae23c9
 1 file changed, 46 insertions(+)
ae23c9
ae23c9
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
ae23c9
index 9da8f3d..99bc605 100644
ae23c9
--- a/tests/virtio-net-test.c
ae23c9
+++ b/tests/virtio-net-test.c
ae23c9
@@ -245,6 +245,48 @@ static void pci_basic(gconstpointer data)
ae23c9
     g_free(dev);
ae23c9
     qtest_shutdown(qs);
ae23c9
 }
ae23c9
+
ae23c9
+static void large_tx(gconstpointer data)
ae23c9
+{
ae23c9
+    QVirtioPCIDevice *dev;
ae23c9
+    QOSState *qs;
ae23c9
+    QVirtQueuePCI *tx, *rx;
ae23c9
+    QVirtQueue *vq;
ae23c9
+    uint64_t req_addr;
ae23c9
+    uint32_t free_head;
ae23c9
+    size_t alloc_size = (size_t)data / 64;
ae23c9
+    int i;
ae23c9
+
ae23c9
+    qs = pci_test_start("-netdev hubport,id=hp0,hubid=0 "
ae23c9
+                        "-device virtio-net-pci,netdev=hp0");
ae23c9
+    dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT);
ae23c9
+
ae23c9
+    rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
ae23c9
+    tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1);
ae23c9
+
ae23c9
+    driver_init(&dev->vdev);
ae23c9
+    vq = &tx->vq;
ae23c9
+
ae23c9
+    /* Bypass the limitation by pointing several descriptors to a single
ae23c9
+     * smaller area */
ae23c9
+    req_addr = guest_alloc(qs->alloc, alloc_size);
ae23c9
+    free_head = qvirtqueue_add(vq, req_addr, alloc_size, false, true);
ae23c9
+
ae23c9
+    for (i = 0; i < 64; i++) {
ae23c9
+        qvirtqueue_add(vq, req_addr, alloc_size, false, i != 63);
ae23c9
+    }
ae23c9
+    qvirtqueue_kick(&dev->vdev, vq, free_head);
ae23c9
+
ae23c9
+    qvirtio_wait_used_elem(&dev->vdev, vq, free_head, NULL,
ae23c9
+                           QVIRTIO_NET_TIMEOUT_US);
ae23c9
+
ae23c9
+    qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc);
ae23c9
+    qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc);
ae23c9
+    qvirtio_pci_device_disable(dev);
ae23c9
+    g_free(dev->pdev);
ae23c9
+    g_free(dev);
ae23c9
+    qtest_shutdown(qs);
ae23c9
+}
ae23c9
 #endif
ae23c9
 
ae23c9
 static void hotplug(void)
ae23c9
@@ -269,6 +311,10 @@ int main(int argc, char **argv)
ae23c9
     qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
ae23c9
     qtest_add_data_func("/virtio/net/pci/rx_stop_cont",
ae23c9
                         stop_cont_test, pci_basic);
ae23c9
+    qtest_add_data_func("/virtio/net/pci/large_tx_uint_max",
ae23c9
+                        (gconstpointer)UINT_MAX, large_tx);
ae23c9
+    qtest_add_data_func("/virtio/net/pci/large_tx_net_bufsize",
ae23c9
+                        (gconstpointer)NET_BUFSIZE, large_tx);
ae23c9
 #endif
ae23c9
     qtest_add_func("/virtio/net/pci/hotplug", hotplug);
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9