From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBe7-0002lP-9B for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adBe6-0006TX-9w for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBe6-0006TP-5i for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:30 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id AE27972651 for ; Tue, 8 Mar 2016 07:01:29 +0000 (UTC) From: Peter Xu Date: Tue, 8 Mar 2016 15:00:42 +0800 Message-Id: <1457420446-25276-5-git-send-email-peterx@redhat.com> In-Reply-To: <1457420446-25276-1-git-send-email-peterx@redhat.com> References: <1457420446-25276-1-git-send-email-peterx@redhat.com> Subject: [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, Gerd Hoffmann , peterx@redhat.com First of all, this function cannot be inlined even with always_inline, so removing inline. After that, make its stack bounded. Suggested-by: Paolo Bonzini CC: Gerd Hoffmann Signed-off-by: Peter Xu --- hw/usb/hcd-xhci.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 44b6f8c..3dd5a02 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -694,18 +694,22 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr, } } -static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, - uint32_t *buf, size_t len) +static void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, + uint32_t *buf, size_t len) { int i; - uint32_t tmp[len / sizeof(uint32_t)]; + uint32_t n = len / sizeof(uint32_t); +#define __BUF_SIZE (12) + uint32_t tmp[__BUF_SIZE]; + assert(__BUF_SIZE >= n); assert((len % sizeof(uint32_t)) == 0); - for (i = 0; i < (len / sizeof(uint32_t)); i++) { + for (i = 0; i < n; i++) { tmp[i] = cpu_to_le32(buf[i]); } pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len); +#undef __BUF_SIZE } static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport) -- 2.4.3