From: Mark Cave-Ayland Date: Sun, 11 Nov 2018 09:40:23 +0000 (+0000) Subject: fdc: fix segfault in fdctrl_stop_transfer() when DMA is disabled X-Git-Tag: v3.0.1~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81e38ad8d0d7f26e3658b30704681fc2f2f219f9;p=thirdparty%2Fqemu.git fdc: fix segfault in fdctrl_stop_transfer() when DMA is disabled Commit c8a35f1cf0f "fdc: use IsaDma interface instead of global DMA_* functions" accidentally introduced a segfault in fdctrl_stop_transfer() for non-DMA transfers. If fdctrl->dma_chann has not been configured then the fdctrl->dma interface reference isn't initialised during isabus_fdc_realize(). Unfortunately fdctrl_stop_transfer() unconditionally references the DMA interface when finishing the transfer causing a NULL pointer dereference. Fix the issue by adding a check in fdctrl_stop_transfer() so that the DMA interface reference and release method is only invoked if fdctrl->dma_chann has been set. (This issue was discovered by Martin testing a recent change in the NetBSD installer under qemu-system-sparc) Cc: qemu-stable@nongnu.org Reported-by: Martin Husemann Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Hervé Poussineau Reviewed-by: John Snow Signed-off-by: Kevin Wolf (cherry picked from commit 441f6692ecc14859b77af2ac6d8f55e6f1354d3b) Signed-off-by: Michael Roth --- diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 2e9c1e1e2ff..6f19f127a55 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -1617,7 +1617,7 @@ static void fdctrl_stop_transfer(FDCtrl *fdctrl, uint8_t status0, fdctrl->fifo[5] = cur_drv->sect; fdctrl->fifo[6] = FD_SECTOR_SC; fdctrl->data_dir = FD_DIR_READ; - if (!(fdctrl->msr & FD_MSR_NONDMA)) { + if (fdctrl->dma_chann != -1 && !(fdctrl->msr & FD_MSR_NONDMA)) { IsaDmaClass *k = ISADMA_GET_CLASS(fdctrl->dma); k->release_DREQ(fdctrl->dma, fdctrl->dma_chann); }