From patchwork Fri Nov 7 10:00:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 408021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 17CB114010F for ; Fri, 7 Nov 2014 21:01:28 +1100 (AEDT) Received: from localhost ([::1]:59234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmgMA-000379-Ah for incoming@patchwork.ozlabs.org; Fri, 07 Nov 2014 05:01:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmgLm-0002fH-NL for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:01:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XmgLg-0005Qi-Jw for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:01:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55845) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmgLg-0005QL-CL for qemu-devel@nongnu.org; Fri, 07 Nov 2014 05:00:56 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sA7A0sQc030130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 7 Nov 2014 05:00:54 -0500 Received: from nilsson.home.kraxel.org (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sA7A0rag011079; Fri, 7 Nov 2014 05:00:53 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 4AAF480F63; Fri, 7 Nov 2014 11:00:52 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 7 Nov 2014 11:00:44 +0100 Message-Id: <1415354444-3893-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] xhci: add sanity checks to xhci_lookup_uport 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Also catch xhci_lookup_uport failures in post_load. https://bugzilla.redhat.com/show_bug.cgi?id=1074219 Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 2930b72..9a942cf 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2262,6 +2262,9 @@ static USBPort *xhci_lookup_uport(XHCIState *xhci, uint32_t *slot_ctx) int i, pos, port; port = (slot_ctx[1]>>16) & 0xFF; + if (port < 1 || port > xhci->numports) { + return NULL; + } port = xhci->ports[port-1].uport->index+1; pos = snprintf(path, sizeof(path), "%d", port); for (i = 0; i < 5; i++) { @@ -3706,6 +3709,12 @@ static int usb_xhci_post_load(void *opaque, int version_id) xhci_mask64(ldq_le_pci_dma(pci_dev, dcbaap + 8 * slotid)); xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx)); slot->uport = xhci_lookup_uport(xhci, slot_ctx); + if (!slot->uport) { + /* should not happen, but may trigger on guest bugs */ + slot->enabled = 0; + slot->addressed = 0; + continue; + } assert(slot->uport && slot->uport->dev); for (epid = 1; epid <= 31; epid++) {