From nobody Mon May 6 23:47:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1625122690752986.5895130902603; Wed, 30 Jun 2021 23:58:10 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-539-gXLHMHWjOaSXAvKtqg7l5A-1; Thu, 01 Jul 2021 02:58:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 690451922965; Thu, 1 Jul 2021 06:58:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70B4D5C25D; Thu, 1 Jul 2021 06:57:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ED1344A712; Thu, 1 Jul 2021 06:57:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1616pS06029693 for ; Thu, 1 Jul 2021 02:51:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 890111111C94; Thu, 1 Jul 2021 06:51:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84ADD11301EC for ; Thu, 1 Jul 2021 06:51:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BEEE800B35 for ; Thu, 1 Jul 2021 06:51:26 +0000 (UTC) Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.223]) by relay.mimecast.com with ESMTP id us-mta-375-22CgF0I5M4-uFZkpVxHp8Q-1; Thu, 01 Jul 2021 02:51:22 -0400 Received: from clientip-202.80.192.39?logid-912866024011462fb547994925eb3e34 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id BA452280029; Thu, 1 Jul 2021 14:51:19 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 912866024011462fb547994925eb3e34 for libvir-list@redhat.com; Thu Jul 1 14:51:18 2021 X-MC-Unique: gXLHMHWjOaSXAvKtqg7l5A-1 X-MC-Unique: 22CgF0I5M4-uFZkpVxHp8Q-1 HMM_SOURCE_IP: 172.18.0.218:39836.1704383845 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: huangy81@chinatelecom.cn X-Transaction-ID: 912866024011462fb547994925eb3e34 X-filter-score: X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.218 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: libvir-list@redhat.com Subject: [PATCH] qemu: code protection for qemuBlockJobEventProcessLegacy Date: Thu, 1 Jul 2021 14:55:56 +0800 Message-Id: <035863fc3777bec2135b54e9a2156803604bf520.1625037031.git.wucy11@chinatelecom.cn> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Mimecast-Bulk-Signature: yes X-Mimecast-Spam-Signature: bulk X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Chongyun Wu X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Chongyun Wu pointer disk might be null in some special cases or new usage scenarios, therefore code protection is needed to prevent segment faults. Signed-off-by: Chongyun Wu --- src/qemu/qemu_blockjob.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index faf9a9f..00506b9 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -781,12 +781,13 @@ qemuBlockJobEventProcessLegacy(virQEMUDriver *driver, { virDomainDiskDef *disk =3D job->disk; =20 - VIR_DEBUG("disk=3D%s, mirrorState=3D%s, type=3D%d, state=3D%d, newstat= e=3D%d", - disk->dst, - NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirrorSta= te)), - job->type, - job->state, - job->newstate); + if (disk) + VIR_DEBUG("disk=3D%s, mirrorState=3D%s, type=3D%d, state=3D%d, new= state=3D%d", + disk->dst, + NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirro= rState)), + job->type, + job->state, + job->newstate); =20 if (job->newstate =3D=3D -1) return; @@ -804,26 +805,30 @@ qemuBlockJobEventProcessLegacy(virQEMUDriver *driver, break; =20 case VIR_DOMAIN_BLOCK_JOB_READY: - disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_READY; - qemuDomainSaveStatus(vm); + if (disk) { + disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_READY; + qemuDomainSaveStatus(vm); + } break; =20 case VIR_DOMAIN_BLOCK_JOB_FAILED: case VIR_DOMAIN_BLOCK_JOB_CANCELED: - if (disk->mirror) { - virDomainLockImageDetach(driver->lockManager, vm, disk->mirror= ); + if (disk) { + if (disk->mirror) { + virDomainLockImageDetach(driver->lockManager, vm, disk->mi= rror); =20 - /* Ideally, we would restore seclabels on the backing chain he= re - * but we don't know if somebody else is not using parts of it. - * Remove security driver metadata so that they are not leaked= . */ - qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirr= or); + /* Ideally, we would restore seclabels on the backing chai= n here + * but we don't know if somebody else is not using parts o= f it. + * Remove security driver metadata so that they are not le= aked. */ + qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->= mirror); =20 - virObjectUnref(disk->mirror); - disk->mirror =3D NULL; + virObjectUnref(disk->mirror); + disk->mirror =3D NULL; + } + disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; + disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; + qemuBlockJobUnregister(job, vm); } - disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; - disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; - qemuBlockJobUnregister(job, vm); break; =20 case VIR_DOMAIN_BLOCK_JOB_LAST: --=20 1.8.3.1