Received: from eggs.gnu.org ([2001:4830:134:3::10]:34705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbngi-0002sP-Tj for qemu-devel@nongnu.org; Wed, 08 Oct 2014 05:37:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbngZ-0007Gp-Sm for qemu-devel@nongnu.org; Wed, 08 Oct 2014 05:37:40 -0400 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:55229) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbngZ-0007Gc-Lm for qemu-devel@nongnu.org; Wed, 08 Oct 2014 05:37:31 -0400 Received: by mail-wg0-f41.google.com with SMTP id b13so11332147wgh.24 for ; Wed, 08 Oct 2014 02:37:30 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 8 Oct 2014 11:37:24 +0200 Message-Id: <1412761044-25859-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] virtio-scsi: fix use-after-free of VirtIOSCSIReq List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: famz@redhat.com, rjones@redhat.com 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