From nobody Thu Nov 6 21:10:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543830228228544.1348840999276; Mon, 3 Dec 2018 01:43:48 -0800 (PST) Received: from localhost ([::1]:47578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTklM-0004BE-IH for importer@patchew.org; Mon, 03 Dec 2018 04:43:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTkj2-0002bh-HL for qemu-devel@nongnu.org; Mon, 03 Dec 2018 04:41:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTkeN-0007wn-Uz for qemu-devel@nongnu.org; Mon, 03 Dec 2018 04:36:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gTkeN-0007wY-QF for qemu-devel@nongnu.org; Mon, 03 Dec 2018 04:36:23 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2698387621; Mon, 3 Dec 2018 09:36:23 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-193.pek2.redhat.com [10.72.12.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6190660923; Mon, 3 Dec 2018 09:36:19 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Mon, 3 Dec 2018 17:35:44 +0800 Message-Id: <20181203093544.6184-5-jasowang@redhat.com> In-Reply-To: <20181203093544.6184-1-jasowang@redhat.com> References: <20181203093544.6184-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 03 Dec 2018 09:36:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH V3 for 3.1 4/4] virtio-net-test: add large tx buffer test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, mst@redhat.com, liq3ea@163.com, Jason Wang , liq3ea@gmail.com, ppandit@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This test tries to build a packet whose size is greater than INT_MAX which tries to trigger integer overflow in qemu_net_queue_append_iov() which may result OOB. Reviewed-by: Thomas Huth Signed-off-by: Jason Wang --- tests/virtio-net-test.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index f12f0afb51..22df5b6f37 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -242,6 +242,50 @@ static void pci_basic(gconstpointer data) g_free(dev); qtest_shutdown(qs); } + +static void large_tx(gconstpointer data) +{ + QVirtioPCIDevice *dev; + QOSState *qs; + QVirtQueuePCI *tx, *rx; + QVirtQueue *vq; + const char *cmd =3D "-netdev hubport,id=3Dhp0,hubid=3D0 " + "-device virtio-net-pci,netdev=3Dhp0 "; + uint64_t req_addr; + uint32_t free_head; + size_t alloc_size =3D UINT_MAX / 64; + int i; + + qs =3D pci_test_start(cmd); + dev =3D virtio_net_pci_init(qs->pcibus, PCI_SLOT); + + rx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); + tx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1); + + driver_init(&dev->vdev); + vq =3D &tx->vq; + + /* Bypass the limitation by pointing several descriptors to a single + * smaller area */ + req_addr =3D guest_alloc(qs->alloc, alloc_size); + free_head =3D qvirtqueue_add(vq, req_addr, alloc_size, false, true); + + for (i =3D 0; i < 64; i++) { + qvirtqueue_add(vq, req_addr, alloc_size, false, i =3D=3D 63 ? + false : true); + } + qvirtqueue_kick(&dev->vdev, vq, free_head); + + qvirtio_wait_used_elem(&dev->vdev, vq, free_head, NULL, + QVIRTIO_NET_TIMEOUT_US); + + qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc); + qvirtio_pci_device_disable(dev); + g_free(dev->pdev); + g_free(dev); + qtest_shutdown(qs); +} #endif =20 static void hotplug(void) @@ -267,6 +311,7 @@ int main(int argc, char **argv) qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic= ); qtest_add_data_func("/virtio/net/pci/rx_stop_cont", stop_cont_test, pci_basic); + qtest_add_data_func("/virtio/net/pci/large_tx", NULL, large_tx); #endif qtest_add_func("/virtio/net/pci/hotplug", hotplug); =20 --=20 2.17.1