From c7658aa776512ce6e96635c32eca614df1f06be1 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 18 Nov 2014 11:49:35 +0100 Subject: [PATCH 1/6] xhci: add sanity checks to xhci_lookup_uport Message-id: <1416311375-14417-2-git-send-email-kraxel@redhat.com> Patchwork-id: 62421 O-Subject: [RHEL-7.1 qemu-kvm-rhev PATCH 1/1] xhci: add sanity checks to xhci_lookup_uport Bugzilla: 1161397 RH-Acked-by: Laszlo Ersek RH-Acked-by: Marcel Apfelbaum RH-Acked-by: Markus Armbruster Also catch xhci_lookup_uport failures in post_load. Signed-off-by: Gerd Hoffmann (cherry picked from commit f2ad97ff81da51c064b9e87720ff48a0874f45d4) Signed-off-by: Miroslav Rezanina --- 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 ea7edbd..7d01f1d 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2268,6 +2268,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++) { @@ -3670,6 +3673,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++) { -- 1.8.3.1