Received: from eggs.gnu.org ([2001:4830:134:3::10]:49948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atrUk-0002XD-9h for qemu-devel@nongnu.org; Sat, 23 Apr 2016 02:56:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atrUj-0002LX-7j for qemu-devel@nongnu.org; Sat, 23 Apr 2016 02:56:46 -0400 From: David Gibson Date: Sat, 23 Apr 2016 16:58:00 +1000 Message-Id: <1461394680-12913-2-git-send-email-david@gibson.dropbear.id.au> In-Reply-To: <1461394680-12913-1-git-send-email-david@gibson.dropbear.id.au> References: <1461394680-12913-1-git-send-email-david@gibson.dropbear.id.au> Subject: [Qemu-devel] [PULL 1/1] hw/ppc/spapr: Fix crash when specifying bad parameters to spapr-pci-host-bridge List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Thomas Huth , David Gibson From: Thomas Huth QEMU currently crashes when using bad parameters for the spapr-pci-host-bridge device: $ qemu-system-ppc64 -device spapr-pci-host-bridge,buid=0x123,liobn=0x321,mem_win_addr=0x1,io_win_addr=0x10 Segmentation fault The problem is that spapr_tce_find_by_liobn() might return NULL, but the code in spapr_populate_pci_dt() does not check for this condition and then tries to dereference this NULL pointer. Apart from that, the return value of spapr_populate_pci_dt() also has to be checked for all PCI buses, not only for the last one, to make sure we catch all errors. Signed-off-by: Thomas Huth Signed-off-by: David Gibson --- hw/ppc/spapr.c | 9 ++++----- hw/ppc/spapr_pci.c | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index feaab08..b69995e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -940,11 +940,10 @@ static void spapr_finalize_fdt(sPAPRMachineState *spapr, QLIST_FOREACH(phb, &spapr->phbs, list) { ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt); - } - - if (ret < 0) { - fprintf(stderr, "couldn't setup PCI devices in fdt\n"); - exit(1); + if (ret < 0) { + error_report("couldn't setup PCI devices in fdt"); + exit(1); + } } /* RTAS */ diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 8c20d34..573e635 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1816,6 +1816,9 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, sizeof(interrupt_map))); tcet = spapr_tce_find_by_liobn(SPAPR_PCI_LIOBN(phb->index, 0)); + if (!tcet) { + return -1; + } spapr_dma_dt(fdt, bus_off, "ibm,dma-window", tcet->liobn, tcet->bus_offset, tcet->nb_table << tcet->page_shift); -- 2.5.5