Received: from eggs.gnu.org ([2001:4830:134:3::10]:38371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xc6mS-0002eB-6Z for qemu-devel@nongnu.org; Thu, 09 Oct 2014 02:00:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xc6mM-00081M-2y for qemu-devel@nongnu.org; Thu, 09 Oct 2014 02:00:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xc6mL-00081A-S0 for qemu-devel@nongnu.org; Thu, 09 Oct 2014 02:00:46 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9960iQK002588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 9 Oct 2014 02:00:44 -0400 Date: Thu, 9 Oct 2014 14:00:52 +0800 From: Fam Zheng Message-ID: <20141009060052.GA1599@fam-t430.nay.redhat.com> References: <1412761044-25859-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1412761044-25859-1-git-send-email-pbonzini@redhat.com> Subject: Re: [Qemu-devel] [PATCH] virtio-scsi: fix use-after-free of VirtIOSCSIReq List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, rjones@redhat.com On Wed, 10/08 11:37, Paolo Bonzini wrote: > scsi_req_continue can complete the request and cause the VirtIOSCSIReq > to be freed. Fetch req->sreq just once to avoid the bug. > > Reported-by: Richard Jones > Tested-by: Richard Jones > Signed-off-by: Paolo Bonzini > --- > hw/scsi/virtio-scsi.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c > index 203e624..6c02fe2 100644 > --- a/hw/scsi/virtio-scsi.c > +++ b/hw/scsi/virtio-scsi.c > @@ -545,11 +545,12 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) > > void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req) > { > - if (scsi_req_enqueue(req->sreq)) { > - scsi_req_continue(req->sreq); > + SCSIRequest *sreq = req->sreq; > + if (scsi_req_enqueue(sreq)) { > + scsi_req_continue(sreq); > } > - bdrv_io_unplug(req->sreq->dev->conf.bs); > - scsi_req_unref(req->sreq); > + bdrv_io_unplug(sreq->dev->conf.bs); > + scsi_req_unref(sreq); > } > > static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq) > -- > 1.8.3.1 > Reviewed-by: Fam Zheng