From patchwork Tue Jul 11 17:08:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9835333 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 4380660363 for ; Tue, 11 Jul 2017 17:28:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 272EF26E74 for ; Tue, 11 Jul 2017 17:28:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BC88284AF; Tue, 11 Jul 2017 17:28:35 +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 88C7F26E74 for ; Tue, 11 Jul 2017 17:28:34 +0000 (UTC) Received: from localhost ([::1]:47850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUyxd-0005Jg-QF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Jul 2017 13:28:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUyeM-0004Lj-3Q for qemu-devel@nongnu.org; Tue, 11 Jul 2017 13:08:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUyeL-0007BI-86 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 13:08:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUyeF-0007A3-TW; Tue, 11 Jul 2017 13:08:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3522780F95; Tue, 11 Jul 2017 17:08:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3522780F95 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ppandit@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3522780F95 Received: from localhost.localdomain (ovpn-117-148.phx2.redhat.com [10.3.117.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 777EA7F81F; Tue, 11 Jul 2017 17:08:25 +0000 (UTC) From: P J P To: Qemu Developers Date: Tue, 11 Jul 2017 22:38:21 +0530 Message-Id: <20170711170821.24669-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 11 Jul 2017 17:08:30 +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] block: check BlockDriverState object before dereference 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: Kevin Wolf , Kieron Shorrock , qemu-block@nongnu.org, 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 When processing ATA_CACHE_FLUSH ide controller command, BlockDriverState object could be null. Add check to avoid null pointer dereference. Reported-by: Kieron Shorrock Signed-off-by: Prasad J Pandit --- block/block-backend.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 0df3457..6a543a4 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1168,8 +1168,13 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes, { BlkAioEmAIOCB *acb; Coroutine *co; + BlockDriverState *bs = blk_bs(blk); - bdrv_inc_in_flight(blk_bs(blk)); + if (!bs) { + return NULL; + } + + bdrv_inc_in_flight(bs); acb = blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco = (BlkRwCo) { .blk = blk, @@ -1182,7 +1187,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes, acb->has_returned = false; co = qemu_coroutine_create(co_entry, acb); - bdrv_coroutine_enter(blk_bs(blk), co); + bdrv_coroutine_enter(bs, co); acb->has_returned = true; if (acb->rwco.ret != NOT_DONE) {