qiov: prevent double free or use-after-free
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Nov 2011 11:06:22 +0000 (12:06 +0100)
committerKevin Wolf <kwolf@redhat.com>
Thu, 15 Dec 2011 11:40:33 +0000 (12:40 +0100)
qemu_iovec_destroy does not clear the QEMUIOVector fully, and the data
could thus be used after free or freed again.  While I do not know any
example in the tree, I observed this using virtio-scsi (and SCSI
scatter/gather) when canceling DMA requests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
cutils.c

index 6db6304..24b3fe3 100644 (file)
--- a/cutils.c
+++ b/cutils.c
@@ -217,7 +217,10 @@ void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
     assert(qiov->nalloc != -1);
 
+    qemu_iovec_reset(qiov);
     g_free(qiov->iov);
+    qiov->nalloc = 0;
+    qiov->iov = NULL;
 }
 
 void qemu_iovec_reset(QEMUIOVector *qiov)