From patchwork Thu Oct 6 05:50:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9363673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C442607D3 for ; Thu, 6 Oct 2016 05:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 891A328DE8 for ; Thu, 6 Oct 2016 05:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79C0E28DEA; Thu, 6 Oct 2016 05:50:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D4A028DE8 for ; Thu, 6 Oct 2016 05:50:46 +0000 (UTC) Received: from localhost ([::1]:53281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs1Zs-000524-1J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Oct 2016 01:50:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs1Zb-00051o-C2 for qemu-devel@nongnu.org; Thu, 06 Oct 2016 01:50:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bs1ZY-00069U-6l for qemu-devel@nongnu.org; Thu, 06 Oct 2016 01:50:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs1ZY-000687-0R for qemu-devel@nongnu.org; Thu, 06 Oct 2016 01:50:24 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 C61B48E67D; Thu, 6 Oct 2016 05:50:20 +0000 (UTC) Received: from javelin.localdomain (vpn-236-77.phx2.redhat.com [10.3.236.77]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u965oDhf003016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 6 Oct 2016 01:50:15 -0400 From: P J P To: Qemu Developers Date: Thu, 6 Oct 2016 11:20:11 +0530 Message-Id: <1475733011-22266-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Oct 2016 05:50:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] usb: xHCI: add check to limit command TRB processing 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: Li Qiang , Gerd Hoffmann , Prasad J Pandit Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit USB xHCI controller uses ring of Transfer Request Blocks(TRB) to process USB commands. These are processed by loop in 'xhci_ring_fetch'. A guest user could make it read and process a same TRB infinitely. Limit number of command TRBs to avoid it. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/usb/hcd-xhci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 188f954..17dba2a 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -140,6 +140,7 @@ #define ERDP_EHB (1<<3) #define TRB_SIZE 16 +#define TRB_MAX 4000 typedef struct XHCITRB { uint64_t parameter; uint32_t status; @@ -999,9 +1000,10 @@ static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring, static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb, dma_addr_t *addr) { + uint16_t trbcnt = 0; PCIDevice *pci_dev = PCI_DEVICE(xhci); - while (1) { + while (trbcnt++ < TRB_MAX) { TRBType type; pci_dma_read(pci_dev, ring->dequeue, trb, TRB_SIZE); trb->addr = ring->dequeue; @@ -1032,6 +1034,8 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb, } } } + + return 0; } static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)