From patchwork Tue Mar 8 07:00:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 8530011 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 227D3C0553 for ; Tue, 8 Mar 2016 07:01:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 919CE20121 for ; Tue, 8 Mar 2016 07:01:51 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id E6C2F2010B for ; Tue, 8 Mar 2016 07:01:50 +0000 (UTC) Received: from localhost ([::1]:60742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBeQ-0002z2-Ca for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Mar 2016 02:01:50 -0500 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) Received: from pxdev.xzpeter.org.com (vpn1-5-232.pek2.redhat.com [10.72.5.232]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2870qvO019713; Tue, 8 Mar 2016 02:01:25 -0500 From: Peter Xu To: qemu-devel@nongnu.org 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> 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.39]); Tue, 08 Mar 2016 07:01:29 +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 Cc: pbonzini@redhat.com, Gerd Hoffmann , peterx@redhat.com Subject: [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)