From nobody Sat Nov 8 05:45:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 155014826496915.204067304002024; Thu, 14 Feb 2019 04:44:24 -0800 (PST) Received: from localhost ([127.0.0.1]:47645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guGNI-0008SU-1n for importer@patchew.org; Thu, 14 Feb 2019 07:44:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guGL6-0007Mg-1U for qemu-devel@nongnu.org; Thu, 14 Feb 2019 07:42:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guG82-0001MN-Ts for qemu-devel@nongnu.org; Thu, 14 Feb 2019 07:28:38 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2176 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guG81-0001H2-52 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 07:28:34 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8CBB8F546E0D5C6FCADB; Thu, 14 Feb 2019 20:28:24 +0800 (CST) Received: from HGHY1z004218071.china.huawei.com (10.177.29.32) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.408.0; Thu, 14 Feb 2019 20:28:16 +0800 From: Xiang Zheng To: Date: Thu, 14 Feb 2019 20:27:00 +0800 Message-ID: <20190214122700.18572-1-zhengxiang9@huawei.com> X-Mailer: git-send-email 2.15.1.windows.2 MIME-Version: 1.0 X-Originating-IP: [10.177.29.32] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH] scsi-cd: Fix crash after remote cdrom detached 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: fam@euphon.net, pbonzini@redhat.com, Xiang Zheng , lizhengui@huawei.com, wanghaibin.wang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is a small window between the twice blk_is_available in scsi_disk_emulate_command which would cause crash due to the later assertion if the remote cdrom is detached in this window. So this patch replaces assertions with return to avoid qemu crash. Signed-off-by: Xiang Zheng --- The qemu error log shows: qemu-system-aarch64: /home/qemu/hw/scsi/scsi-disk.c:1896: scsi_disk_emulate= _command: Assertion `blk_is_available(s->qdev.conf.blk)' failed. 2019-02-15 04:35:18.592: shutting down, reason=3Dcrashed --- hw/scsi/scsi-disk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index d4e83ae..6bcafe2 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1890,7 +1890,10 @@ static int32_t scsi_disk_emulate_command(SCSIRequest= *req, uint8_t *buf) memset(outbuf, 0, r->buflen); switch (req->cmd.buf[0]) { case TEST_UNIT_READY: - assert(blk_is_available(s->qdev.conf.blk)); + if (!blk_is_available(s->qdev.conf.blk)) { + scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); + return 0; + } break; case INQUIRY: buflen =3D scsi_disk_emulate_inquiry(req, outbuf); --=20 1.8.3.1