From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: P J P Date: Thu, 6 Oct 2016 11:20:11 +0530 Message-Id: <1475733011-22266-1-git-send-email-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH] usb: xHCI: add check to limit command TRB processing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Developers Cc: Gerd Hoffmann , Li Qiang , Prasad J Pandit 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) -- 2.5.5