From patchwork Mon Jan 22 15:01:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 10178711 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 C078560353 for ; Mon, 22 Jan 2018 15:01:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB4AB22B27 for ; Mon, 22 Jan 2018 15:01:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D40327FA1; Mon, 22 Jan 2018 15:01: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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 25A6122B27 for ; Mon, 22 Jan 2018 15:01:18 +0000 (UTC) Received: from localhost ([::1]:46732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eddb3-0002l9-9n for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Jan 2018 10:01:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eddZo-0001fs-CC for qemu-devel@nongnu.org; Mon, 22 Jan 2018 10:00:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eddZn-0007sM-Kd for qemu-devel@nongnu.org; Mon, 22 Jan 2018 10:00:00 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:45812) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eddZj-0007lz-03; Mon, 22 Jan 2018 09:59:55 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0MEutJ9095856; Mon, 22 Jan 2018 14:59:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=qbQPdjp8fTirCqUTj9cBmylh9IXQsYfhn24vJn5/oas=; b=Cvmr1ECED2qegx+r3Nx+PJYOE9maGdtI17/JdZuOWrgJMqNtlrPyZEN3tIeMRNKlGloX FPHNZKcobFyAbHCp4hGbdiHQNQOyMuUy49u9VwklusAdrIvAWvOG7kWhSaBMqVX8wnYO ksLBBpeBp/PRD+Jv6wODq0XP1mCXmusV/aMVaYeKa6NWSqTa902yF1JpQGqXZNplsnQG lrpLtepuRBWISrVs1cZ4MPDkZo6mayo0kaa2YVNMQCeS9X2WZKoBF+q1J6FUoOyakG/x HpqdBTY/xAMZS5oMijdbY/NAjIdaTGCqJYeTDyMsYGHlM3z68XCc2iLgxBW9HuacCChq Qw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2fnh6f0ep8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jan 2018 14:59:48 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0MExmWV020086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Jan 2018 14:59:48 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0MExmFs017775; Mon, 22 Jan 2018 14:59:48 GMT Received: from mhkanda-aus-1.us.oracle.com (/10.135.188.192) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Jan 2018 06:59:47 -0800 From: Mark Kanda To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 22 Jan 2018 09:01:49 -0600 Message-Id: <1516633309-20803-1-git-send-email-mark.kanda@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8781 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=702 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801220212 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH] virtio-blk: check for NULL BlockDriverState 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: ameya.more@oracle.com, karl.heubaum@oracle.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a BlockDriverState NULL check to virtio_blk_handle_request() to prevent a segfault if the drive is forcibly removed using HMP 'drive_del' (without performing a hotplug 'device_del' first). Signed-off-by: Mark Kanda Reviewed-by: Karl Heubaum Reviewed-by: Ameya More --- hw/block/virtio-blk.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index b1532e4..76ddbbf 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -507,6 +507,13 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) return -1; } + /* If the drive was forcibly removed (e.g. HMP 'drive_del'), the block + * driver state may be NULL and there is nothing left to do. */ + if (!blk_bs(req->dev->blk)) { + virtio_error(vdev, "virtio-blk BlockDriverState is NULL"); + return -1; + } + /* We always touch the last byte, so just see how big in_iov is. */ req->in_len = iov_size(in_iov, in_num); req->in = (void *)in_iov[in_num - 1].iov_base