From patchwork Wed Dec 6 11:21:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10095581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 933AF60210 for ; Wed, 6 Dec 2017 11:22:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85A7A29CC4 for ; Wed, 6 Dec 2017 11:22:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7968929CCC; Wed, 6 Dec 2017 11:22:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 777D729CC4 for ; Wed, 6 Dec 2017 11:22:12 +0000 (UTC) Received: from localhost ([::1]:54965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMXmE-00020u-9b for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Dec 2017 06:22:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMXlb-0001eG-1s for qemu-devel@nongnu.org; Wed, 06 Dec 2017 06:21:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMXlW-0002Rm-OY for qemu-devel@nongnu.org; Wed, 06 Dec 2017 06:21:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMXlW-0002Qb-IC for qemu-devel@nongnu.org; Wed, 06 Dec 2017 06:21:26 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 143904A702; Wed, 6 Dec 2017 11:21:24 +0000 (UTC) Received: from localhost.localdomain (ovpn-120-2.rdu2.redhat.com [10.10.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 047E45DA6F; Wed, 6 Dec 2017 11:21:21 +0000 (UTC) From: P J P To: Qemu Developers Date: Wed, 6 Dec 2017 16:51:16 +0530 Message-Id: <20171206112116.29413-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Dec 2017 11:21:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] scsi: check current request object before use X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Zhangboxian , Prasad J Pandit Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit During a dma access, SCSIRequest object 'current_req' could be null, leading to a null pointer dereference. Add check to avoid it. Reported-by: Zhangboxian Signed-off-by: Prasad J Pandit --- hw/scsi/esp.c | 2 +- hw/scsi/scsi-bus.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index ee586e7d6c..0c6925a708 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -273,7 +273,7 @@ static void esp_do_dma(ESPState *s) s->ti_size += len; else s->ti_size -= len; - if (s->async_len == 0) { + if (s->current_req && s->async_len == 0) { scsi_req_continue(s->current_req); /* If there is still data to be read from the device then complete the DMA operation immediately. Otherwise defer diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 977f7bce1f..ac64a239e9 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1338,6 +1338,9 @@ void scsi_req_unref(SCSIRequest *req) will start the next chunk or complete the command. */ void scsi_req_continue(SCSIRequest *req) { + if (!req) { + return; + } if (req->io_canceled) { trace_scsi_req_continue_canceled(req->dev->id, req->lun, req->tag); return;