From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOshB-0004fh-RA for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:57:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOsh8-0001VE-G7 for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:57:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOsh8-0001V9-A6 for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:57:30 -0500 References: <1454010530-16804-1-git-send-email-ppandit@redhat.com> From: John Snow Message-ID: <56AA72A8.4040302@redhat.com> Date: Thu, 28 Jan 2016 14:57:28 -0500 MIME-Version: 1.0 In-Reply-To: <1454010530-16804-1-git-send-email-ppandit@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] ide: ahci: add check before calling dma_memory_unmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: P J P , QEMU Developers Cc: Peter Maydell , Prasad J Pandit , Zuozhi fzz On 01/28/2016 02:48 PM, P J P wrote: > From: Prasad J Pandit > > When IDE AHCI emulation uses Frame Information Structures(FIS) > engine for data transfer, the mapped FIS buffer address is stored > in a static 'bounce.buffer'. When a request is made to map another > memory region, address_space_map() returns NULL because > 'bounce.buffer' is in_use. It leads to a null pointer dereference > error while doing 'dma_memory_unmap'. Add a check to avoid it. > > Reported-by: Zuozhi fzz > Signed-off-by: Prasad J Pandit > --- > hw/ide/ahci.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > Update as per review > -> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg05715.html > > diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c > index 17f1cbd..f413a59 100644 > --- a/hw/ide/ahci.c > +++ b/hw/ide/ahci.c > @@ -661,9 +661,11 @@ static bool ahci_map_fis_address(AHCIDevice *ad) > > static void ahci_unmap_fis_address(AHCIDevice *ad) > { > - dma_memory_unmap(ad->hba->as, ad->res_fis, 256, > - DMA_DIRECTION_FROM_DEVICE, 256); > - ad->res_fis = NULL; > + if (ad->res_fis) { > + dma_memory_unmap(ad->hba->as, ad->res_fis, 256, > + DMA_DIRECTION_FROM_DEVICE, 256); > + ad->res_fis = NULL; > + } > } > > static bool ahci_map_clb_address(AHCIDevice *ad) > @@ -677,9 +679,11 @@ static bool ahci_map_clb_address(AHCIDevice *ad) > > static void ahci_unmap_clb_address(AHCIDevice *ad) > { > - dma_memory_unmap(ad->hba->as, ad->lst, 1024, > - DMA_DIRECTION_FROM_DEVICE, 1024); > - ad->lst = NULL; > + if (ad->lst) { > + dma_memory_unmap(ad->hba->as, ad->lst, 1024, > + DMA_DIRECTION_FROM_DEVICE, 1024); > + ad->lst = NULL; > + } > } > > static void ahci_write_fis_sdb(AHCIState *s, NCQTransferState *ncq_tfs) > This is fine for now as it protects us against doing something stupid in a mechanical fashion, but I still wonder under which case we are "starting" the FIS or CLB engines without getting a valid address. (The unmap should only be happening when we /stop/ the engines, which implies they were started -- which points to a bug somewhere else, too.) Do you have a reproducer for the original issue?