From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asP5g-00057W-C1 for qemu-devel@nongnu.org; Tue, 19 Apr 2016 02:24:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asP5c-0006Fa-6E for qemu-devel@nongnu.org; Tue, 19 Apr 2016 02:24:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42975) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asP5c-0006FS-0c for qemu-devel@nongnu.org; Tue, 19 Apr 2016 02:24:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BD55C04B300 for ; Tue, 19 Apr 2016 06:24:47 +0000 (UTC) From: Gerd Hoffmann Date: Tue, 19 Apr 2016 08:24:43 +0200 Message-Id: <1461047084-17810-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1461047084-17810-1-git-send-email-kraxel@redhat.com> References: <1461047084-17810-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 1/2] ehci: apply limit to iTD/sidt descriptors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Commit "156a2e4 ehci: make idt processing more robust" tries to avoid a DoS by the guest (create a circular iTD queue and let qemu ehci emulation run in circles forever). Unfortunately this has two problems: First it misses the case of siTDs, and second it reportedly breaks FreeBSD. So lets go for a different approach: just count the number of iTDs and siTDs we have seen per frame and apply a limit. That should really catch all cases now. Reported-by: =E6=9D=9C=E5=B0=91=E5=8D=9A Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 159f58d..d5c0e1c 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2011,6 +2011,7 @@ static int ehci_state_writeback(EHCIQueue *q) static void ehci_advance_state(EHCIState *ehci, int async) { EHCIQueue *q =3D NULL; + int itd_count =3D 0; int again; =20 do { @@ -2035,10 +2036,12 @@ static void ehci_advance_state(EHCIState *ehci, i= nt async) =20 case EST_FETCHITD: again =3D ehci_state_fetchitd(ehci, async); + itd_count++; break; =20 case EST_FETCHSITD: again =3D ehci_state_fetchsitd(ehci, async); + itd_count++; break; =20 case EST_ADVANCEQUEUE: @@ -2087,7 +2090,8 @@ static void ehci_advance_state(EHCIState *ehci, int= async) break; } =20 - if (again < 0) { + if (again < 0 || itd_count > 16) { + /* TODO: notify guest (raise HSE irq?) */ fprintf(stderr, "processing error - resetting ehci HC\n"); ehci_reset(ehci); again =3D 0; --=20 1.8.3.1