From patchwork Thu Jan 28 19:48:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 8153601 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D659A9F440 for ; Thu, 28 Jan 2016 19:49:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 205AB201FA for ; Thu, 28 Jan 2016 19:49:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC915202F8 for ; Thu, 28 Jan 2016 19:49:09 +0000 (UTC) Received: from localhost ([::1]:58345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOsZ3-0001bi-9K for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Jan 2016 14:49:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOsYw-0001bV-9W for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:49:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOsYs-0005Es-7Y for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:49:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOsYs-0005El-1t for qemu-devel@nongnu.org; Thu, 28 Jan 2016 14:48:58 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1F8B4C00354F; Thu, 28 Jan 2016 19:48:57 +0000 (UTC) Received: from javelin.localdomain (vpn1-7-33.sin2.redhat.com [10.67.7.33]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0SJmpxe016020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 28 Jan 2016 14:48:53 -0500 From: P J P To: QEMU Developers Date: Fri, 29 Jan 2016 01:18:50 +0530 Message-Id: <1454010530-16804-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , John Snow , Prasad J Pandit , Zuozhi fzz Subject: [Qemu-devel] [PATCH v2] ide: ahci: add check before calling dma_memory_unmap 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)