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 From: P J P Date: Tue, 11 Jul 2017 22:38:21 +0530 Message-Id: <20170711170821.24669-1-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH] block: check BlockDriverState object before dereference List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Developers Cc: qemu-block@nongnu.org, Kevin Wolf , Kieron Shorrock , Prasad J Pandit 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) { -- 2.9.4