yeahuh / rpms / qemu-kvm

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