From nobody Sun Apr 28 18:27:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516633301167778.7291293817708; Mon, 22 Jan 2018 07:01:41 -0800 (PST) Received: from localhost ([::1]:46732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eddbQ-0002l9-Ci for importer@patchew.org; Mon, 22 Jan 2018 10:01:40 -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 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 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== 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 *r= eq, MultiReqBuffer *mrb) return -1; } =20 + /* 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 =3D iov_size(in_iov, in_num); req->in =3D (void *)in_iov[in_num - 1].iov_base --=20 1.8.3.1