From nobody Sat May 4 07:54:04 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486035445505134.46176984645763; Thu, 2 Feb 2017 03:37:25 -0800 (PST) Received: from localhost ([::1]:55926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZFha-00033M-1t for importer@patchew.org; Thu, 02 Feb 2017 06:37:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZFgi-000243-TC for qemu-devel@nongnu.org; Thu, 02 Feb 2017 06:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZFgf-0002iZ-Na for qemu-devel@nongnu.org; Thu, 02 Feb 2017 06:36:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZFgf-0002gq-HD for qemu-devel@nongnu.org; Thu, 02 Feb 2017 06:36:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 6B4953E9; Thu, 2 Feb 2017 11:36:25 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-68.ams2.redhat.com [10.36.116.68]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12BaOTf028780; Thu, 2 Feb 2017 06:36:25 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 7EF01804D8; Thu, 2 Feb 2017 12:36:21 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 2 Feb 2017 12:36:12 +0100 Message-Id: <1486035372-3621-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 02 Feb 2017 11:36:25 +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] xhci: guard xhci_kick_epctx against recursive calls 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: Gerd Hoffmann , 1653384@bugs.launchpad.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Track xhci_kick_epctx processing being active in a variable. Check the variable before calling xhci_kick_epctx from xhci_kick_ep. Add an assert to make sure we don't call recursively into xhci_kick_epctx. Cc: 1653384@bugs.launchpad.net Fixes: 94b037f2a451b3dc855f9f2c346e5049a361bd55 Reported-by: Fabian Lesniak Signed-off-by: Gerd Hoffmann Message-id: 1485790607-31399-5-git-send-email-kraxel@redhat.com --- hw/usb/hcd-xhci.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 899a410..df75907 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -390,6 +390,7 @@ struct XHCIEPContext { dma_addr_t pctx; unsigned int max_psize; uint32_t state; + uint32_t kick_active; =20 /* streams */ unsigned int max_pstreams; @@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned in= t slotid, return; } =20 + if (epctx->kick_active) { + return; + } xhci_kick_epctx(epctx, streamid); } =20 @@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, uns= igned int streamid) int i; =20 trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid); + assert(!epctx->kick_active); =20 /* If the device has been detached, but the guest has not noticed this yet the 2 above checks will succeed, but we must NOT continue */ @@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, uns= igned int streamid) } assert(ring->dequeue !=3D 0); =20 + epctx->kick_active++; while (1) { length =3D xhci_ring_chain_length(xhci, ring); if (length <=3D 0) { @@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, uns= igned int streamid) break; } } + epctx->kick_active--; =20 ep =3D xhci_epid_to_usbep(epctx); if (ep) { --=20 1.8.3.1