From nobody Sun May 5 16:36:39 2024 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 1543493838078959.9510897795516; Thu, 29 Nov 2018 04:17:18 -0800 (PST) Received: from localhost ([::1]:53724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLFs-0000Cp-Kf for importer@patchew.org; Thu, 29 Nov 2018 07:17:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLDp-0007Zq-2W for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSLDo-0003s1-CT for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSLDo-0003rj-6S; Thu, 29 Nov 2018 07:15:08 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FABB89AF2; Thu, 29 Nov 2018 12:15:07 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19E5A1019639; Thu, 29 Nov 2018 12:15:00 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 29 Nov 2018 20:14:46 +0800 Message-Id: <20181129121449.4322-2-jasowang@redhat.com> In-Reply-To: <20181129121449.4322-1-jasowang@redhat.com> References: <20181129121449.4322-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 29 Nov 2018 12:15:07 +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 V2 for 3.1 1/4] net: drop too large packet early 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: mst@redhat.com, liq3ea@163.com, Jason Wang , liq3ea@gmail.com, qemu-stable@nongnu.org, 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" We try to detect and drop too large packet (>INT_MAX) in 1592a9947036 ("net: ignore packet size greater than INT_MAX") during packet delivering. Unfortunately, this is not sufficient as we may hit another integer overflow when trying to queue such large packet in qemu_net_queue_append_iov(): - size of the allocation may overflow on 32bit - packet->size is integer which may overflow even on 64bit Fixing this by move the check to qemu_sendv_packet_async() which is the entrance of all networking codes and reduce the limit to NET_BUFSIZE to be more conservative. Cc: qemu-stable@nongnu.org Cc: Li Qiang Reported-by: Li Qiang Reviewed-by: Li Qiang Signed-off-by: Jason Wang --- net/net.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/net.c b/net/net.c index 07c194a8f6..affe1877cf 100644 --- a/net/net.c +++ b/net/net.c @@ -712,15 +712,11 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sende= r, void *opaque) { NetClientState *nc =3D opaque; - size_t size =3D iov_size(iov, iovcnt); int ret; =20 - if (size > INT_MAX) { - return size; - } =20 if (nc->link_down) { - return size; + return iov_size(iov, iovcnt); } =20 if (nc->receive_disabled) { @@ -745,10 +741,15 @@ ssize_t qemu_sendv_packet_async(NetClientState *sende= r, NetPacketSent *sent_cb) { NetQueue *queue; + size_t size =3D iov_size(iov, iovcnt); int ret; =20 + if (size > NET_BUFSIZE) { + return size; + } + if (sender->link_down || !sender->peer) { - return iov_size(iov, iovcnt); + return size; } =20 /* Let filters handle the packet first */ --=20 2.17.1 From nobody Sun May 5 16:36:39 2024 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 1543493867342468.13173817189784; Thu, 29 Nov 2018 04:17:47 -0800 (PST) Received: from localhost ([::1]:53726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLGM-0000WM-4M for importer@patchew.org; Thu, 29 Nov 2018 07:17:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLE3-0007mY-OS for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSLDy-00040A-SF for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSLDy-0003zb-LH for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B275C30024AF; Thu, 29 Nov 2018 12:15:17 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 550051019639; Thu, 29 Nov 2018 12:15:08 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 29 Nov 2018 20:14:47 +0800 Message-Id: <20181129121449.4322-3-jasowang@redhat.com> In-Reply-To: <20181129121449.4322-1-jasowang@redhat.com> References: <20181129121449.4322-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 29 Nov 2018 12:15:17 +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 V2 for 3.1 2/4] virtio-net-test: remove unused macro 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: 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" Reviewed-by: Thomas Huth Signed-off-by: Jason Wang --- tests/virtio-net-test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index dcb87a8b6e..231e7c767e 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -24,7 +24,6 @@ =20 #define PCI_SLOT_HP 0x06 #define PCI_SLOT 0x04 -#define PCI_FN 0x00 =20 #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000) #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf) --=20 2.17.1 From nobody Sun May 5 16:36:39 2024 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 154349387153426.560806663861513; Thu, 29 Nov 2018 04:17:51 -0800 (PST) Received: from localhost ([::1]:53728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLGQ-0000YF-5f for importer@patchew.org; Thu, 29 Nov 2018 07:17:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLE4-0007mm-3Z for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSLE3-00042P-84 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44844) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSLE3-00042B-1p for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:23 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 571D33154853; Thu, 29 Nov 2018 12:15:22 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C1261019639; Thu, 29 Nov 2018 12:15:18 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 29 Nov 2018 20:14:48 +0800 Message-Id: <20181129121449.4322-4-jasowang@redhat.com> In-Reply-To: <20181129121449.4322-1-jasowang@redhat.com> References: <20181129121449.4322-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 29 Nov 2018 12:15:22 +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 V2 for 3.1 3/4] virtio-net-test: accept variable length argument in pci_test_start() 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: 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 allows flexibility to be reused for all kinds of command line used by other tests. Reviewed-by: Thomas Huth Signed-off-by: Jason Wang --- tests/virtio-net-test.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index 231e7c767e..33d26ab079 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -51,17 +51,20 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *b= us, int slot) return dev; } =20 -static QOSState *pci_test_start(int socket) +static QOSState *pci_test_start(const char *cmd, ...) { QOSState *qs; + va_list ap; const char *arch =3D qtest_get_arch(); - const char *cmd =3D "-netdev socket,fd=3D%d,id=3Dhs0 -device " - "virtio-net-pci,netdev=3Dhs0"; =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qs =3D qtest_pc_boot(cmd, socket); + va_start(ap, cmd); + qs =3D qtest_pc_vboot(cmd, ap); + va_end(ap); } else if (strcmp(arch, "ppc64") =3D=3D 0) { - qs =3D qtest_spapr_boot(cmd, socket); + va_start(ap, cmd); + qs =3D qtest_spapr_vboot(cmd, ap); + va_end(ap); } else { g_printerr("virtio-net tests are only available on x86 or ppc64\n"= ); exit(EXIT_FAILURE); @@ -218,11 +221,13 @@ static void pci_basic(gconstpointer data) QVirtQueue *tvq, int socket) =3D data; int sv[2], ret; + const char *cmd =3D "-netdev socket,fd=3D%d,id=3Dhs0 -device " + "virtio-net-pci,netdev=3Dhs0"; =20 ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, sv); g_assert_cmpint(ret, !=3D, -1); =20 - qs =3D pci_test_start(sv[1]); + qs =3D pci_test_start(cmd, sv[1]); dev =3D virtio_net_pci_init(qs->pcibus, PCI_SLOT); =20 rx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); --=20 2.17.1 From nobody Sun May 5 16:36:39 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543494071228910.7524226677194; Thu, 29 Nov 2018 04:21:11 -0800 (PST) Received: from localhost ([::1]:53745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLJS-0004Sm-4h for importer@patchew.org; Thu, 29 Nov 2018 07:20:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSLE8-0007p8-FK for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSLE7-00044d-Pz for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSLE7-00044N-KN for qemu-devel@nongnu.org; Thu, 29 Nov 2018 07:15:27 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E93CE3001384; Thu, 29 Nov 2018 12:15:26 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id E04451019639; Thu, 29 Nov 2018 12:15:22 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 29 Nov 2018 20:14:49 +0800 Message-Id: <20181129121449.4322-5-jasowang@redhat.com> In-Reply-To: <20181129121449.4322-1-jasowang@redhat.com> References: <20181129121449.4322-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 29 Nov 2018 12:15:27 +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 V2 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: 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. Signed-off-by: Jason Wang Reviewed-by: Thomas Huth --- 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 33d26ab079..1b39a73b6a 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -245,6 +245,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) @@ -270,6 +314,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